0029559: Samples - wrong copyright statement in FuncDemo
[occt.git] / tools / DFBrowser / DFBrowser_ItemBase.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/DFBrowser_ItemBase.hxx>
14bbbdcb 17
0cb512c0 18#include <inspector/DFBrowser_Item.hxx>
19#include <inspector/DFBrowser_Module.hxx>
20#include <inspector/DFBrowser_Tools.hxx>
14bbbdcb 21
0cb512c0 22#include <inspector/DFBrowserPane_AttributePane.hxx>
23#include <inspector/DFBrowserPane_ItemRole.hxx>
24#include <inspector/DFBrowserPane_Tools.hxx>
14bbbdcb 25
26#include <TDataStd_Name.hxx>
27#include <TDF_ChildIterator.hxx>
28
29#include <QColor>
30#include <QIcon>
31#include <QVariant>
32
14bbbdcb 33// =======================================================================
34// function : Constructor
35// purpose :
36// =======================================================================
37DFBrowser_ItemBase::DFBrowser_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
38: TreeModel_ItemBase (theParent, theRow, theColumn), myModule (0), myIsUseAdditionalInfo (true)
39{
40}
41
42// =======================================================================
43// function : reset
44// purpose :
45// =======================================================================
46void DFBrowser_ItemBase::Reset()
47{
48 setLabel (TDF_Label());
49 TreeModel_ItemBase::Reset();
50}
51
52// =======================================================================
53// function : GetLabel
54// purpose :
55// =======================================================================
56TDF_Label DFBrowser_ItemBase::GetLabel() const
57{
58 initItem();
59 return myLabel;
60}
61
62// =======================================================================
63// function : data
64// purpose :
65// =======================================================================
66QVariant DFBrowser_ItemBase::data (const QModelIndex& theIndex, int theRole) const
67{
68 int aRole = theRole;
69 if (Column() == 0 && useAdditionalInfo())
70 {
71 switch (theRole)
72 {
73 case Qt::DisplayRole: { aRole = DFBrowserPane_ItemRole_DisplayExtended; break; }
74 case Qt::ToolTipRole: { aRole = DFBrowserPane_ItemRole_ToolTipExtended; break; }
75 }
76 }
77 return TreeModel_ItemBase::data (theIndex, aRole);
78}
79
80// =======================================================================
81// function : initRowCount
82// purpose :
83// =======================================================================
84int DFBrowser_ItemBase::initRowCount() const
85{
86 TDF_Label aLabel = GetLabel();
87 if (aLabel.IsNull())
88 return 0;
89
90 return aLabel.NbChildren() + aLabel.NbAttributes();
91}
92
93// =======================================================================
94// function : initValue
95// purpose :
96// =======================================================================
97QVariant DFBrowser_ItemBase::initValue (const int theItemRole) const
98{
99 switch (theItemRole)
100 {
101 case Qt::DisplayRole:
102 case Qt::EditRole:
103 case Qt::ToolTipRole:
104 return DFBrowser_Tools::GetLabelInfo (myLabel, false);
105 case DFBrowserPane_ItemRole_DisplayExtended:
106 case DFBrowserPane_ItemRole_ToolTipExtended:
107 return DFBrowser_Tools::GetLabelInfo (myLabel, true);
108 case Qt::ForegroundRole:
109 {
110 QVariant aValue = QColor (Qt::black);
111 if (DFBrowser_Tools::IsEmptyLabel(GetLabel()))
112 aValue = QColor (Qt::lightGray);
113 else
114 { //! TEMPORARY HERE : should be moved in the pane of TDataStd_Name kind of attribute
115 Handle(TDataStd_Name) aName;
116 if (useAdditionalInfo() && myLabel.FindAttribute (TDataStd_Name::GetID(), aName))
117 aValue = QColor (Qt::darkGreen);
118 }
119 return aValue;
120 }
121 case Qt::DecorationRole: return DFBrowser_Tools::GetLabelIcon (myLabel);
122 default: break;
123 }
124 return QVariant();
125}
126
127// =======================================================================
128// function : createChild
129// purpose :
130// =======================================================================
131TreeModel_ItemBasePtr DFBrowser_ItemBase::createChild (int theRow, int theColumn)
132{
133 TreeModel_ItemBasePtr anItem = DFBrowser_Item::CreateItem (currentItem(), theRow, theColumn);
134 DFBrowser_ItemBasePtr aBaseItem = itemDynamicCast<DFBrowser_ItemBase> (anItem);
135 aBaseItem->SetModule (GetModule());
136
137 return anItem;
138}
139
140// =======================================================================
141// function : SetUseAdditionalInfo
142// purpose :
143// =======================================================================
144bool DFBrowser_ItemBase::SetUseAdditionalInfo (const bool theValue)
145{
146 bool aPreviousValue = myIsUseAdditionalInfo;
147 myIsUseAdditionalInfo = theValue;
148 return aPreviousValue;
149}
150