0029807: [Regression to 7.0.0] Impossible to cut cone from prism
[occt.git] / tools / VInspector / VInspector_ItemHistoryRoot.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/VInspector_ItemHistoryRoot.hxx>
14bbbdcb 17
0cb512c0 18#include <inspector/VInspector_ItemHistoryType.hxx>
14bbbdcb 19
20// =======================================================================
21// function : Constructor
22// purpose :
23// =======================================================================
24VInspector_ItemHistoryRoot::VInspector_ItemHistoryRoot(TreeModel_ItemBasePtr theParent,
25 const int theRow, const int theColumn)
26: VInspector_ItemBase (theParent, theRow, theColumn), myFirstIndex (0), myLastIndex (0), myInfoMaxSize (10)
27{
28}
29
30// =======================================================================
31// function : AddElement
32// purpose :
33// =======================================================================
34void VInspector_ItemHistoryRoot::AddElement (const VInspector_CallBackMode& theMode, const QList<QVariant>& theInfo)
35{
36 if (!myLastIndex)
37 {
38 myInfoMap[myLastIndex] = VInspector_ItemHistoryTypeInfo(theMode, theInfo);
39 myLastIndex++;
40 }
41 else
42 {
43 if (myInfoMap[myLastIndex].myMode == theMode)
44 myInfoMap[myLastIndex].AddElement(theInfo);
45 else
46 {
47 myLastIndex++;
48 myInfoMap[myLastIndex] = VInspector_ItemHistoryTypeInfo(theMode, theInfo);
49 }
50 }
51
52 // clear cache
53 if (myInfoMap.size() >= myInfoMaxSize)
54 {
55 myInfoMap.remove (myFirstIndex);
56 myFirstIndex++;
57 }
58}
59
60// =======================================================================
61// function : GetTypeInfo
62// purpose :
63// =======================================================================
64const VInspector_ItemHistoryTypeInfo& VInspector_ItemHistoryRoot::GetTypeInfo (const int theChildRowIndex)
65{
66 int anInfoMapIndex = theChildRowIndex + myFirstIndex;
67 return myInfoMap[anInfoMapIndex];
68}
69
70// =======================================================================
71// function : initValue
72// purpose :
73// =======================================================================
74QVariant VInspector_ItemHistoryRoot::initValue (const int theRole) const
75{
76 if (theRole != Qt::DisplayRole && theRole != Qt::EditRole && theRole != Qt::ToolTipRole)
77 return QVariant();
78
79 switch (Column())
80 {
81 case 0: return "History";
82 case 1: return theRole == Qt::ToolTipRole ? QVariant ("Count of children") : QVariant (rowCount());
83 default:
84 break;
85 }
86 return QVariant();
87}
88
89// =======================================================================
90// function : createChild
91// purpose :
92// =======================================================================
93TreeModel_ItemBasePtr VInspector_ItemHistoryRoot::createChild (int theRow, int theColumn)
94{
95 return VInspector_ItemHistoryType::CreateItem (currentItem(), theRow, theColumn);
96}
97