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