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_Item.hxx>
18 #include <inspector/DFBrowser_ItemRole.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 <TDF_AttributeIterator.hxx>
27 #include <TDF_ChildIterator.hxx>
32 const int INFO_LENGHT = 60;
34 // =======================================================================
35 // function : hasAttribute
37 // =======================================================================
38 bool DFBrowser_Item::HasAttribute() const
41 return myAttributeGUID != Standard_GUID();
44 // =======================================================================
45 // function : getAttribute
47 // =======================================================================
48 Handle(TDF_Attribute) DFBrowser_Item::GetAttribute() const
51 Handle(TDF_Attribute) anAttribute;
52 GetLabel().FindAttribute (myAttributeGUID, anAttribute);
56 // =======================================================================
59 // =======================================================================
60 void DFBrowser_Item::Init()
62 DFBrowser_ItemBasePtr aParentItem = itemDynamicCast<DFBrowser_ItemBase> (Parent());
65 TDF_Label aParentLabel = aParentItem->GetLabel();
66 // items can exist only by items with not empty label
67 if (aParentLabel.IsNull())
70 int aNbAttributes = aParentLabel.NbAttributes();
72 if (aRowId < aNbAttributes)
74 Handle(TDF_Attribute) anAttribute;
75 int anAttributeId = 0;
76 for (TDF_AttributeIterator anAttrIt (aParentLabel); anAttrIt.More(); anAttrIt.Next(), anAttributeId++)
78 if (anAttributeId == aRowId)
79 anAttribute = anAttrIt.Value();
81 SetAttribute (anAttribute);
84 int aCurrentId = aRowId - aNbAttributes;
85 TDF_ChildIterator aLabelsIt (aParentLabel);
87 for (int aLabelId = 0; aLabelsIt.More(); aLabelsIt.Next(), aLabelId++)
89 if (aLabelId < aCurrentId)
91 aLabel = aLabelsIt.Value();
97 TreeModel_ItemBase::Init();
100 // =======================================================================
103 // =======================================================================
104 void DFBrowser_Item::Reset()
106 SetAttribute (Handle(TDF_Attribute)());
108 DFBrowser_ItemBase::Reset();
111 // =======================================================================
112 // function : initRowCount
114 // =======================================================================
115 int DFBrowser_Item::initRowCount() const
117 return HasAttribute() ? 0 : DFBrowser_ItemBase::initRowCount();
120 // =======================================================================
121 // function : initValue
123 // =======================================================================
124 QVariant DFBrowser_Item::initValue (const int theItemRole) const
127 return DFBrowser_ItemBase::initValue (theItemRole);
129 if (theItemRole == DFBrowserPane_ItemRole_DisplayExtended || theItemRole == DFBrowserPane_ItemRole_ToolTipExtended)
131 int aRole = theItemRole == DFBrowserPane_ItemRole_DisplayExtended ? Qt::DisplayRole : Qt::ToolTipRole;
132 QVariant aValue = DFBrowser_Module::GetAttributeInfo (GetAttribute(), GetModule(), aRole, Column());
133 QString anAdditionalInfo = DFBrowser_Module::GetAttributeInfo (GetAttribute(), GetModule(),
134 DFBrowser_ItemRole_AdditionalInfo, Column()).toString();
135 if (!anAdditionalInfo.isEmpty())
137 if (theItemRole == DFBrowserPane_ItemRole_DisplayExtended && anAdditionalInfo.length() > INFO_LENGHT)
138 anAdditionalInfo = anAdditionalInfo.mid (0, INFO_LENGHT - 3) + "...";
139 if (!anAdditionalInfo.isEmpty())
140 aValue = QVariant (aValue.toString() + QString (" [%1]").arg (anAdditionalInfo));
141 //if (aRole == Qt::ToolTipRole)
142 // aValue = wrapTextByWords(aValue.toString().toStdString(), INFO_LENGHT).c_str();
147 return DFBrowser_Module::GetAttributeInfo (GetAttribute(), GetModule(), theItemRole, Column());
150 // =======================================================================
151 // function : GetAttributeInfo
153 // =======================================================================
154 QVariant DFBrowser_Item::GetAttributeInfo (int theRole) const
157 return cachedValue (theRole);
160 // =======================================================================
161 // function : initItem
163 // =======================================================================
164 void DFBrowser_Item::initItem() const
169 const_cast<DFBrowser_Item*>(this)->Init();
172 // =======================================================================
173 // function : SetAttribute
175 // =======================================================================
176 void DFBrowser_Item::SetAttribute (Handle(TDF_Attribute) theAttribute)
178 if (!theAttribute.IsNull())
180 setLabel (theAttribute->Label());
181 myAttributeGUID = theAttribute->ID();
185 setLabel (TDF_Label());
186 myAttributeGUID = Standard_GUID();