0029025: TInspector include files are not installed to inc directory by CMake
[occt.git] / tools / DFBrowserPane / DFBrowserPane_AttributePaneModel.cxx
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
0cb512c0 16#include <inspector/DFBrowserPane_AttributePaneModel.hxx>
14bbbdcb 17
18// =======================================================================
19// function : Constructor
20// purpose :
21// =======================================================================
22DFBrowserPane_AttributePaneModel::DFBrowserPane_AttributePaneModel (QObject* theParent)
23: QAbstractTableModel (theParent), myOrientation (Qt::Vertical), myColumnCount (1)
24{
25}
26
27// =======================================================================
28// function : Init
29// purpose :
30// =======================================================================
31void DFBrowserPane_AttributePaneModel::Init (const QList<QVariant>& theValues)
32{
33 myValuesMap.clear();
34
35 if (myOrientation == Qt::Vertical)
36 {
37 int aRows = theValues.size() / myColumnCount;
38 QList<QVariant> aRowValues;
39 int aValuesIndex = 0;
40 for (int aRowId = 0; aRowId < aRows; aRowId++)
41 {
42 aRowValues.clear();
43 for (int aColumnId = 0; aColumnId < myColumnCount; aColumnId++)
44 {
45 aRowValues.append (theValues[aValuesIndex]);
46 aValuesIndex++;
47 }
48 myValuesMap[aRowId] = aRowValues;
49 }
50 }
51 else {
52 int aCols = theValues.size() / myColumnCount;
53 QList<QVariant> aColValues;
54 int aValuesIndex = 0;
55 for (int aColumnId = 0; aColumnId < aCols; aColumnId++)
56 {
57 aColValues.clear();
58 for (int aRowId = 0; aRowId < myColumnCount; aRowId++)
59 {
60 aColValues.append (theValues[aValuesIndex]);
61 aValuesIndex++;
62 }
63 myValuesMap[aColumnId] = aColValues;
64 }
65 }
66 emit layoutChanged();
67}
68
69// =======================================================================
70// function : SetHeaderValues
71// purpose :
72// =======================================================================
73void DFBrowserPane_AttributePaneModel::SetHeaderValues (const QList<QVariant>& theValues,
74 Qt::Orientation theOrientation)
75{
76 if (theOrientation == Qt::Horizontal)
77 myHorizontalHeaderValues = theValues;
78 else
79 myVerticalHeaderValues = theValues;
80}
81
82// =======================================================================
83// function : columnCount
84// purpose :
85// =======================================================================
86int DFBrowserPane_AttributePaneModel::columnCount (const QModelIndex&/* theParent*/) const
87{
88 return myOrientation == Qt::Vertical ? myColumnCount : myValuesMap.size();
89}
90
91// =======================================================================
92// function : rowCount
93// purpose :
94// =======================================================================
95int DFBrowserPane_AttributePaneModel::rowCount (const QModelIndex&/* theParent*/) const
96{
97 return myOrientation == Qt::Vertical ? myValuesMap.size() : myColumnCount;
98}
99
100// =======================================================================
101// function : data
102// purpose :
103// =======================================================================
104QVariant DFBrowserPane_AttributePaneModel::data (const QModelIndex& theIndex, int theRole) const
105{
106 QVariant aValue;
107
108 if (theRole == Qt::DisplayRole)
109 {
110 if (myOrientation == Qt::Vertical)
111 {
112 int aRowId = theIndex.row();
113 QList<QVariant> aRowValues = myValuesMap[aRowId];
114 aValue = aRowValues.at (theIndex.column());
115 }
116 else
117 {
118 int aColId = theIndex.column();
119 QList<QVariant> aColValues = myValuesMap[aColId];
120 aValue = aColValues.at (theIndex.row());
121 }
122 }
123 return aValue;
124}
125
126// =======================================================================
127// function : headerData
128// purpose :
129// =======================================================================
130QVariant DFBrowserPane_AttributePaneModel::headerData (int theSection, Qt::Orientation theOrientation,
131 int theRole) const
132{
133 QVariant aValue = QAbstractTableModel::headerData (theSection, theOrientation, theRole);
134 if (theRole == Qt::DisplayRole)
135 {
136 if (theOrientation == Qt::Horizontal)
137 {
138 if (!myHorizontalHeaderValues.empty() && theSection < myHorizontalHeaderValues.size())
139 aValue = myHorizontalHeaderValues[theSection];
140 }
141 else
142 { // vertical
143 if (!myVerticalHeaderValues.empty() && theSection < myVerticalHeaderValues.size())
144 aValue = myVerticalHeaderValues[theSection];
145 }
146 }
147 return aValue;
148}