]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_DocumentDataModel.h
Salome HOME
3631f79850bbf0f162180cf277e7ffca4b612d89
[modules/shaper.git] / src / PartSet / PartSet_DocumentDataModel.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef PartSet_DocumentDataModel_H
4 #define PartSet_DocumentDataModel_H
5
6 #include "PartSet.h"
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_ResultPart.h>
9 #include <ModelAPI_Feature.h>
10 #include <ModuleBase_IDocumentDataModel.h>
11
12 #include <Events_Listener.h>
13 #include <QList>
14 #include <QMap>
15
16 class ModelAPI_Document;
17 class PartSet_PartModel;
18 class PartSet_TopDataModel;
19
20 /**\class PartSet_DocumentDataModel
21  * \ingroup GUI
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.
24  */
25 class PARTSET_EXPORT PartSet_DocumentDataModel : public ModuleBase_IDocumentDataModel, public Events_Listener
26 {
27 Q_OBJECT
28  public:
29    /// Constructor
30    /// \param theParent a parent object
31   PartSet_DocumentDataModel(QObject* theParent);
32   virtual ~PartSet_DocumentDataModel();
33
34   /// Event Listener method
35   /// \param theMessage an event message
36   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
37
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;
42
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;
49
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;
54
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;
59
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 =
65                                 QModelIndex()) const;
66
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;
71
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;
75
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());
82
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());
88
89   /// Returns the item flags for the given index.
90   /// \param theIndex a model index
91   virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
92
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;
96
97   //! Returns index of the object
98   //! \param theObject object to find
99   virtual QModelIndex objectIndex(const ObjectPtr theObject) const;
100
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;
105
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);
110
111   //! Retrurns active part
112   ResultPartPtr activePart() const;
113
114   //! Retrurns QModelIndex of active part
115   QModelIndex activePartIndex() const
116   {
117     return myActivePartIndex;
118   }
119
120   //! Returns parent index of active part tree (index of Part feature) 
121   QModelIndex activePartTree() const;
122
123   //! Deactivates a Part
124   void deactivatePart();
125
126   //! Rebuild data tree
127   virtual void rebuildDataTree();
128
129   //! Clear internal data
130   virtual void clear();
131
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);
135
136   QModelIndex lastHistoryItem() const;
137
138   //! Returns icon name according to feature
139   static QIcon featureIcon(const FeaturePtr& theFeature);
140
141  private:
142
143   enum
144   {
145     PartsFolder = -100,
146     HistoryNode,
147     PartResult
148   };
149
150   //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
151   QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
152
153   //! Finds a pointer on QModelIndex which is equal to the given one
154   QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
155
156   //! Returns pointer on QModelIndex which is equal to the given one.
157   QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
158
159   //! Deletes all saved pointers on QModelIndex objects.
160   void clearModelIndexes();
161
162   //! Deletes all saved pointers on QModelIndex objects.
163   void clearSubModels();
164
165   //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
166   void removeSubModel(int theModelId);
167
168   //! Returns true if the given model is a one of sub-models (of both types)
169   bool isSubModel(const QAbstractItemModel* theModel) const;
170
171   //! Returns true if the given model is a one of sub-models of Part type
172   bool isPartSubModel(const QAbstractItemModel* theModel) const;
173
174   //! Returns Parts Folder node
175   //! \param theColumn an Id of column
176   QModelIndex partFolderNode(int theColumn) const;
177
178   int lastHistoryRow() const;
179
180   int historyOffset() const;
181
182   //! Data model of top part of data tree (not parts object)
183   PartSet_TopDataModel* myModel;
184
185   //! Data models for Parts data tree representation (one data model per a one part)
186   QMap<int, PartSet_PartModel*> myPartModels;
187
188   //! Active part in part editing mode
189   int myActivePartId;
190
191   QModelIndex myActivePartIndex;
192
193   //! List of saved QModelIndexes created by sub-models
194   QList<QModelIndex*> myIndexes;
195
196   int myHistoryBackOffset;
197
198   static QMap<QString, QString> myIcons;
199 };
200
201 #endif