7e1c1e48 |
1 | // Created on: 2020-01-25 |
6822a3be |
2 | // Created by: Natalia ERMOLAEVA |
7e1c1e48 |
3 | // Copyright (c) 2020 OPEN CASCADE SAS |
6822a3be |
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 | |
7e1c1e48 |
16 | #include <inspector/TreeModel_ItemStream.hxx> |
6822a3be |
17 | |
7e1c1e48 |
18 | #include <inspector/TreeModel_ItemProperties.hxx> |
19 | |
20 | #include <Standard_Dump.hxx> |
6822a3be |
21 | |
22 | // ======================================================================= |
7e1c1e48 |
23 | // function : Constructor |
6822a3be |
24 | // purpose : |
25 | // ======================================================================= |
7e1c1e48 |
26 | TreeModel_ItemStream::TreeModel_ItemStream (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn) |
27 | : TreeModel_ItemBase (theParent, theRow, theColumn) |
6822a3be |
28 | { |
6822a3be |
29 | } |
30 | |
31 | // ======================================================================= |
7e1c1e48 |
32 | // function : Init |
6822a3be |
33 | // purpose : |
34 | // ======================================================================= |
7e1c1e48 |
35 | void TreeModel_ItemStream::Init() |
6822a3be |
36 | { |
7e1c1e48 |
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); |
6822a3be |
52 | } |
53 | |
54 | // ======================================================================= |
7e1c1e48 |
55 | // function : Rest |
6822a3be |
56 | // purpose : |
57 | // ======================================================================= |
7e1c1e48 |
58 | void TreeModel_ItemStream::Reset() |
6822a3be |
59 | { |
7e1c1e48 |
60 | myStream.str (""); |
61 | TreeModel_ItemBase::Reset(); |
6822a3be |
62 | } |
63 | |
64 | // ======================================================================= |
7e1c1e48 |
65 | // function : initValue |
6822a3be |
66 | // purpose : |
67 | // ======================================================================= |
7e1c1e48 |
68 | QVariant TreeModel_ItemStream::initValue (const int theItemRole) const |
6822a3be |
69 | { |
7e1c1e48 |
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(); |
6822a3be |
88 | } |
89 | |
90 | // ======================================================================= |
7e1c1e48 |
91 | // function : initStream |
6822a3be |
92 | // purpose : |
93 | // ======================================================================= |
7e1c1e48 |
94 | void TreeModel_ItemStream::initStream (Standard_OStream& theOStream) const |
6822a3be |
95 | { |
7e1c1e48 |
96 | if (!Properties()) |
97 | return; |
98 | |
99 | theOStream << Properties()->StreamValue(); |
6822a3be |
100 | } |
101 | |
102 | // ======================================================================= |
103 | // function : initItem |
104 | // purpose : |
105 | // ======================================================================= |
7e1c1e48 |
106 | void TreeModel_ItemStream::initItem() const |
6822a3be |
107 | { |
108 | if (IsInitialized()) |
109 | return; |
7e1c1e48 |
110 | const_cast<TreeModel_ItemStream*>(this)->Init(); |
6822a3be |
111 | } |
112 | |
113 | // ======================================================================= |
7e1c1e48 |
114 | // function : createChild |
6822a3be |
115 | // purpose : |
116 | // ======================================================================= |
7e1c1e48 |
117 | TreeModel_ItemBasePtr TreeModel_ItemStream::createChild (int theRow, int theColumn) |
6822a3be |
118 | { |
7e1c1e48 |
119 | return TreeModel_ItemStream::CreateItem (currentItem(), theRow, theColumn); |
6822a3be |
120 | } |