ManaPlus
Public Member Functions | Private Attributes
ItemsModal Class Reference

#include <itemsmodel.h>

Inheritance diagram for ItemsModal:
ListModel

Public Member Functions

 ItemsModal ()
 
int getNumberOfElements ()
 
std::string getElementAt (int i)
 
- Public Member Functions inherited from ListModel
 ListModel ()
 
virtual ~ListModel ()
 

Private Attributes

StringVect mStrings
 

Detailed Description

Definition at line 39 of file itemsmodel.h.

Constructor & Destructor Documentation

◆ ItemsModal()

ItemsModal::ItemsModal ( )
inline

Definition at line 42 of file itemsmodel.h.

42  :
43  mStrings()
44  {
45  const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
46  std::list<std::string> tempStrings;
47 
48  for (std::map<int, ItemInfo*>::const_iterator
49  i = items.begin(), i_end = items.end();
50  i != i_end; ++i)
51  {
52  if (i->first < 0)
53  continue;
54 
55  const ItemInfo &info = *i->second;
56  const std::string &name = info.getName();
57  if (name != "unnamed" && !info.getName().empty()
58  && info.getName() != "unnamed")
59  {
60  tempStrings.push_back(name);
61  }
62  }
63  tempStrings.sort();
64  FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
65  mStrings.push_back(*i);
66  }
StringVect mStrings
Definition: itemsmodel.h:83
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
bool info(InputEvent &event)
Definition: commands.cpp:57
const ItemDB::ItemInfos & getItemInfos()
Definition: itemdb.cpp:829

References FOR_EACH, ItemDB::getItemInfos(), Actions::info(), and mStrings.

Member Function Documentation

◆ getElementAt()

std::string ItemsModal::getElementAt ( int  i)
inlinevirtual

Gets an element at a certain index in the list.

Parameters
iAn index in the list.
Returns
An element as a string at the a certain index.

Implements ListModel.

Definition at line 75 of file itemsmodel.h.

76  {
77  if (i < 0 || i >= getNumberOfElements())
78  return "???";
79  return mStrings.at(i);
80  }
int getNumberOfElements()
Definition: itemsmodel.h:70

References getNumberOfElements(), and mStrings.

Referenced by ItemAmountWindow::action().

◆ getNumberOfElements()

int ItemsModal::getNumberOfElements ( )
inlinevirtual

Gets the number of elements in the list.

Returns
The number of elements in the list

Implements ListModel.

Definition at line 70 of file itemsmodel.h.

71  {
72  return CAST_S32(mStrings.size());
73  }
#define CAST_S32
Definition: cast.h:30

References CAST_S32, and mStrings.

Referenced by getElementAt().

Field Documentation

◆ mStrings

StringVect ItemsModal::mStrings
private

Definition at line 83 of file itemsmodel.h.

Referenced by getElementAt(), getNumberOfElements(), and ItemsModal().


The documentation for this class was generated from the following file: