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