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