0029559: Samples - wrong copyright statement in FuncDemo
[occt.git] / tools / TreeModel / TreeModel_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/TreeModel_ItemBase.hxx>
14bbbdcb 17
0cb512c0 18#include <inspector/TreeModel_ItemRole.hxx>
14bbbdcb 19
20#include <QStringList>
21
22// =======================================================================
23// function : Constructor
24// purpose :
25// =======================================================================
26TreeModel_ItemBase::TreeModel_ItemBase (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
27 : m_bInitialized (false)
28{
29 m_pParent = theParent;
30 m_iRow = theRow;
31 m_iColumn = theColumn;
32}
33
34// =======================================================================
35// function : reset
36// purpose :
37// =======================================================================
38void TreeModel_ItemBase::Reset()
39{
40 for (PositionToItemHash::const_iterator aChildrenIt = m_ChildItems.begin(); aChildrenIt != m_ChildItems.end(); aChildrenIt++)
41 {
42 TreeModel_ItemBasePtr anItem = aChildrenIt.value();
43 if (anItem)
44 anItem->Reset();
45 }
46 m_bInitialized = false;
47 mycachedValues.clear();
48
49}
50
51// =======================================================================
52// function : child
53// purpose :
54// =======================================================================
55TreeModel_ItemBasePtr TreeModel_ItemBase::Child (int theRow, int theColumn, const bool isToCreate)
56{
57 QPair<int, int> aPos = qMakePair (theRow, theColumn);
58
59 if (m_ChildItems.contains (aPos))
60 return m_ChildItems[aPos];
61
62 TreeModel_ItemBasePtr anItem;
63 if (isToCreate) {
64 anItem = createChild (theRow, theColumn);
65 if (anItem)
66 m_ChildItems[aPos] = anItem;
67 }
68 return anItem;
69}
70
71// =======================================================================
72// function : currentItem
73// purpose :
74// =======================================================================
75const TreeModel_ItemBasePtr TreeModel_ItemBase::currentItem()
76{
77 return TreeModel_ItemBasePtr (this);
78}
79
80// =======================================================================
81// function : cachedValue
82// purpose :
83// =======================================================================
84QVariant TreeModel_ItemBase::cachedValue (const int theItemRole) const
85{
86 if (mycachedValues.contains (theItemRole))
87 return mycachedValues[theItemRole];
88
89 const_cast<TreeModel_ItemBase*>(this)->mycachedValues.insert (theItemRole,
90 theItemRole == TreeModel_ItemRole_RowCountRole ? QVariant (initRowCount()) : initValue (theItemRole));
91
92 return mycachedValues.contains (theItemRole) ? mycachedValues[theItemRole] : QVariant();
93}