Salome HOME
Validator for partition
[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
10 /**\class PartSet_PartDataModel
11  * \ingroup GUI
12  * \brief This is a data model for Object Browser (QTreeView).
13  * It represents data tree only of a one part
14  */
15 class PartSet_PartDataModel : public PartSet_PartModel
16 {
17 Q_OBJECT
18  public:
19    /// Constructor
20    /// \param theParent a parent object
21   PartSet_PartDataModel(QObject* theParent);
22   virtual ~PartSet_PartDataModel();
23
24   // Reimpl from QAbstractItemModel
25
26   /// Returns the data stored under the given role for the item referred to by the index.
27   /// \param theIndex a model index
28   /// \param theRole a data role (see Qt::ItemDataRole)
29   virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
30
31   /// Returns the data for the given role and section in the header with the specified orientation.
32   /// \param theSection a section
33   /// \param theOrient an orientation
34   /// \param theRole a data role (see Qt::ItemDataRole)
35   virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
36                               int theRole = Qt::DisplayRole) const;
37
38   /// Returns the number of rows under the given parent. When the parent is valid it means that 
39   /// rowCount is returning the number of children of parent.
40   /// \param theParent a parent model index
41   virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const;
42
43   /// Returns the number of columns for the children of the given parent.
44   /// It has a one column
45   /// \param theParent a parent model index
46   virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const;
47
48   /// Returns the item flags for the given index.
49   /// \param theIndex a model index
50   virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
51
52   /// Returns the index of the item in the model specified by the given row, column and parent index.
53   /// \param theRow a row
54   /// \param theColumn a column
55   /// \param theParent a parent model index
56   virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
57                                 QModelIndex()) const;
58
59   /// Returns the parent of the model item with the given index. 
60   /// If the item has no parent, an invalid QModelIndex is returned.
61   /// \param theIndex a model index
62   virtual QModelIndex parent(const QModelIndex& theIndex) const;
63
64   /// Returns true if parent has any children; otherwise returns false.
65   /// \param theParent a parent model index
66   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
67
68   //! Returns object by the given Model index.
69   //! Returns 0 if the given index is not index of a object
70   virtual ObjectPtr object(const QModelIndex& theIndex) const;
71
72   //! Returns QModelIndex which corresponds to the given object
73   //! If the object is not found then index is not valid
74   virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
75
76   //! Returns true if the given document is a sub-document of this tree
77   virtual bool hasDocument(const DocumentPtr& theDoc) const;
78
79   //! Returns parent index of the given object
80   virtual QModelIndex findParent(const ObjectPtr& theObject) const;
81
82   //! Returns index corresponded to the group
83   virtual QModelIndex findGroup(const std::string& theGroup) const;
84
85   //! Set an Index which will be considered as a last history index
86   //! \param theIndex a last index for history
87   void setLastHistoryItem(const QModelIndex& theIndex);
88
89   //! Returns last history item
90   QModelIndex lastHistoryItem() const;
91
92  private:
93
94   //! Returns document of the current part
95   DocumentPtr partDocument() const;
96
97   //! Returns defult number of rows
98   int getRowsNumber() const;
99
100   int lastHistoryRow() const;
101
102   //! Types of QModelIndexes
103   //! All types have negative Id's. Positive Id means sub-feature and contains row of its parent
104   enum DataIds
105   {
106     //MyRoot,
107     ParamsFolder = -100,
108     ParamObject,
109     ConstructFolder,
110     ConstructObject,
111     BodiesFolder,
112     BodiesObject,
113     GroupsFolder,
114     GroupObject,
115     HistoryObject
116   };
117 };
118
119 #endif