summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/Action/PropertyModel.h
blob: a833752b8cda3526b3fea3a0aa7991fede64b570 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef PROPERTYMODEL_H
#define PROPERTYMODEL_H

#include <QAbstractListModel>

#include "Qt3DSDMHandles.h"
#include "Qt3DSDMDataTypes.h"
#include "Qt3DSDMMetaDataTypes.h"

struct PropertyInfo {
    Q_PROPERTY(QString name MEMBER m_name CONSTANT FINAL)
    Q_PROPERTY(float min MEMBER m_min CONSTANT FINAL)
    Q_PROPERTY(float max MEMBER m_max CONSTANT FINAL)
    Q_PROPERTY(qt3dsdm::DataModelDataType::Value type MEMBER m_type CONSTANT FINAL)
    Q_PROPERTY(qt3dsdm::AdditionalMetaDataType::Value additionalType MEMBER m_additionalType CONSTANT FINAL)
    Q_PROPERTY(QStringList possibleValues MEMBER m_possibleValues CONSTANT FINAL)

    qt3dsdm::Qt3DSDMPropertyHandle m_handle;
    QString m_name;
    QString m_nameId;
    qt3dsdm::DataModelDataType::Value m_type;
    qt3dsdm::AdditionalMetaDataType::Value m_additionalType;
    QStringList m_possibleValues;
    float m_min = 0.0f;
    float m_max = 0.0f;

    Q_GADGET
};

class PropertyModel : public QAbstractListModel
{
    Q_PROPERTY(int valueHandle READ valueHandle NOTIFY valueHandleChanged FINAL)
    Q_PROPERTY(QVariant value READ value NOTIFY valueChanged FINAL)
    Q_PROPERTY(int defaultPropertyIndex READ defaultPropertyIndex NOTIFY defaultPropertyIndexChanged FINAL)
    Q_OBJECT

public:
    explicit PropertyModel(QObject *parent = nullptr);

    enum Roles {
        NameRole = Qt::DisplayRole,
        HandleRole = Qt::UserRole + 1
    };

    void setAction(const qt3dsdm::Qt3DSDMActionHandle &action);
    void setNameHandle(const qt3dsdm::Qt3DSDMHandlerArgHandle &valueHandle);
    void setValueHandle(const qt3dsdm::Qt3DSDMHandlerArgHandle &valueHandle);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

    PropertyInfo property(int index) const;
    qt3dsdm::Qt3DSDMActionHandle action() const { return m_action; }
    int valueHandle() const;

    QVariant value() const;
    int defaultPropertyIndex() const;

Q_SIGNALS:
    void valueHandleChanged();
    void valueChanged();
    void defaultPropertyIndexChanged();

private:
    void updateValue();
    void updateDefaultPropertyIndex();

    QVector<PropertyInfo> m_properties;
    qt3dsdm::Qt3DSDMActionHandle m_action;
    qt3dsdm::Qt3DSDMHandlerArgHandle m_nameHandle;
    qt3dsdm::Qt3DSDMHandlerArgHandle m_valueHandle;
    int m_defaultPropertyIndex = -1;
    QVariant m_value;
};

Q_DECLARE_METATYPE(PropertyInfo)

#endif // PROPERTYMODEL_H