Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / XGUI / XGUI_PartDataModel.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef XGUI_PartDataModel_H
4 #define XGUI_PartDataModel_H
5
6 #include "XGUI.h"
7 #include "XGUI_DataTreeModel.h"
8
9 /**\class XGUI_TopDataModel
10  * \ingroup GUI
11  * \brief This is a data model for Object Browser (QTreeView).
12  * It represents only upper part of data tree (non-parts tree items)
13  */
14 class XGUI_EXPORT XGUI_TopDataModel : public XGUI_FeaturesModel
15 {
16 Q_OBJECT
17  public:
18    /// Constructor
19    /// \param theParent a parent object
20   XGUI_TopDataModel(QObject* theParent);
21   virtual ~XGUI_TopDataModel();
22
23   // Reimpl from QAbstractItemModel
24
25   /// Returns the data stored under the given role for the item referred to by the index.
26   /// \param theIndex a model index
27   /// \param theRole a data role (see Qt::ItemDataRole)
28   virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
29
30   /// Returns the data for the given role and section in the header with the specified orientation.
31   /// \param theSection a section
32   /// \param theOrient an orientation
33   /// \param theRole a data role (see Qt::ItemDataRole)
34   virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
35                               int theRole = Qt::DisplayRole) const;
36
37   /// Returns the number of rows under the given parent. When the parent is valid it means that 
38   /// rowCount is returning the number of children of parent.
39   /// \param theParent a parent model index
40   virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const;
41
42   /// Returns the number of columns for the children of the given parent.
43   /// It has a one column
44   /// \param theParent a parent model index
45   virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const;
46
47
48   /// Returns the index of the item in the model specified by the given row, column and parent index.
49   /// \param theRow a row
50   /// \param theColumn a column
51   /// \param theParent a parent model index
52   virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
53                                 QModelIndex()) const;
54
55   /// Returns the parent of the model item with the given index. 
56   /// If the item has no parent, an invalid QModelIndex is returned.
57   /// \param theIndex a model index
58   virtual QModelIndex parent(const QModelIndex& theIndex) const;
59
60   /// Returns true if parent has any children; otherwise returns false.
61   /// \param theParent a parent model index
62   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
63
64   //! Returns object by the given Model index.
65   //! Returns 0 if the given index is not index of a object
66   virtual ObjectPtr object(const QModelIndex& theIndex) const;
67
68   //! Returns QModelIndex which corresponds to the given object
69   //! If the object is not found then index is not valid
70   virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
71
72   //! Returns parent index of the given object
73   virtual QModelIndex findParent(const ObjectPtr& theObject) const;
74
75   //! Returns index corresponded to the group
76   virtual QModelIndex findGroup(const std::string& theGroup) const;
77
78  private:
79   //! Types of QModelIndexes
80   enum DataIds
81   {
82     ParamsFolder,
83     ParamObject,
84     ConstructFolder,
85     ConstructObject
86     //GroupsFolder,
87     //GroupObject
88   };
89
90 };
91
92 /**\class XGUI_PartDataModel
93  * \ingroup GUI
94  * \brief This is a data model for Object Browser (QTreeView).
95  * It represents data tree only of a one part
96  */
97 class XGUI_PartDataModel : public XGUI_PartModel
98 {
99 Q_OBJECT
100  public:
101    /// Constructor
102    /// \param theParent a parent object
103   XGUI_PartDataModel(QObject* theParent);
104   virtual ~XGUI_PartDataModel();
105
106   // Reimpl from QAbstractItemModel
107
108   /// Returns the data stored under the given role for the item referred to by the index.
109   /// \param theIndex a model index
110   /// \param theRole a data role (see Qt::ItemDataRole)
111   virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
112
113   /// Returns the data for the given role and section in the header with the specified orientation.
114   /// \param theSection a section
115   /// \param theOrient an orientation
116   /// \param theRole a data role (see Qt::ItemDataRole)
117   virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
118                               int theRole = Qt::DisplayRole) const;
119
120   /// Returns the number of rows under the given parent. When the parent is valid it means that 
121   /// rowCount is returning the number of children of parent.
122   /// \param theParent a parent model index
123   virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const;
124
125   /// Returns the number of columns for the children of the given parent.
126   /// It has a one column
127   /// \param theParent a parent model index
128   virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const;
129
130   /// Returns the index of the item in the model specified by the given row, column and parent index.
131   /// \param theRow a row
132   /// \param theColumn a column
133   /// \param theParent a parent model index
134   virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
135                                 QModelIndex()) const;
136
137   /// Returns the parent of the model item with the given index. 
138   /// If the item has no parent, an invalid QModelIndex is returned.
139   /// \param theIndex a model index
140   virtual QModelIndex parent(const QModelIndex& theIndex) const;
141
142   /// Returns true if parent has any children; otherwise returns false.
143   /// \param theParent a parent model index
144   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
145
146   //! Returns object by the given Model index.
147   //! Returns 0 if the given index is not index of a object
148   virtual ObjectPtr object(const QModelIndex& theIndex) const;
149
150   //! Returns QModelIndex which corresponds to the given object
151   //! If the object is not found then index is not valid
152   virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
153
154   //! Returns true if the given document is a sub-document of this tree
155   virtual bool hasDocument(const DocumentPtr& theDoc) const;
156
157   //! Returns parent index of the given object
158   virtual QModelIndex findParent(const ObjectPtr& theObject) const;
159
160   //! Returns index corresponded to the group
161   virtual QModelIndex findGroup(const std::string& theGroup) const;
162
163   //! Return a Part object
164   virtual ResultPartPtr part() const;
165
166  private:
167
168   //! Returns document of the current part
169   DocumentPtr partDocument() const;
170
171   //! Returns defult number of rows
172   int getRowsNumber() const;
173
174   //! Types of QModelIndexes
175   enum DataIds
176   {
177     MyRoot,
178     ParamsFolder,
179     ParamObject,
180     ConstructFolder,
181     ConstructObject,
182     BodiesFolder,
183     BodiesObject,
184     GroupsFolder,
185     GroupObject,
186     HistoryObject
187   };
188
189 };
190
191 #endif