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>
15 class ModelAPI_Document;
16 class PartSet_PartModel;
17 class PartSet_TopDataModel;
19 /**\class PartSet_DocumentDataModel
21 * \brief This is a proxy data model for Object Browser (QTreeView).
22 * It contains several sub-models for generation of each sub-part of data tree.
24 class PARTSET_EXPORT PartSet_DocumentDataModel : public ModuleBase_IDocumentDataModel, public Events_Listener
29 /// \param theParent a parent object
30 PartSet_DocumentDataModel(QObject* theParent);
31 virtual ~PartSet_DocumentDataModel();
33 /// Event Listener method
34 /// \param theMessage an event message
35 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
37 /// Returns the data stored under the given role for the item referred to by the index.
38 /// \param theIndex a model index
39 /// \param theRole a data role (see Qt::ItemDataRole)
40 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
42 /// Returns the data for the given role and section in the header with the specified orientation.
43 /// \param theSection a section
44 /// \param theOrient an orientation
45 /// \param theRole a data role (see Qt::ItemDataRole)
46 virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
47 Qt::DisplayRole) const;
49 /// Returns the number of rows under the given parent. When the parent is valid it means that
50 /// rowCount is returning the number of children of parent.
51 /// \param theParent a parent model index
52 virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
54 /// Returns the number of columns for the children of the given parent.
55 /// It has a one column
56 /// \param theParent a parent model index
57 virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
59 /// Returns the index of the item in the model specified by the given row, column and parent index.
60 /// \param theRow a row
61 /// \param theColumn a column
62 /// \param theParent a parent model index
63 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &theParent =
66 /// Returns the parent of the model item with the given index.
67 /// If the item has no parent, an invalid QModelIndex is returned.
68 /// \param theIndex a model index
69 virtual QModelIndex parent(const QModelIndex& theIndex) const;
71 /// Returns true if parent has any children; otherwise returns false.
72 /// \param theParent a parent model index
73 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
75 /// Inserts count rows into the model before the given row.
76 /// Items in the new row will be children of the item represented by the parent model index.
77 /// \param theRow a start row
78 /// \param theCount a nember of rows to insert
79 /// \param theParent a parent model index
80 bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
82 /// Removes count rows starting with the given row under parent parent from the model.
83 /// \param theRow a start row
84 /// \param theCount a nember of rows to remove
85 /// \param theParent a parent model index
86 bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
88 /// Returns the item flags for the given index.
89 /// \param theIndex a model index
90 virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
92 //! Returns an object by the given Model index.
93 //! Returns 0 if the given index is not index of an object
94 virtual ObjectPtr object(const QModelIndex& theIndex) const;
96 //! Returns index of the object
97 //! \param theObject object to find
98 virtual QModelIndex objectIndex(const ObjectPtr theObject) const;
100 //! Returns QModelIndex which corresponds to the given part
101 //! If the object is not found then index is not valid
102 //! \param thePart a part for analysis
103 QModelIndex partIndex(const ResultPartPtr& thePart) const;
105 //! Activates a part data model if the index is a Part node index.
106 //! Returns true if active part changed.
107 //! \param theIndex a model index
108 bool activatePart(const QModelIndex& theIndex);
110 //! Retrurns active part
111 ResultPartPtr activePart() const;
113 //! Retrurns QModelIndex of active part
114 QModelIndex activePartIndex() const
116 return myActivePartIndex;
119 //! Deactivates a Part
120 void deactivatePart();
122 //! Rebuild data tree
123 virtual void rebuildDataTree();
125 //! Clear internal data
126 virtual void clear();
128 //! Set an Index which will be considered as a last history index
129 //! \param theIndex a last index for history
130 void setLastHistoryItem(const QModelIndex& theIndex);
132 QModelIndex lastHistoryItem() const;
134 //! Returns icon name according to feature
135 static QIcon featureIcon(const FeaturePtr& theFeature);
145 //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
146 QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
148 //! Finds a pointer on QModelIndex which is equal to the given one
149 QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
151 //! Returns pointer on QModelIndex which is equal to the given one.
152 QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
154 //! Deletes all saved pointers on QModelIndex objects.
155 void clearModelIndexes();
157 //! Deletes all saved pointers on QModelIndex objects.
158 void clearSubModels();
160 //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
161 void removeSubModel(int theModelId);
163 //! Returns true if the given model is a one of sub-models (of both types)
164 bool isSubModel(const QAbstractItemModel* theModel) const;
166 //! Returns true if the given model is a one of sub-models of Part type
167 bool isPartSubModel(const QAbstractItemModel* theModel) const;
169 //! Returns Parts Folder node
170 //! \param theColumn an Id of column
171 QModelIndex partFolderNode(int theColumn) const;
173 int lastHistoryRow() const;
175 int historyOffset() const;
177 //! Data model of top part of data tree (not parts object)
178 PartSet_TopDataModel* myModel;
180 //! Data models for Parts data tree representation (one data model per a one part)
181 QList<PartSet_PartModel*> myPartModels;
183 //! Active part in part editing mode
184 PartSet_PartModel* myActivePart;
186 QModelIndex myActivePartIndex;
188 //! List of saved QModelIndexes created by sub-models
189 QList<QModelIndex*> myIndexes;
191 int myHistoryBackOffset;
193 static QMap<QString, QString> myIcons;