summaryrefslogtreecommitdiffstats
path: root/src/qdoc/propertynode.h
blob: be1ccfa095f5143303c25fc9957a11739d75fbcd (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
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the tools applications of the Qt Toolkit.
**
** $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 PROPERTYNODE_H
#define PROPERTYNODE_H

#include "functionnode.h"
#include "node.h"

#include <QtCore/qglobal.h>
#include <QtCore/qstring.h>

QT_BEGIN_NAMESPACE

class Aggregate;

class PropertyNode : public Node
{
public:
    enum PropertyType { Standard, Bindable };
    enum FunctionRole { Getter, Setter, Resetter, Notifier };
    enum { NumFunctionRoles = Notifier + 1 };

    PropertyNode(Aggregate *parent, const QString &name);

    void setDataType(const QString &dataType) override { m_type = dataType; }
    void addFunction(FunctionNode *function, FunctionRole role);
    void addSignal(FunctionNode *function, FunctionRole role);
    void setStored(bool stored) { m_stored = toFlagValue(stored); }
    void setDesignable(bool designable) { m_designable = toFlagValue(designable); }
    void setScriptable(bool scriptable) { m_scriptable = toFlagValue(scriptable); }
    void setWritable(bool writable) { m_writable = toFlagValue(writable); }
    void setUser(bool user) { m_user = toFlagValue(user); }
    void setOverriddenFrom(const PropertyNode *baseProperty);
    void setRuntimeDesFunc(const QString &rdf) { m_runtimeDesFunc = rdf; }
    void setRuntimeScrFunc(const QString &scrf) { m_runtimeScrFunc = scrf; }
    void setConstant() { m_const = true; }
    void setFinal() { m_final = true; }
    void setRequired() { m_required = true; }
    void setPropertyType(PropertyType type) { m_propertyType = type; }
    void setRevision(int revision) { m_revision = revision; }

    const QString &dataType() const { return m_type; }
    QString qualifiedDataType() const;
    NodeList functions() const;
    const NodeList &functions(FunctionRole role) const { return m_functions[(int)role]; }
    const NodeList &getters() const { return functions(Getter); }
    const NodeList &setters() const { return functions(Setter); }
    const NodeList &resetters() const { return functions(Resetter); }
    const NodeList &notifiers() const { return functions(Notifier); }
    bool hasAccessFunction(const QString &name) const;
    FunctionRole role(const FunctionNode *functionNode) const;
    bool isStored() const { return fromFlagValue(m_stored, storedDefault()); }
    bool isDesignable() const { return fromFlagValue(m_designable, designableDefault()); }
    bool isScriptable() const { return fromFlagValue(m_scriptable, scriptableDefault()); }
    const QString &runtimeDesignabilityFunction() const { return m_runtimeDesFunc; }
    const QString &runtimeScriptabilityFunction() const { return m_runtimeScrFunc; }
    bool isWritable() const { return fromFlagValue(m_writable, writableDefault()); }
    bool isUser() const { return fromFlagValue(m_user, userDefault()); }
    bool isConstant() const { return m_const; }
    bool isFinal() const { return m_final; }
    bool isRequired() const { return m_required; }
    PropertyType propertyType() const { return m_propertyType; }
    const PropertyNode *overriddenFrom() const { return m_overrides; }

    bool storedDefault() const { return true; }
    bool userDefault() const { return false; }
    bool designableDefault() const { return !setters().isEmpty(); }
    bool scriptableDefault() const { return true; }
    bool writableDefault() const { return !setters().isEmpty(); }

private:
    QString m_type {};
    PropertyType m_propertyType { Standard };
    QString m_runtimeDesFunc {};
    QString m_runtimeScrFunc {};
    NodeList m_functions[NumFunctionRoles] {};
    FlagValue m_stored { FlagValueDefault };
    FlagValue m_designable { FlagValueDefault };
    FlagValue m_scriptable { FlagValueDefault };
    FlagValue m_writable { FlagValueDefault };
    FlagValue m_user { FlagValueDefault };
    bool m_const { false };
    bool m_final { false };
    bool m_required { false };
    int m_revision { -1 };
    const PropertyNode *m_overrides { nullptr };
};

inline void PropertyNode::addFunction(FunctionNode *function, FunctionRole role)
{
    m_functions[(int)role].append(function);
    function->addAssociatedProperty(this);
}

inline void PropertyNode::addSignal(FunctionNode *function, FunctionRole role)
{
    m_functions[(int)role].append(function);
    function->addAssociatedProperty(this);
}

inline NodeList PropertyNode::functions() const
{
    NodeList list;
    for (int i = 0; i < NumFunctionRoles; ++i)
        list += m_functions[i];
    return list;
}

QT_END_NAMESPACE

#endif // PROPERTYNODE_H