CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxTreeItemModel.h
Go to the documentation of this file.
1 #ifndef CXTREEITEMMODEL_H
2 #define CXTREEITEMMODEL_H
3 
4 #include "cxBaseWidget.h"
5 
6 #include <QtGui>
7 #include "cxImage.h"
8 #include "cxTreeNode.h"
9 #include "cxStringProperty.h"
10 #include "cxXmlOptionItem.h"
12 
13 class QTreeWidget;
14 class QVBoxLayout;
15 class QTreeWidgetItem;
16 class QTreeView;
17 
18 namespace cx
19 {
20 
21 typedef boost::shared_ptr<class StringListProperty> StringListPropertyPtr;
22 typedef boost::shared_ptr<class TreeRepository> TreeRepositoryPtr;
23 
28 class TreeItemModel : public QAbstractItemModel
29 {
30  Q_OBJECT
31 public:
32  TreeItemModel(XmlOptionFile options, VisServicesPtr services, QObject* parent = 0);
33  virtual ~TreeItemModel();
34  void setSelectionModel(QItemSelectionModel* selectionModel);
35 
36  virtual int columnCount (const QModelIndex& parent = QModelIndex() ) const;
37  virtual int rowCount(const QModelIndex& parent = QModelIndex() ) const;
38 
39  virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole ) const;
40  virtual bool setData(const QModelIndex& index, const QVariant& value, int role);
41  virtual Qt::ItemFlags flags(const QModelIndex& index ) const;
42  virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
43 
44  virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex() ) const;
45  virtual QModelIndex parent(const QModelIndex& index ) const;
46 
48  TreeNodePtr getNodeFromIndex(const QModelIndex& index);
49  TreeRepositoryPtr repo() { return mRepository; }
50  StringListPropertyPtr getShowColumnsProperty() { return mShowColumnsProperty; }
51 
52 signals:
53 // void hasBeenReset();
54  void loaded();
55  void currentItemChanged();
56 
57 public slots:
58  void update();
59 
60 private slots:
61  void currentItemChangedSlot(const QModelIndex& current, const QModelIndex& previous);
62  void onRepositoryChanged();
63 
64 private:
65  int mViewGroupCount, mViewGroupIndex, mColorIndex, mNameIndex, mColumnCount;
66 
67  TreeRepositoryPtr mRepository;
68  QItemSelectionModel* mSelectionModel;
69  XmlOptionFile mOptions;
70  VisServicesPtr mServices;
71  StringListPropertyPtr mShowColumnsProperty;
72 
73  bool isViewGroupColumn(int col) const;
74  int viewGroupFromColumn(int col) const;
75 
76  TreeNode* itemFromIndex(const QModelIndex& index) const;
77  void fillModelTreeFromViewManager(TreeNodePtr root);
78  QIcon getColorIcon(QColor color) const;
79  QColor adjustColorToContrastWithWhite(QColor color) const;
80  void createShowColumnsProperty();
81  void onShowColumnsChanged();
82 };
83 
84 }//end namespace cx
85 
86 
87 #endif // CXTREEITEMMODEL_H
boost::shared_ptr< class TreeRepository > TreeRepositoryPtr
void currentItemChanged()
boost::shared_ptr< TreeNode > TreeNodePtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
virtual Qt::ItemFlags flags(const QModelIndex &index) const
TreeRepositoryPtr repo()
TreeNodePtr getCurrentItem()
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual QModelIndex parent(const QModelIndex &index) const
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
TreeItemModel(XmlOptionFile options, VisServicesPtr services, QObject *parent=0)
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
boost::shared_ptr< class StringListProperty > StringListPropertyPtr
void setSelectionModel(QItemSelectionModel *selectionModel)
TreeNodePtr getNodeFromIndex(const QModelIndex &index)
StringListPropertyPtr getShowColumnsProperty()
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Helper class for xml files used to store ssc/cx data.