1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef DFBrowserPane_AttributePaneModel_H
17 #define DFBrowserPane_AttributePaneModel_H
19 #include <Standard.hxx>
20 #include <TDocStd_Document.hxx>
22 #include <Standard_WarningsDisable.hxx>
23 #include <QAbstractTableModel>
26 #include <Standard_WarningsRestore.hxx>
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.
34 class DFBrowserPane_AttributePaneModel : public QAbstractTableModel
39 Standard_EXPORT DFBrowserPane_AttributePaneModel(QObject* theParent = 0);
42 virtual ~DFBrowserPane_AttributePaneModel() {}
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 applied by rows, otherwise by columns
46 void SetOrientation (const Qt::Orientation& theOrientation) { myOrientation = theOrientation; }
48 //! Returns table orientation for setting data values
49 //! \return thye current orientation
50 Qt::Orientation GetOrientation() const { return myOrientation; }
52 //! Sets number of columns
53 //! \param theColumnCount a column count
54 void SetColumnCount (const int theColumnCount) { myColumnCount = theColumnCount; }
56 //! Fills the model with the values. Store the values in a cache.
57 //! \param theValues a container of values
58 Standard_EXPORT void Init (const QList<QVariant>& theValues);
60 //! Fills the model header values for orientation.
61 //! \param theValues a container of header text values
62 //! \param theOrientation an orientation of header
63 Standard_EXPORT void SetHeaderValues (const QList<QVariant>& theValues, Qt::Orientation theOrientation);
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; }
71 //! Returns indices of italic columns
72 //! \return indices of columns
73 const QList<int>& GetItalicColumns() const { return myItalicColumns; }
75 //! Sets indices of italic columns
76 //! \param theValues indices of columns
77 void SetItalicColumns (const QList<int>& theValues) { myItalicColumns = theValues; }
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
82 Standard_EXPORT virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
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
87 Standard_EXPORT virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE;
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 interpreted depending on the given role
94 Standard_EXPORT virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
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 interpreted depending on the given role
102 Standard_EXPORT virtual QVariant headerData (int theSection, Qt::Orientation theOrientation, int theRole = Qt::DisplayRole) const Standard_OVERRIDE;
104 //! Returns flags for the item: ItemIsEnabled | Qt::ItemIsSelectable
105 //! \param theIndex a model index
107 virtual Qt::ItemFlags flags (const QModelIndex& theIndex) const Standard_OVERRIDE
108 { return theIndex.isValid() ? Qt::ItemIsEnabled | Qt::ItemIsSelectable : Qt::NoItemFlags; }
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
117 QList<int> myItalicColumns; //!< indices of columns that should be visualized in gray and italic