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 #include <DFBrowserPane_AttributePane.hxx>
17 #include <DFBrowserPane_ItemRole.hxx>
18 #include <DFBrowserPane_TableView.hxx>
19 #include <DFBrowserPane_Tools.hxx>
20 #include <DFBrowserPane_AttributePaneModel.hxx>
22 #include <AIS_InteractiveObject.hxx>
24 #include <QGridLayout>
25 #include <QHeaderView>
26 #include <QItemSelectionModel>
30 //#define REQUIRE_OCAF_REVIEW:3 : start
32 // =======================================================================
33 // function : Constructor
35 // =======================================================================
36 DFBrowserPane_AttributePane::DFBrowserPane_AttributePane()
37 : DFBrowserPane_AttributePaneAPI(), myMainWidget (0), myTableView (0), myPaneModel (0)
39 myPaneModel = new DFBrowserPane_AttributePaneModel();
41 QList<QVariant> aHeaderValues;
42 aHeaderValues << "Values";
43 getPaneModel()->SetHeaderValues (aHeaderValues, Qt::Horizontal);
45 mySelectionModels.push_back (new QItemSelectionModel (myPaneModel));
48 // =======================================================================
49 // function : GetWidget
51 // =======================================================================
52 QWidget* DFBrowserPane_AttributePane::GetWidget (QWidget* theParent, const bool isToCreate)
54 if (!myMainWidget && isToCreate)
55 myMainWidget = CreateWidget (theParent);
59 // =======================================================================
60 // function : CreateWidget
62 // =======================================================================
63 QWidget* DFBrowserPane_AttributePane::CreateWidget (QWidget* theParent)
65 QWidget* aMainWidget = new QWidget (theParent);
66 aMainWidget->setVisible (false);
68 myTableView = new DFBrowserPane_TableView (aMainWidget, getTableColumnWidths());
69 myTableView->SetModel (myPaneModel);
70 QTableView* aTableView = myTableView->GetTableView();
71 aTableView->setSelectionModel (mySelectionModels.front());
72 aTableView->setSelectionBehavior (QAbstractItemView::SelectRows);
74 QGridLayout* aLay = new QGridLayout (aMainWidget);
75 aLay->setContentsMargins (0, 0, 0, 0);
76 aLay->addWidget (myTableView);
81 // =======================================================================
84 // =======================================================================
85 void DFBrowserPane_AttributePane::Init (const Handle(TDF_Attribute)& theAttribute)
87 QList<QVariant> aValues;
88 GetValues (theAttribute, aValues);
89 getPaneModel()->Init (aValues);
92 // =======================================================================
93 // function : GetAttributeInfo
95 // =======================================================================
96 QVariant DFBrowserPane_AttributePane::GetAttributeInfo (const Handle(TDF_Attribute)& theAttribute,
97 int theRole, int theColumnId)
101 case DFBrowserPane_ItemRole_ShortInfo:
103 QList<QVariant> aValues;
104 GetShortAttributeInfo (theAttribute, aValues);
105 QStringList anInfoList;
106 for (QList<QVariant>::const_iterator aValuesIt = aValues.begin(); aValuesIt != aValues.end(); aValuesIt++)
107 anInfoList.append (aValuesIt->toString());
108 return QVariant (anInfoList.join (", "));
111 return DFBrowserPane_AttributePane::GetAttributeInfoByType (theAttribute.IsNull() ? ""
112 : theAttribute->DynamicType()->Name(), theRole, theColumnId);
116 // =======================================================================
117 // function : GetAttributeInfoByType
119 // =======================================================================
120 QVariant DFBrowserPane_AttributePane::GetAttributeInfoByType (const Standard_CString& theAttributeName,
121 int theRole, int theColumnId)
123 if (theColumnId != 0)
128 case Qt::DisplayRole:
129 case Qt::ToolTipRole: return QVariant (theAttributeName);
130 case Qt::DecorationRole: return QIcon (":/icons/attribute.png");
131 case DFBrowserPane_ItemRole_Decoration_40x40: return QIcon (":/icons/attribute_40x40.png");
137 // =======================================================================
138 // function : getPaneModel
140 // =======================================================================
141 DFBrowserPane_AttributePaneModel* DFBrowserPane_AttributePane::getPaneModel() const
143 return dynamic_cast<DFBrowserPane_AttributePaneModel*> (myPaneModel);
146 // =======================================================================
147 // function : getTableColumnWidths
149 // =======================================================================
150 QMap<int, int> DFBrowserPane_AttributePane::getTableColumnWidths() const
152 QMap<int, int> aValues;
153 for (int aColumnId = 0, aCount = getPaneModel()->columnCount(); aColumnId < aCount; aColumnId++)
154 aValues.insert (aColumnId, DFBrowserPane_Tools::DefaultPanelColumnWidth (aColumnId));
157 //#define REQUIRE_OCAF_REVIEW:2 : end