summaryrefslogtreecommitdiffstats
path: root/src/qdoc/qdoc/src/qdoc/propertynode.h
blob: 9ae59932bb9f6b036c0341b663bb37a0e8caecde (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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#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 class PropertyType { StandardProperty, BindableProperty };
    enum class FunctionRole { Getter, Setter, Resetter, Notifier, Bindable, NumFunctionRoles };
    static QString roleName(FunctionRole role);

    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 setWritable(bool writable) { m_writable = toFlagValue(writable); }
    void setOverriddenFrom(const PropertyNode *baseProperty);
    void setConstant() { m_const = true; }
    void setRequired() { m_required = true; }
    void setPropertyType(PropertyType type) { m_propertyType = type; }

    [[nodiscard]] const QString &dataType() const { return m_type; }
    [[nodiscard]] QString qualifiedDataType() const;
    [[nodiscard]] NodeList functions() const;
    [[nodiscard]] const NodeList &functions(FunctionRole role) const
    {
        return m_functions[(int)role];
    }
    [[nodiscard]] const NodeList &getters() const { return functions(FunctionRole::Getter); }
    [[nodiscard]] const NodeList &setters() const { return functions(FunctionRole::Setter); }
    [[nodiscard]] const NodeList &resetters() const { return functions(FunctionRole::Resetter); }
    [[nodiscard]] const NodeList &notifiers() const { return functions(FunctionRole::Notifier); }
    [[nodiscard]] bool hasAccessFunction(const QString &name) const;
    FunctionRole role(const FunctionNode *functionNode) const;
    [[nodiscard]] bool isStored() const { return fromFlagValue(m_stored, storedDefault()); }
    [[nodiscard]] bool isWritable() const { return fromFlagValue(m_writable, writableDefault()); }
    [[nodiscard]] bool isConstant() const { return m_const; }
    [[nodiscard]] bool isRequired() const { return m_required; }
    [[nodiscard]] PropertyType propertyType() const { return m_propertyType; }
    [[nodiscard]] const PropertyNode *overriddenFrom() const { return m_overrides; }

    [[nodiscard]] bool storedDefault() const { return true; }
    [[nodiscard]] bool writableDefault() const { return !setters().isEmpty(); }

private:
    QString m_type {};
    PropertyType m_propertyType { PropertyType::StandardProperty };
    NodeList m_functions[(qsizetype)FunctionRole::NumFunctionRoles] {};
    FlagValue m_stored { FlagValueDefault };
    FlagValue m_writable { FlagValueDefault };
    FlagValue m_user { FlagValueDefault };
    bool m_const { false };
    bool m_required { false };
    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 (qsizetype i{0}; i < (qsizetype)FunctionRole::NumFunctionRoles; ++i)
        list += m_functions[i];
    return list;
}

QT_END_NAMESPACE

#endif // PROPERTYNODE_H