From 602fd127d09c995bc5470218c862b2cebfc558d5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 3 May 2015 20:09:53 +0300 Subject: Add filter into buy dialogs. --- src/gui/models/shopitems.cpp | 18 +++++++++++++++++- src/gui/models/shopitems.h | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src/gui/models') 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::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 &items() A_WARN_UNUSED { return mShopItems; } + std::vector &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 mAllShopItems; + std::vector mShopItems; /** Look for duplicate entries on addition. */ -- cgit v1.2.3-60-g2f50