MeVisLab Toolbox Reference
mlItemModelAttributeFilter.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2014, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_ITEM_MODEL_ATTRIBUTE_FILTER_H
14 #define ML_ITEM_MODEL_ATTRIBUTE_FILTER_H
15 
16 
20 
21 #include <mlItemModelProxy.h>
22 
23 #include <boost/unordered_map.hpp>
24 
25 ML_START_NAMESPACE
26 
27 //===========================================================================
28 
30 {
31 public:
32  ItemModelAttributeFilter(AbstractItemModelPtr baseModel, const std::vector<std::string>& attributes);
34 
35 public:
37 
38  bool isFlat() const override;
39 
40  bool hasChildren(const ModelIndex& parent) override;
41 
42  unsigned int getChildCount(const ModelIndex& parent) override;
43 
44  ModelIndex getChild(const ModelIndex& parent, unsigned int index) override;
45 
46  ModelIndex getParent(const ModelIndex& child) override;
48 
50 
52  int getAttributeCount() const override;
53 
55  std::string getAttributeName(int index) const override;
56 
59  Variant getAttributeDefault(int index) const override;
60 
63  int getAttributeIndex(const std::string& name) override;
65 
67 
68  Variant getData(const ModelIndex& item, int attributeIndex) override;
69  bool setData(const ModelIndex& item, int attributeIndex, const Variant& data,
70  void* skipListener = nullptr) override;
71  bool bulkSetData(const std::vector<ModelIndex>& items,
72  int attributeIndex, const Variant& data,
73  void* skipListener = nullptr) override;
74  bool bulkSetData(const std::vector<ModelIndex>& items,
75  int attributeIndex, const std::vector<Variant>& data,
76  void* skipListener = nullptr) override;
77 
78  bool rawSetData(const ModelIndex& item, int attributeIndex, const Variant& data) override;
79 
81 
83 
84 private:
86  void sourceItemsInserted(ml::ItemsInsertedEvent* ev) override;
87  void sourceItemsRemoved(ml::ItemsRemovedEvent* ev) override;
88  void sourceItemsDataChanged(ml::ItemsDataChangedEvent* evt) override;
89  void sourceItemChanged(ml::ItemChangedEvent* ev) override;
91 
92  int mapAttributeIndexToSource(int index) const;
93  int mapAttributeIndexFromSource(int index) const;
94 
95  boost::unordered_map<int,int> _mapAttributeToSource;
96  boost::unordered_map<int,int> _mapAttributeFromSource;
97 
98  void* _listenerToSkipForDataChange;
99 };
100 
101 //===========================================================================
102 
103 ML_END_NAMESPACE
104 
105 #endif // __mlItemModelAttributeFilter_H
#define MLITEMMODEL_EXPORT
defined Header file mlItemModelSystem.h
This event tells us that the children of the item have changed completely (for an invalid ModelIndex ...
bool isFlat() const override
item traversal interface, overridden for filtering
bool bulkSetData(const std::vector< ModelIndex > &items, int attributeIndex, const std::vector< Variant > &data, void *skipListener=nullptr) override
This method can be used to update whole columns with varying data.
bool hasChildren(const ModelIndex &parent) override
Or rather mightHaveChildren.
Variant getAttributeDefault(int index) const override
Return default value of n-th attribute.
int getAttributeIndex(const std::string &name) override
Get index of attribute with the given name.
ModelIndex getParent(const ModelIndex &child) override
Get parent of an item.
bool setData(const ModelIndex &item, int attributeIndex, const Variant &data, void *skipListener=nullptr) override
Update a single attribute on a single item.
ModelIndex getChild(const ModelIndex &parent, unsigned int index) override
Get n-th child of an item (or n-th top-level item if parent index is invalid).
ItemModelAttributeFilter(AbstractItemModelPtr baseModel, const std::vector< std::string > &attributes)
std::string getAttributeName(int index) const override
Get name of n-th attribute. Must be overridden.
unsigned int getChildCount(const ModelIndex &parent) override
Get number of children of the given item, an invalid index means number of top-level items.
Variant getData(const ModelIndex &item, int attributeIndex) override
data access, overridden to apply filter mapping
bool bulkSetData(const std::vector< ModelIndex > &items, int attributeIndex, const Variant &data, void *skipListener=nullptr) override
bulkSetData will be used by views to set selection state to an attribute, so that we only get a singl...
int getAttributeCount() const override
attribute discovery, overridden to pass on requests
bool rawSetData(const ModelIndex &item, int attributeIndex, const Variant &data) override
This will be called by setData and bulkSetData, which will do the necessary notifications afterwards;...
This event informs about attributes that have changed their values.
This event informs about inserted items.
This event informs about removed items.
This class serves as an index into an AbstractItemModel.
The Variant class stores different data types.
Definition: mlVariant.h:36
#define ML_ABSTRACT_CLASS_HEADER(className)
Same like ML_ABSTRACT_CLASS_HEADER_EXPORTED with a non existing export symbol.