Salome HOME
Fix for crash and invisible bodies on Debian Squeeze SALOME version.
[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   //! Clear internal data
82   void clear();
83
84
85  private:
86
87   enum
88   {
89     PartsFolder,
90     HistoryNode
91   };
92
93   //! Converts QModelIndex of this model to QModelIndex of a one of sub-models.
94   QModelIndex* toSourceModelIndex(const QModelIndex& theProxy) const;
95
96   //! Finds a pointer on QModelIndex which is equal to the given one
97   QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
98
99   //! Returns pointer on QModelIndex which is equal to the given one.
100   QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
101
102   //! Deletes all saved pointers on QModelIndex objects.
103   void clearModelIndexes();
104
105   //! Deletes all saved pointers on QModelIndex objects.
106   void clearSubModels();
107
108   //! Removes sub-model on removing a part object. Also it removes QModelIndex-es which refer to this model
109   void removeSubModel(int theModelId);
110
111   //! Returns true if the given model is a one of sub-models (of both types)
112   bool isSubModel(const QAbstractItemModel* theModel) const;
113
114   //! Returns true if the given model is a one of sub-models of Part type
115   bool isPartSubModel(const QAbstractItemModel* theModel) const;
116
117   //! Returns Parts Folder node
118   QModelIndex partFolderNode() const;
119
120   int historyOffset() const;
121
122   //! Data model of top part of data tree (not parts object)
123   XGUI_TopDataModel* myModel;
124
125   //! Data models for Parts data tree representation (one data model per a one part)
126   QList<XGUI_PartModel*> myPartModels;
127
128   //! Active part in part editing mode
129   XGUI_PartModel* myActivePart;
130
131   QModelIndex myActivePartIndex;
132
133   //! List of saved QModelIndexes created by sub-models
134   QList<QModelIndex*> myIndexes;
135
136 };
137
138 #endif