1 // Created on: 2020-01-25
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2020 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
16 #include <inspector/TreeModel_ItemStream.hxx>
17
18 #include <inspector/TreeModel_ItemProperties.hxx>
19
20 #include <Standard_Dump.hxx>
21
22 // =======================================================================
23 // function : Constructor
24 // purpose :
25 // =======================================================================
TreeModel_ItemStream(TreeModel_ItemBasePtr theParent,const int theRow,const int theColumn)26 TreeModel_ItemStream::TreeModel_ItemStream (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
27 : TreeModel_ItemBase (theParent, theRow, theColumn)
28 {
29 }
30
31 // =======================================================================
32 // function : Init
33 // purpose :
34 // =======================================================================
Init()35 void TreeModel_ItemStream::Init()
36 {
37 TreeModel_ItemBase::Init();
38
39 int aStreamChildrenCount = 0;
40 if (Column() == 0)
41 {
42 if (!myProperties)
43 {
44 myProperties = new TreeModel_ItemProperties();
45 myProperties->SetItem (currentItem());
46 }
47 myProperties->Init();
48 aStreamChildrenCount = myProperties->Children().Extent();
49 }
50 m_iStreamChildren = aStreamChildrenCount;
51 initStream (myStream);
52 }
53
54 // =======================================================================
55 // function : Rest
56 // purpose :
57 // =======================================================================
Reset()58 void TreeModel_ItemStream::Reset()
59 {
60 myStream.str ("");
61 TreeModel_ItemBase::Reset();
62 }
63
64 // =======================================================================
65 // function : initValue
66 // purpose :
67 // =======================================================================
initValue(const int theItemRole) const68 QVariant TreeModel_ItemStream::initValue (const int theItemRole) const
69 {
70 QVariant aParentValue = TreeModel_ItemBase::initValue (theItemRole);
71 if (aParentValue.isValid())
72 return aParentValue;
73
74 if (Column() != 0)
75 return QVariant();
76
77 if (theItemRole == Qt::ForegroundRole)
78 return QColor (Qt::darkBlue);
79
80 if (theItemRole != Qt::DisplayRole && theItemRole != Qt::EditRole && theItemRole != Qt::ToolTipRole)
81 return QVariant();
82
83 switch (Column())
84 {
85 case 0: return Properties() ? Properties()->Key().ToCString() : "";
86 }
87 return QVariant();
88 }
89
90 // =======================================================================
91 // function : StoreItemProperties
92 // purpose :
93 // =======================================================================
StoreItemProperties(const int,const int,const QVariant & theValue)94 void TreeModel_ItemStream::StoreItemProperties (const int, const int, const QVariant& theValue)
95 {
96 Parent()->StoreItemProperties (-1, -1, theValue);
97 }
98
99 // =======================================================================
100 // function : initStream
101 // purpose :
102 // =======================================================================
initStream(Standard_OStream & theOStream) const103 void TreeModel_ItemStream::initStream (Standard_OStream& theOStream) const
104 {
105 if (!Properties())
106 return;
107
108 theOStream << Properties()->StreamValue();
109 }
110
111 // =======================================================================
112 // function : initItem
113 // purpose :
114 // =======================================================================
initItem() const115 void TreeModel_ItemStream::initItem() const
116 {
117 if (IsInitialized())
118 return;
119 const_cast<TreeModel_ItemStream*>(this)->Init();
120 }
121
122 // =======================================================================
123 // function : createChild
124 // purpose :
125 // =======================================================================
createChild(int theRow,int theColumn)126 TreeModel_ItemBasePtr TreeModel_ItemStream::createChild (int theRow, int theColumn)
127 {
128 return TreeModel_ItemStream::CreateItem (currentItem(), theRow, theColumn);
129 }
130