diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-09-12 17:03:52 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-01-13 16:47:57 +0100 |
commit | 2c3419e127e55810da1741725b4ff39f118cd577 (patch) | |
tree | 670ec93d28dadad06bd840a5694935ef8a7b2ac0 /examples | |
parent | 4eff7299501ff932071300b3fa34fbeccb03d0d8 (diff) |
Generate registrations for all examples
Now that we can generate all QML type information at build time, we
should also use it.
Change-Id: I647c72bbe38fdb2deb565b75c86a696af3d15b61
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'examples')
94 files changed, 658 insertions, 443 deletions
diff --git a/examples/qml/doc/src/qml-extending.qdoc b/examples/qml/doc/src/qml-extending.qdoc index 64d7235031..1ad3ae9a10 100644 --- a/examples/qml/doc/src/qml-extending.qdoc +++ b/examples/qml/doc/src/qml-extending.qdoc @@ -52,10 +52,6 @@ type, the C++ class can be named differently, or appear in a namespace. The Person class implementation is quite basic. The property accessors simply return members of the object instance. -The \c main.cpp file also calls the \c qmlRegisterType() function to -register the \c Person type with QML as a type in the People library version 1.0, -and defines the mapping between the C++ and QML class names. - \section1 Running the Example The main.cpp file in the example includes a simple shell application that @@ -77,9 +73,11 @@ Shows how to use \l {QQmlEngine::}{qmlRegisterExtendedType()} to provide an \l {Registering Extension Objects}{extension object} to a \l QLineEdit without modifying or subclassing it. -Firstly, the LineEditExtension class is registered with the QML system as an extension of QLineEdit: +Firstly, the LineEditExtension class is registered with the QML system as an +extension of QLineEdit. We declare a foreign type to do this as we cannot modify +Qt's internal QLineEdit class. -\snippet referenceexamples/extended/main.cpp 0 +\snippet referenceexamples/extended/lineedit.h 0 The QML engine then instantiates a \l QLineEdit: @@ -182,9 +180,8 @@ directly - an explicit Boy or Girl should be instantiated instead. While we want to disallow instantiating Person from within QML, it still needs to be registered with the QML engine, so that it can be used as a property type -and other types can be coerced to it. - -\snippet referenceexamples/coercion/main.cpp 0 +and other types can be coerced to it. This is what the QML_UNCREATABLE macro +does. \section2 Define Boy and Girl diff --git a/examples/qml/qmlextensionplugins/plugin.cpp b/examples/qml/qmlextensionplugins/plugin.cpp index a6d1d3ff63..99d8c5378c 100644 --- a/examples/qml/qmlextensionplugins/plugin.cpp +++ b/examples/qml/qmlextensionplugins/plugin.cpp @@ -49,117 +49,13 @@ ****************************************************************************/ #include <QtQml/QQmlExtensionPlugin> -#include <QtQml/qqml.h> #include <qdebug.h> -#include <qdatetime.h> -#include <qbasictimer.h> -#include <qcoreapplication.h> - -// Implements a "TimeModel" class with hour and minute properties -// that change on-the-minute yet efficiently sleep the rest -// of the time. - -class MinuteTimer : public QObject -{ - Q_OBJECT -public: - MinuteTimer(QObject *parent) : QObject(parent) - { - } - - void start() - { - if (!timer.isActive()) { - time = QTime::currentTime(); - timer.start(60000-time.second()*1000, this); - } - } - - void stop() - { - timer.stop(); - } - - int hour() const { return time.hour(); } - int minute() const { return time.minute(); } - -signals: - void timeChanged(); - -protected: - void timerEvent(QTimerEvent *) override - { - QTime now = QTime::currentTime(); - if (now.second() == 59 && now.minute() == time.minute() && now.hour() == time.hour()) { - // just missed time tick over, force it, wait extra 0.5 seconds - time = time.addSecs(60); - timer.start(60500, this); - } else { - time = now; - timer.start(60000-time.second()*1000, this); - } - emit timeChanged(); - } - -private: - QTime time; - QBasicTimer timer; -}; - -//![0] -class TimeModel : public QObject -{ - Q_OBJECT - Q_PROPERTY(int hour READ hour NOTIFY timeChanged) - Q_PROPERTY(int minute READ minute NOTIFY timeChanged) - QML_NAMED_ELEMENT(Time) -//![0] - -public: - TimeModel(QObject *parent=nullptr) : QObject(parent) - { - if (++instances == 1) { - if (!timer) - timer = new MinuteTimer(QCoreApplication::instance()); - connect(timer, &MinuteTimer::timeChanged, this, &TimeModel::timeChanged); - timer->start(); - } - } - - ~TimeModel() override - { - if (--instances == 0) { - timer->stop(); - } - } - - int minute() const { return timer->minute(); } - int hour() const { return timer->hour(); } - -signals: - void timeChanged(); - -private: - QTime t; - static MinuteTimer *timer; - static int instances; -}; - -int TimeModel::instances=0; -MinuteTimer *TimeModel::timer=nullptr; //![plugin] -class QExampleQmlPlugin : public QQmlExtensionPlugin +class QExampleQmlPlugin : public QQmlEngineExtensionPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) - -public: - void registerTypes(const char *uri) override - { - Q_ASSERT(uri == QLatin1String("TimeExample")); - qmlRegisterTypesAndRevisions<TimeModel>(uri, 1); - } + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) }; //![plugin] diff --git a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro index 946626cce7..40c2b396a3 100644 --- a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro +++ b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro @@ -1,25 +1,37 @@ TEMPLATE = lib -CONFIG += plugin +CONFIG += plugin qmltypes QT += qml -DESTDIR = imports/TimeExample +QML_IMPORT_NAME = TimeExample +QML_IMPORT_MAJOR_VERSION = 1 + +DESTDIR = imports/$$QML_IMPORT_NAME TARGET = qmlqtimeexampleplugin -SOURCES += plugin.cpp +SOURCES += \ + plugin.cpp \ + timemodel.cpp + +HEADERS += \ + timemodel.h -pluginfiles.files += \ - imports/TimeExample/qmldir \ - imports/TimeExample/center.png \ - imports/TimeExample/clock.png \ - imports/TimeExample/Clock.qml \ - imports/TimeExample/hour.png \ - imports/TimeExample/minute.png +PLUGINFILES = \ + imports/$$QML_IMPORT_NAME/qmldir \ + imports/$$QML_IMPORT_NAME/center.png \ + imports/$$QML_IMPORT_NAME/clock.png \ + imports/$$QML_IMPORT_NAME/Clock.qml \ + imports/$$QML_IMPORT_NAME/hour.png \ + imports/$$QML_IMPORT_NAME/minute.png + +pluginfiles.files += $$PLUGINFILES qml.files = plugins.qml qml.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins -target.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/TimeExample -pluginfiles.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/TimeExample +target.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME +pluginfiles.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME INSTALLS += target qml pluginfiles +OTHER_FILES += $$PLUGINFILES plugins.qml + CONFIG += install_ok # Do not cargo-cult this! diff --git a/examples/qml/qmlextensionplugins/timemodel.cpp b/examples/qml/qmlextensionplugins/timemodel.cpp new file mode 100644 index 0000000000..af5ccb2988 --- /dev/null +++ b/examples/qml/qmlextensionplugins/timemodel.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "timemodel.h" + +int TimeModel::instances=0; +MinuteTimer *TimeModel::timer=nullptr; + +void MinuteTimer::start() +{ + if (!timer.isActive()) { + time = QTime::currentTime(); + timer.start(60000-time.second()*1000, this); + } +} + +void MinuteTimer::stop() +{ + timer.stop(); +} + +void MinuteTimer::timerEvent(QTimerEvent *) +{ + QTime now = QTime::currentTime(); + if (now.second() == 59 && now.minute() == time.minute() && now.hour() == time.hour()) { + // just missed time tick over, force it, wait extra 0.5 seconds + time = time.addSecs(60); + timer.start(60500, this); + } else { + time = now; + timer.start(60000-time.second()*1000, this); + } + emit timeChanged(); +} + +TimeModel::TimeModel(QObject *parent) : QObject(parent) +{ + if (++instances == 1) { + if (!timer) + timer = new MinuteTimer(QCoreApplication::instance()); + connect(timer, &MinuteTimer::timeChanged, this, &TimeModel::timeChanged); + timer->start(); + } +} + +TimeModel::~TimeModel() +{ + if (--instances == 0) { + timer->stop(); + } +} diff --git a/examples/qml/qmlextensionplugins/timemodel.h b/examples/qml/qmlextensionplugins/timemodel.h new file mode 100644 index 0000000000..bb107aeb71 --- /dev/null +++ b/examples/qml/qmlextensionplugins/timemodel.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TIMEMODEL_H +#define TIMEMODEL_H + +#include <QtQml/qqml.h> +#include <QtCore/qdatetime.h> +#include <QtCore/qbasictimer.h> +#include <QtCore/qcoreapplication.h> + +// Implements a "TimeModel" class with hour and minute properties +// that change on-the-minute yet efficiently sleep the rest +// of the time. + +class MinuteTimer : public QObject +{ + Q_OBJECT +public: + MinuteTimer(QObject *parent) : QObject(parent) {} + + void start(); + void stop(); + + int hour() const { return time.hour(); } + int minute() const { return time.minute(); } + +signals: + void timeChanged(); + +protected: + void timerEvent(QTimerEvent *) override; + +private: + QTime time; + QBasicTimer timer; +}; + +//![0] +class TimeModel : public QObject +{ + Q_OBJECT + Q_PROPERTY(int hour READ hour NOTIFY timeChanged) + Q_PROPERTY(int minute READ minute NOTIFY timeChanged) + QML_NAMED_ELEMENT(Time) +//![0] + +public: + TimeModel(QObject *parent=nullptr); + ~TimeModel() override; + + int minute() const { return timer->minute(); } + int hour() const { return timer->hour(); } + +signals: + void timeChanged(); + +private: + QTime t; + static MinuteTimer *timer; + static int instances; +}; + +#endif // TIMEMODEL_H diff --git a/examples/qml/referenceexamples/adding/adding.pro b/examples/qml/referenceexamples/adding/adding.pro index ae135c7925..a4a677c3c4 100644 --- a/examples/qml/referenceexamples/adding/adding.pro +++ b/examples/qml/referenceexamples/adding/adding.pro @@ -1,4 +1,8 @@ QT = core qml +CONFIG += qmltypes + +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 SOURCES += main.cpp \ person.cpp diff --git a/examples/qml/referenceexamples/adding/main.cpp b/examples/qml/referenceexamples/adding/main.cpp index ffd0e90c42..6c3920f04b 100644 --- a/examples/qml/referenceexamples/adding/main.cpp +++ b/examples/qml/referenceexamples/adding/main.cpp @@ -56,9 +56,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); -//![0] - qmlRegisterTypesAndRevisions<Person>("People", 1); -//![0] QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); diff --git a/examples/qml/referenceexamples/attached/attached.pro b/examples/qml/referenceexamples/attached/attached.pro index 16b585bc45..8c66b189f7 100644 --- a/examples/qml/referenceexamples/attached/attached.pro +++ b/examples/qml/referenceexamples/attached/attached.pro @@ -1,4 +1,8 @@ QT += qml +CONFIG += qmltypes + +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 SOURCES += main.cpp \ person.cpp \ diff --git a/examples/qml/referenceexamples/attached/main.cpp b/examples/qml/referenceexamples/attached/main.cpp index ab1c6b9637..2fceb98ac9 100644 --- a/examples/qml/referenceexamples/attached/main.cpp +++ b/examples/qml/referenceexamples/attached/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions<BirthdayPartyAttached, - BirthdayParty, ShoeDescription, - Person, Boy, Girl>("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); diff --git a/examples/qml/referenceexamples/binding/binding.pro b/examples/qml/referenceexamples/binding/binding.pro index 636d0a10f1..dce780d0a2 100644 --- a/examples/qml/referenceexamples/binding/binding.pro +++ b/examples/qml/referenceexamples/binding/binding.pro @@ -1,5 +1,9 @@ QT += qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp \ diff --git a/examples/qml/referenceexamples/binding/happybirthdaysong.h b/examples/qml/referenceexamples/binding/happybirthdaysong.h index a1582f0d4b..c84e9d9e5e 100644 --- a/examples/qml/referenceexamples/binding/happybirthdaysong.h +++ b/examples/qml/referenceexamples/binding/happybirthdaysong.h @@ -55,6 +55,7 @@ #include <qqml.h> #include <QStringList> +#include <qqml.h> class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource { diff --git a/examples/qml/referenceexamples/binding/main.cpp b/examples/qml/referenceexamples/binding/main.cpp index 8c6e3222d8..2e9995fcd8 100644 --- a/examples/qml/referenceexamples/binding/main.cpp +++ b/examples/qml/referenceexamples/binding/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions<BirthdayPartyAttached, BirthdayParty, HappyBirthdaySong, - ShoeDescription, Person, Boy, Girl>("People", 1); QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); diff --git a/examples/qml/referenceexamples/coercion/birthdayparty.h b/examples/qml/referenceexamples/coercion/birthdayparty.h index 554e7ab0da..ba8b2445f1 100644 --- a/examples/qml/referenceexamples/coercion/birthdayparty.h +++ b/examples/qml/referenceexamples/coercion/birthdayparty.h @@ -60,6 +60,7 @@ class BirthdayParty : public QObject // ![0] Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) + QML_ELEMENT // ![0] public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/coercion/coercion.pro b/examples/qml/referenceexamples/coercion/coercion.pro index 373a15fc28..225fd13e08 100644 --- a/examples/qml/referenceexamples/coercion/coercion.pro +++ b/examples/qml/referenceexamples/coercion/coercion.pro @@ -1,5 +1,9 @@ QT = core qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/coercion/main.cpp b/examples/qml/referenceexamples/coercion/main.cpp index 2c2bd92e8d..6b47d0d4c4 100644 --- a/examples/qml/referenceexamples/coercion/main.cpp +++ b/examples/qml/referenceexamples/coercion/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - //![0] - qmlRegisterTypesAndRevisions<BirthdayParty, Person, Boy, Girl>("People", 1); - //![0] - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); diff --git a/examples/qml/referenceexamples/coercion/person.h b/examples/qml/referenceexamples/coercion/person.h index 6865e0093a..7e2828da04 100644 --- a/examples/qml/referenceexamples/coercion/person.h +++ b/examples/qml/referenceexamples/coercion/person.h @@ -59,7 +59,8 @@ class Person : public QObject Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) //![0] - QML_ANONYMOUS + QML_ELEMENT + QML_UNCREATABLE("Person is an abstract base class.") //![0] public: Person(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/default/birthdayparty.h b/examples/qml/referenceexamples/default/birthdayparty.h index ea63a6a16d..5eb6c88763 100644 --- a/examples/qml/referenceexamples/default/birthdayparty.h +++ b/examples/qml/referenceexamples/default/birthdayparty.h @@ -61,6 +61,7 @@ class BirthdayParty : public QObject Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") + QML_ELEMENT public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/default/default.pro b/examples/qml/referenceexamples/default/default.pro index c119ef0d2e..f52f749ddd 100644 --- a/examples/qml/referenceexamples/default/default.pro +++ b/examples/qml/referenceexamples/default/default.pro @@ -1,5 +1,9 @@ QT = core qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/default/main.cpp b/examples/qml/referenceexamples/default/main.cpp index bbe4a239e2..6b47d0d4c4 100644 --- a/examples/qml/referenceexamples/default/main.cpp +++ b/examples/qml/referenceexamples/default/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions<BirthdayParty, Person, Boy, Girl>("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); diff --git a/examples/qml/referenceexamples/extended/extended.pro b/examples/qml/referenceexamples/extended/extended.pro index 22d8ded708..094e5201ca 100644 --- a/examples/qml/referenceexamples/extended/extended.pro +++ b/examples/qml/referenceexamples/extended/extended.pro @@ -1,5 +1,9 @@ QT += qml widgets +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ lineedit.cpp HEADERS += lineedit.h diff --git a/examples/qml/referenceexamples/extended/lineedit.h b/examples/qml/referenceexamples/extended/lineedit.h index e8f7d90853..5c315ad5ac 100644 --- a/examples/qml/referenceexamples/extended/lineedit.h +++ b/examples/qml/referenceexamples/extended/lineedit.h @@ -51,6 +51,7 @@ #define LINEEDIT_H #include <QLineEdit> +#include <qqml.h> class LineEditExtension : public QObject { @@ -80,4 +81,14 @@ private: QLineEdit *m_lineedit; }; +// ![0] +struct QLineEditForeign +{ + Q_GADGET + QML_FOREIGN(QLineEdit) + QML_ELEMENT + QML_EXTENDED(LineEditExtension) +}; +// ![0] + #endif // LINEEDIT_H diff --git a/examples/qml/referenceexamples/extended/main.cpp b/examples/qml/referenceexamples/extended/main.cpp index 5f8582d08f..26048d9189 100644 --- a/examples/qml/referenceexamples/extended/main.cpp +++ b/examples/qml/referenceexamples/extended/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char ** argv) { QApplication app(argc, argv); -// ![0] - qmlRegisterExtendedType<QLineEdit, LineEditExtension>("People", 1,0, "QLineEdit"); -// ![0] - // ![1] QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); diff --git a/examples/qml/referenceexamples/grouped/birthdayparty.h b/examples/qml/referenceexamples/grouped/birthdayparty.h index edaa11fa88..f6834dad89 100644 --- a/examples/qml/referenceexamples/grouped/birthdayparty.h +++ b/examples/qml/referenceexamples/grouped/birthdayparty.h @@ -60,6 +60,7 @@ class BirthdayParty : public QObject Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") + QML_ELEMENT public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/grouped/grouped.pro b/examples/qml/referenceexamples/grouped/grouped.pro index ef66ea3e1d..1513ac552d 100644 --- a/examples/qml/referenceexamples/grouped/grouped.pro +++ b/examples/qml/referenceexamples/grouped/grouped.pro @@ -1,5 +1,9 @@ QT += qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/grouped/main.cpp b/examples/qml/referenceexamples/grouped/main.cpp index e233aab5b1..63dbe988a4 100644 --- a/examples/qml/referenceexamples/grouped/main.cpp +++ b/examples/qml/referenceexamples/grouped/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions<BirthdayParty, ShoeDescription, Person, Boy, Girl>("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); diff --git a/examples/qml/referenceexamples/methods/birthdayparty.h b/examples/qml/referenceexamples/methods/birthdayparty.h index 0eb968a841..5c2f3c9def 100644 --- a/examples/qml/referenceexamples/methods/birthdayparty.h +++ b/examples/qml/referenceexamples/methods/birthdayparty.h @@ -59,6 +59,7 @@ class BirthdayParty : public QObject Q_OBJECT Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) + QML_ELEMENT public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/methods/main.cpp b/examples/qml/referenceexamples/methods/main.cpp index 4dd616f8cd..e30e1d9fb1 100644 --- a/examples/qml/referenceexamples/methods/main.cpp +++ b/examples/qml/referenceexamples/methods/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions<BirthdayParty, Person>("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); diff --git a/examples/qml/referenceexamples/methods/methods.pro b/examples/qml/referenceexamples/methods/methods.pro index 008ba19d96..2a5f3cff41 100644 --- a/examples/qml/referenceexamples/methods/methods.pro +++ b/examples/qml/referenceexamples/methods/methods.pro @@ -1,5 +1,9 @@ QT = core qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/properties/birthdayparty.h b/examples/qml/referenceexamples/properties/birthdayparty.h index 8d62c8dcd5..fb8b63a79d 100644 --- a/examples/qml/referenceexamples/properties/birthdayparty.h +++ b/examples/qml/referenceexamples/properties/birthdayparty.h @@ -67,6 +67,7 @@ class BirthdayParty : public QObject Q_PROPERTY(QQmlListProperty<Person> guests READ guests) // ![2] // ![3] + QML_ELEMENT public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/properties/main.cpp b/examples/qml/referenceexamples/properties/main.cpp index 216869bf6c..e30e1d9fb1 100644 --- a/examples/qml/referenceexamples/properties/main.cpp +++ b/examples/qml/referenceexamples/properties/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); -//![register list] - qmlRegisterTypesAndRevisions<BirthdayParty, Person>("People", 1); -//![register list] - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); diff --git a/examples/qml/referenceexamples/properties/properties.pro b/examples/qml/referenceexamples/properties/properties.pro index 101c878abd..6697afa2c5 100644 --- a/examples/qml/referenceexamples/properties/properties.pro +++ b/examples/qml/referenceexamples/properties/properties.pro @@ -1,5 +1,9 @@ QT = core qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/signal/main.cpp b/examples/qml/referenceexamples/signal/main.cpp index f431e2bdc8..7ef3595a8c 100644 --- a/examples/qml/referenceexamples/signal/main.cpp +++ b/examples/qml/referenceexamples/signal/main.cpp @@ -58,9 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions<BirthdayPartyAttached, BirthdayParty, ShoeDescription, - Person, Boy, Girl>("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); diff --git a/examples/qml/referenceexamples/signal/signal.pro b/examples/qml/referenceexamples/signal/signal.pro index 2dbc8e624b..3c31234b3c 100644 --- a/examples/qml/referenceexamples/signal/signal.pro +++ b/examples/qml/referenceexamples/signal/signal.pro @@ -1,5 +1,9 @@ QT += qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/valuesource/happybirthdaysong.h b/examples/qml/referenceexamples/valuesource/happybirthdaysong.h index e2205a4ebb..2600208968 100644 --- a/examples/qml/referenceexamples/valuesource/happybirthdaysong.h +++ b/examples/qml/referenceexamples/valuesource/happybirthdaysong.h @@ -64,6 +64,7 @@ class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource // ![0] Q_PROPERTY(QString name READ name WRITE setName) // ![1] + QML_ELEMENT public: HappyBirthdaySong(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/valuesource/main.cpp b/examples/qml/referenceexamples/valuesource/main.cpp index 72e75fdea1..2e9995fcd8 100644 --- a/examples/qml/referenceexamples/valuesource/main.cpp +++ b/examples/qml/referenceexamples/valuesource/main.cpp @@ -59,9 +59,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions<BirthdayPartyAttached, BirthdayParty, HappyBirthdaySong, - ShoeDescription, Person, Boy, Girl>("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); diff --git a/examples/qml/referenceexamples/valuesource/valuesource.pro b/examples/qml/referenceexamples/valuesource/valuesource.pro index 01cfeeb6d8..6d29cf1b70 100644 --- a/examples/qml/referenceexamples/valuesource/valuesource.pro +++ b/examples/qml/referenceexamples/valuesource/valuesource.pro @@ -1,5 +1,9 @@ QT += qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp \ diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro b/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro index 9911e02484..294a9ad0e8 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += piechart.h SOURCES += piechart.cpp \ main.cpp diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp b/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp index af50cc14f2..10df9c2566 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp @@ -56,8 +56,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<PieChart>("Charts", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.pro b/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.pro index 7fd850ce36..264f028f5c 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.pro +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += piechart.h SOURCES += piechart.cpp \ main.cpp diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp b/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp index af50cc14f2..10df9c2566 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp @@ -56,8 +56,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<PieChart>("Charts", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.pro b/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.pro index 1ae83f71eb..152f17ce8c 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.pro +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += piechart.h SOURCES += piechart.cpp \ main.cpp diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp b/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp index af50cc14f2..10df9c2566 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp @@ -56,8 +56,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<PieChart>("Charts", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro index 12dfbd6280..e277f74676 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += piechart.h \ pieslice.h SOURCES += piechart.cpp \ diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp index 7c5d1a6885..76e075a72c 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp @@ -59,10 +59,6 @@ int main(int argc, char *argv[]) //![0] QGuiApplication app(argc, argv); -//![1] - qmlRegisterTypesAndRevisions<PieChart, PieSlice>("Charts", 1); -//![1] - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.pro b/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.pro index 67d1cd35c3..edbd3c237d 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.pro +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += piechart.h \ pieslice.h SOURCES += piechart.cpp \ diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp b/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp index 70ef103e4d..7262969b62 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp @@ -57,8 +57,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<PieChart, PieSlice>("Charts", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h index 69a858d48b..0b1cfcc8f1 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h @@ -53,13 +53,10 @@ //![0] #include <QQmlExtensionPlugin> -class ChartsPlugin : public QQmlExtensionPlugin +class ChartsPlugin : public QQmlEngineExtensionPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) - -public: - void registerTypes(const char *uri); + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) }; //![0] diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro index 5cf4621420..c37cd1fdee 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro @@ -1,8 +1,11 @@ TEMPLATE = lib -CONFIG += plugin +CONFIG += plugin qmltypes QT += qml quick -DESTDIR = ../Charts +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + +DESTDIR = ../$$QML_IMPORT_NAME TARGET = $$qtLibraryTarget(chartsplugin) HEADERS += piechart.h \ @@ -10,10 +13,13 @@ HEADERS += piechart.h \ chartsplugin.h SOURCES += piechart.cpp \ - pieslice.cpp \ - chartsplugin.cpp + pieslice.cpp + +DESTPATH=$$[QT_INSTALL_EXAMPLES]/qml/tutorials/extending-qml/chapter6-plugins/$$QML_IMPORT_NAME -DESTPATH=$$[QT_INSTALL_EXAMPLES]/qml/tutorials/extending-qml/chapter6-plugins/Charts +copy_qmltypes.files = $$OUT_PWD/plugins.qmltypes +copy_qmltypes.path = $$DESTDIR +COPIES += copy_qmltypes target.path=$$DESTPATH qmldir.files=$$PWD/qmldir diff --git a/examples/quick/customitems/maskedmousearea/main.cpp b/examples/quick/customitems/maskedmousearea/main.cpp index 626f0fd765..5b42516154 100644 --- a/examples/quick/customitems/maskedmousearea/main.cpp +++ b/examples/quick/customitems/maskedmousearea/main.cpp @@ -53,14 +53,11 @@ #include "maskedmousearea.h" - int main(int argc, char* argv[]) { QGuiApplication app(argc,argv); QQuickView view; - qmlRegisterTypesAndRevisions<MaskedMouseArea>("Example", 1); - view.setSource(QUrl("qrc:///customitems/maskedmousearea/maskedmousearea.qml")); view.show(); return app.exec(); diff --git a/examples/quick/customitems/maskedmousearea/maskedmousearea.pro b/examples/quick/customitems/maskedmousearea/maskedmousearea.pro index fe5c05ce61..c5cedf4e6e 100644 --- a/examples/quick/customitems/maskedmousearea/maskedmousearea.pro +++ b/examples/quick/customitems/maskedmousearea/maskedmousearea.pro @@ -2,6 +2,10 @@ TEMPLATE = app QT += quick qml +CONFIG += qmltypes +QML_IMPORT_NAME = Example +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += maskedmousearea.h SOURCES += main.cpp \ diff --git a/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h b/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h index 41750d1647..972859f80e 100644 --- a/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h +++ b/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h @@ -52,13 +52,8 @@ #include "../textballoon.h" -class TextBalloonPlugin : public QQmlExtensionPlugin +class TextBalloonPlugin : public QQmlEngineExtensionPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) -public: - void registerTypes(const char *uri) - { - qmlRegisterTypesAndRevisions<TextBalloon>(uri, 1); - } + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) }; diff --git a/examples/quick/customitems/painteditem/painteditem.pro b/examples/quick/customitems/painteditem/painteditem.pro index bc7480ab9e..641833f3aa 100644 --- a/examples/quick/customitems/painteditem/painteditem.pro +++ b/examples/quick/customitems/painteditem/painteditem.pro @@ -1,21 +1,25 @@ TEMPLATE = lib -CONFIG += plugin +CONFIG += plugin qmltypes QT += qml quick +QML_IMPORT_NAME = TextBalloonPlugin +QML_IMPORT_MAJOR_VERSION = 1 + TARGET = qmltextballoonplugin -HEADERS += TextBalloonPlugin/plugin.h \ +HEADERS += \ + TextBalloonPlugin/plugin.h \ textballoon.h SOURCES += textballoon.cpp RESOURCES += painteditem.qrc -DESTDIR = TextBalloonPlugin +DESTDIR = $$QML_IMPORT_NAME -target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/TextBalloonPlugin -qmldir.files = TextBalloonPlugin/qmldir -qmldir.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/TextBalloonPlugin +target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME +qmldir.files = $$QML_IMPORT_NAME/qmldir +qmldir.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME INSTALLS += qmldir target diff --git a/examples/quick/imageprovider/imageprovider.cpp b/examples/quick/imageprovider/imageprovider.cpp index 2d927ea79a..a606352cce 100644 --- a/examples/quick/imageprovider/imageprovider.cpp +++ b/examples/quick/imageprovider/imageprovider.cpp @@ -90,22 +90,16 @@ public: }; -class ImageProviderExtensionPlugin : public QQmlExtensionPlugin +class ImageProviderExtensionPlugin : public QQmlEngineExtensionPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - void registerTypes(const char *uri) override - { - Q_UNUSED(uri); - } - void initializeEngine(QQmlEngine *engine, const char *uri) override { Q_UNUSED(uri); engine->addImageProvider("colors", new ColorImageProvider); } - }; diff --git a/examples/quick/imageresponseprovider/imageresponseprovider.cpp b/examples/quick/imageresponseprovider/imageresponseprovider.cpp index 32510dbec8..4ab1090361 100644 --- a/examples/quick/imageresponseprovider/imageresponseprovider.cpp +++ b/examples/quick/imageresponseprovider/imageresponseprovider.cpp @@ -128,16 +128,11 @@ private: }; -class ImageProviderExtensionPlugin : public QQmlExtensionPlugin +class ImageProviderExtensionPlugin : public QQmlEngineExtensionPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) public: - void registerTypes(const char *uri) override - { - Q_UNUSED(uri); - } - void initializeEngine(QQmlEngine *engine, const char *uri) override { Q_UNUSED(uri); diff --git a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp index 6ebf36c454..850ecd147b 100644 --- a/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp +++ b/examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp @@ -86,8 +86,6 @@ MainWindow::MainWindow(bool transparency, bool noRenderAlpha) m_labelStatus = new QLabel; layout->addWidget(m_labelStatus); - qmlRegisterTypesAndRevisions<FbItem>("fbitem", 1); - QWidget *quickContainer = new QWidget; layout->addWidget(quickContainer); layout->setStretchFactor(quickContainer, 8); diff --git a/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro b/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro index 80216da346..7809c20b3a 100644 --- a/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro +++ b/examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro @@ -1,6 +1,10 @@ TEMPLATE = app TARGET = qquickviewcomparison +CONFIG += qmltypes +QML_IMPORT_NAME = fbitem +QML_IMPORT_MAJOR_VERSION = 1 + QT += quick widgets quickwidgets SOURCES += main.cpp \ diff --git a/examples/quick/quickwidgets/quickwidget/main.cpp b/examples/quick/quickwidgets/quickwidget/main.cpp index 541f543f07..f28b2f1443 100644 --- a/examples/quick/quickwidgets/quickwidget/main.cpp +++ b/examples/quick/quickwidgets/quickwidget/main.cpp @@ -214,8 +214,6 @@ int main(int argc, char **argv) optMultipleSample = parser.isSet(multipleSampleOption); optCoreProfile = parser.isSet(coreProfileOption); - qmlRegisterTypesAndRevisions<FbItem>("QuickWidgetExample", 1); - MainWindow mainWindow; mainWindow.show(); diff --git a/examples/quick/quickwidgets/quickwidget/quickwidget.pro b/examples/quick/quickwidgets/quickwidget/quickwidget.pro index 5be006f7fa..b824c520f5 100644 --- a/examples/quick/quickwidgets/quickwidget/quickwidget.pro +++ b/examples/quick/quickwidgets/quickwidget/quickwidget.pro @@ -3,6 +3,10 @@ QT += core gui quick widgets quickwidgets TARGET = quickwidget TEMPLATE = app +CONFIG += qmltypes +QML_IMPORT_NAME = QuickWidgetExample +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp fbitem.cpp HEADERS += fbitem.h diff --git a/examples/quick/scenegraph/customgeometry/beziercurve.h b/examples/quick/scenegraph/customgeometry/beziercurve.h index be9e4ef49f..fd0085a08e 100644 --- a/examples/quick/scenegraph/customgeometry/beziercurve.h +++ b/examples/quick/scenegraph/customgeometry/beziercurve.h @@ -64,7 +64,9 @@ class BezierCurve : public QQuickItem Q_PROPERTY(QPointF p4 READ p4 WRITE setP4 NOTIFY p4Changed) Q_PROPERTY(int segmentCount READ segmentCount WRITE setSegmentCount NOTIFY segmentCountChanged) +//! [3] QML_ELEMENT +//! [3] public: BezierCurve(QQuickItem *parent = 0); diff --git a/examples/quick/scenegraph/customgeometry/customgeometry.pro b/examples/quick/scenegraph/customgeometry/customgeometry.pro index 17c30fc560..3785f88c7e 100644 --- a/examples/quick/scenegraph/customgeometry/customgeometry.pro +++ b/examples/quick/scenegraph/customgeometry/customgeometry.pro @@ -1,6 +1,10 @@ TARGET = customgeometry QT += quick +CONFIG += qmltypes +QML_IMPORT_NAME = CustomGeometry +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += \ main.cpp \ beziercurve.cpp diff --git a/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc b/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc index 959114b424..bd235e5dfb 100644 --- a/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc +++ b/examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc @@ -169,11 +169,16 @@ \snippet scenegraph/customgeometry/main.cpp 1 The application is a straightforward QML application, with a - QGuiApplication and a QQuickView that we pass a .qml file. To make - use of the BezierCurve item, we need to register it in the QML - engine, using the qmlRegisterType() function. We give it the name - BezierCurve and make it part of the \c {CustomGeometry 1.0} - module. + QGuiApplication and a QQuickView that we pass a .qml file. + + \snippet scenegraph/customgeometry/beziercurve.h 3 + + To make use of the BezierCurve item, we need to register it in the QML + engine, using the QML_ELEMENT macro. This gives it the name + BezierCurve and makes it part of the \c {CustomGeometry 1.0} + module as defined in the customgeometry.pro file: + + \quotefile scenegraph/customgeometry/customgeometry.pro As the bezier curve is drawn using GL_LINE_STRIP, we specify that the view should be multisampled to get antialiasing. This is not diff --git a/examples/quick/scenegraph/customgeometry/main.cpp b/examples/quick/scenegraph/customgeometry/main.cpp index 9352e4bd24..15310d279f 100644 --- a/examples/quick/scenegraph/customgeometry/main.cpp +++ b/examples/quick/scenegraph/customgeometry/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<BezierCurve>("CustomGeometry", 1); - QQuickView view; QSurfaceFormat format = view.format(); format.setSamples(16); diff --git a/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro b/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro index 7658a9a813..4f052cf388 100644 --- a/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro +++ b/examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro @@ -2,6 +2,10 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = D3D11UnderQML +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += d3d11squircle.h SOURCES += d3d11squircle.cpp main.cpp RESOURCES += d3d11underqml.qrc diff --git a/examples/quick/scenegraph/d3d11underqml/main.cpp b/examples/quick/scenegraph/d3d11underqml/main.cpp index dcab8c879c..bcefae6cb5 100644 --- a/examples/quick/scenegraph/d3d11underqml/main.cpp +++ b/examples/quick/scenegraph/d3d11underqml/main.cpp @@ -56,8 +56,6 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<D3D11Squircle>("D3D11UnderQML", 1); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Direct3D11Rhi); QQuickView view; diff --git a/examples/quick/scenegraph/fboitem/fboitem.pro b/examples/quick/scenegraph/fboitem/fboitem.pro index e40e5f4cf8..180c2288e2 100644 --- a/examples/quick/scenegraph/fboitem/fboitem.pro +++ b/examples/quick/scenegraph/fboitem/fboitem.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = SceneGraphRendering +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += fboinsgrenderer.h SOURCES += fboinsgrenderer.cpp main.cpp diff --git a/examples/quick/scenegraph/fboitem/main.cpp b/examples/quick/scenegraph/fboitem/main.cpp index 056bf24ade..153bd931ec 100644 --- a/examples/quick/scenegraph/fboitem/main.cpp +++ b/examples/quick/scenegraph/fboitem/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<FboInSGRenderer>("SceneGraphRendering", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///scenegraph/fboitem/main.qml")); diff --git a/examples/quick/scenegraph/graph/graph.pro b/examples/quick/scenegraph/graph/graph.pro index 1a880b61f1..fe36585d77 100644 --- a/examples/quick/scenegraph/graph/graph.pro +++ b/examples/quick/scenegraph/graph/graph.pro @@ -4,6 +4,10 @@ TARGET = graph TEMPLATE = app +CONFIG += qmltypes +QML_IMPORT_NAME = Graph +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ graph.cpp \ noisynode.cpp \ diff --git a/examples/quick/scenegraph/graph/main.cpp b/examples/quick/scenegraph/graph/main.cpp index 9a575944b9..854fad84e3 100644 --- a/examples/quick/scenegraph/graph/main.cpp +++ b/examples/quick/scenegraph/graph/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char *argv[]) { QGuiApplication a(argc, argv); - qmlRegisterTypesAndRevisions<Graph>("Graph", 1); - QQuickView view; view.resize(800, 400); view.setResizeMode(QQuickView::SizeRootObjectToView); diff --git a/examples/quick/scenegraph/metalunderqml/main.cpp b/examples/quick/scenegraph/metalunderqml/main.cpp index 3e620137cd..cefb1c10a9 100644 --- a/examples/quick/scenegraph/metalunderqml/main.cpp +++ b/examples/quick/scenegraph/metalunderqml/main.cpp @@ -56,8 +56,6 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<MetalSquircle>("MetalUnderQML", 1); - QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi); QQuickView view; diff --git a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro index 2f4c3f63da..3b0489ecdf 100644 --- a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro +++ b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro @@ -2,6 +2,10 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = MetalUnderQML +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += metalsquircle.h SOURCES += metalsquircle.mm main.cpp RESOURCES += metalunderqml.qrc diff --git a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc index 9676815c44..c2944970a5 100644 --- a/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc +++ b/examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc @@ -60,6 +60,7 @@ First of all, we need an object we can expose to QML. This is a subclass of QQuickItem so we can easily access \l QQuickItem::window(). + We expose it to QML using the QML_ELEMENT macro. \snippet scenegraph/openglunderqml/squircle.h 1 @@ -145,9 +146,7 @@ \snippet scenegraph/openglunderqml/main.cpp 1 The application's \c main() function instantiates a QQuickView and - launches the \c main.qml file. The only thing worth noting is that - we export the \c Squircle class to QML using the \l - qmlRegisterType() macro. + launches the \c main.qml file. \snippet scenegraph/openglunderqml/main.qml 1 diff --git a/examples/quick/scenegraph/openglunderqml/main.cpp b/examples/quick/scenegraph/openglunderqml/main.cpp index c04d0da68f..4ca8d05f1c 100644 --- a/examples/quick/scenegraph/openglunderqml/main.cpp +++ b/examples/quick/scenegraph/openglunderqml/main.cpp @@ -59,8 +59,6 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<Squircle>("OpenGLUnderQML", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///scenegraph/openglunderqml/main.qml")); diff --git a/examples/quick/scenegraph/openglunderqml/openglunderqml.pro b/examples/quick/scenegraph/openglunderqml/openglunderqml.pro index 54558ce9e9..7eaace1133 100644 --- a/examples/quick/scenegraph/openglunderqml/openglunderqml.pro +++ b/examples/quick/scenegraph/openglunderqml/openglunderqml.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = OpenGLUnderQML +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += squircle.h SOURCES += squircle.cpp main.cpp RESOURCES += openglunderqml.qrc diff --git a/examples/quick/scenegraph/rendernode/customrenderitem.h b/examples/quick/scenegraph/rendernode/customrenderitem.h index 74115b2505..28be54925b 100644 --- a/examples/quick/scenegraph/rendernode/customrenderitem.h +++ b/examples/quick/scenegraph/rendernode/customrenderitem.h @@ -53,6 +53,7 @@ #include <QQuickItem> +//! [0] class CustomRenderItem : public QQuickItem { Q_OBJECT @@ -62,5 +63,6 @@ public: CustomRenderItem(QQuickItem *parent = nullptr); QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override; }; +//! [0] #endif diff --git a/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc b/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc index ba6551fddf..87e3c8b506 100644 --- a/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc +++ b/examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc @@ -69,7 +69,7 @@ Let's go through the most important parts of the code: - \snippet scenegraph/rendernode/main.cpp 1 + \snippet scenegraph/rendernode/customrenderitem.h 0 Our custom QML type is implemented in the class CustomRenderItem. diff --git a/examples/quick/scenegraph/rendernode/main.cpp b/examples/quick/scenegraph/rendernode/main.cpp index b1dfe47829..645360eaba 100644 --- a/examples/quick/scenegraph/rendernode/main.cpp +++ b/examples/quick/scenegraph/rendernode/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); -//! [1] - qmlRegisterTypesAndRevisions<CustomRenderItem>("SceneGraphRendering", 2); -//! [1] - QQuickView view; QCoreApplication::setApplicationName("Qt Scene Graph Render Node Example"); diff --git a/examples/quick/scenegraph/rendernode/rendernode.pro b/examples/quick/scenegraph/rendernode/rendernode.pro index 897b0b1f08..cfec905764 100644 --- a/examples/quick/scenegraph/rendernode/rendernode.pro +++ b/examples/quick/scenegraph/rendernode/rendernode.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = SceneGraphRendering +QML_IMPORT_MAJOR_VERSION = 2 + HEADERS += customrenderitem.h \ openglrenderer.h \ softwarerenderer.h diff --git a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc index 67ca2d8dbd..d7de1613e4 100644 --- a/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc +++ b/examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc @@ -47,7 +47,7 @@ material state is what we assign to each individual node; in this case to give them different colors. - \snippet scenegraph/simplematerial/simplematerial.cpp 1 + \snippet scenegraph/simplematerial/simplematerialitem.cpp 1 The first thing we do when creating custom materials with the simplified scheme is to create a state class. In this case the @@ -55,7 +55,7 @@ compare function which the scene graph can use to reorder the node rendering. - \snippet scenegraph/simplematerial/simplematerial.cpp 2 + \snippet scenegraph/simplematerial/simplematerialitem.cpp 2 Next we define the material shader, by subclassing a template instantiation of \l QSGSimpleMaterialShader with our \c State. @@ -74,21 +74,21 @@ classes. Using the same \c State class in multiple shaders will will lead to undefined behavior. - \snippet scenegraph/simplematerial/simplematerial.cpp 3 + \snippet scenegraph/simplematerial/simplematerialitem.cpp 3 Next comes the declaration of the shader source code, where we define a vertex and fragment shader. The simple material assumes the presence of \c qt_Matrix in the vertex shader and \c qt_Opacity in the fragment shader. - \snippet scenegraph/simplematerial/simplematerial.cpp 4 + \snippet scenegraph/simplematerial/simplematerialitem.cpp 4 We reimplement the \c attributes function to return the name of the \c aVertex and \c aTexCoord attributes. These attributes will be mapped to attribute indices 0 and 1 in the node's geometry. - \snippet scenegraph/simplematerial/simplematerial.cpp 6 + \snippet scenegraph/simplematerial/simplematerialitem.cpp 6 Uniforms can be accessed either by name or by index, where index is faster than name. We reimplement the \c resolveUniforms() @@ -96,7 +96,7 @@ to worry about resolving \c qt_Opacity or \c qt_Matrix as these are handled by the baseclass. - \snippet scenegraph/simplematerial/simplematerial.cpp 5 + \snippet scenegraph/simplematerial/simplematerialitem.cpp 5 The \c updateState() function is called once for every unique state and we use it to update the shader program with the current @@ -105,7 +105,7 @@ use case, where all the colors are different, the updateState() function will be called once for every node. - \snippet scenegraph/simplematerial/simplematerial.cpp 7 + \snippet scenegraph/simplematerial/simplematerialitem.cpp 7 The \c ColorNode class is supposed to draw something, so it needs to be a subclass of \l QSGGeometryNode. @@ -129,12 +129,13 @@ Finally, we tell the node to take ownership of the material, so we do not have to explicitly memory-manage it. - \snippet scenegraph/simplematerial/simplematerial.cpp 8 + \snippet scenegraph/simplematerial/simplematerialitem.h 8 Since the Item is providing its own graphics to the scene graph, - we set the flag \l QQuickItem::ItemHasContents. + we set the flag \l QQuickItem::ItemHasContents. We also make sure + the item is exposed to QML by adding the QML_ELEMENT macro. - \snippet scenegraph/simplematerial/simplematerial.cpp 9 + \snippet scenegraph/simplematerial/simplematerialitem.cpp 9 Whenever the Item has changed graphically, the \l QQuickItem::updatePaintNode() function is called. @@ -159,9 +160,8 @@ \snippet scenegraph/simplematerial/simplematerial.cpp 11 - The \c main() function of the application adds the custom QML type - using \l qmlRegisterType() and opens up a \l QQuickView with our - QML file. + The \c main() function of the application opens up a \l QQuickView + with our QML file. \snippet scenegraph/simplematerial/main.qml 1 diff --git a/examples/quick/scenegraph/simplematerial/simplematerial.cpp b/examples/quick/scenegraph/simplematerial/simplematerial.cpp index 55e1d879ca..35866bd6d0 100644 --- a/examples/quick/scenegraph/simplematerial/simplematerial.cpp +++ b/examples/quick/scenegraph/simplematerial/simplematerial.cpp @@ -49,163 +49,13 @@ ****************************************************************************/ #include <qguiapplication.h> - -#include <qsgmaterial.h> -#include <qsgnode.h> - -#include <qquickitem.h> #include <qquickview.h> -#include <qsgsimplerectnode.h> - -#include <qsgsimplematerial.h> - -//! [1] -struct State -{ - QColor color; - - int compare(const State *other) const { - uint rgb = color.rgba(); - uint otherRgb = other->color.rgba(); - - if (rgb == otherRgb) { - return 0; - } else if (rgb < otherRgb) { - return -1; - } else { - return 1; - } - } -}; -//! [1] - -//! [2] -class Shader : public QSGSimpleMaterialShader<State> -{ - QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State); -//! [2] //! [3] -public: - - const char *vertexShader() const override { - return - "attribute highp vec4 aVertex; \n" - "attribute highp vec2 aTexCoord; \n" - "uniform highp mat4 qt_Matrix; \n" - "varying highp vec2 texCoord; \n" - "void main() { \n" - " gl_Position = qt_Matrix * aVertex; \n" - " texCoord = aTexCoord; \n" - "}"; - } - - const char *fragmentShader() const override { - return - "uniform lowp float qt_Opacity; \n" - "uniform lowp vec4 color; \n" - "varying highp vec2 texCoord; \n" - "void main () \n" - "{ \n" - " gl_FragColor = texCoord.y * texCoord.x * color * qt_Opacity; \n" - "}"; - } -//! [3] //! [4] - QList<QByteArray> attributes() const override - { - return QList<QByteArray>() << "aVertex" << "aTexCoord"; - } -//! [4] //! [5] - void updateState(const State *state, const State *) override - { - program()->setUniformValue(id_color, state->color); - } -//! [5] //! [6] - void resolveUniforms() override - { - id_color = program()->uniformLocation("color"); - } - -private: - int id_color; -//! [6] -}; - - -//! [7] -class ColorNode : public QSGGeometryNode -{ -public: - ColorNode() - : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) - { - setGeometry(&m_geometry); - - QSGSimpleMaterial<State> *material = Shader::createMaterial(); - material->setFlag(QSGMaterial::Blending); - setMaterial(material); - setFlag(OwnsMaterial); - } - - QSGGeometry m_geometry; -}; -//! [7] - - -//! [8] -class Item : public QQuickItem -{ - Q_OBJECT - - Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) - QML_NAMED_ELEMENT(SimpleMaterialItem) - -public: - - Item() - { - setFlag(ItemHasContents, true); - } - - void setColor(const QColor &color) { - if (m_color != color) { - m_color = color; - emit colorChanged(); - update(); - } - } - QColor color() const { - return m_color; - } - -signals: - void colorChanged(); - -private: - QColor m_color; - -//! [8] //! [9] -public: - QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override - { - ColorNode *n = static_cast<ColorNode *>(node); - if (!node) - n = new ColorNode(); - - QSGGeometry::updateTexturedRectGeometry(n->geometry(), boundingRect(), QRectF(0, 0, 1, 1)); - static_cast<QSGSimpleMaterial<State>*>(n->material())->state()->color = m_color; - - n->markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial); - - return n; - } -}; -//! [9] //! [11] +//! [11] int main(int argc, char **argv) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<Item>("SimpleMaterial", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///scenegraph/simplematerial/main.qml")); @@ -213,6 +63,4 @@ int main(int argc, char **argv) return app.exec(); } - -#include "simplematerial.moc" //! [11] diff --git a/examples/quick/scenegraph/simplematerial/simplematerial.pro b/examples/quick/scenegraph/simplematerial/simplematerial.pro index 6ae935f357..131af45974 100644 --- a/examples/quick/scenegraph/simplematerial/simplematerial.pro +++ b/examples/quick/scenegraph/simplematerial/simplematerial.pro @@ -1,8 +1,13 @@ QT += quick +CONFIG += qmltypes +QML_IMPORT_NAME = SimpleMaterial +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += \ - simplematerial.cpp + simplematerial.cpp \ + simplematerialitem.cpp RESOURCES += simplematerial.qrc target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial @@ -10,3 +15,6 @@ qml.files = main.qml qml.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial INSTALLS += target qml + +HEADERS += \ + simplematerialitem.h diff --git a/examples/quick/scenegraph/simplematerial/simplematerialitem.cpp b/examples/quick/scenegraph/simplematerial/simplematerialitem.cpp new file mode 100644 index 0000000000..c4c7b2e07e --- /dev/null +++ b/examples/quick/scenegraph/simplematerial/simplematerialitem.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "simplematerialitem.h" + +#include <QtQuick/qsgsimplematerial.h> +#include <QtQuick/qsggeometry.h> +#include <QtQuick/qsgnode.h> + +//! [1] +struct State +{ + QColor color; + + int compare(const State *other) const { + uint rgb = color.rgba(); + uint otherRgb = other->color.rgba(); + + if (rgb == otherRgb) { + return 0; + } else if (rgb < otherRgb) { + return -1; + } else { + return 1; + } + } +}; +//! [1] + +//! [2] +class Shader : public QSGSimpleMaterialShader<State> +{ + QSG_DECLARE_SIMPLE_COMPARABLE_SHADER(Shader, State); +//! [2] //! [3] +public: + + const char *vertexShader() const override { + return + "attribute highp vec4 aVertex; \n" + "attribute highp vec2 aTexCoord; \n" + "uniform highp mat4 qt_Matrix; \n" + "varying highp vec2 texCoord; \n" + "void main() { \n" + " gl_Position = qt_Matrix * aVertex; \n" + " texCoord = aTexCoord; \n" + "}"; + } + + const char *fragmentShader() const override { + return + "uniform lowp float qt_Opacity; \n" + "uniform lowp vec4 color; \n" + "varying highp vec2 texCoord; \n" + "void main () \n" + "{ \n" + " gl_FragColor = texCoord.y * texCoord.x * color * qt_Opacity; \n" + "}"; + } +//! [3] //! [4] + QList<QByteArray> attributes() const override + { + return QList<QByteArray>() << "aVertex" << "aTexCoord"; + } +//! [4] //! [5] + void updateState(const State *state, const State *) override + { + program()->setUniformValue(id_color, state->color); + } +//! [5] //! [6] + void resolveUniforms() override + { + id_color = program()->uniformLocation("color"); + } + +private: + int id_color; +//! [6] +}; + + +//! [7] +class ColorNode : public QSGGeometryNode +{ +public: + ColorNode() + : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) + { + setGeometry(&m_geometry); + + QSGSimpleMaterial<State> *material = Shader::createMaterial(); + material->setFlag(QSGMaterial::Blending); + setMaterial(material); + setFlag(OwnsMaterial); + } + + QSGGeometry m_geometry; +}; +//! [7] + +void SimpleMaterialItem::setColor(const QColor &color) { + if (m_color != color) { + m_color = color; + emit colorChanged(); + update(); + } +} + +//! [9] +QSGNode *SimpleMaterialItem::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *) +{ + ColorNode *n = static_cast<ColorNode *>(node); + if (!node) + n = new ColorNode(); + + QSGGeometry::updateTexturedRectGeometry(n->geometry(), boundingRect(), QRectF(0, 0, 1, 1)); + static_cast<QSGSimpleMaterial<State>*>(n->material())->state()->color = m_color; + + n->markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial); + + return n; +} +//! [9] diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp b/examples/quick/scenegraph/simplematerial/simplematerialitem.h index 74d382ec57..5775ad097b 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp +++ b/examples/quick/scenegraph/simplematerial/simplematerialitem.h @@ -1,9 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** -** This file is part of the documentation of the Qt Toolkit. +** This file is part of the demonstration applications of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage @@ -47,16 +47,36 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "chartsplugin.h" -//![0] -#include "piechart.h" -#include "pieslice.h" -#include <qqml.h> -void ChartsPlugin::registerTypes(const char *uri) +#ifndef SIMPLEMATERIALITEM_H +#define SIMPLEMATERIALITEM_H + +#include <QtQuick/qquickitem.h> + +//! [8] +class SimpleMaterialItem : public QQuickItem { - qmlRegisterTypesAndRevisions<PieChart, PieSlice>(uri, 1); -} + Q_OBJECT + + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + QML_ELEMENT + +public: + + SimpleMaterialItem() { setFlag(ItemHasContents, true); } + + void setColor(const QColor &color); + QColor color() const { return m_color; } + +signals: + void colorChanged(); + +private: + QColor m_color; -//![0] +public: + QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override; +}; +//! [8] +#endif // SIMPLEMATERIALITEM_H diff --git a/examples/quick/scenegraph/textureinthread/main.cpp b/examples/quick/scenegraph/textureinthread/main.cpp index 7c22fa7fdf..cb00946bf7 100644 --- a/examples/quick/scenegraph/textureinthread/main.cpp +++ b/examples/quick/scenegraph/textureinthread/main.cpp @@ -70,7 +70,6 @@ int main(int argc, char **argv) return app.exec(); } - qmlRegisterTypesAndRevisions<ThreadRenderer>("SceneGraphRendering", 1); int execReturn = 0; { diff --git a/examples/quick/scenegraph/textureinthread/textureinthread.pro b/examples/quick/scenegraph/textureinthread/textureinthread.pro index 7f5fbb76e9..4d41daa7bf 100644 --- a/examples/quick/scenegraph/textureinthread/textureinthread.pro +++ b/examples/quick/scenegraph/textureinthread/textureinthread.pro @@ -3,6 +3,10 @@ QT += quick # To make threaded gl check... QT += core-private gui-private +CONFIG += qmltypes +QML_IMPORT_NAME = SceneGraphRendering +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += threadrenderer.h SOURCES += threadrenderer.cpp main.cpp diff --git a/examples/quick/scenegraph/threadedanimation/main.cpp b/examples/quick/scenegraph/threadedanimation/main.cpp index c77a291f5d..85ff486b16 100644 --- a/examples/quick/scenegraph/threadedanimation/main.cpp +++ b/examples/quick/scenegraph/threadedanimation/main.cpp @@ -57,8 +57,6 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<Spinner>("Spinner", 1); - QQuickView view; view.setSource(QUrl("qrc:///scenegraph/threadedanimation/main.qml")); view.show(); diff --git a/examples/quick/scenegraph/threadedanimation/threadedanimation.pro b/examples/quick/scenegraph/threadedanimation/threadedanimation.pro index 419ee97e2e..3caf3fa94b 100644 --- a/examples/quick/scenegraph/threadedanimation/threadedanimation.pro +++ b/examples/quick/scenegraph/threadedanimation/threadedanimation.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Spinner +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += spinner.h SOURCES += spinner.cpp main.cpp RESOURCES += threadedanimation.qrc diff --git a/examples/quick/scenegraph/twotextureproviders/main.cpp b/examples/quick/scenegraph/twotextureproviders/main.cpp index 3f53bb6e32..df0454ce40 100644 --- a/examples/quick/scenegraph/twotextureproviders/main.cpp +++ b/examples/quick/scenegraph/twotextureproviders/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char **argv) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions<XorBlender>("SceneGraphRendering", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///scenegraph/twotextureproviders/main.qml")); diff --git a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro index 7b7c093b48..b87a0a2611 100644 --- a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro +++ b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = SceneGraphRendering +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += xorblender.h SOURCES += xorblender.cpp main.cpp diff --git a/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc b/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc index 069513636a..b61ba90a58 100644 --- a/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc +++ b/examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc @@ -50,9 +50,6 @@ the view should be scrolled to. \snippet tableview/gameoflife/main.qml model - The model that we use is a custom C++ class that we register - in the QML system: - \snippet tableview/gameoflife/main.cpp registertype \section1 The C++ Model @@ -61,7 +58,8 @@ used as the model of our TableView component. Therefore, it needs to implement some functions so the TableView component can interact with the model. As you can see in the \c private part of the class, the model - uses a fixed-size array to store the current state of all the cells. + uses a fixed-size array to store the current state of all the cells. We + also use the QML_ELEMENT macro in order to expose the class to QML. \snippet tableview/gameoflife/gameoflifemodel.cpp modelsize Here, the \c rowCount and \c columnCount methods are implemented so diff --git a/examples/quick/tableview/gameoflife/gameoflife.pro b/examples/quick/tableview/gameoflife/gameoflife.pro index 98050b0d79..9c47a9b530 100644 --- a/examples/quick/tableview/gameoflife/gameoflife.pro +++ b/examples/quick/tableview/gameoflife/gameoflife.pro @@ -1,6 +1,11 @@ TEMPLATE = app QT += quick qml + +CONFIG += qmltypes +QML_IMPORT_NAME = GameOfLifeModel +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += \ main.cpp \ gameoflifemodel.cpp diff --git a/examples/quick/tableview/gameoflife/main.cpp b/examples/quick/tableview/gameoflife/main.cpp index fcea7080ea..1500efdcca 100644 --- a/examples/quick/tableview/gameoflife/main.cpp +++ b/examples/quick/tableview/gameoflife/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); QQmlApplicationEngine engine; - //! [registertype] - qmlRegisterTypesAndRevisions<GameOfLifeModel>("GameOfLifeModel", 1); - //! [registertype] - engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; diff --git a/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc b/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc index 9e199a5347..88b28769cd 100644 --- a/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc +++ b/examples/quick/tableview/pixelator/doc/src/pixelator.qdoc @@ -42,6 +42,7 @@ TableView. We use the \l{The Property System}{Qt Property System} and a source property as \c QString to set the path of the image. + We also add the QML_ELEMENT macro to expose the model to QML. \snippet tableview/pixelator/imagemodel.cpp setsource @@ -59,11 +60,6 @@ When we call this function with the display role, we return the pixel's gray value. - \snippet tableview/pixelator/main.cpp registertype - - We need to register our model in the QML type system to be able to use it - from the QML side. - \snippet tableview/pixelator/main.qml pixelcomponent Each pixel in the \c TableView is displayed via a delegate component. diff --git a/examples/quick/tableview/pixelator/main.cpp b/examples/quick/tableview/pixelator/main.cpp index a8cb6c4e86..c07f43dc27 100644 --- a/examples/quick/tableview/pixelator/main.cpp +++ b/examples/quick/tableview/pixelator/main.cpp @@ -59,10 +59,6 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; - //! [registertype] - qmlRegisterTypesAndRevisions<ImageModel>("ImageModel", 1); - //! [registertype] - engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; diff --git a/examples/quick/tableview/pixelator/pixelator.pro b/examples/quick/tableview/pixelator/pixelator.pro index 6c863cb304..f27303b56b 100644 --- a/examples/quick/tableview/pixelator/pixelator.pro +++ b/examples/quick/tableview/pixelator/pixelator.pro @@ -5,6 +5,10 @@ HEADERS += imagemodel.h SOURCES += main.cpp \ imagemodel.cpp +CONFIG += qmltypes +QML_IMPORT_NAME = ImageModel +QML_IMPORT_MAJOR_VERSION = 1 + RESOURCES += qt.png main.qml target.path = $$[QT_INSTALL_EXAMPLES]/quick/tableview/pixelator |