1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef UNIFORMMODEL_H
5#define UNIFORMMODEL_H
6
7#include <QAbstractTableModel>
8#include <QtQml/qqmlregistration.h>
9#include "custommaterial.h"
10
11QT_BEGIN_NAMESPACE
12
13class UniformModel : public QAbstractListModel
14{
15 Q_OBJECT
16 QML_ELEMENT
17public:
18 using UniformTable = CustomMaterial::UniformTable;
19 // This enum is used in QML to get the type of the uniform
20 // but should map to CustomMaterial::Uniform::Type
21 enum UniformType {
22 Bool,
23 Int,
24 Float,
25 Vec2,
26 Vec3,
27 Vec4,
28 Mat44,
29 Sampler,
30 };
31 Q_ENUM(UniformType)
32
33 enum UniformModelRoles {
34 Type = Qt::UserRole + 1,
35 Name,
36 Value
37 };
38
39 explicit UniformModel(QObject *parent = nullptr);
40
41 void setModelData(UniformTable *data);
42 int rowCount(const QModelIndex & = QModelIndex()) const final;
43 QVariant data(const QModelIndex &index, int role) const final;
44 QHash<int, QByteArray> roleNames() const final;
45 bool setData(const QModelIndex &index, const QVariant &value, int role) final;
46
47 Q_INVOKABLE bool insertRow(int rowIndex, int type, const QString &id);
48 Q_INVOKABLE void removeRow(int rowIndex, int rows = 1);
49
50private:
51 bool validateUniformName(const QString &uniformName);
52 UniformTable *m_uniformTable = nullptr;
53};
54
55QT_END_NAMESPACE
56
57#endif // UNIFORMMODEL_H
58

source code of qtquick3d/tools/materialeditor/uniformmodel.h