Salome HOME
A sketcher operations manager is created
[modules/shaper.git] / src / XGUI / XGUI_DocumentDataModel.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef XGUI_DocumentDataModel_H
4 #define XGUI_DocumentDataModel_H
5
6 #include "XGUI.h"
7 #include <ModuleBase_Definitions.h>
8 #include <ModelAPI_ResultPart.h>
9
10 #include <Events_Listener.h>
11
12 #include <QAbstractItemModel>
13 #include <QList>
14
15 class ModelAPI_Document;
16 class XGUI_PartModel;
17 class XGUI_TopDataModel;
18
19 /**\class XGUI_DocumentDataModel
20  * \ingroup GUI
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.
23  */
24 class XGUI_EXPORT XGUI_DocumentDataModel : public QAbstractItemModel, public Events_Listener
25 {
26 Q_OBJECT
27  public:
28
29   XGUI_DocumentDataModel(QObject* theParent);
30   virtual ~XGUI_DocumentDataModel();
31
32   // Event Listener method
33   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
34
35   virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
36   virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
37                                   Qt::DisplayRole) const;
38
39   virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
40   virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
41
42   virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &parent =
43                                 QModelIndex()) const;
44
45   virtual QModelIndex parent(const QModelIndex& theIndex) const;
46
47   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
48
49   bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
50
51   bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
52
53   Qt::ItemFlags flags(const QModelIndex& theIndex) const;
54
55   //! Returns an object by the given Model index.
56   //! Returns 0 if the given index is not index of an object
57   ObjectPtr object(const QModelIndex& theIndex) const;
58
59   QModelIndex objectIndex(const ObjectPtr theObject) const;
60
61   //! Returns QModelIndex which corresponds to the given part
62   //! If the object is not found then index is not valid
63   QModelIndex partIndex(const ResultPartPtr& thePart) const;
64
65   //! Activates a part data model if the index is a Part node index. 
66   //! Returns true if active part changed.
67   bool activatedIndex(const QModelIndex& theIndex);
68
69   //! Retrurns active part
70   ResultPartPtr activePart() const;
71
72   //! Retrurns QModelIndex of active part
73   QModelIndex activePartIndex() const
74   {
75     return myActivePartIndex;
76   }
77
78   //! Deactivates a Part
79   void deactivatePart();
80
81   void rebuildDataTree();
82
83   //! Clear internal data
84   void clear();
85
86
87  private:
88
89   enum
90   {
91     PartsFolder,
92     HistoryNode
93   };
94
95   //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
96   QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
97
98   //! Finds a pointer on QModelIndex which is equal to the given one
99   QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
100
101   //! Returns pointer on QModelIndex which is equal to the given one.
102   QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
103
104   //! Deletes all saved pointers on QModelIndex objects.
105   void clearModelIndexes();
106
107   //! Deletes all saved pointers on QModelIndex objects.
108   void clearSubModels();
109
110   //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
111   void removeSubModel(int theModelId);
112
113   //! Returns true if the given model is a one of sub-models (of both types)
114   bool isSubModel(const QAbstractItemModel* theModel) const;
115
116   //! Returns true if the given model is a one of sub-models of Part type
117   bool isPartSubModel(const QAbstractItemModel* theModel) const;
118
119   //! Returns Parts Folder node
120   QModelIndex partFolderNode() const;
121
122   int historyOffset() const;
123
124   //! Data model of top part of data tree (not parts object)
125   XGUI_TopDataModel* myModel;
126
127   //! Data models for Parts data tree representation (one data model per a one part)
128   QList<XGUI_PartModel*> myPartModels;
129
130   //! Active part in part editing mode
131   XGUI_PartModel* myActivePart;
132
133   QModelIndex myActivePartIndex;
134
135   //! List of saved QModelIndexes created by sub-models
136   QList<QModelIndex*> myIndexes;
137
138 };
139
140 #endif