diff options
Diffstat (limited to 'examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.h')
-rw-r--r-- | examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.h b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.h new file mode 100644 index 0000000000..1a28ef2632 --- /dev/null +++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.h @@ -0,0 +1,48 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef BIRTHDAYPARTY_H +#define BIRTHDAYPARTY_H + +#include "person.h" + +#include <QObject> +#include <QQmlListProperty> + +class BirthdayParty : public QObject +{ + Q_OBJECT + Q_PROPERTY(Person *host READ host WRITE setHost NOTIFY hostChanged FINAL) + Q_PROPERTY(QQmlListProperty<Person> guests READ guests NOTIFY guestsChanged FINAL) + QML_ELEMENT +public: + using QObject::QObject; + + Person *host() const; + void setHost(Person *); + + QQmlListProperty<Person> guests(); + void appendGuest(Person *); + qsizetype guestCount() const; + Person *guest(qsizetype) const; + void clearGuests(); + void replaceGuest(qsizetype, Person *); + void removeLastGuest(); + +signals: + void hostChanged(); + void guestsChanged(); + +private: + static void appendGuest(QQmlListProperty<Person> *, Person *); + static qsizetype guestCount(QQmlListProperty<Person> *); + static Person *guest(QQmlListProperty<Person> *, qsizetype); + static void clearGuests(QQmlListProperty<Person> *); + static void replaceGuest(QQmlListProperty<Person> *, qsizetype, Person *); + static void removeLastGuest(QQmlListProperty<Person> *); + + Person *m_host = nullptr; + QList<Person *> m_guests; +}; + +#endif // BIRTHDAYPARTY_H |