diff options
Diffstat (limited to 'examples/qml/referenceexamples/attached')
9 files changed, 0 insertions, 380 deletions
diff --git a/examples/qml/referenceexamples/attached/CMakeLists.txt b/examples/qml/referenceexamples/attached/CMakeLists.txt deleted file mode 100644 index ce4ff3e80f..0000000000 --- a/examples/qml/referenceexamples/attached/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(attached LANGUAGES CXX) - -set(CMAKE_AUTOMOC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/referenceexamples/attached") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml) - -qt_add_executable(attached - birthdayparty.cpp birthdayparty.h - main.cpp - person.cpp person.h -) - -set_target_properties(attached PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(attached PUBLIC - Qt::Core - Qt::Gui - Qt::Qml -) - -qt_add_qml_module(attached - URI People - QML_FILES example.qml - NO_RESOURCE_TARGET_PATH -) - -install(TARGETS attached - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/qml/referenceexamples/attached/attached.pro b/examples/qml/referenceexamples/attached/attached.pro deleted file mode 100644 index 8c66b189f7..0000000000 --- a/examples/qml/referenceexamples/attached/attached.pro +++ /dev/null @@ -1,15 +0,0 @@ -QT += qml -CONFIG += qmltypes - -QML_IMPORT_NAME = People -QML_IMPORT_MAJOR_VERSION = 1 - -SOURCES += main.cpp \ - person.cpp \ - birthdayparty.cpp -HEADERS += person.h \ - birthdayparty.h -RESOURCES += attached.qrc - -target.path = $$[QT_INSTALL_EXAMPLES]/qml/referenceexamples/attached -INSTALLS += target diff --git a/examples/qml/referenceexamples/attached/attached.qrc b/examples/qml/referenceexamples/attached/attached.qrc deleted file mode 100644 index e2fa01d5e7..0000000000 --- a/examples/qml/referenceexamples/attached/attached.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource> - <file>example.qml</file> -</qresource> -</RCC> diff --git a/examples/qml/referenceexamples/attached/birthdayparty.cpp b/examples/qml/referenceexamples/attached/birthdayparty.cpp deleted file mode 100644 index a76b0f55cb..0000000000 --- a/examples/qml/referenceexamples/attached/birthdayparty.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "birthdayparty.h" - -QDate BirthdayPartyAttached::rsvp() const -{ - return m_rsvp; -} - -void BirthdayPartyAttached::setRsvp(QDate d) -{ - m_rsvp = d; -} - -Person *BirthdayParty::host() const -{ - return m_host; -} - -void BirthdayParty::setHost(Person *c) -{ - m_host = c; -} - -QQmlListProperty<Person> BirthdayParty::guests() -{ - return {this, &m_guests}; -} - -qsizetype BirthdayParty::guestCount() const -{ - return m_guests.count(); -} - -Person *BirthdayParty::guest(qsizetype index) const -{ - return m_guests.at(index); -} - -BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object) -{ - return new BirthdayPartyAttached(object); -} - diff --git a/examples/qml/referenceexamples/attached/birthdayparty.h b/examples/qml/referenceexamples/attached/birthdayparty.h deleted file mode 100644 index 7eb6508869..0000000000 --- a/examples/qml/referenceexamples/attached/birthdayparty.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef BIRTHDAYPARTY_H -#define BIRTHDAYPARTY_H - -#include <QObject> -#include <QDate> -#include <qqml.h> -#include "person.h" - -class BirthdayPartyAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) - QML_ANONYMOUS -public: - using QObject::QObject; - - QDate rsvp() const; - void setRsvp(QDate); - -private: - QDate m_rsvp; -}; - -class BirthdayParty : public QObject -{ - Q_OBJECT - Q_PROPERTY(Person *host READ host WRITE setHost) - Q_PROPERTY(QQmlListProperty<Person> guests READ guests) - Q_CLASSINFO("DefaultProperty", "guests") - QML_ELEMENT - -//! [declare attached] - QML_ATTACHED(BirthdayPartyAttached) -//! [declare attached] - -public: - using QObject::QObject; - - Person *host() const; - void setHost(Person *); - - QQmlListProperty<Person> guests(); - qsizetype guestCount() const; - Person *guest(qsizetype) const; - - //! [static attached] - static BirthdayPartyAttached *qmlAttachedProperties(QObject *); - //! [static attached] -private: - Person *m_host = nullptr; - QList<Person *> m_guests; -}; - -#endif // BIRTHDAYPARTY_H diff --git a/examples/qml/referenceexamples/attached/example.qml b/examples/qml/referenceexamples/attached/example.qml deleted file mode 100644 index a4e675fe51..0000000000 --- a/examples/qml/referenceexamples/attached/example.qml +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import People -import QtQuick // For QColor - -//! [begin] -BirthdayParty { -//! [begin] - -//! [rsvp] - Boy { - name: "Robert Campbell" - BirthdayParty.rsvp: "2009-07-01" - } -//! [rsvp] - // ![1] - Boy { - name: "Leo Hodges" - shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 } - - BirthdayParty.rsvp: "2009-07-06" - } - // ![1] - host: Boy { - name: "Jack Smith" - shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 } - } -//! [end] -} -//! [end] - diff --git a/examples/qml/referenceexamples/attached/main.cpp b/examples/qml/referenceexamples/attached/main.cpp deleted file mode 100644 index cfe0a1b9b2..0000000000 --- a/examples/qml/referenceexamples/attached/main.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QCoreApplication> -#include <QQmlEngine> -#include <QQmlComponent> -#include <QDebug> -#include "birthdayparty.h" -#include "person.h" - -int main(int argc, char ** argv) -{ - QCoreApplication app(argc, argv); - - QQmlEngine engine; - QQmlComponent component(&engine, QUrl("qrc:example.qml")); - auto *party = qobject_cast<BirthdayParty *>(component.create()); - - if (party && party->host()) { - qInfo() << party->host()->name() << "is having a birthday!"; - - if (qobject_cast<Boy *>(party->host())) - qInfo() << "He is inviting:"; - else - qInfo() << "She is inviting:"; - - for (qsizetype ii = 0; ii < party->guestCount(); ++ii) { - Person *guest = party->guest(ii); - - //! [query rsvp] - QDate rsvpDate; - QObject *attached = qmlAttachedPropertiesObject<BirthdayParty>(guest, false); - - if (attached) - rsvpDate = attached->property("rsvp").toDate(); - //! [query rsvp] - if (rsvpDate.isNull()) - qInfo() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; - else - qInfo() << " " << guest->name() << "RSVP date:" << rsvpDate.toString(); - } - - return EXIT_SUCCESS; - } - - qWarning() << component.errors(); - return EXIT_FAILURE; -} diff --git a/examples/qml/referenceexamples/attached/person.cpp b/examples/qml/referenceexamples/attached/person.cpp deleted file mode 100644 index 358fbf0ed8..0000000000 --- a/examples/qml/referenceexamples/attached/person.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include "person.h" - -int ShoeDescription::size() const -{ - return m_size; -} - -void ShoeDescription::setSize(int s) -{ - m_size = s; -} - -QColor ShoeDescription::color() const -{ - return m_color; -} - -void ShoeDescription::setColor(const QColor &c) -{ - m_color = c; -} - -QString ShoeDescription::brand() const -{ - return m_brand; -} - -void ShoeDescription::setBrand(const QString &b) -{ - m_brand = b; -} - -qreal ShoeDescription::price() const -{ - return m_price; -} - -void ShoeDescription::setPrice(qreal p) -{ - m_price = p; -} - -QString Person::name() const -{ - return m_name; -} - -void Person::setName(const QString &n) -{ - m_name = n; -} - -ShoeDescription *Person::shoe() -{ - return &m_shoe; -} diff --git a/examples/qml/referenceexamples/attached/person.h b/examples/qml/referenceexamples/attached/person.h deleted file mode 100644 index 9c617ee9ab..0000000000 --- a/examples/qml/referenceexamples/attached/person.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#ifndef PERSON_H -#define PERSON_H - -#include <QObject> -#include <QColor> -#include <QtQml/qqml.h> - -class ShoeDescription : public QObject -{ - Q_OBJECT - Q_PROPERTY(int size READ size WRITE setSize) - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(QString brand READ brand WRITE setBrand) - Q_PROPERTY(qreal price READ price WRITE setPrice) - QML_ANONYMOUS -public: - using QObject::QObject; - - int size() const; - void setSize(int); - - QColor color() const; - void setColor(const QColor &); - - QString brand() const; - void setBrand(const QString &); - - qreal price() const; - void setPrice(qreal); - -private: - int m_size = 0; - QColor m_color; - QString m_brand; - qreal m_price = 0; -}; - -class Person : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(ShoeDescription *shoe READ shoe) - QML_ANONYMOUS -public: - using QObject::QObject; - - QString name() const; - void setName(const QString &); - - ShoeDescription *shoe(); -private: - QString m_name; - ShoeDescription m_shoe; -}; - -class Boy : public Person -{ - Q_OBJECT - QML_ELEMENT -public: - using Person::Person; -}; - -class Girl : public Person -{ - Q_OBJECT - QML_ELEMENT -public: - using Person::Person; -}; - -#endif // PERSON_H |