0029310: Coding - multiple compiler warnings in Inspectors
[occt.git] / tools / DFBrowser / DFBrowser_TreeLevelViewModel.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 DFBrowser_TreeLevelViewModel_H
17 #define DFBrowser_TreeLevelViewModel_H
18
19 #include <Standard.hxx>
20 #include <Standard_Macro.hxx>
21
22 #include <Standard_WarningsDisable.hxx>
23 #include <QAbstractTableModel>
24 #include <QVariant>
25 #include <Standard_WarningsRestore.hxx>
26
27 class QObject;
28
29 //! \class DFBrowser_TreeLevelViewModel
30 //! Tree Model of one level of OCAF tree view model. It is initialized by tree view index and
31 //! contains children and attributes of this label.
32 class DFBrowser_TreeLevelViewModel : public QAbstractTableModel
33 {
34 public:
35
36   //! Constructor
37   DFBrowser_TreeLevelViewModel (QObject* theParent) : QAbstractTableModel (theParent), myRowCount (0) {}
38
39   //! Destructor
40   virtual ~DFBrowser_TreeLevelViewModel() Standard_OVERRIDE {}
41
42   //! Reset OCAF tree model index
43   void Reset() { myIndex = QModelIndex(); }
44
45   //! Fills OCAF tree model index
46   //! \param theTreeIndex an index
47   Standard_EXPORT void Init (const QModelIndex& theTreeIndex);
48
49   //! Returns true if the index is filled
50   bool IsInitialized() const { return myIndex.isValid(); }
51
52   //! Return OCAF tree view model index on level defined by column of the parameter index
53   //! \param theIndex a tree level view model index
54   //! \return model index
55   Standard_EXPORT QModelIndex GetTreeViewIndex (const QModelIndex& theIndex) const;
56
57   //! Emits the layoutChanged signal from outside of this class
58   void EmitLayoutChanged() { emit layoutChanged(); }
59
60   //! It returns value only for DisplayRole for column = 1
61   //! \param theSection an index of value in the container 
62   //! \param theIndex a model index
63   //! \param theRole a view role
64   //! \return value intepreted depending on the given role
65   Standard_EXPORT virtual QVariant headerData (int theSection, Qt::Orientation theOrientation,
66                                                int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
67
68   //! Creates new model index
69   //! \param theRow the index row position
70   //! \param theColummn the index column position
71   //! \param theParent the parent index
72   //! \return the model index
73   Standard_EXPORT virtual QModelIndex index (int theRow, int theColumn,
74                                              const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
75
76   //! Returns item information(short) for display role.
77   //! \param theIndex a model index
78   //! \param theRole a view role
79   //! \return value intepreted depending on the given role
80   Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex,
81                                          int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
82
83   //! Returns Enabled and Selectable item for any index
84   //! \param theIndex a model index
85   //! \return flags
86   Standard_EXPORT virtual Qt::ItemFlags flags (const QModelIndex& theIndex) const Standard_OVERRIDE;
87
88   //! Returns number of rows
89   virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
90   { (void)theParent; return myRowCount; }
91
92   //! Returns 2 columns
93   virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE
94   { (void)theParent; return 2; }
95
96 private:
97
98   QModelIndex myIndex; //!< OCAF tree view model index
99   int myRowCount; //!< number of rows of item of treeview model index
100 };
101 #endif