aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmltc/QmltcTests/cpptypes/typewithmanyproperties.h
blob: b0f1a17adcc46ab5c1cbb666ddedcc9cf9807acd (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
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef PROPERTYALIASATTRIBUTES_H
#define PROPERTYALIASATTRIBUTES_H

#include <QtCore/qobject.h>
#include <QtCore/QBindable>
#include <QtQml/qqmlregistration.h>

using namespace Qt::Literals;

class TypeWithManyProperties : public QObject
{
    Q_OBJECT
    QML_ELEMENT

    const QString m_readOnly = u"Hello World!"_s;
    QString m_readAndWrite;
    QString m_resettable;
    QString m_unresettable;
    QString m_hasAllAttributes;
    QString m_hasAllAttributes2;

public:
    TypeWithManyProperties()
    {
        hasAllAttributesBindable().setBinding(
                [&] { return u"From the bindable: "_s + readOnly(); });
    }

    Q_PROPERTY(QString readOnly READ readOnly);
    Q_PROPERTY(QString readAndWrite READ readAndWrite WRITE setReadAndWrite);
    Q_PROPERTY(QString readAndWriteMember MEMBER m_readAndWrite);
    Q_PROPERTY(QString resettable READ resettable WRITE setReadAndWrite RESET resetResettable);
    Q_PROPERTY(QString unresettable READ unresettable WRITE setUnresettable);
    Q_PROPERTY(QString notifiable READ readAndWrite WRITE setReadAndWriteAndNotify NOTIFY
                       notifiableChanged);
    Q_PROPERTY(QString notifiableMember MEMBER m_readAndWrite NOTIFY notifiableChanged);
    Q_PROPERTY(QString latestReadAndWrite MEMBER m_readAndWrite REVISION(1, 0));
    Q_PROPERTY(QString notExisting MEMBER m_readAndWrite REVISION(6, 0));

    Q_PROPERTY(QString hasAllAttributes READ hasAllAttributes WRITE setHasAllAttributes RESET
                       resetHasAllAttributes NOTIFY hasAllAttributesChanged REVISION(1, 0)
                               BINDABLE hasAllAttributesBindable
                                       DESIGNABLE false SCRIPTABLE true STORED false USER true FINAL
                                               REQUIRED);

    Q_OBJECT_BINDABLE_PROPERTY(TypeWithManyProperties, QString, hasAllAttributesProperty);

    QBindable<QString> hasAllAttributesBindable()
    {
        return QBindable<QString>(&hasAllAttributesProperty);
    }

    Q_PROPERTY(QString hasAllAttributes2 READ hasAllAttributes2
                       DESIGNABLE true SCRIPTABLE true STORED true USER false CONSTANT);

    QString readOnly() { return m_readOnly; }

    QString readAndWrite() { return m_readAndWrite; }

    void setReadAndWrite(const QString &s) { m_readAndWrite = s; }

    void setReadAndWriteAndNotify(const QString &s)
    {
        if (s != readAndWrite()) {
            setReadAndWrite(s);
            emit notifiableChanged(s);
        }
    }

    void resetResettable() { m_resettable = u"Reset!"_s; }

    QString resettable() { return m_resettable; }
    QString unresettable() { return m_unresettable; }
    void setResettable(const QString &s) { m_resettable = s; }
    void setUnresettable(const QString &s) { m_unresettable = s; }

    QString hasAllAttributes2() { return u"Some Constant string"_s; }
    QString hasAllAttributes() { return m_hasAllAttributes; }
    void setHasAllAttributes(const QString &s) { m_hasAllAttributes = s; }
    void resetHasAllAttributes() { m_hasAllAttributes = "This value has been reset."; }

signals:
    void notifiableChanged(const QString &newValue);
    void hasAllAttributesChanged(const QString &newValue);
};

#endif // PROPERTYALIASATTRIBUTES_H