aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmltc/QmltcTests/cpptypes/testprivateproperty.h
blob: 230c86affdfdf059a586c8a8cd755ea2bd93e3ab (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
// 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 TESTPRIVATEPROPERTY_H
#define TESTPRIVATEPROPERTY_H

#include "testgroupedtype.h"

#include <QtCore/qobject.h>
#include <QtCore/qproperty.h>
#include <qqml.h>

#include <private/qobject_p.h>

class ValueTypeGroup
{
    Q_GADGET
    QML_ANONYMOUS
    Q_PROPERTY(int count READ count WRITE setCount)

    int m_count;

public:
    int count() const { return m_count; }
    void setCount(int c) { m_count = c; }
};

class PrivatePropertyTypePrivate;
class PrivatePropertyType : public QObject
{
    Q_OBJECT
    QML_ELEMENT

    Q_PRIVATE_PROPERTY(PrivatePropertyType::d_func(), ValueTypeGroup vt READ vt WRITE setVt)
    Q_PRIVATE_PROPERTY(PrivatePropertyType::d_func(),
                       int smth READ smth WRITE setSmth BINDABLE bindableSmth)
    Q_PRIVATE_PROPERTY(PrivatePropertyType::d_func(),
                       QString foo READ foo WRITE setFoo NOTIFY fooChanged)
    Q_PRIVATE_PROPERTY(PrivatePropertyType::d_func(), TestTypeGrouped *group READ getGroup)

    Q_DECLARE_PRIVATE(PrivatePropertyType)
public:
    PrivatePropertyType(QObject *parent = nullptr);
signals:
    void fooChanged();
};

class PrivatePropertyTypePrivate : public QObjectPrivate
{
    Q_DECLARE_PUBLIC(PrivatePropertyType)

    QProperty<int> m_smth;
    QProperty<ValueTypeGroup> m_vt;
    QString m_foo;
    TestTypeGrouped m_group;

public:
    static PrivatePropertyTypePrivate *get(PrivatePropertyType *q) { return q->d_func(); }
    static const PrivatePropertyTypePrivate *get(const PrivatePropertyType *q)
    {
        return q->d_func();
    }

    ValueTypeGroup vt() const;
    void setVt(ValueTypeGroup vt);

    int smth() const;
    void setSmth(int s);
    QBindable<int> bindableSmth();

    QString foo() const;
    void setFoo(const QString &foo);

    TestTypeGrouped *getGroup();
};

#endif // TESTPRIVATEPROPERTY_H