Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5
6#include <QtCore/QRegularExpression>
7
9
10QHash<int, QByteArray> QQuick3DRenderStatsMeshesModel::roleNames() const
11{
12 return { {Qt::DisplayRole, "display"} };
13}
14
16{
18 return m_data.count();
19}
20
22{
24 return 5;
25}
26
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 // Submeshes 1
40 if (column == 1)
41 return m_data[row].submeshes;
42 // Vertices 2
43 if (column == 2)
44 return m_data[row].vertices;
45 // Vertex Buffer Size 3
46 if (column == 3)
47 return m_data[row].vertexBufferSize;
48 // Index Buffer Size 4
49 if (column == 4)
50 return m_data[row].indexBufferSize;
51 }
52
53 return QVariant();
54}
55
57{
58 if (role != Qt::DisplayRole || orientation != Qt::Horizontal || section > 5)
59 return QVariant();
60
61 switch (section) {
62 case 0:
63 return QStringLiteral("Name");
64 case 1:
65 return QStringLiteral("Submeshes");
66 case 2:
67 return QStringLiteral("Vertices");
68 case 3:
69 return QStringLiteral("VBuf Size");
70 case 4:
71 return QStringLiteral("IBuf Size");
72 default:
73 Q_UNREACHABLE();
74 return QVariant();
75 }
76}
77
79{
80 return m_meshData;
81}
82
84{
85 if (m_meshData == newMeshData)
86 return;
87
88 m_meshData = newMeshData;
90
91 // newMeshData is just a markdown table...
92 QVector<Data> newData;
93 if (!m_meshData.isEmpty()) {
94 auto lines = m_meshData.split(QRegularExpression(QStringLiteral("[\r\n]")), Qt::SkipEmptyParts);
95 if (lines.size() > 2) {
96 for (qsizetype i = 2; i < lines.size(); ++i) {
97 const auto &line = lines.at(i);
98 auto fields = line.split(QLatin1Char('|'), Qt::SkipEmptyParts);
99 if (fields.size() != 5)
100 continue;
101 Data data;
102 bool isUInt64 = false;
103 data.name = fields[0];
104 data.submeshes = fields[1].toULongLong(&isUInt64);
105 if (!isUInt64)
106 continue;
107 data.vertices = fields[2].toULongLong(&isUInt64);
108 if (!isUInt64)
109 continue;
110 data.vertexBufferSize = fields[3].toULongLong(&isUInt64);
111 if (!isUInt64)
112 continue;
113 data.indexBufferSize = fields[4].toULongLong(&isUInt64);
114 if (!isUInt64)
115 continue;
116 newData.append(data);
117 }
118 }
119 }
120
121 // update the model
123 m_data = newData;
125}
126
void endResetModel()
Completes a model reset operation.
void beginResetModel()
Begins a model reset operation.
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore
int rowCount(const QModelIndex &parent) const override
Returns the number of rows under the given parent.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns the data for the given role and section in the header with the specified orientation.
QHash< int, QByteArray > roleNames() const override
int columnCount(const QModelIndex &parent) const override
Returns the number of columns for the children of the given parent.
QVariant data(const QModelIndex &index, int role) const override
Returns the data stored under the given role for the item referred to by the index.
void setMeshData(const QString &newMeshData)
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
Definition qstring.cpp:8218
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
@ DisplayRole
@ SkipEmptyParts
Definition qnamespace.h:128
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
#define QStringLiteral(str)
#define emit
#define Q_UNUSED(x)
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned int uint
Definition qtypes.h:34
\inmodule QtCore \reentrant
Definition qchar.h:18