summaryrefslogtreecommitdiff
path: root/src/plugins/qmldesigner/components/bindingeditor/actioneditordialog.h
blob: 06427271b3866212d292aceb77205b23fdbcbb62 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#ifndef ACTIONEDITORDIALOG_H
#define ACTIONEDITORDIALOG_H

#include <bindingeditor/abstracteditordialog.h>
#include <qmljs/parser/qmljsast_p.h>

#include <QStackedLayout>

QT_BEGIN_NAMESPACE
class QComboBox;
QT_END_NAMESPACE

namespace QmlDesigner {

class ActionEditorDialog : public AbstractEditorDialog
{
    Q_OBJECT

public:
    enum ConnectionType { Action, Assignment };
    Q_ENUM(ConnectionType)

    enum ComboBox { Type, TargetItem, TargetProperty, SourceItem, SourceProperty };
    Q_ENUM(ComboBox)

    class PropertyOption
    {
    public:
        PropertyOption(const QString &n, const TypeName &t, bool writeable = true)
            : name(n)
            , type(t)
            , isWriteable(writeable)
        {}

        bool operator==(const QString &value) const { return value == name; }
        bool operator==(const PropertyOption &value) const { return value.name == name; }

        QString name;
        TypeName type;
        bool isWriteable;
    };

    class SingletonOption
    {
    public:
        SingletonOption() {}
        SingletonOption(const QString &value) { item = value; }

        bool containsType(const TypeName &t) const
        {
            for (const auto &p : properties) {
                if (t == p.type || (isNumeric(t) && isNumeric(p.type)))
                    return true;
            }

            return false;
        }

        bool hasWriteableProperties() const
        {
            for (const auto &p : properties) {
                if (p.isWriteable)
                    return true;
            }

            return false;
        }

        bool operator==(const QString &value) const { return value == item; }
        bool operator==(const SingletonOption &value) const { return value.item == item; }

        QString item;
        QList<PropertyOption> properties;
    };

    class ConnectionOption : public SingletonOption
    {
    public:
        ConnectionOption(const QString &value) : SingletonOption(value) {}

        QStringList methods;
    };


    ActionEditorDialog(QWidget *parent = nullptr);
    ~ActionEditorDialog() override;

    void adjustProperties() override;

    void setAllConnections(const QList<ConnectionOption> &connections,
                           const QList<SingletonOption> &singeltons,
                           const QStringList &states);

    void updateComboBoxes(int idx, ComboBox type);

private:
    void setupUIComponents();

    void setType(ConnectionType type);

    void fillAndSetTargetItem(const QString &value, bool useDefault = false);
    void fillAndSetTargetProperty(const QString &value, bool useDefault = false);

    void fillAndSetSourceItem(const QString &value, bool useDefault = false);
    void fillAndSetSourceProperty(const QString &value,
                                  QmlJS::AST::Node::Kind kind = QmlJS::AST::Node::Kind::Kind_Undefined,
                                  bool useDefault = false);

    void insertAndSetUndefined(QComboBox *comboBox);

private:
    QComboBox *m_comboBoxType = nullptr;

    QStackedLayout *m_stackedLayout = nullptr;

    QWidget *m_actionPlaceholder = nullptr;
    QWidget *m_assignmentPlaceholder = nullptr;

    QHBoxLayout *m_actionLayout = nullptr;
    QHBoxLayout *m_assignmentLayout = nullptr;

    QComboBox *m_actionTargetItem = nullptr;
    QComboBox *m_actionMethod = nullptr;

    QComboBox *m_assignmentTargetItem = nullptr;
    QComboBox *m_assignmentTargetProperty = nullptr;
    QComboBox *m_assignmentSourceItem = nullptr;
    QComboBox *m_assignmentSourceProperty = nullptr; // Value

    QList<ConnectionOption> m_connections;
    QList<SingletonOption> m_singletons;
    QStringList m_states;

    const TypeName specificItem = {"specific"};
    const TypeName singletonItem = {"singleton"};
};

}

#endif //ACTIONEDITORDIALOG_H