1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #ifndef PartSet_DocumentDataModel_H
4 #define PartSet_DocumentDataModel_H
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_ResultPart.h>
9 #include <ModelAPI_Feature.h>
10 #include <ModuleBase_IDocumentDataModel.h>
12 #include <Events_Listener.h>
16 class ModelAPI_Document;
17 class PartSet_PartModel;
18 class PartSet_TopDataModel;
20 /**\class PartSet_DocumentDataModel
22 * \brief This is a proxy data model for Object Browser (QTreeView).
23 * It contains several sub-models for generation of each sub-part of data tree.
25 class PARTSET_EXPORT PartSet_DocumentDataModel : public ModuleBase_IDocumentDataModel, public Events_Listener
30 /// \param theParent a parent object
31 PartSet_DocumentDataModel(QObject* theParent);
32 virtual ~PartSet_DocumentDataModel();
34 /// Event Listener method
35 /// \param theMessage an event message
36 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
38 /// Returns the data stored under the given role for the item referred to by the index.
39 /// \param theIndex a model index
40 /// \param theRole a data role (see Qt::ItemDataRole)
41 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
43 /// Returns the data for the given role and section in the header with the specified orientation.
44 /// \param theSection a section
45 /// \param theOrient an orientation
46 /// \param theRole a data role (see Qt::ItemDataRole)
47 virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
48 Qt::DisplayRole) const;
50 /// Returns the number of rows under the given parent. When the parent is valid it means that
51 /// rowCount is returning the number of children of parent.
52 /// \param theParent a parent model index
53 virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
55 /// Returns the number of columns for the children of the given parent.
56 /// It has a one column
57 /// \param theParent a parent model index
58 virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
60 /// Returns the index of the item in the model specified by the given row, column and parent index.
61 /// \param theRow a row
62 /// \param theColumn a column
63 /// \param theParent a parent model index
64 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &theParent =
67 /// Returns the parent of the model item with the given index.
68 /// If the item has no parent, an invalid QModelIndex is returned.
69 /// \param theIndex a model index
70 virtual QModelIndex parent(const QModelIndex& theIndex) const;
72 /// Returns true if parent has any children; otherwise returns false.
73 /// \param theParent a parent model index
74 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
76 /// Inserts count rows into the model before the given row.
77 /// Items in the new row will be children of the item represented by the parent model index.
78 /// \param theRow a start row
79 /// \param theCount a nember of rows to insert
80 /// \param theParent a parent model index
81 bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
83 /// Removes count rows starting with the given row under parent parent from the model.
84 /// \param theRow a start row
85 /// \param theCount a nember of rows to remove
86 /// \param theParent a parent model index
87 bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
89 /// Returns the item flags for the given index.
90 /// \param theIndex a model index
91 virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
93 //! Returns an object by the given Model index.
94 //! Returns 0 if the given index is not index of an object
95 virtual ObjectPtr object(const QModelIndex& theIndex) const;
97 //! Returns index of the object
98 //! \param theObject object to find
99 virtual QModelIndex objectIndex(const ObjectPtr theObject) const;
101 //! Returns QModelIndex which corresponds to the given part
102 //! If the object is not found then index is not valid
103 //! \param thePart a part for analysis
104 QModelIndex partIndex(const ResultPartPtr& thePart) const;
106 //! Activates a part data model if the index is a Part node index.
107 //! Returns true if active part changed.
108 //! \param theIndex a model index
109 bool activatePart(const QModelIndex& theIndex);
111 //! Retrurns active part
112 ResultPartPtr activePart() const;
114 //! Retrurns QModelIndex of active part
115 QModelIndex activePartIndex() const
117 return myActivePartIndex;
120 //! Returns parent index of active part tree (index of Part feature)
121 QModelIndex activePartTree() const;
123 //! Deactivates a Part
124 void deactivatePart();
126 //! Rebuild data tree
127 virtual void rebuildDataTree();
129 //! Clear internal data
130 virtual void clear();
132 //! Set an Index which will be considered as a last history index
133 //! \param theIndex a last index for history
134 void setLastHistoryItem(const QModelIndex& theIndex);
136 //! Returns last history item
137 QModelIndex lastHistoryItem() const;
139 //! Returns icon name according to feature
140 static QIcon featureIcon(const FeaturePtr& theFeature);
143 void onMouseDoubleClick(const QModelIndex& theIndex);
154 //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
155 QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
157 //! Finds a pointer on QModelIndex which is equal to the given one
158 QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
160 //! Returns pointer on QModelIndex which is equal to the given one.
161 QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
163 //! Deletes all saved pointers on QModelIndex objects.
164 void clearModelIndexes();
166 //! Deletes all saved pointers on QModelIndex objects.
167 void clearSubModels();
169 //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
170 void removeSubModel(int theModelId);
172 //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
173 void removeSubModel(PartSet_PartModel* theModel);
175 //! Returns true if the given model is a one of sub-models (of both types)
176 bool isSubModel(const QAbstractItemModel* theModel) const;
178 //! Returns true if the given model is a one of sub-models of Part type
179 bool isPartSubModel(const QAbstractItemModel* theModel) const;
181 //! Returns Parts Folder node
182 //! \param theColumn an Id of column
183 QModelIndex partFolderNode(int theColumn) const;
185 int lastHistoryRow() const;
187 int historyOffset() const;
189 PartSet_PartModel* findPartModel(FeaturePtr thePart) const;
191 PartSet_PartModel* findPartModel(int thePosition) const;
193 //! Data model of top part of data tree (not parts object)
194 PartSet_TopDataModel* myModel;
196 //! Data models for Parts data tree representation (one data model per a one part)
197 QList<PartSet_PartModel*> myPartModels;
199 //! Active part in part editing mode
200 PartSet_PartModel* myActivePartModel;
202 QModelIndex myActivePartIndex;
204 //! List of saved QModelIndexes created by sub-models
205 QList<QModelIndex*> myIndexes;
207 static QMap<QString, QString> myIcons;