1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qquick3drenderstatspassesmodel_p.h"
5
6#include <QtCore/QRegularExpression>
7
8QT_BEGIN_NAMESPACE
9
10QHash<int, QByteArray> QQuick3DRenderStatsPassesModel::roleNames() const
11{
12 return { {Qt::DisplayRole, "display"} };
13}
14
15int QQuick3DRenderStatsPassesModel::rowCount(const QModelIndex &parent) const
16{
17 Q_UNUSED(parent);
18 return m_data.count();
19}
20
21int QQuick3DRenderStatsPassesModel::columnCount(const QModelIndex &parent) const
22{
23 Q_UNUSED(parent);
24 return 4;
25}
26
27QVariant QQuick3DRenderStatsPassesModel::data(const QModelIndex &index, int role) const
28{
29 if (!index.isValid())
30 return QVariant();
31
32 const uint row = index.row();
33 const uint column = index.column();
34
35 if (role == Qt::DisplayRole) {
36 // Name 0
37 if (column == 0)
38 return m_data[row].name;
39 // Size 1
40 if (column == 1)
41 return m_data[row].size;
42 // Vertices 2
43 if (column == 2)
44 return m_data[row].vertices;
45 // DrawCalls 3
46 if (column == 3)
47 return m_data[row].drawCalls;
48 }
49
50 return QVariant();
51}
52
53QVariant QQuick3DRenderStatsPassesModel::headerData(int section, Qt::Orientation orientation, int role) const
54{
55 if (role != Qt::DisplayRole || orientation != Qt::Horizontal || section > 4)
56 return QVariant();
57
58 switch (section) {
59 case 0:
60 return QStringLiteral("Name");
61 case 1:
62 return QStringLiteral("Size");
63 case 2:
64 return QStringLiteral("Vertices");
65 case 3:
66 return QStringLiteral("Draw Calls");
67 default:
68 Q_UNREACHABLE();
69 return QVariant();
70 }
71}
72
73const QString &QQuick3DRenderStatsPassesModel::passData() const
74{
75 return m_passData;
76}
77
78void QQuick3DRenderStatsPassesModel::setPassData(const QString &newPassData)
79{
80 if (m_passData == newPassData)
81 return;
82
83 m_passData = newPassData;
84 emit passDataChanged();
85
86 // newPassData is just a markdown table...
87 QVector<Data> newData;
88 if (!m_passData.isEmpty()) {
89 auto lines = m_passData.split(sep: QRegularExpression(QStringLiteral("[\r\n]")), behavior: Qt::SkipEmptyParts);
90 if (lines.size() > 2) {
91 for (qsizetype i = 2; i < lines.size(); ++i) {
92 const auto &line = lines.at(i);
93 auto fields = line.split(sep: QLatin1Char('|'), behavior: Qt::SkipEmptyParts);
94 if (fields.size() != 4)
95 continue;
96 Data data;
97 bool isUInt64 = false;
98 bool isUint32 = false;
99 data.name = fields[0];
100 data.size = fields[1];
101 data.vertices = fields[2].toULongLong(ok: &isUInt64);
102 if (!isUInt64)
103 continue;
104 data.drawCalls = fields[3].toULong(ok: &isUint32);
105 if (!isUint32)
106 continue;
107 newData.append(t: data);
108 }
109 }
110 }
111
112 // update the model
113 beginResetModel();
114 m_data = newData;
115 endResetModel();
116}
117
118QT_END_NAMESPACE
119
120

source code of qtquick3d/src/helpers/impl/qquick3drenderstatspassesmodel.cpp