0029310: Coding - multiple compiler warnings in Inspectors
[occt.git] / tools / DFBrowserPane / DFBrowserPane_AttributePane.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_AttributePane.hxx>
17#include <inspector/DFBrowserPane_ItemRole.hxx>
18#include <inspector/DFBrowserPane_TableView.hxx>
19#include <inspector/DFBrowserPane_Tools.hxx>
20#include <inspector/DFBrowserPane_AttributePaneModel.hxx>
14bbbdcb 21
22#include <AIS_InteractiveObject.hxx>
23
130eb114 24#include <Standard_WarningsDisable.hxx>
14bbbdcb 25#include <QGridLayout>
26#include <QHeaderView>
27#include <QItemSelectionModel>
28#include <QTableView>
29#include <QWidget>
130eb114 30#include <Standard_WarningsRestore.hxx>
14bbbdcb 31
14bbbdcb 32// =======================================================================
33// function : Constructor
34// purpose :
35// =======================================================================
36DFBrowserPane_AttributePane::DFBrowserPane_AttributePane()
d2c90917 37: DFBrowserPane_AttributePaneAPI(), myMainWidget (0), myTableView (0)
14bbbdcb 38{
39 myPaneModel = new DFBrowserPane_AttributePaneModel();
40
d2c90917 41 getPaneModel()->SetColumnCount (getColumnCount());
42 getPaneModel()->SetHeaderValues (getHeaderValues(Qt::Horizontal), Qt::Horizontal);
14bbbdcb 43
44 mySelectionModels.push_back (new QItemSelectionModel (myPaneModel));
45}
46
47// =======================================================================
48// function : GetWidget
49// purpose :
50// =======================================================================
51QWidget* DFBrowserPane_AttributePane::GetWidget (QWidget* theParent, const bool isToCreate)
52{
53 if (!myMainWidget && isToCreate)
54 myMainWidget = CreateWidget (theParent);
55 return myMainWidget;
56}
57
58// =======================================================================
59// function : CreateWidget
60// purpose :
61// =======================================================================
62QWidget* DFBrowserPane_AttributePane::CreateWidget (QWidget* theParent)
63{
64 QWidget* aMainWidget = new QWidget (theParent);
65 aMainWidget->setVisible (false);
66
67 myTableView = new DFBrowserPane_TableView (aMainWidget, getTableColumnWidths());
68 myTableView->SetModel (myPaneModel);
69 QTableView* aTableView = myTableView->GetTableView();
d2c90917 70 DFBrowserPane_AttributePaneModel* aPaneModel = dynamic_cast<DFBrowserPane_AttributePaneModel*>(myPaneModel);
71 if (aPaneModel)
72 {
73 if (aPaneModel->GetOrientation() == Qt::Vertical)
74 aTableView->horizontalHeader()->setVisible (!aPaneModel->HeaderValues (Qt::Horizontal).isEmpty());
75 else
76 aTableView->verticalHeader()->setVisible (!aPaneModel->HeaderValues (Qt::Vertical).isEmpty());
77 }
14bbbdcb 78 aTableView->setSelectionModel (mySelectionModels.front());
79 aTableView->setSelectionBehavior (QAbstractItemView::SelectRows);
80
81 QGridLayout* aLay = new QGridLayout (aMainWidget);
82 aLay->setContentsMargins (0, 0, 0, 0);
83 aLay->addWidget (myTableView);
84
85 return aMainWidget;
86}
87
88// =======================================================================
89// function : Init
90// purpose :
91// =======================================================================
92void DFBrowserPane_AttributePane::Init (const Handle(TDF_Attribute)& theAttribute)
93{
94 QList<QVariant> aValues;
95 GetValues (theAttribute, aValues);
96 getPaneModel()->Init (aValues);
d2c90917 97
98 if (myTableView)
99 myTableView->GetTableView()->resizeColumnToContents (0);
14bbbdcb 100}
101
102// =======================================================================
103// function : GetAttributeInfo
104// purpose :
105// =======================================================================
106QVariant DFBrowserPane_AttributePane::GetAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
107 int theRole, int theColumnId)
108{
109 switch (theRole)
110 {
111 case DFBrowserPane_ItemRole_ShortInfo:
112 {
113 QList<QVariant> aValues;
114 GetShortAttributeInfo (theAttribute, aValues);
115 QStringList anInfoList;
116 for (QList<QVariant>::const_iterator aValuesIt = aValues.begin(); aValuesIt != aValues.end(); aValuesIt++)
117 anInfoList.append (aValuesIt->toString());
118 return QVariant (anInfoList.join (", "));
119 }
120 default:
121 return DFBrowserPane_AttributePane::GetAttributeInfoByType (theAttribute.IsNull() ? ""
122 : theAttribute->DynamicType()->Name(), theRole, theColumnId);
123 }
124}
125
d2c90917 126// =======================================================================
127// function : GetShortAttributeInfo
128// purpose :
129// =======================================================================
130void DFBrowserPane_AttributePane::GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
131{
132 QList<QVariant> aValues;
133 GetValues(theAttribute, aValues);
134
135 for (int aValuesEvenId = 1; aValuesEvenId < aValues.size(); aValuesEvenId = aValuesEvenId + 2)
136 theValues.append (aValues[aValuesEvenId]);
137}
138
14bbbdcb 139// =======================================================================
140// function : GetAttributeInfoByType
141// purpose :
142// =======================================================================
143QVariant DFBrowserPane_AttributePane::GetAttributeInfoByType (const Standard_CString& theAttributeName,
144 int theRole, int theColumnId)
145{
146 if (theColumnId != 0)
147 return QVariant();
148
149 switch (theRole)
150 {
151 case Qt::DisplayRole:
152 case Qt::ToolTipRole: return QVariant (theAttributeName);
153 case Qt::DecorationRole: return QIcon (":/icons/attribute.png");
154 case DFBrowserPane_ItemRole_Decoration_40x40: return QIcon (":/icons/attribute_40x40.png");
155 default: break;
156 }
157 return QVariant();
158}
159
160// =======================================================================
161// function : getPaneModel
162// purpose :
163// =======================================================================
164DFBrowserPane_AttributePaneModel* DFBrowserPane_AttributePane::getPaneModel() const
165{
166 return dynamic_cast<DFBrowserPane_AttributePaneModel*> (myPaneModel);
167}
168
169// =======================================================================
170// function : getTableColumnWidths
171// purpose :
172// =======================================================================
173QMap<int, int> DFBrowserPane_AttributePane::getTableColumnWidths() const
174{
175 QMap<int, int> aValues;
176 for (int aColumnId = 0, aCount = getPaneModel()->columnCount(); aColumnId < aCount; aColumnId++)
177 aValues.insert (aColumnId, DFBrowserPane_Tools::DefaultPanelColumnWidth (aColumnId));
178 return aValues;
179}