]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_PartDataModel.h
Salome HOME
Using mouse double click for history line change
[modules/shaper.git] / src / PartSet / PartSet_PartDataModel.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef PartSet_PartDataModel_H
4 #define PartSet_PartDataModel_H
5
6 #include "PartSet.h"
7 #include "PartSet_DataTreeModel.h"
8
9 /**\class PartSet_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 PARTSET_EXPORT PartSet_TopDataModel : public PartSet_FeaturesModel
15 {
16 Q_OBJECT
17  public:
18    /// Constructor
19    /// \param theParent a parent object
20   PartSet_TopDataModel(QObject* theParent);
21   virtual ~PartSet_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 PartSet_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 PartSet_PartDataModel : public PartSet_PartModel
98 {
99 Q_OBJECT
100  public:
101    /// Constructor
102    /// \param theParent a parent object
103   PartSet_PartDataModel(QObject* theParent);
104   virtual ~PartSet_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 item flags for the given index.
131   /// \param theIndex a model index
132   virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
133
134   /// Returns the index of the item in the model specified by the given row, column and parent index.
135   /// \param theRow a row
136   /// \param theColumn a column
137   /// \param theParent a parent model index
138   virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
139                                 QModelIndex()) const;
140
141   /// Returns the parent of the model item with the given index. 
142   /// If the item has no parent, an invalid QModelIndex is returned.
143   /// \param theIndex a model index
144   virtual QModelIndex parent(const QModelIndex& theIndex) const;
145
146   /// Returns true if parent has any children; otherwise returns false.
147   /// \param theParent a parent model index
148   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
149
150   //! Returns object by the given Model index.
151   //! Returns 0 if the given index is not index of a object
152   virtual ObjectPtr object(const QModelIndex& theIndex) const;
153
154   //! Returns QModelIndex which corresponds to the given object
155   //! If the object is not found then index is not valid
156   virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
157
158   //! Returns true if the given document is a sub-document of this tree
159   virtual bool hasDocument(const DocumentPtr& theDoc) const;
160
161   //! Returns parent index of the given object
162   virtual QModelIndex findParent(const ObjectPtr& theObject) const;
163
164   //! Returns index corresponded to the group
165   virtual QModelIndex findGroup(const std::string& theGroup) const;
166
167   //! Return a Part object
168   virtual ResultPartPtr part() const;
169
170   //! Set an Index which will be considered as a last history index
171   //! \param theIndex a last index for history
172   void setLastHistoryItem(const QModelIndex& theIndex);
173
174   //! Returns last history item
175   QModelIndex lastHistoryItem() const;
176
177  private:
178
179   //! Returns document of the current part
180   DocumentPtr partDocument() const;
181
182   //! Returns defult number of rows
183   int getRowsNumber() const;
184
185   int lastHistoryRow() const;
186
187   //! Types of QModelIndexes
188   enum DataIds
189   {
190     //MyRoot,
191     ParamsFolder,
192     ParamObject,
193     ConstructFolder,
194     ConstructObject,
195     BodiesFolder,
196     BodiesObject,
197     GroupsFolder,
198     GroupObject,
199     HistoryObject
200   };
201
202   int myHistoryBackOffset;
203 };
204
205 #endif