blob: dac01905b67f8e59b8d9fdac54a86bbad0a6dae7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "effectmakeruniformsmodel.h"
#include "uniform.h"
#include <utils/qtcassert.h>
namespace QmlDesigner {
EffectMakerUniformsModel::EffectMakerUniformsModel(QObject *parent)
: QAbstractListModel{parent}
{
}
QHash<int, QByteArray> EffectMakerUniformsModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[NameRole] = "uniformName";
roles[DescriptionRole] = "uniformDescription";
roles[ValueRole] = "uniformValue";
roles[BackendValueRole] = "uniformBackendValue";
roles[DefaultValueRole] = "uniformDefaultValue";
roles[MinValueRole] = "uniformMinValue";
roles[MaxValueRole] = "uniformMaxValue";
roles[TypeRole] = "uniformType";
return roles;
}
int EffectMakerUniformsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return m_uniforms.size();
}
QVariant EffectMakerUniformsModel::data(const QModelIndex &index, int role) const
{
QTC_ASSERT(index.isValid() && index.row() < m_uniforms.size(), return {});
QTC_ASSERT(roleNames().contains(role), return {});
return m_uniforms.at(index.row())->property(roleNames().value(role));
}
bool EffectMakerUniformsModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid() || !roleNames().contains(role))
return false;
m_uniforms.at(index.row())->setValue(value);
emit dataChanged(index, index, {role});
return true;
}
void EffectMakerUniformsModel::resetModel()
{
beginResetModel();
endResetModel();
}
void EffectMakerUniformsModel::addUniform(Uniform *uniform)
{
beginInsertRows({}, m_uniforms.size(), m_uniforms.size());
m_uniforms.append(uniform);
endInsertRows();
}
QList<Uniform *> EffectMakerUniformsModel::uniforms() const
{
return m_uniforms;
}
} // namespace QmlDesigner
|