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 <inspector/DFBrowser_ItemBase.hxx>
18 #include <inspector/DFBrowser_Item.hxx>
19 #include <inspector/DFBrowser_Module.hxx>
20 #include <inspector/DFBrowser_Tools.hxx>
22 #include <inspector/DFBrowserPane_AttributePane.hxx>
23 #include <inspector/DFBrowserPane_ItemRole.hxx>
24 #include <inspector/DFBrowserPane_Tools.hxx>
26 #include <TDataStd_Name.hxx>
27 #include <TDF_ChildIterator.hxx>
29 #include <Standard_WarningsDisable.hxx>
33 #include <Standard_WarningsRestore.hxx>
35 // =======================================================================
36 // function : Constructor
38 // =======================================================================
39 DFBrowser_ItemBase::DFBrowser_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
40 : TreeModel_ItemBase (theParent, theRow, theColumn), myModule (0), myIsUseAdditionalInfo (true)
44 // =======================================================================
47 // =======================================================================
48 void DFBrowser_ItemBase::Reset()
50 setLabel (TDF_Label());
51 TreeModel_ItemBase::Reset();
54 // =======================================================================
55 // function : GetLabel
57 // =======================================================================
58 TDF_Label DFBrowser_ItemBase::GetLabel() const
64 // =======================================================================
67 // =======================================================================
68 QVariant DFBrowser_ItemBase::data (const QModelIndex& theIndex, int theRole) const
71 if (Column() == 0 && useAdditionalInfo())
75 case Qt::DisplayRole: { aRole = DFBrowserPane_ItemRole_DisplayExtended; break; }
76 case Qt::ToolTipRole: { aRole = DFBrowserPane_ItemRole_ToolTipExtended; break; }
79 return TreeModel_ItemBase::data (theIndex, aRole);
82 // =======================================================================
83 // function : initRowCount
85 // =======================================================================
86 int DFBrowser_ItemBase::initRowCount() const
88 TDF_Label aLabel = GetLabel();
92 return aLabel.NbChildren() + aLabel.NbAttributes();
95 // =======================================================================
96 // function : initValue
98 // =======================================================================
99 QVariant DFBrowser_ItemBase::initValue (const int theItemRole) const
103 case Qt::DisplayRole:
105 case Qt::ToolTipRole:
106 return DFBrowser_Tools::GetLabelInfo (myLabel, false);
107 case DFBrowserPane_ItemRole_DisplayExtended:
108 case DFBrowserPane_ItemRole_ToolTipExtended:
109 return DFBrowser_Tools::GetLabelInfo (myLabel, true);
110 case Qt::ForegroundRole:
112 QVariant aValue = QColor (Qt::black);
113 if (DFBrowser_Tools::IsEmptyLabel(GetLabel()))
114 aValue = QColor (Qt::lightGray);
116 { // TEMPORARY HERE : should be moved in the pane of TDataStd_Name kind of attribute
117 Handle(TDataStd_Name) aName;
118 if (useAdditionalInfo() && myLabel.FindAttribute (TDataStd_Name::GetID(), aName))
119 aValue = QColor (Qt::darkGreen);
123 case Qt::DecorationRole: return DFBrowser_Tools::GetLabelIcon (myLabel);
129 // =======================================================================
130 // function : createChild
132 // =======================================================================
133 TreeModel_ItemBasePtr DFBrowser_ItemBase::createChild (int theRow, int theColumn)
135 TreeModel_ItemBasePtr anItem = DFBrowser_Item::CreateItem (currentItem(), theRow, theColumn);
136 DFBrowser_ItemBasePtr aBaseItem = itemDynamicCast<DFBrowser_ItemBase> (anItem);
137 aBaseItem->SetModule (GetModule());
142 // =======================================================================
143 // function : SetUseAdditionalInfo
145 // =======================================================================
146 bool DFBrowser_ItemBase::SetUseAdditionalInfo (const bool theValue)
148 bool aPreviousValue = myIsUseAdditionalInfo;
149 myIsUseAdditionalInfo = theValue;
150 return aPreviousValue;