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/TreeModel_ItemBase.hxx>
17 #include <inspector/TreeModel_ItemProperties.hxx>
18 #include <inspector/TreeModel_ItemRole.hxx>
19 #include <inspector/TreeModel_ItemStream.hxx>
21 #include <Standard_Dump.hxx>
22 #include <Standard_WarningsDisable.hxx>
23 #include <QStringList>
24 #include <Standard_WarningsRestore.hxx>
26 // =======================================================================
27 // function : Constructor
29 // =======================================================================
30 TreeModel_ItemBase::TreeModel_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
31 : m_iStreamChildren (0), m_bInitialized (false)
33 m_pParent = theParent;
35 m_iColumn = theColumn;
38 // =======================================================================
41 // =======================================================================
42 void TreeModel_ItemBase::Reset()
44 for (PositionToItemHash::const_iterator aChildrenIt = m_ChildItems.begin(); aChildrenIt != m_ChildItems.end(); aChildrenIt++)
46 TreeModel_ItemBasePtr anItem = aChildrenIt.value();
50 m_bInitialized = false;
51 if (!myProperties.IsNull())
53 myProperties->Reset();
55 myCachedValues.clear();
59 // =======================================================================
62 // =======================================================================
63 void TreeModel_ItemBase::Reset (int theRole)
65 if (!myCachedValues.contains (theRole))
68 myCachedValues.remove (theRole);
71 // =======================================================================
74 // =======================================================================
75 TreeModel_ItemBasePtr TreeModel_ItemBase::Child (int theRow, int theColumn, const bool isToCreate)
77 QPair<int, int> aPos = qMakePair (theRow, theColumn);
79 if (m_ChildItems.contains (aPos))
80 return m_ChildItems[aPos];
82 TreeModel_ItemBasePtr anItem;
84 if (theRow < m_iStreamChildren)
85 anItem = TreeModel_ItemStream::CreateItem (currentItem(), theRow, theColumn);
87 anItem = createChild (theRow - m_iStreamChildren, theColumn);
90 m_ChildItems[aPos] = anItem;
95 // =======================================================================
96 // function : Presentations
98 // =======================================================================
99 void TreeModel_ItemBase::Presentations (NCollection_List<Handle(Standard_Transient)>& thePresentations)
104 const Handle(TreeModel_ItemProperties)& anItemProperties = Properties();
105 if (anItemProperties)
107 anItemProperties->Presentations (thePresentations);
111 // =======================================================================
112 // function : currentItem
114 // =======================================================================
115 const TreeModel_ItemBasePtr TreeModel_ItemBase::currentItem()
117 return TreeModel_ItemBasePtr (this);
120 // =======================================================================
121 // function : cachedValue
123 // =======================================================================
124 QVariant TreeModel_ItemBase::cachedValue (const int theItemRole) const
126 if (myCachedValues.contains (theItemRole))
127 return myCachedValues[theItemRole];
129 QVariant aValueToCache;
130 if (theItemRole == TreeModel_ItemRole_RowCountRole)
131 aValueToCache = initRowCount() + const_cast<TreeModel_ItemBase*>(this)->initStreamRowCount();
133 aValueToCache = initValue (theItemRole);
135 myCachedValues.insert (theItemRole, aValueToCache);
136 return myCachedValues.contains (theItemRole) ? myCachedValues[theItemRole] : QVariant();
139 // =======================================================================
142 // =======================================================================
143 void TreeModel_ItemBase::Init()
145 m_bInitialized = true;
147 initStream(myStream);
148 initStreamRowCount();
151 // =======================================================================
154 // =======================================================================
155 const Handle(Standard_Transient)& TreeModel_ItemBase::Object() const
157 static Handle(Standard_Transient) aNullObject;
161 // =======================================================================
162 // function : initStreamRowCount
164 // =======================================================================
165 int TreeModel_ItemBase::initStreamRowCount()
167 int aStreamChildrenCount = 0;
170 Standard_SStream aStream;
171 initStream (aStream);
172 if (!Standard_Dump::Text (aStream).IsEmpty())
176 myProperties = new TreeModel_ItemProperties();
177 myProperties->SetItem (currentItem());
179 myProperties->Init();
180 aStreamChildrenCount = myProperties->Children().Extent();
183 m_iStreamChildren = aStreamChildrenCount;
184 return m_iStreamChildren;
187 // =======================================================================
188 // function : initValue
190 // =======================================================================
191 QVariant TreeModel_ItemBase::initValue (const int theItemRole) const
193 if (theItemRole != Qt::DisplayRole && theItemRole != Qt::ToolTipRole)
198 case 1: { return Row(); }