0029025: TInspector include files are not installed to inc directory by CMake
[occt.git] / tools / TreeModel / TreeModel_ModelBase.hxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #ifndef TreeModel_ModelBase_H
17 #define TreeModel_ModelBase_H
18
19 #include <Standard.hxx>
20 #include <inspector/TreeModel_ItemBase.hxx>
21
22 #include <QAbstractItemModel>
23 #include <QExplicitlySharedDataPointer>
24 #include <QModelIndex>
25 #include <QVariant>
26
27 //! \class TreeModel_ModelBase
28 //! \brief Implementation of the tree item based model of QAbstractItemModel.
29 //! The TreeModel_ModelBase class defines the abstract model realization throught the base item architecture.
30 //! By the model index creation, a base item is created and attached to the index.
31 //! Each item contains an iformation about the item parent, position in the parent and
32 //! the item's children. So, it is possible to get the model index relation from the item.
33 class TreeModel_ModelBase : public QAbstractItemModel
34 {
35 public:
36
37   //! Constructor
38   //! \param theParent the parent object
39   Standard_EXPORT TreeModel_ModelBase (QObject* theParent = 0);
40
41   //! Destructor
42   virtual ~TreeModel_ModelBase() {}
43
44   //! Returns the item shared pointer by the model index
45   //! if it is in the index internal pointer
46   //! @param theIndex a model index
47   Standard_EXPORT static TreeModel_ItemBasePtr GetItemByIndex (const QModelIndex& theIndex);
48
49   //! Resets the model items content. Calls the same method of the root item.
50   //! It leads to reset of all child/sub child items.
51   Standard_EXPORT virtual void Reset();
52
53   //! Returns the model root item.
54   //! It is realized for OCAFBrowser
55   virtual TreeModel_ItemBasePtr RootItem (const int theColumn) const { (void)theColumn; return m_pRootItem; }
56
57   //! Emits the layoutChanged signal from outside of this class
58   Standard_EXPORT void EmitLayoutChanged();
59
60   //! Returns the index of the item in the model specified by the given row, column and parent index.
61   //! Saves an internal pointer at the createIndex. This pointer is a shared pointer to the class,
62   //! that realizes a base item interface. If the parent is invalid, a root item is used, otherwise a new item
63   //! is created by the pointer item saved the parent model index
64   //! \param theRow the index row position
65   //! \param theColummn the index column position
66   //! \param theParent the parent index
67   //! \return the model index
68   Standard_EXPORT virtual QModelIndex index (int theRow, int theColumn,
69                                              const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
70
71   //! Returns the data stored under the given role for the item referred to by the index.
72   //! \param theIndex a model index
73   //! \param theRole an enumeration value of role for data obtaining
74   Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
75
76   //! Returns the parent index by the child index. Founds the item, saved in the index;
77   //! obtains the parent item by the item. Create a new index by the item and containing it.
78   //! \param theIndex a model index
79   Standard_EXPORT virtual QModelIndex parent (const QModelIndex& theIndex) const Standard_OVERRIDE;
80
81   //! Returns the item flags for the given index. The base class implementation returns a combination of flags that
82   //! enables the item (ItemIsEnabled) and allows it to be selected (ItemIsSelectable)
83   //! \param theIndex the model index
84   //! \return Qt flag combination
85   Standard_EXPORT virtual Qt::ItemFlags flags (const QModelIndex& theIndex) const Standard_OVERRIDE;
86
87   //! Returns the header data for the given role and section in the header with the specified orientation.
88   //! \param theSection the header section. For horizontal headers - column number, for vertical headers - row number.
89   //! \param theOrientation a header orientation
90   //! \param theRole a data role
91   //! \return the header data
92   Standard_EXPORT virtual QVariant headerData (int theSection, Qt::Orientation theOrientation,
93                                                int theRole = Qt::DisplayRole) const Standard_OVERRIDE
94   { (void)theSection, (void)theOrientation; (void)theRole; return QVariant(); }
95
96   //! Returns the number of rows under the given parent. When the parent is valid it means that rowCount is returning
97   //! the number of children of parent.
98   //! \param theParent a parent model index
99   //! \return the number of rows
100   Standard_EXPORT virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
101
102   //! Returns the number of columns for the children of the given parent.
103   //! \param theParent a parent model index
104   //! \return the number of columns
105   virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
106   { (void)theParent; return 1; }
107
108 protected:
109
110   //! Converts the item shared pointer to void* type
111   //! \param theItem
112   //!  \return an item pointer
113   Standard_EXPORT static void* getIndexValue (const TreeModel_ItemBasePtr& theItem);
114
115 protected:
116
117   TreeModel_ItemBasePtr m_pRootItem; //!< the model root item. It should be created in the
118   //!< model subclass. The model is fulfilled by this item content
119 };
120
121 #endif