Salome HOME
Initial pre-design of XML based Tree Model
[modules/shaper.git] / src / XGUI / XGUI_DataModel.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_DataModel.h
4 // Created:     21 Jul 2015
5 // Author:      Vitaly SMETANNIKOV
6
7
8 #ifndef XGUI_DataModel_H
9 #define XGUI_DataModel_H
10
11 #include "XGUI.h"
12 #include <ModelAPI_Object.h>
13 #include <Config_DataModelReader.h>
14 #include <QAbstractItemModel>
15
16 class XGUI_EXPORT XGUI_DataModel : public QAbstractItemModel
17 {
18 Q_OBJECT
19 public:
20   XGUI_DataModel(QObject* theParent);
21
22   //! Returns an object by the given Model index.
23   //! Returns 0 if the given index is not index of an object
24   virtual ObjectPtr object(const QModelIndex& theIndex) const;
25
26   //! Returns index of the object
27   //! \param theObject object to find
28   virtual QModelIndex objectIndex(const ObjectPtr theObject) const;
29
30   //! Clear internal data
31   virtual void clear();
32
33   //! Rebuild data tree
34   virtual void rebuildDataTree();
35
36
37   /// Returns the data stored under the given role for the item referred to by the index.
38   /// \param theIndex a model index
39   /// \param theRole a data role (see Qt::ItemDataRole)
40   virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
41
42   /// Returns the data for the given role and section in the header with the specified orientation.
43   /// \param theSection a section
44   /// \param theOrient an orientation
45   /// \param theRole a data role (see Qt::ItemDataRole)
46   virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
47                                   Qt::DisplayRole) const;
48
49   /// Returns the number of rows under the given parent. When the parent is valid it means that 
50   /// rowCount is returning the number of children of parent.
51   /// \param theParent a parent model index
52   virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
53
54   /// Returns the number of columns for the children of the given parent.
55   /// It has a one column
56   /// \param theParent a parent model index
57   virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
58
59   /// Returns the index of the item in the model specified by the given row, column and parent index.
60   /// \param theRow a row
61   /// \param theColumn a column
62   /// \param theParent a parent model index
63   virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &theParent =
64                                 QModelIndex()) const;
65
66   /// Returns the parent of the model item with the given index. 
67   /// If the item has no parent, an invalid QModelIndex is returned.
68   /// \param theIndex a model index
69   virtual QModelIndex parent(const QModelIndex& theIndex) const;
70
71   /// Returns true if parent has any children; otherwise returns false.
72   /// \param theParent a parent model index
73   virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
74
75
76 private:
77   Config_DataModelReader myXMLReader;
78 };
79
80 #endif