1 // Created on: 2021-04-27
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2021 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/MessageModel_TreeModel.hxx>
17
18 #include <inspector/MessageModel_ItemAlert.hxx>
19 #include <inspector/MessageModel_ItemRoot.hxx>
20 #include <inspector/MessageModel_ItemReport.hxx>
21 #include <inspector/TreeModel_ColumnType.hxx>
22
23 #include <Message.hxx>
24
25 const int COLUMN_NAME_WIDTH = 230;
26 const int COLUMN_SIZE_WIDTH = 30;
27
28 const int COLUMN_REAL_VALUE_WIDTH = 115;
29 const int COLUMN_PERCENT_VALUE_WIDTH = 50;
30
31 // =======================================================================
32 // function : Constructor
33 // purpose :
34 // =======================================================================
MessageModel_TreeModel(QObject * theParent)35 MessageModel_TreeModel::MessageModel_TreeModel (QObject* theParent)
36 : TreeModel_ModelBase (theParent)
37 {
38 }
39
40 // =======================================================================
41 // function : InitColumns
42 // purpose :
43 // =======================================================================
InitColumns()44 void MessageModel_TreeModel::InitColumns()
45 {
46 // 0 - Name, 1 - visibility, 2 - Row
47 setHeaderItem (TreeModel_ColumnType_Name, TreeModel_HeaderSection ("Name", COLUMN_NAME_WIDTH));
48 setHeaderItem (TreeModel_ColumnType_Visibility, TreeModel_HeaderSection ("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
49 setHeaderItem (TreeModel_ColumnType_Row, TreeModel_HeaderSection ("Row", COLUMN_SIZE_WIDTH, Standard_True /*hidden*/));
50
51 int aNextIndex = 3;
52 for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
53 {
54 Message_MetricType aMetricType = (Message_MetricType)aMetricId;
55 OSD_MemInfo::Counter aMemInfo;
56 bool isMemInfo = Message::ToOSDMetric (aMetricType, aMemInfo);
57
58 setHeaderItem (aNextIndex++,
59 TreeModel_HeaderSection (QString("%1 [%2]").arg (Message::MetricToString (aMetricType)).arg(isMemInfo ? "Mb" : "s"),
60 COLUMN_REAL_VALUE_WIDTH));
61 setHeaderItem (aNextIndex++, TreeModel_HeaderSection (isMemInfo ? "Delta" : "%", COLUMN_PERCENT_VALUE_WIDTH));
62 }
63 }
64
65 // =======================================================================
66 // function : GetMetricColumns
67 // purpose :
68 // =======================================================================
GetMetricColumns(const Message_MetricType theMetricType,QList<int> & theMetricColumns)69 void MessageModel_TreeModel::GetMetricColumns (const Message_MetricType theMetricType, QList<int>& theMetricColumns)
70 {
71 theMetricColumns.clear();
72 int aNextIndex = 3; // after default parent columns, see InitColumns
73 for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
74 {
75 if (theMetricType != (Message_MetricType)aMetricId)
76 {
77 aNextIndex += 2;
78 continue;
79 }
80 theMetricColumns.append (aNextIndex++);
81 theMetricColumns.append (aNextIndex++);
82 }
83 }
84
85 // =======================================================================
86 // function : IsMetricColumn
87 // purpose :
88 // =======================================================================
IsMetricColumn(const int theColumnId,Message_MetricType & theMetricType,int & thePosition)89 bool MessageModel_TreeModel::IsMetricColumn (const int theColumnId, Message_MetricType& theMetricType, int& thePosition)
90 {
91 int aNextIndex = 3; // after default parent columns, see InitColumns
92 for (int aMetricId = (int)Message_MetricType_None + 1; aMetricId <= (int)Message_MetricType_MemHeapUsage; aMetricId++)
93 {
94 if (theColumnId == aNextIndex || theColumnId == aNextIndex + 1)
95 {
96 theMetricType = (Message_MetricType)aMetricId;
97 thePosition = theColumnId - aNextIndex;
98 return true;
99 }
100 aNextIndex += 2;
101 }
102 return false;
103 }
104
105 // =======================================================================
106 // function : createRootItem
107 // purpose :
108 // =======================================================================
createRootItem(const int theColumnId)109 TreeModel_ItemBasePtr MessageModel_TreeModel::createRootItem (const int theColumnId)
110 {
111 return MessageModel_ItemRoot::CreateItem (TreeModel_ItemBasePtr(), 0, theColumnId);
112 }
113
114 // =======================================================================
115 // function : HasReport
116 // purpose :
117 // =======================================================================
HasReport(const Handle (Message_Report)& theReport)118 Standard_Boolean MessageModel_TreeModel::HasReport (const Handle(Message_Report)& theReport)
119 {
120 if (columnCount() == 0)
121 return Standard_False;
122
123 MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (0));
124 return aRootItem && aRootItem->HasReport (theReport);
125 }
126
127 // =======================================================================
128 // function : AddReport
129 // purpose :
130 // =======================================================================
AddReport(const Handle (Message_Report)& theReport,const TCollection_AsciiString & theReportDescription)131 void MessageModel_TreeModel::AddReport (const Handle(Message_Report)& theReport,
132 const TCollection_AsciiString& theReportDescription)
133 {
134 for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
135 {
136 MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (aColId));
137 if (!aRootItem)
138 continue;
139 aRootItem->AddReport (theReport, theReportDescription);
140 }
141
142 Reset();
143 EmitLayoutChanged();
144 }
145
146 // =======================================================================
147 // function : SetReport
148 // purpose :
149 // =======================================================================
SetReport(const int theRowId,const Handle (Message_Report)& theReport,const TCollection_AsciiString & theReportDescription)150 void MessageModel_TreeModel::SetReport (const int theRowId, const Handle(Message_Report)& theReport,
151 const TCollection_AsciiString& theReportDescription)
152 {
153 for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
154 {
155 MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (aColId));
156 if (!aRootItem)
157 continue;
158 aRootItem->SetReport (theRowId, theReport, theReportDescription);
159 }
160 Reset();
161 EmitLayoutChanged();
162 }
163
164 // =======================================================================
165 // function : Reports
166 // purpose :
167 // =======================================================================
Reports() const168 const NCollection_List<MessageModel_ReportInformation>& MessageModel_TreeModel::Reports() const
169 {
170 MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (0));
171 return aRootItem->Reports();
172 }
173
174 // =======================================================================
175 // function : UpdateTreeModel
176 // purpose :
177 // =======================================================================
SetRootItemName(const TCollection_AsciiString & theName)178 void MessageModel_TreeModel::SetRootItemName (const TCollection_AsciiString& theName)
179 {
180 MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot> (RootItem (0));
181 if (aRootItem)
182 aRootItem->SetName (theName);
183 }
184
185 // =======================================================================
186 // function : UpdateTreeModel
187 // purpose :
188 // =======================================================================
UpdateTreeModel()189 void MessageModel_TreeModel::UpdateTreeModel()
190 {
191 Reset();
192 EmitLayoutChanged();
193 }
194