1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #ifndef PartSet_PartDataModel_H
4 #define PartSet_PartDataModel_H
7 #include "PartSet_DataTreeModel.h"
9 /**\class PartSet_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 PARTSET_EXPORT PartSet_TopDataModel : public PartSet_FeaturesModel
19 /// \param theParent a parent object
20 PartSet_TopDataModel(QObject* theParent);
21 virtual ~PartSet_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 PartSet_PartDataModel
94 * \brief This is a data model for Object Browser (QTreeView).
95 * It represents data tree only of a one part
97 class PartSet_PartDataModel : public PartSet_PartModel
102 /// \param theParent a parent object
103 PartSet_PartDataModel(QObject* theParent);
104 virtual ~PartSet_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 item flags for the given index.
131 /// \param theIndex a model index
132 virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
134 /// Returns the index of the item in the model specified by the given row, column and parent index.
135 /// \param theRow a row
136 /// \param theColumn a column
137 /// \param theParent a parent model index
138 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
139 QModelIndex()) const;
141 /// Returns the parent of the model item with the given index.
142 /// If the item has no parent, an invalid QModelIndex is returned.
143 /// \param theIndex a model index
144 virtual QModelIndex parent(const QModelIndex& theIndex) const;
146 /// Returns true if parent has any children; otherwise returns false.
147 /// \param theParent a parent model index
148 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
150 //! Returns object by the given Model index.
151 //! Returns 0 if the given index is not index of a object
152 virtual ObjectPtr object(const QModelIndex& theIndex) const;
154 //! Returns QModelIndex which corresponds to the given object
155 //! If the object is not found then index is not valid
156 virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
158 //! Returns true if the given document is a sub-document of this tree
159 virtual bool hasDocument(const DocumentPtr& theDoc) const;
161 //! Returns parent index of the given object
162 virtual QModelIndex findParent(const ObjectPtr& theObject) const;
164 //! Returns index corresponded to the group
165 virtual QModelIndex findGroup(const std::string& theGroup) const;
167 //! Set an Index which will be considered as a last history index
168 //! \param theIndex a last index for history
169 void setLastHistoryItem(const QModelIndex& theIndex);
171 //! Returns last history item
172 QModelIndex lastHistoryItem() const;
176 //! Returns document of the current part
177 DocumentPtr partDocument() const;
179 //! Returns defult number of rows
180 int getRowsNumber() const;
182 int lastHistoryRow() const;
184 //! Types of QModelIndexes