OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
itemmodel.hpp
Go to the documentation of this file.
1 #ifndef MWGUI_ITEM_MODEL_H
2 #define MWGUI_ITEM_MODEL_H
3 
4 #include "../mwworld/ptr.hpp"
5 
6 namespace MWGui
7 {
8 
9  class ItemModel;
10 
12  struct ItemStack
13  {
14  ItemStack (const MWWorld::Ptr& base, ItemModel* creator, size_t count);
15  ItemStack();
16  bool stacks (const ItemStack& other);
18 
19  enum Type
20  {
24  };
26 
27  enum Flags
28  {
29  Flag_Enchanted = (1<<0),
30  Flag_Bound = (1<<1)
31  };
32  int mFlags;
33 
35  size_t mCount;
37  };
38 
39  bool operator == (const ItemStack& left, const ItemStack& right);
40 
41 
43  class ItemModel
44  {
45  public:
46  ItemModel();
47  virtual ~ItemModel() {}
48 
49  typedef int ModelIndex; // -1 means invalid index
50 
52  virtual ItemStack getItem (ModelIndex index) = 0;
53 
56  virtual size_t getItemCount() = 0;
57 
59  virtual ModelIndex getIndex (ItemStack item) = 0;
60 
62  virtual void update() = 0;
63 
66  virtual MWWorld::Ptr moveItem (const ItemStack& item, size_t count, ItemModel* otherModel);
67 
70  virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false) = 0;
71  virtual void removeItem (const ItemStack& item, size_t count) = 0;
72 
74  virtual bool allowedToInsertItems() const;
75 
76  private:
77  ItemModel(const ItemModel&);
78  ItemModel& operator=(const ItemModel&);
79  };
80 
83  class ProxyItemModel : public ItemModel
84  {
85  public:
87  virtual ~ProxyItemModel();
88  virtual MWWorld::Ptr copyItem (const ItemStack& item, size_t count, bool setNewOwner=false);
89  virtual void removeItem (const ItemStack& item, size_t count);
90  virtual ModelIndex getIndex (ItemStack item);
91 
93  void setSourceModel(ItemModel* sourceModel);
94 
97  protected:
99  };
100 
101 }
102 
103 #endif
Definition: itemmodel.hpp:30
Definition: itemmodel.hpp:29
ItemModel()
Definition: itemmodel.cpp:111
Type mType
Definition: itemmodel.hpp:25
ItemModel & operator=(const ItemModel &)
The base class that all item models should derive from.
Definition: itemmodel.hpp:43
Definition: itemmodel.hpp:22
ProxyItemModel()
Definition: itemmodel.cpp:128
Definition: itemmodel.hpp:23
virtual size_t getItemCount()=0
virtual MWWorld::Ptr copyItem(const ItemStack &item, size_t count, bool setNewOwner=false)
Definition: itemmodel.cpp:138
ModelIndex mapToSource(ModelIndex index)
Definition: itemmodel.cpp:148
virtual ModelIndex getIndex(ItemStack item)
Returns an invalid index if the item was not found.
Definition: itemmodel.cpp:172
virtual ~ItemModel()
Definition: itemmodel.hpp:47
virtual bool allowedToInsertItems() const
Is the player allowed to insert items into this model? (default true)
Definition: itemmodel.cpp:122
A proxy item model can be used to filter or rearrange items from a source model (or even add new item...
Definition: itemmodel.hpp:83
A single item stack managed by an item model.
Definition: itemmodel.hpp:12
ItemStack()
Definition: itemmodel.cpp:61
virtual ModelIndex getIndex(ItemStack item)=0
Returns an invalid index if the item was not found.
virtual MWWorld::Ptr moveItem(const ItemStack &item, size_t count, ItemModel *otherModel)
Definition: itemmodel.cpp:115
size_t mCount
Definition: itemmodel.hpp:35
bool operator==(const ItemStack &left, const ItemStack &right)
Definition: itemmodel.cpp:89
void setSourceModel(ItemModel *sourceModel)
Definition: itemmodel.cpp:177
int mFlags
Definition: itemmodel.hpp:32
virtual void removeItem(const ItemStack &item, size_t count)=0
Definition: itemmodel.hpp:21
ModelIndex mapFromSource(ModelIndex index)
Definition: itemmodel.cpp:160
bool stacks(const ItemStack &other)
like operator==, only without checking mType
Definition: itemmodel.cpp:69
int ModelIndex
Definition: itemmodel.hpp:49
virtual ~ProxyItemModel()
Definition: itemmodel.cpp:133
ItemModel * mCreator
Definition: itemmodel.hpp:34
virtual MWWorld::Ptr copyItem(const ItemStack &item, size_t count, bool setNewOwner=false)=0
ItemModel * mSourceModel
Definition: itemmodel.hpp:98
virtual void removeItem(const ItemStack &item, size_t count)
Definition: itemmodel.cpp:143
Pointer to a LiveCellRef.
Definition: ptr.hpp:19
Type
Definition: itemmodel.hpp:19
virtual ItemStack getItem(ModelIndex index)=0
Throws for invalid index or out of range index.
virtual void update()=0
Rebuild the item model, this will invalidate existing model indices.
MWWorld::Ptr mBase
Definition: itemmodel.hpp:36
Flags
Definition: itemmodel.hpp:27