058d008e951945425986707461bd1478b8735356
[occt.git] / tools / ViewControl / ViewControl_TableModelValues.hxx
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_TableModelValues_H
17 #define ViewControl_TableModelValues_H
18
19 #include <Standard.hxx>
20
21 #include <inspector/TreeModel_HeaderSection.hxx>
22 #include <inspector/TreeModel_ItemProperties.hxx>
23 #include <inspector/ViewControl_EditType.hxx>
24
25 #include <Standard_WarningsDisable.hxx>
26 #include <QAbstractTableModel>
27 #include <QColor>
28 #include <QList>
29 #include <QModelIndexList>
30 #include <QVariant>
31 #include <Standard_WarningsRestore.hxx>
32
33 //! \class ViewControl_TableModelValues
34 //! \brief This is an interace for ViewControl_TableModel to give real values of the model
35 //! It should be filled or redefined.
36 class ViewControl_TableModelValues
37 {
38 public:
39
40   //! Constructor
41   ViewControl_TableModelValues (const Qt::Orientation& theOrientation = Qt::Vertical) { SetOrientation (theOrientation); }
42
43   //! Destructor
44   virtual ~ViewControl_TableModelValues() {}
45
46   //! Returns item table properties builder
47   Handle(TreeModel_ItemProperties) Properties() const { return myProperties; }
48
49   //! Sets item table properties builder
50   void SetProperties (const Handle(TreeModel_ItemProperties)& theProperties) { myProperties = theProperties; }
51
52   //! Sets direction of the values applying, whether it should be placed by rows or by columns
53   //! \param theOrientation if horizontal, the values are applied by rows, otherwise by columns
54   void SetOrientation (const Qt::Orientation& theOrientation) { myOrientation = theOrientation; }
55
56   //! Fills the model header values for orientation.
57   //! \param theValues a container of header text values
58   //! \param theOrientation an orientation of header
59   void SetHeaderValues (const QList<TreeModel_HeaderSection>& theValues, const Qt::Orientation theOrientation)
60   { myHeaderValues.insert (theOrientation, theValues); }
61
62   //! Returns whether the column is hidden by default
63   //! \param theColumnId a column index
64   //! \return header section values container
65   TreeModel_HeaderSection HeaderItem (const Qt::Orientation theOrientation, const int theColumnId) const
66   { return myHeaderValues.contains(theOrientation) ? myHeaderValues[theOrientation][theColumnId] : TreeModel_HeaderSection(); }
67
68   //! Stores information about table view header visibility
69   //! \param theOrientation an orientation of header
70   //! \param theVisibility if true, header is visible
71   void SetHeaderVisible (const Qt::Orientation theOrientation, const bool theVisibility)
72   { myVisibleHeader.insert (theOrientation, theVisibility); }
73
74   //! Stores information about table view header visibility
75   //! \param theOrientation an orientation of header
76   //! \param theVisibility if true, header is visible
77   bool IsHeaderVisible (const Qt::Orientation theOrientation) const
78   { return myVisibleHeader.contains(theOrientation) ? myVisibleHeader[theOrientation] : true; }
79
80   //! Get default section size if defined
81   //! \param theOrientation an orientation of header
82   //! \param theVisibility if true, header is visible
83   bool DefaultSectionSize (const Qt::Orientation theOrientation, int& theSectionSize)
84   {
85     theSectionSize = myDefaultSectionSize.contains (theOrientation) ? myDefaultSectionSize[theOrientation] : -1;
86     return myDefaultSectionSize.contains (theOrientation);
87   }
88
89   //! Set default section size if defined
90   //! \param theOrientation an orientation of header
91   //! \param theVisibility if true, header is visible
92   void SetDefaultSectionSize (const Qt::Orientation theOrientation, const int& theSectionSize)
93   { myDefaultSectionSize.insert(theOrientation, theSectionSize); }
94
95   //! Returns number of columns, size of header values
96   //! \param theParent an index of the parent item
97   //! \return an integer value
98   Standard_EXPORT virtual int ColumnCount (const QModelIndex& theParent = QModelIndex()) const;
99
100   //! Returns number of rows, depending on orientation: myColumnCount or size of values container
101   //! \param theParent an index of the parent item
102   //! \return an integer value
103   Standard_EXPORT virtual int RowCount (const QModelIndex& theParent = QModelIndex()) const;
104
105   //! Returns content of the model index for the given role, it is obtained from internal container of values
106   //! It returns value only for DisplayRole.
107   //! \param theRow a model index row
108   //! \param theColumn a model index column
109   //! \param theRole a view role
110   //! \return value intepreted depending on the given role
111   Standard_EXPORT virtual QVariant Data (const int theRow, const int theColumn, int theRole = Qt::DisplayRole) const;
112
113   //! Sets content of the model index for the given role, it is applied to internal container of values
114   //! \param theRow a model index row
115   //! \param theColumn a model index column
116   //! \param theRole a view role
117   //! \return true if the value is changed
118   Standard_EXPORT virtual bool SetData (const int theRow, const int theColumn, const QVariant& theValue,
119                                         int theRole = Qt::DisplayRole);
120
121   //! Returns content of the model index for the given role, it is obtainer from internal container of header values
122   //! It returns value only for DisplayRole.
123   //! \param theSection an index of value in the container 
124   //! \param theIndex a model index
125   //! \param theRole a view role
126   //! \return value intepreted depending on the given role
127   Standard_EXPORT virtual QVariant HeaderData (int theSection, Qt::Orientation theOrientation, int theRole = Qt::DisplayRole) const;
128
129   //! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable
130   //! \param theIndex a model index
131   //! \return flags
132   Standard_EXPORT virtual Qt::ItemFlags Flags (const QModelIndex& theIndex) const;
133
134   //! Returns type of edit control for the model index. By default, it is an empty control
135   //! \param theRow a model index row
136   //! \param theColumn a model index column
137   //! \return edit type
138   Standard_EXPORT virtual ViewControl_EditType EditType (const int theRow, const int theColumn) const;
139
140   //! Returns default color for editable cell
141   //! \return color value
142   static QColor EditCellColor() { return QColor (Qt::darkBlue); }
143
144 protected:
145   //! Returns true if the header item is italic of the parameter index
146   //! \param theRow a model index row
147   //! \param theColumn a model index column
148   //! \param boolean value
149   bool isItalicHeader (const int theRow, const int theColumn) const;
150
151 protected:
152
153   Qt::Orientation myOrientation; //!< orientation how the values should fill the current table view
154   QMap<Qt::Orientation, QList<TreeModel_HeaderSection> > myHeaderValues; //!< table header values
155   QMap<Qt::Orientation, bool> myVisibleHeader; //!< table header visibility
156   QMap<Qt::Orientation, int> myDefaultSectionSize; //!< table section default size
157
158   Handle(TreeModel_ItemProperties) myProperties; //!< item properties
159 };
160
161 #endif