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_ItemRole.hxx>
19 #include <Standard_WarningsDisable.hxx>
20 #include <QStringList>
21 #include <Standard_WarningsRestore.hxx>
23 // =======================================================================
24 // function : Constructor
26 // =======================================================================
27 TreeModel_ItemBase::TreeModel_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
28 : m_bInitialized (false)
30 m_pParent = theParent;
32 m_iColumn = theColumn;
35 // =======================================================================
38 // =======================================================================
39 void TreeModel_ItemBase::Reset()
41 for (PositionToItemHash::const_iterator aChildrenIt = m_ChildItems.begin(); aChildrenIt != m_ChildItems.end(); aChildrenIt++)
43 TreeModel_ItemBasePtr anItem = aChildrenIt.value();
47 m_bInitialized = false;
48 mycachedValues.clear();
52 // =======================================================================
55 // =======================================================================
56 TreeModel_ItemBasePtr TreeModel_ItemBase::Child (int theRow, int theColumn, const bool isToCreate)
58 QPair<int, int> aPos = qMakePair (theRow, theColumn);
60 if (m_ChildItems.contains (aPos))
61 return m_ChildItems[aPos];
63 TreeModel_ItemBasePtr anItem;
65 anItem = createChild (theRow, theColumn);
67 m_ChildItems[aPos] = anItem;
72 // =======================================================================
73 // function : currentItem
75 // =======================================================================
76 const TreeModel_ItemBasePtr TreeModel_ItemBase::currentItem()
78 return TreeModel_ItemBasePtr (this);
81 // =======================================================================
82 // function : cachedValue
84 // =======================================================================
85 QVariant TreeModel_ItemBase::cachedValue (const int theItemRole) const
87 if (mycachedValues.contains (theItemRole))
88 return mycachedValues[theItemRole];
90 const_cast<TreeModel_ItemBase*>(this)->mycachedValues.insert (theItemRole,
91 theItemRole == TreeModel_ItemRole_RowCountRole ? QVariant (initRowCount()) : initValue (theItemRole));
93 return mycachedValues.contains (theItemRole) ? mycachedValues[theItemRole] : QVariant();