0027398: Integrate Qt Browser Widget to Open CASCADE Technology
[occt.git] / tools / DFBrowserPane / DFBrowserPane_TDataStdRealArray.cxx
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 #include <DFBrowserPane_TDataStdRealArray.hxx>
17
18 #include <DFBrowserPane_AttributePaneModel.hxx>
19 #include <DFBrowserPane_HelperArray.hxx>
20 #include <DFBrowserPane_TableView.hxx>
21
22 #include <TDataStd_RealArray.hxx>
23
24 #include <QVariant>
25 #include <QWidget>
26
27 // =======================================================================
28 // function : CreateWidget
29 // purpose :
30 // =======================================================================
31 QWidget* DFBrowserPane_TDataStdRealArray::CreateWidget (QWidget* theParent)
32 {
33   QWidget* aMainWidget = new QWidget (theParent);
34   myTableView = new DFBrowserPane_TableView (aMainWidget);
35   myTableView->SetModel (getPaneModel());
36
37   myArrayTableHelper.CreateWidget (aMainWidget, myTableView);
38
39   return aMainWidget;
40 }
41
42 // =======================================================================
43 // function : Init
44 // purpose :
45 // =======================================================================
46 void DFBrowserPane_TDataStdRealArray::Init (const Handle(TDF_Attribute)& theAttribute)
47 {
48   QList<QVariant> aValues;
49   GetValues (theAttribute, aValues);
50   myArrayTableHelper.Init (aValues);
51 }
52
53 // =======================================================================
54 // function : GetValues
55 // purpose :
56 // =======================================================================
57 void DFBrowserPane_TDataStdRealArray::GetValues (const Handle(TDF_Attribute)& theAttribute, QList<QVariant>& theValues)
58 {
59   Handle(TDataStd_RealArray) anAttribute = Handle(TDataStd_RealArray)::DownCast (theAttribute);
60   if (anAttribute.IsNull())
61     return;
62   theValues.append (anAttribute->Lower());
63   theValues.append (anAttribute->Upper());
64   for (int aValueId = anAttribute->Lower(); aValueId <= anAttribute->Upper(); aValueId++)
65     theValues.append (anAttribute->Value(aValueId));
66 }
67
68 // =======================================================================
69 // function : GetShortAttributeInfo
70 // purpose :
71 // =======================================================================
72 void DFBrowserPane_TDataStdRealArray::GetShortAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
73                                                              QList<QVariant>& theValues)
74 {
75   QList<QVariant> aValues;
76   GetValues (theAttribute, aValues);
77   myArrayTableHelper.Init (aValues);
78   return myArrayTableHelper.GetShortAttributeInfo (theAttribute, theValues);
79 }