diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-05-03 20:09:53 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-05-03 20:09:53 +0300 |
commit | 602fd127d09c995bc5470218c862b2cebfc558d5 (patch) | |
tree | 6937760eb81a234c2aaf9c7494f6bce02176a2f5 /src/gui/models | |
parent | fef6ebca9c454f99d44e950c4628270b124c445f (diff) | |
download | plus-602fd127d09c995bc5470218c862b2cebfc558d5.tar.gz plus-602fd127d09c995bc5470218c862b2cebfc558d5.tar.bz2 plus-602fd127d09c995bc5470218c862b2cebfc558d5.tar.xz plus-602fd127d09c995bc5470218c862b2cebfc558d5.zip |
Add filter into buy dialogs.
Diffstat (limited to 'src/gui/models')
-rw-r--r-- | src/gui/models/shopitems.cpp | 18 | ||||
-rw-r--r-- | src/gui/models/shopitems.h | 7 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/gui/models/shopitems.cpp b/src/gui/models/shopitems.cpp index 1a9b89994..2fd399cb0 100644 --- a/src/gui/models/shopitems.cpp +++ b/src/gui/models/shopitems.cpp @@ -29,6 +29,7 @@ #include "debug.h" ShopItems::ShopItems(const bool mergeDuplicates) : + mAllShopItems(), mShopItems(), mMergeDuplicates(mergeDuplicates) { @@ -58,6 +59,7 @@ ShopItem *ShopItems::addItem(const int id, { ShopItem *const item = new ShopItem(-1, id, type, color, amount, price); mShopItems.push_back(item); + mAllShopItems.push_back(item); return item; } @@ -72,6 +74,7 @@ ShopItem *ShopItems::addItemNoDup(const int id, { item = new ShopItem(-1, id, type, color, amount, price); mShopItems.push_back(item); + mAllShopItems.push_back(item); } return item; } @@ -95,6 +98,7 @@ ShopItem *ShopItems::addItem2(const int inventoryIndex, { item = new ShopItem(inventoryIndex, id, type, color, quantity, price); mShopItems.push_back(item); + mAllShopItems.push_back(item); } return item; } @@ -127,7 +131,8 @@ void ShopItems::del(const unsigned int i) void ShopItems::clear() { - delete_all(mShopItems); + delete_all(mAllShopItems); + mAllShopItems.clear(); mShopItems.clear(); } @@ -146,3 +151,14 @@ ShopItem *ShopItems::findItem(const int id, const unsigned char color) const return nullptr; } + +void ShopItems::updateList() +{ + mShopItems.clear(); + FOR_EACH (std::vector<ShopItem*>::iterator, it, mAllShopItems) + { + ShopItem *const item = *it; + if (item && item->isVisible()) + mShopItems.push_back(item); + } +} diff --git a/src/gui/models/shopitems.h b/src/gui/models/shopitems.h index 880bc4f71..50269cff1 100644 --- a/src/gui/models/shopitems.h +++ b/src/gui/models/shopitems.h @@ -129,9 +129,14 @@ class ShopItems final : public ListModel std::vector<ShopItem*> &items() A_WARN_UNUSED { return mShopItems; } + std::vector<ShopItem*> &allItems() A_WARN_UNUSED + { return mAllShopItems; } + void setMergeDuplicates(const bool b) { mMergeDuplicates = b; } + void updateList(); + private: /** * Searches the current items in the shop for the specified @@ -143,6 +148,8 @@ class ShopItems final : public ListModel const unsigned char color) const A_WARN_UNUSED; /** The list of items in the shop. */ + std::vector<ShopItem*> mAllShopItems; + std::vector<ShopItem*> mShopItems; /** Look for duplicate entries on addition. */ |