0029018: Documentation - Provide user guide for Qt browser
[occt.git] / tools / DFBrowserPane / DFBrowserPane_TDataStdReferenceArray.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_TDataStdReferenceArray.hxx>
14bbbdcb 17
0cb512c0 18#include <inspector/DFBrowserPane_AttributePaneModel.hxx>
19#include <inspector/DFBrowserPane_HelperArray.hxx>
20#include <inspector/DFBrowserPane_TableView.hxx>
21#include <inspector/DFBrowserPane_Tools.hxx>
14bbbdcb 22
23#include <TDataStd_ReferenceArray.hxx>
24
25#include <QGridLayout>
26#include <QItemSelectionModel>
27#include <QTableView>
28#include <QVariant>
29#include <QWidget>
30
14bbbdcb 31// =======================================================================
32// function : CreateWidget
33// purpose :
34// =======================================================================
35QWidget* DFBrowserPane_TDataStdReferenceArray::CreateWidget (QWidget* theParent)
36{
37 QWidget* aMainWidget = new QWidget (theParent);
38 myTableView = new DFBrowserPane_TableView (aMainWidget);
39 myTableView->SetModel (getPaneModel());
40 myTableView->GetTableView()->setSelectionModel (mySelectionModels.front());
41
42 myArrayTableHelper.CreateWidget (aMainWidget, myTableView);
43
44 return aMainWidget;
45}
46
47// =======================================================================
48// function : Init
49// purpose :
50// =======================================================================
51void DFBrowserPane_TDataStdReferenceArray::Init (const Handle(TDF_Attribute)& theAttribute)
52{
53 QList<QVariant> aValues;
54 GetValues (theAttribute, aValues);
55 myArrayTableHelper.Init (aValues);
56}
57
58// =======================================================================
59// function : GetValues
60// purpose :
61// =======================================================================
62void DFBrowserPane_TDataStdReferenceArray::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
63{
64 Handle(TDataStd_ReferenceArray) anAttribute = Handle(TDataStd_ReferenceArray)::DownCast (theAttribute);
65 if (anAttribute.IsNull())
66 return;
67
68 theValues.append (anAttribute->Lower());
69 theValues.append (anAttribute->Upper());
70 for (int aValueId = anAttribute->Lower(); aValueId <= anAttribute->Upper(); aValueId++)
71 theValues.append (DFBrowserPane_Tools::GetEntry (anAttribute->Value(aValueId)).ToCString());
72}
73
74// =======================================================================
75// function : GetShortAttributeInfo
76// purpose :
77// =======================================================================
78void DFBrowserPane_TDataStdReferenceArray::GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
79 QList<QVariant>& theValues)
80{
81 QList<QVariant> aValues;
82 GetValues (theAttribute, aValues);
83 myArrayTableHelper.Init (aValues);
84 return myArrayTableHelper.GetShortAttributeInfo (theAttribute, theValues);
85}
86
87// =======================================================================
88// function : GetReferences
89// purpose :
90// =======================================================================
91void DFBrowserPane_TDataStdReferenceArray::GetReferences (const Handle(TDF_Attribute)& theAttribute,
92 NCollection_List<TDF_Label>& theRefLabels,
93 Handle(Standard_Transient)& /*theRefPresentation*/)
94{
95 if (!getTableView())
96 return;
d2c90917 97 QStringList aSelectedEntries = DFBrowserPane_TableView::GetSelectedColumnValues (getTableView()->GetTableView(), 1);
14bbbdcb 98
99 Handle(TDataStd_ReferenceArray) anAttribute = Handle(TDataStd_ReferenceArray)::DownCast (theAttribute);
100 if (anAttribute.IsNull())
101 return;
102
103 for (int aValueId = anAttribute->Lower(); aValueId <= anAttribute->Upper(); aValueId++)
104 {
105 TDF_Label aLabel = anAttribute->Value (aValueId);
106 if (aSelectedEntries.contains (DFBrowserPane_Tools::GetEntry (aLabel).ToCString()))
107 theRefLabels.Append (aLabel);
108 }
109}