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
qquick3drenderstatstexturesmodel.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> QQuick3DRenderStatsTexturesModel::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 // Size 1
40 if (column == 1)
41 return m_data[row].size;
42 // Format 2
43 if (column == 2)
44 return m_data[row].format;
45 // Mip Levels 3
46 if (column == 3)
47 return m_data[row].mipLevels;
48 // Flags 4
49 if (column == 4)
50 return m_data[row].flags;
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("Size");
66 case 2:
67 return QStringLiteral("Format");
68 case 3:
69 return QStringLiteral("Mip Levels");
70 case 4:
71 return QStringLiteral("Flags");
72 default:
73 Q_UNREACHABLE();
74 return QVariant();
75 }
76}
77
79{
80 return m_textureData;
81}
82
84{
85 if (m_textureData == newTextureData)
86 return;
87
88 m_textureData = newTextureData;
90
91 // newTextureData is just a markdown table...
92 QVector<Data> newData;
93 if (!m_textureData.isEmpty()) {
94 auto lines = m_textureData.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() < 4) // flags field can be empty
100 continue;
101 Data data;
102 bool isUInt32 = false;
103 data.name = fields[0];
104 data.size = fields[1];
105 data.format = fields[2];
106 data.mipLevels = fields[3].toULong(&isUInt32);
107 if (!isUInt32)
108 continue;
109 if (fields.size() == 5)
110 data.flags = fields[4];
111 newData.append(data);
112 }
113 }
114 }
115
116 // update the model
118 m_data = newData;
120}
121
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
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.
int rowCount(const QModelIndex &parent) const override
Returns the number of rows under the given parent.
void setTextureData(const QString &newTextureData)
int columnCount(const QModelIndex &parent) const override
Returns the number of columns for the children of the given parent.
QHash< int, QByteArray > roleNames() const override
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.
\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