File: MessageModel_TreeModel.cxx

package info (click to toggle)
opencascade 7.9.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 301,932 kB
  • sloc: cpp: 1,523,264; tcl: 10,159; cs: 5,173; java: 1,554; sh: 1,342; ansic: 827; xml: 699; makefile: 31; javascript: 22
file content (209 lines) | stat: -rw-r--r-- 7,866 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Created on: 2021-04-27
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2021 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.

#include <inspector/MessageModel_TreeModel.hxx>

#include <inspector/MessageModel_ItemAlert.hxx>
#include <inspector/MessageModel_ItemRoot.hxx>
#include <inspector/MessageModel_ItemReport.hxx>
#include <inspector/TreeModel_ColumnType.hxx>

#include <Message.hxx>

const int COLUMN_NAME_WIDTH = 230;
const int COLUMN_SIZE_WIDTH = 30;

const int COLUMN_REAL_VALUE_WIDTH    = 115;
const int COLUMN_PERCENT_VALUE_WIDTH = 50;

// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
MessageModel_TreeModel::MessageModel_TreeModel(QObject* theParent)
    : TreeModel_ModelBase(theParent)
{
}

// =======================================================================
// function : InitColumns
// purpose :
// =======================================================================
void MessageModel_TreeModel::InitColumns()
{
  // 0 - Name, 1 - visibility, 2 - Row
  setHeaderItem(TreeModel_ColumnType_Name, TreeModel_HeaderSection("Name", COLUMN_NAME_WIDTH));
  setHeaderItem(
    TreeModel_ColumnType_Visibility,
    TreeModel_HeaderSection("Visibility", TreeModel_ModelBase::ColumnVisibilityWidth()));
  setHeaderItem(TreeModel_ColumnType_Row,
                TreeModel_HeaderSection("Row", COLUMN_SIZE_WIDTH, Standard_True /*hidden*/));

  int aNextIndex = 3;
  for (int aMetricId = (int)Message_MetricType_None + 1;
       aMetricId <= (int)Message_MetricType_MemHeapUsage;
       aMetricId++)
  {
    Message_MetricType   aMetricType = (Message_MetricType)aMetricId;
    OSD_MemInfo::Counter aMemInfo;
    bool                 isMemInfo = Message::ToOSDMetric(aMetricType, aMemInfo);

    setHeaderItem(
      aNextIndex++,
      TreeModel_HeaderSection(
        QString("%1 [%2]").arg(Message::MetricToString(aMetricType)).arg(isMemInfo ? "Mb" : "s"),
        COLUMN_REAL_VALUE_WIDTH));
    setHeaderItem(aNextIndex++,
                  TreeModel_HeaderSection(isMemInfo ? "Delta" : "%", COLUMN_PERCENT_VALUE_WIDTH));
  }
}

// =======================================================================
// function : GetMetricColumns
// purpose :
// =======================================================================
void MessageModel_TreeModel::GetMetricColumns(const Message_MetricType theMetricType,
                                              QList<int>&              theMetricColumns)
{
  theMetricColumns.clear();
  int aNextIndex = 3; // after default parent columns, see InitColumns
  for (int aMetricId = (int)Message_MetricType_None + 1;
       aMetricId <= (int)Message_MetricType_MemHeapUsage;
       aMetricId++)
  {
    if (theMetricType != (Message_MetricType)aMetricId)
    {
      aNextIndex += 2;
      continue;
    }
    theMetricColumns.append(aNextIndex++);
    theMetricColumns.append(aNextIndex++);
  }
}

// =======================================================================
// function : IsMetricColumn
// purpose :
// =======================================================================
bool MessageModel_TreeModel::IsMetricColumn(const int           theColumnId,
                                            Message_MetricType& theMetricType,
                                            int&                thePosition)
{
  int aNextIndex = 3; // after default parent columns, see InitColumns
  for (int aMetricId = (int)Message_MetricType_None + 1;
       aMetricId <= (int)Message_MetricType_MemHeapUsage;
       aMetricId++)
  {
    if (theColumnId == aNextIndex || theColumnId == aNextIndex + 1)
    {
      theMetricType = (Message_MetricType)aMetricId;
      thePosition   = theColumnId - aNextIndex;
      return true;
    }
    aNextIndex += 2;
  }
  return false;
}

// =======================================================================
// function : createRootItem
// purpose :
// =======================================================================
TreeModel_ItemBasePtr MessageModel_TreeModel::createRootItem(const int theColumnId)
{
  return MessageModel_ItemRoot::CreateItem(TreeModel_ItemBasePtr(), 0, theColumnId);
}

// =======================================================================
// function : HasReport
// purpose :
// =======================================================================
Standard_Boolean MessageModel_TreeModel::HasReport(const Handle(Message_Report)& theReport)
{
  if (columnCount() == 0)
    return Standard_False;

  MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot>(RootItem(0));
  return aRootItem && aRootItem->HasReport(theReport);
}

// =======================================================================
// function : AddReport
// purpose :
// =======================================================================
void MessageModel_TreeModel::AddReport(const Handle(Message_Report)&  theReport,
                                       const TCollection_AsciiString& theReportDescription)
{
  for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
  {
    MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot>(RootItem(aColId));
    if (!aRootItem)
      continue;
    aRootItem->AddReport(theReport, theReportDescription);
  }

  Reset();
  EmitLayoutChanged();
}

// =======================================================================
// function : SetReport
// purpose :
// =======================================================================
void MessageModel_TreeModel::SetReport(const int                      theRowId,
                                       const Handle(Message_Report)&  theReport,
                                       const TCollection_AsciiString& theReportDescription)
{
  for (int aColId = 0, aNbColumns = columnCount(); aColId < aNbColumns; aColId++)
  {
    MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot>(RootItem(aColId));
    if (!aRootItem)
      continue;
    aRootItem->SetReport(theRowId, theReport, theReportDescription);
  }
  Reset();
  EmitLayoutChanged();
}

// =======================================================================
// function : Reports
// purpose :
// =======================================================================
const NCollection_List<MessageModel_ReportInformation>& MessageModel_TreeModel::Reports() const
{
  MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot>(RootItem(0));
  return aRootItem->Reports();
}

// =======================================================================
// function : UpdateTreeModel
// purpose :
// =======================================================================
void MessageModel_TreeModel::SetRootItemName(const TCollection_AsciiString& theName)
{
  MessageModel_ItemRootPtr aRootItem = itemDynamicCast<MessageModel_ItemRoot>(RootItem(0));
  if (aRootItem)
    aRootItem->SetName(theName);
}

// =======================================================================
// function : UpdateTreeModel
// purpose :
// =======================================================================
void MessageModel_TreeModel::UpdateTreeModel()
{
  Reset();
  EmitLayoutChanged();
}