ManaPlus
iconsmodel.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2009 The Mana World Development Team
4  * Copyright (C) 2011-2019 The ManaPlus Developers
5  * Copyright (C) 2009-2021 Andrei Karas
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef GUI_MODELS_ICONSMODEL_H
24 #define GUI_MODELS_ICONSMODEL_H
25 
26 #include "gui/models/listmodel.h"
27 
28 #include "utils/foreach.h"
29 
30 #include "resources/iteminfo.h"
31 
32 #include "resources/db/itemdb.h"
33 
34 #include <list>
35 
36 #include "localconsts.h"
37 
38 class IconsModel final : public ListModel
39 {
40  public:
42  mStrings()
43  {
44  const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
45  std::list<std::string> tempStrings;
46 
47  for (std::map<int, ItemInfo*>::const_iterator
48  i = items.begin(), i_end = items.end();
49  i != i_end; ++i)
50  {
51  if (i->first < 0)
52  continue;
53 
54  const ItemInfo &info = (*i->second);
55  const std::string &name = info.getName();
56  if (name != "unnamed" && !info.getName().empty()
57  && info.getName() != "unnamed")
58  {
59  tempStrings.push_back(name);
60  }
61  }
62  tempStrings.sort();
63  mStrings.push_back("");
64  FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
65  mStrings.push_back(*i);
66  }
67 
69 
71  {
72  return CAST_S32(mStrings.size());
73  }
74 
75  std::string getElementAt(int i) override final
76  {
77  if (i < 0 || i >= getNumberOfElements())
78  return "???";
79  return mStrings.at(i);
80  }
81  private:
83 };
84 
85 #endif // GUI_MODELS_ICONSMODEL_H
#define CAST_S32
Definition: cast.h:30
StringVect mStrings
Definition: iconsmodel.h:82
int getNumberOfElements()
Definition: iconsmodel.h:70
std::string getElementAt(int i)
Definition: iconsmodel.h:75
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
#define override
Definition: localconsts.h:47
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
bool info(InputEvent &event)
Definition: commands.cpp:57
const ItemDB::ItemInfos & getItemInfos()
Definition: itemdb.cpp:829
std::vector< std::string > StringVect
Definition: stringvector.h:29