0029571: Samples: build qt samples together with OCCT
[occt.git] / tools / DFBrowserPane / DFBrowserPane_AttributePaneModel.hxx
CommitLineData
14bbbdcb 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 DFBrowserPane_AttributePaneModel_H
17#define DFBrowserPane_AttributePaneModel_H
18
19#include <Standard.hxx>
20#include <TDocStd_Document.hxx>
21
130eb114 22#include <Standard_WarningsDisable.hxx>
14bbbdcb 23#include <QAbstractTableModel>
24#include <QList>
25#include <QVariant>
130eb114 26#include <Standard_WarningsRestore.hxx>
14bbbdcb 27
28//! \class DFBrowserPane_AttributePaneModel
29//! \brief This is an extension of table model to visualize a container of values
30//! It is possible to:
31//! - set orientation to interpretate the values.
32//! - set table view header values.
33//! Items of the view are enabled and selectable.
34class DFBrowserPane_AttributePaneModel : public QAbstractTableModel
35{
36public:
37
38 //! Constructor
39 Standard_EXPORT DFBrowserPane_AttributePaneModel(QObject* theParent = 0);
40
41 //! Destructor
42 virtual ~DFBrowserPane_AttributePaneModel() {}
43
44 //! Sets direction of the values applying, whether it should be placed by rows or by columns
45 //! \param theOrientation if horizontal, the values are applyed by rows, otherwise by columns
46 void SetOrientation (const Qt::Orientation& theOrientation) { myOrientation = theOrientation; }
47
d2c90917 48 //! Returns table orientation for setting data values
49 //! \return thye current orientation
50 Qt::Orientation GetOrientation() const { return myOrientation; }
51
14bbbdcb 52 //! Sets number of columns
53 //! \param theColumnCount a column count
54 void SetColumnCount (const int theColumnCount) { myColumnCount = theColumnCount; }
55
56 //! Fills the model with the values. Store the values in a cache.
57 //! \param theValues a container of values
d2c90917 58 Standard_EXPORT void Init (const QList<QVariant>& theValues);
14bbbdcb 59
60 //! Fills the model header values for orientation.
61 //! \param theValues a container of header text values
62 //! \param theOrientation an orientation of header
d2c90917 63 Standard_EXPORT void SetHeaderValues (const QList<QVariant>& theValues, Qt::Orientation theOrientation);
64
65 //! Returns header values for orientation.
66 //! \param theValues a container of header text values
67 //! \param theOrientation an orientation of header
68 const QList<QVariant>& HeaderValues (Qt::Orientation theOrientation)
69 { return theOrientation == Qt::Horizontal ? myHorizontalHeaderValues : myVerticalHeaderValues; }
70
71 //! Returns indices of italic columns
72 //! \return indices of columns
73 const QList<int>& GetItalicColumns() const { return myItalicColumns; }
74
75 //! Sets indices of italic columns
76 //! \param theValues indices of columns
77 void SetItalicColumns (const QList<int>& theValues) { myItalicColumns = theValues; }
14bbbdcb 78
79 //! Returns number of columns, depending on orientation: myColumnCount or size of values container
80 //! \param theParent an index of the parent item
81 //! \return an integer value
d2c90917 82 Standard_EXPORT virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
14bbbdcb 83
84 //! Returns number of rows, depending on orientation: myColumnCount or size of values container
85 //! \param theParent an index of the parent item
86 //! \return an integer value
d2c90917 87 Standard_EXPORT virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
14bbbdcb 88
89 //! Returns content of the model index for the given role, it is obtained from internal container of values
90 //! It returns value only for DisplayRole.
91 //! \param theIndex a model index
92 //! \param theRole a view role
93 //! \return value intepreted depending on the given role
d2c90917 94 Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
14bbbdcb 95
96 //! Returns content of the model index for the given role, it is obtainer from internal container of header values
97 //! It returns value only for DisplayRole.
98 //! \param theSection an index of value in the container
99 //! \param theIndex a model index
100 //! \param theRole a view role
101 //! \return value intepreted depending on the given role
d2c90917 102 Standard_EXPORT virtual QVariant headerData (int theSection, Qt::Orientation theOrientation, int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
14bbbdcb 103
104 //! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable
105 //! \param theIndex a model index
106 //! \return flags
107 Qt::ItemFlags flags (const QModelIndex& theIndex) const
108 { return theIndex.isValid() ? Qt::ItemIsEnabled | Qt::ItemIsSelectable : Qt::NoItemFlags; }
109
110private:
111
112 Qt::Orientation myOrientation; //!< orientation how the values should fill the current table view
113 int myColumnCount; //!< number of table columns
114 QMap< int, QList<QVariant> > myValuesMap; //!< container of values, filled in Init(), used in data()
115 QList<QVariant> myHorizontalHeaderValues; //!< table horizontal header values
116 QList<QVariant> myVerticalHeaderValues; //!< table vertical header values
d2c90917 117 QList<int> myItalicColumns; //!< indices of columns that should be visualized in gray and italic
118
14bbbdcb 119};
120
121#endif