7e1c1e48 |
1 | // Created on: 2020-01-25 |
2 | // Created by: Natalia ERMOLAEVA |
3 | // Copyright (c) 2020 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 ViewControl_TableModel_H |
17 | #define ViewControl_TableModel_H |
18 | |
19 | #include <Standard.hxx> |
20 | |
21 | #include <inspector/ViewControl_TableModelValues.hxx> |
22 | |
23 | #include <Standard_WarningsDisable.hxx> |
24 | #include <QAbstractTableModel> |
25 | #include <QList> |
26 | #include <QVariant> |
27 | #include <Standard_WarningsRestore.hxx> |
28 | |
29 | #include <vector> |
30 | |
31 | //! \class ViewControl_TableModel |
32 | //! \brief This is an extension of table model to visualize a container of values |
33 | //! It is possible to: |
34 | //! - set orientation to interpretate the values. |
35 | //! - set table view header values. |
36 | //! Items of the view are enabled and selectable. |
37 | class ViewControl_TableModel : public QAbstractTableModel |
38 | { |
39 | public: |
40 | |
41 | //! Constructor |
42 | ViewControl_TableModel (QObject* theParent = 0) : myModelValues (0) { (void)theParent; } |
43 | |
44 | //! Destructor |
45 | virtual ~ViewControl_TableModel() {} |
46 | |
47 | //! Returns instance of interface for access totable values |
48 | //! \return interface or NULL |
49 | ViewControl_TableModelValues* ModelValues() const { return myModelValues; } |
50 | |
51 | //! Sets interface to table values |
52 | //! \theModelValues instance of values |
53 | Standard_EXPORT void SetModelValues (ViewControl_TableModelValues* theModelValues); |
54 | |
55 | //! Emits the layoutChanged signal from outside of this class |
56 | void EmitLayoutChanged() { emit layoutChanged(); } |
57 | |
58 | //! Returns number of columns, depending on orientation: myColumnCount or size of values container |
59 | //! \param theParent an index of the parent item |
60 | //! \return an integer value |
61 | Standard_EXPORT virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE; |
62 | |
63 | //! Returns number of rows, depending on orientation: myColumnCount or size of values container |
64 | //! \param theParent an index of the parent item |
65 | //! \return an integer value |
66 | Standard_EXPORT virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE; |
67 | |
68 | //! Returns content of the model index for the given role, it is obtained from internal container of values |
69 | //! It returns value only for DisplayRole. |
70 | //! \param theIndex a model index |
71 | //! \param theRole a view role |
a110c4a3 |
72 | //! \return value interpreted depending on the given role |
7e1c1e48 |
73 | Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE; |
74 | |
75 | //! Sets the new value of passed role to tree cell. |
76 | //! \param[in] index refers to item in tree. |
77 | //! \param[in] value the new value. |
78 | //! \param[in] role the role of value. |
79 | Standard_EXPORT virtual bool setData (const QModelIndex& theIndex, const QVariant& theValue, int theRole) Standard_OVERRIDE; |
80 | |
81 | //! Returns content of the model index for the given role, it is obtainer from internal container of header values |
82 | //! It returns value only for DisplayRole. |
83 | //! \param theSection an index of value in the container |
84 | //! \param theIndex a model index |
85 | //! \param theRole a view role |
a110c4a3 |
86 | //! \return value interpreted depending on the given role |
7e1c1e48 |
87 | virtual QVariant headerData (int theSection, Qt::Orientation theOrientation, int theRole = Qt::DisplayRole) const Standard_OVERRIDE |
88 | { return myModelValues ? myModelValues->HeaderData (theSection, theOrientation, theRole) : QVariant(); } |
89 | |
90 | //! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable |
91 | //! \param theIndex a model index |
92 | //! \return flags |
9e5e4c0c |
93 | virtual Qt::ItemFlags flags (const QModelIndex& theIndex) const Standard_OVERRIDE |
7e1c1e48 |
94 | { return myModelValues ? myModelValues->Flags (theIndex) : Qt::NoItemFlags; } |
95 | |
96 | private: |
97 | ViewControl_TableModelValues* myModelValues; //!< interface to table values |
98 | }; |
99 | |
100 | #endif |