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