From 41cc92f73e39cec5dfea6b1164176610cccc7df4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 15 Aug 2015 13:58:32 +0300 Subject: Add strong typed int for item color. --- src/shortcutbase.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/shortcutbase.cpp') diff --git a/src/shortcutbase.cpp b/src/shortcutbase.cpp index 0b076b16b..8bb0b3a54 100644 --- a/src/shortcutbase.cpp +++ b/src/shortcutbase.cpp @@ -31,12 +31,12 @@ ShortcutBase::ShortcutBase(const std::string &itemName, const std::string &colorName, const int maxSize) : mItems(new int[maxSize]), - mItemColors(new unsigned char[maxSize]), + mItemColors(new ItemColor[maxSize]), mItemName(itemName), mColorName(colorName), mItemSelected(-1), mMaxSize(maxSize), - mItemColorSelected(1) + mItemColorSelected(ItemColor_one) { clear(false); load(); @@ -61,8 +61,9 @@ void ShortcutBase::load(const bool oldConfig) for (int i = 0; i < mMaxSize; i++) { const int itemId = cfg->getValue(mItemName + toString(i), -1); - const unsigned char itemColor = static_cast( - cfg->getValue(mColorName + toString(i), -1)); + const ItemColor itemColor = fromInt( + cfg->getValue(mColorName + toString(i), -1), + ItemColor); if (itemId != -1) { @@ -77,7 +78,8 @@ void ShortcutBase::save() const for (int i = 0; i < mMaxSize; i++) { const int itemId = mItems[i] ? mItems[i] : -1; - const int itemColor = mItemColors[i] ? mItemColors[i] : 1; + const int itemColor = (mItemColors[i] != ItemColor_zero) + ? toInt(mItemColors[i], int) : 1; if (itemId != -1) { serverConfig.setValue(mItemName + toString(i), itemId); @@ -101,7 +103,7 @@ void ShortcutBase::setItemSelected(const Item *const item) else { mItemSelected = -1; - mItemColorSelected = 1; + mItemColorSelected = ItemColor_one; } } @@ -120,7 +122,7 @@ void ShortcutBase::clear(const bool isSave) for (int i = 0; i < mMaxSize; i++) { mItems[i] = -1; - mItemColors[i] = 1; + mItemColors[i] = ItemColor_one; } if (isSave) save(); -- cgit v1.2.3-60-g2f50