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
qquick3drenderstatsmeshesmodel.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> QQuick3DRenderStatsMeshesModel::roleNames() const
13{
14 return { {Qt::DisplayRole, "display"} };
15}
16
17int QQuick3DRenderStatsMeshesModel::rowCount(const QModelIndex &parent) const
18{
19 Q_UNUSED(parent);
20 return m_data.count();
21}
22
23int QQuick3DRenderStatsMeshesModel::columnCount(const QModelIndex &parent) const
24{
25 Q_UNUSED(parent);
26 return 5;
27}
28
29QVariant QQuick3DRenderStatsMeshesModel::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 // Submeshes 1
42 if (column == 1)
43 return m_data[row].submeshes;
44 // Vertices 2
45 if (column == 2)
46 return m_data[row].vertices;
47 // Vertex Buffer Size 3
48 if (column == 3)
49 return m_data[row].vertexBufferSize;
50 // Index Buffer Size 4
51 if (column == 4)
52 return m_data[row].indexBufferSize;
53 }
54
55 return QVariant();
56}
57
58QVariant QQuick3DRenderStatsMeshesModel::headerData(int section, Qt::Orientation orientation, int role) const
59{
60 if (role != Qt::DisplayRole || orientation != Qt::Horizontal || section > 5)
61 return QVariant();
62
63 switch (section) {
64 case 0:
65 return QStringLiteral("Name");
66 case 1:
67 return QStringLiteral("Submeshes");
68 case 2:
69 return QStringLiteral("Vertices");
70 case 3:
71 return QStringLiteral("VBuf Size");
72 case 4:
73 return QStringLiteral("IBuf Size");
74 default:
75 Q_UNREACHABLE();
76 return QVariant();
77 }
78}
79
80const QString &QQuick3DRenderStatsMeshesModel::meshData() const
81{
82 return m_meshData;
83}
84
85void QQuick3DRenderStatsMeshesModel::setMeshData(const QString &newMeshData)
86{
87 if (m_meshData == newMeshData)
88 return;
89
90 m_meshData = newMeshData;
91 emit meshDataChanged();
92
93 // newMeshData is just a markdown table...
94 QVector<Data> newData;
95 if (!m_meshData.isEmpty()) {
96 auto lines = m_meshData.split(QRegularExpression(QStringLiteral("[\r\n]")), Qt::SkipEmptyParts);
97 if (lines.size() > 2) {
98 for (qsizetype i = 2; i < lines.size(); ++i) {
99 const auto &line = lines.at(i);
100 auto fields = line.split(QLatin1Char('|'), Qt::SkipEmptyParts);
101 if (fields.size() != 5)
102 continue;
103 Data data;
104 bool isUInt64 = false;
105 data.name = fields[0];
106 data.submeshes = fields[1].toULongLong(&isUInt64);
107 if (!isUInt64)
108 continue;
109 data.vertices = fields[2].toULongLong(&isUInt64);
110 if (!isUInt64)
111 continue;
112 data.vertexBufferSize = fields[3].toULongLong(&isUInt64);
113 if (!isUInt64)
114 continue;
115 data.indexBufferSize = fields[4].toULongLong(&isUInt64);
116 if (!isUInt64)
117 continue;
118 newData.append(data);
119 }
120 }
121 }
122
123 // update the model
124 beginResetModel();
125 m_data = newData;
126 endResetModel();
127}
128
129QT_END_NAMESPACE
Combined button and popup list for selecting options.