1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #ifndef XGUI_PartDataModel_H
4 #define XGUI_PartDataModel_H
7 #include "XGUI_DataTreeModel.h"
9 /**\class XGUI_TopDataModel
11 * \brief This is a data model for Object Browser (QTreeView).
12 * It represents only upper part of data tree (non-parts tree items)
14 class XGUI_EXPORT XGUI_TopDataModel : public XGUI_FeaturesModel
19 /// \param theParent a parent object
20 XGUI_TopDataModel(QObject* theParent);
21 virtual ~XGUI_TopDataModel();
23 // Reimpl from QAbstractItemModel
25 /// Returns the data stored under the given role for the item referred to by the index.
26 /// \param theIndex a model index
27 /// \param theRole a data role (see Qt::ItemDataRole)
28 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
30 /// Returns the data for the given role and section in the header with the specified orientation.
31 /// \param theSection a section
32 /// \param theOrient an orientation
33 /// \param theRole a data role (see Qt::ItemDataRole)
34 virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
35 int theRole = Qt::DisplayRole) const;
37 /// Returns the number of rows under the given parent. When the parent is valid it means that
38 /// rowCount is returning the number of children of parent.
39 /// \param theParent a parent model index
40 virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const;
42 /// Returns the number of columns for the children of the given parent.
43 /// It has a one column
44 /// \param theParent a parent model index
45 virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const;
48 /// Returns the index of the item in the model specified by the given row, column and parent index.
49 /// \param theRow a row
50 /// \param theColumn a column
51 /// \param theParent a parent model index
52 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
55 /// Returns the parent of the model item with the given index.
56 /// If the item has no parent, an invalid QModelIndex is returned.
57 /// \param theIndex a model index
58 virtual QModelIndex parent(const QModelIndex& theIndex) const;
60 /// Returns true if parent has any children; otherwise returns false.
61 /// \param theParent a parent model index
62 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
64 //! Returns object by the given Model index.
65 //! Returns 0 if the given index is not index of a object
66 virtual ObjectPtr object(const QModelIndex& theIndex) const;
68 //! Returns QModelIndex which corresponds to the given object
69 //! If the object is not found then index is not valid
70 virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
72 //! Returns parent index of the given object
73 virtual QModelIndex findParent(const ObjectPtr& theObject) const;
75 //! Returns index corresponded to the group
76 virtual QModelIndex findGroup(const std::string& theGroup) const;
79 //! Types of QModelIndexes
92 /**\class XGUI_PartDataModel
94 * \brief This is a data model for Object Browser (QTreeView).
95 * It represents data tree only of a one part
97 class XGUI_PartDataModel : public XGUI_PartModel
102 /// \param theParent a parent object
103 XGUI_PartDataModel(QObject* theParent);
104 virtual ~XGUI_PartDataModel();
106 // Reimpl from QAbstractItemModel
108 /// Returns the data stored under the given role for the item referred to by the index.
109 /// \param theIndex a model index
110 /// \param theRole a data role (see Qt::ItemDataRole)
111 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
113 /// Returns the data for the given role and section in the header with the specified orientation.
114 /// \param theSection a section
115 /// \param theOrient an orientation
116 /// \param theRole a data role (see Qt::ItemDataRole)
117 virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
118 int theRole = Qt::DisplayRole) const;
120 /// Returns the number of rows under the given parent. When the parent is valid it means that
121 /// rowCount is returning the number of children of parent.
122 /// \param theParent a parent model index
123 virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const;
125 /// Returns the number of columns for the children of the given parent.
126 /// It has a one column
127 /// \param theParent a parent model index
128 virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const;
130 /// Returns the index of the item in the model specified by the given row, column and parent index.
131 /// \param theRow a row
132 /// \param theColumn a column
133 /// \param theParent a parent model index
134 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
135 QModelIndex()) const;
137 /// Returns the parent of the model item with the given index.
138 /// If the item has no parent, an invalid QModelIndex is returned.
139 /// \param theIndex a model index
140 virtual QModelIndex parent(const QModelIndex& theIndex) const;
142 /// Returns true if parent has any children; otherwise returns false.
143 /// \param theParent a parent model index
144 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
146 //! Returns object by the given Model index.
147 //! Returns 0 if the given index is not index of a object
148 virtual ObjectPtr object(const QModelIndex& theIndex) const;
150 //! Returns QModelIndex which corresponds to the given object
151 //! If the object is not found then index is not valid
152 virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
154 //! Returns true if the given document is a sub-document of this tree
155 virtual bool hasDocument(const DocumentPtr& theDoc) const;
157 //! Returns parent index of the given object
158 virtual QModelIndex findParent(const ObjectPtr& theObject) const;
160 //! Returns index corresponded to the group
161 virtual QModelIndex findGroup(const std::string& theGroup) const;
163 //! Return a Part object
164 virtual ResultPartPtr part() const;
168 //! Returns document of the current part
169 DocumentPtr partDocument() const;
171 //! Returns defult number of rows
172 int getRowsNumber() const;
174 //! Types of QModelIndexes