aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/data/birthdayparty.h
blob: 8dd640c67f4522cda2afccdacd57cc09c680fcfa (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
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef BIRTHDAYPARTY_H
#define BIRTHDAYPARTY_H

#include <QObject>
#include <QQmlListProperty>
#include <QProperty>
#include <QBindable>
#include <QDateTime>
#include "person.h"

class BirthdayPartyAttached : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QDateTime rsvp READ rsvp WRITE setRsvp BINDABLE rsvpBindable)
    QML_ANONYMOUS
public:
    BirthdayPartyAttached(QObject *parent);

    QDateTime rsvp() const;
    void setRsvp(const QDateTime &rsvp);
    QBindable<QDateTime> rsvpBindable();

private:
    QProperty<QDateTime> m_rsvp;
};

class BirthDayPartyExtended : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int eee READ eee WRITE setEee NOTIFY eeeChanged)
public:

    BirthDayPartyExtended(QObject *parent) : QObject(parent) {}

    int eee() const { return m_eee; }
    void setEee(int eee)
    {
        if (eee != m_eee) {
            m_eee = eee;
            emit eeeChanged();
        }
    }

signals:
    void eeeChanged();

private:
    int m_eee = 25;
};

struct Foozle {
    int foo = 1;
};

class BirthdayParty : public QObject
{
    Q_OBJECT
    Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL)
    Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
    Q_PROPERTY(QStringList guestNames READ guestNames FINAL)
    Q_PROPERTY(QVariantList stuffs READ stuffs FINAL)
    QML_ELEMENT
    QML_ATTACHED(BirthdayPartyAttached)
    QML_EXTENDED(BirthDayPartyExtended)
public:
    BirthdayParty(QObject *parent = nullptr);

    Person *host() const;
    void setHost(Person *);

    QQmlListProperty<Person> guests();
    int guestCount() const;
    Person *guest(int) const;

    QStringList guestNames() const;
    QVariantList stuffs() const;

    Q_INVOKABLE void invite(const QString &name);
    static BirthdayPartyAttached *qmlAttachedProperties(QObject *object);

signals:
    void hostChanged();
    void partyStarted(Foozle foozle);

private:
    Person *m_host;
    QList<Person *> m_guests;
};

class NastyBase : public QObject {
public:
    NastyBase(QObject *parent) : QObject(parent) {}
};

class Nasty : public NastyBase
{
    Q_OBJECT
    QML_ELEMENT
    QML_ATTACHED(Nasty)

public:
    Nasty(QObject *parent = nullptr) : NastyBase(parent) {}
    static Nasty *qmlAttachedProperties(QObject *object) { return new Nasty(object); }
};

#endif // BIRTHDAYPARTY_H