1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef ADDNODEMODEL_H
5#define ADDNODEMODEL_H
6
7#include <QAbstractListModel>
8#include <QList>
9#include <QString>
10#include <QVariant>
11
12class EffectManager;
13
14struct NodeDataProperty {
15 Q_GADGET
16 Q_PROPERTY(QString name MEMBER m_name)
17 Q_PROPERTY(QString type MEMBER m_type)
18public:
19 QString m_name;
20 QString m_type;
21};
22
23class AddNodeModel : public QAbstractListModel
24{
25 Q_OBJECT
26 Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
27
28public:
29 struct NodeData {
30 QString name;
31 QString description;
32 QString file;
33 QString group;
34 QStringList requiredNodes;
35 // Properties as variant list to get access from QML
36 QVariantList properties;
37 // False when node would overlap with existing node in view
38 bool canBeAdded = true;
39 bool show = false;
40 };
41
42 enum AddNodeModelRoles {
43 Name = Qt::UserRole + 1,
44 Description,
45 File,
46 Group,
47 Properties,
48 CanBeAdded,
49 Show,
50 RequiredNodes
51 };
52
53 explicit AddNodeModel(QObject *effectManager);
54
55 int rowCount(const QModelIndex & = QModelIndex()) const final;
56 QVariant data(const QModelIndex &index, int role) const final;
57 QHash<int, QByteArray> roleNames() const final;
58
59 void updateCanBeAdded(const QStringList &propertyNames);
60 void updateShowHide(const QString &groupName, bool show);
61 void updateNodesList();
62
63signals:
64 void rowCountChanged();
65
66private:
67 void loadNodesFromPath(const QString &path);
68 QList<NodeData> m_modelList;
69 EffectManager *m_effectManager = nullptr;
70
71};
72
73bool operator==(const AddNodeModel::NodeData &a, const AddNodeModel::NodeData &b) noexcept;
74
75Q_DECLARE_METATYPE(NodeDataProperty);
76
77#endif // ADDNODEMODEL_H
78

source code of qtquickeffectmaker/tools/qqem/addnodemodel.h