aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2020-01-16 16:25:06 +0100
committerLeander Beernaert <leander.beernaert@qt.io>2020-01-16 16:25:06 +0100
commit1d333d3375874efb8d37df37dc5ef561573794ad (patch)
tree2d8c995f64c05c84c1fcceb2c5cb40fcae69855f /examples
parentb106d86c433706928b0b0c206a0d9f831681e1bf (diff)
parente79a2658cde899d6ee11ec3c0d0a3768eb2c864b (diff)
Merge remote-tracking branch 'origin/dev' into wip/cmake
Diffstat (limited to 'examples')
-rw-r--r--examples/qml/doc/src/qml-extending.qdoc15
-rw-r--r--examples/qml/qmlextensionplugins/plugin.cpp108
-rw-r--r--examples/qml/qmlextensionplugins/plugins.qmlproject2
-rw-r--r--examples/qml/qmlextensionplugins/qmlextensionplugins.pro51
-rw-r--r--examples/qml/qmlextensionplugins/timemodel.cpp98
-rw-r--r--examples/qml/qmlextensionplugins/timemodel.h111
-rw-r--r--examples/qml/referenceexamples/adding/adding.pro4
-rw-r--r--examples/qml/referenceexamples/adding/main.cpp3
-rw-r--r--examples/qml/referenceexamples/attached/attached.pro4
-rw-r--r--examples/qml/referenceexamples/attached/main.cpp4
-rw-r--r--examples/qml/referenceexamples/binding/binding.pro4
-rw-r--r--examples/qml/referenceexamples/binding/happybirthdaysong.h3
-rw-r--r--examples/qml/referenceexamples/binding/main.cpp2
-rw-r--r--examples/qml/referenceexamples/coercion/birthdayparty.h1
-rw-r--r--examples/qml/referenceexamples/coercion/coercion.pro4
-rw-r--r--examples/qml/referenceexamples/coercion/main.cpp4
-rw-r--r--examples/qml/referenceexamples/coercion/person.h3
-rw-r--r--examples/qml/referenceexamples/default/birthdayparty.h1
-rw-r--r--examples/qml/referenceexamples/default/default.pro4
-rw-r--r--examples/qml/referenceexamples/default/main.cpp2
-rw-r--r--examples/qml/referenceexamples/extended/extended.pro4
-rw-r--r--examples/qml/referenceexamples/extended/lineedit.h11
-rw-r--r--examples/qml/referenceexamples/extended/main.cpp4
-rw-r--r--examples/qml/referenceexamples/grouped/birthdayparty.h1
-rw-r--r--examples/qml/referenceexamples/grouped/grouped.pro4
-rw-r--r--examples/qml/referenceexamples/grouped/main.cpp2
-rw-r--r--examples/qml/referenceexamples/methods/birthdayparty.h1
-rw-r--r--examples/qml/referenceexamples/methods/main.cpp2
-rw-r--r--examples/qml/referenceexamples/methods/methods.pro4
-rw-r--r--examples/qml/referenceexamples/properties/birthdayparty.h1
-rw-r--r--examples/qml/referenceexamples/properties/main.cpp4
-rw-r--r--examples/qml/referenceexamples/properties/properties.pro4
-rw-r--r--examples/qml/referenceexamples/signal/main.cpp3
-rw-r--r--examples/qml/referenceexamples/signal/signal.pro4
-rw-r--r--examples/qml/referenceexamples/valuesource/happybirthdaysong.h1
-rw-r--r--examples/qml/referenceexamples/valuesource/main.cpp3
-rw-r--r--examples/qml/referenceexamples/valuesource/valuesource.pro4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.pro4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.pro4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.pro4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h7
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro16
-rw-r--r--examples/quick/animation/animation.qrc1
-rw-r--r--examples/quick/animation/behaviors/FocusRect.qml115
-rw-r--r--examples/quick/animation/behaviors/SideRect.qml7
-rw-r--r--examples/quick/animation/behaviors/behavior-example.qml43
-rw-r--r--examples/quick/animation/doc/src/animation.qdoc2
-rw-r--r--examples/quick/animation/easing/easing.qml29
-rw-r--r--examples/quick/canvas/smile/smile.qml1
-rw-r--r--examples/quick/customitems/maskedmousearea/main.cpp3
-rw-r--r--examples/quick/customitems/maskedmousearea/maskedmousearea.pro4
-rw-r--r--examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h9
-rw-r--r--examples/quick/customitems/painteditem/painteditem.pro16
-rw-r--r--examples/quick/draganddrop/draganddrop.qrc1
-rw-r--r--examples/quick/draganddrop/views/Icon.qml96
-rw-r--r--examples/quick/draganddrop/views/gridview.qml56
-rw-r--r--examples/quick/imageprovider/imageprovider.cpp10
-rw-r--r--examples/quick/imageresponseprovider/imageresponseprovider.cpp9
-rw-r--r--examples/quick/layouts/layouts.qml13
-rw-r--r--examples/quick/localstorage/localstorage/Header.qml10
-rw-r--r--examples/quick/localstorage/localstorage/localstorage.qml4
-rw-r--r--examples/quick/quick-accessibility/content/Button.qml1
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/mainwindow.cpp2
-rw-r--r--examples/quick/quickwidgets/qquickviewcomparison/qquickviewcomparison.pro4
-rw-r--r--examples/quick/quickwidgets/quickwidget/main.cpp2
-rw-r--r--examples/quick/quickwidgets/quickwidget/quickwidget.pro4
-rw-r--r--examples/quick/scenegraph/customgeometry/beziercurve.h2
-rw-r--r--examples/quick/scenegraph/customgeometry/customgeometry.pro4
-rw-r--r--examples/quick/scenegraph/customgeometry/doc/src/customgeometry.qdoc15
-rw-r--r--examples/quick/scenegraph/customgeometry/main.cpp2
-rw-r--r--examples/quick/scenegraph/d3d11underqml/d3d11underqml.pro4
-rw-r--r--examples/quick/scenegraph/d3d11underqml/main.cpp2
-rw-r--r--examples/quick/scenegraph/fboitem/fboitem.pro4
-rw-r--r--examples/quick/scenegraph/fboitem/main.cpp2
-rw-r--r--examples/quick/scenegraph/graph/graph.pro4
-rw-r--r--examples/quick/scenegraph/graph/main.cpp2
-rw-r--r--examples/quick/scenegraph/metaltextureimport/doc/src/metaltextureimport.qdoc2
-rw-r--r--examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro5
-rw-r--r--examples/quick/scenegraph/metalunderqml/main.cpp2
-rw-r--r--examples/quick/scenegraph/metalunderqml/metalsquircle.mm5
-rw-r--r--examples/quick/scenegraph/metalunderqml/metalunderqml.pro9
-rw-r--r--examples/quick/scenegraph/openglunderqml/doc/src/openglunderqml.qdoc5
-rw-r--r--examples/quick/scenegraph/openglunderqml/main.cpp2
-rw-r--r--examples/quick/scenegraph/openglunderqml/openglunderqml.pro4
-rw-r--r--examples/quick/scenegraph/rendernode/customrenderitem.cpp11
-rw-r--r--examples/quick/scenegraph/rendernode/customrenderitem.h2
-rw-r--r--examples/quick/scenegraph/rendernode/d3d12renderer.cpp309
-rw-r--r--examples/quick/scenegraph/rendernode/doc/src/rendernode.qdoc2
-rw-r--r--examples/quick/scenegraph/rendernode/main.cpp4
-rw-r--r--examples/quick/scenegraph/rendernode/main.qml1
-rw-r--r--examples/quick/scenegraph/rendernode/rendernode.pro10
-rw-r--r--examples/quick/scenegraph/rendernode/rendernode.qrc2
-rw-r--r--examples/quick/scenegraph/rendernode/shader_frag.csobin908 -> 0 bytes
-rw-r--r--examples/quick/scenegraph/rendernode/shader_vert.csobin1720 -> 0 bytes
-rw-r--r--examples/quick/scenegraph/rendernode/softwarerenderer.cpp2
-rw-r--r--examples/quick/scenegraph/scenegraph.pro6
-rw-r--r--examples/quick/scenegraph/simplematerial/doc/src/simplematerial.qdoc26
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerial.cpp154
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerial.pro10
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerialitem.cpp169
-rw-r--r--examples/quick/scenegraph/simplematerial/simplematerialitem.h82
-rw-r--r--examples/quick/scenegraph/textureinthread/main.cpp1
-rw-r--r--examples/quick/scenegraph/textureinthread/textureinthread.pro4
-rw-r--r--examples/quick/scenegraph/threadedanimation/main.cpp2
-rw-r--r--examples/quick/scenegraph/threadedanimation/threadedanimation.pro4
-rw-r--r--examples/quick/scenegraph/twotextureproviders/main.cpp2
-rw-r--r--examples/quick/scenegraph/twotextureproviders/twotextureproviders.pro4
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpgbin0 -> 28887 bytes
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc48
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/main.cpp (renamed from examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp)30
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/main.qml123
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/squircle.frag.spvbin0 -> 1432 bytes
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/squircle.vert.spvbin0 -> 644 bytes
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp823
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h (renamed from examples/quick/scenegraph/rendernode/d3d12renderer.h)63
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro12
-rw-r--r--examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc7
-rw-r--r--examples/quick/shadereffects/content/shaders/+hlsl/blur.frag18
-rw-r--r--examples/quick/shadereffects/content/shaders/+hlsl/colorize.frag17
-rw-r--r--examples/quick/shadereffects/content/shaders/+hlsl/genie.vert31
-rw-r--r--examples/quick/shadereffects/content/shaders/+hlsl/outline.frag21
-rw-r--r--examples/quick/shadereffects/content/shaders/+hlsl/shadow.frag20
-rw-r--r--examples/quick/shadereffects/content/shaders/+hlsl/wobble.frag17
-rw-r--r--examples/quick/shadereffects/doc/src/shadereffects.qdoc15
-rw-r--r--examples/quick/shadereffects/shadereffects.qrc6
-rw-r--r--examples/quick/shared/FlickrRssModel.qml6
-rw-r--r--examples/quick/shared/SimpleLauncherDelegate.qml4
-rw-r--r--examples/quick/tableview/gameoflife/doc/src/gameoflife.qdoc6
-rw-r--r--examples/quick/tableview/gameoflife/gameoflife.pro5
-rw-r--r--examples/quick/tableview/gameoflife/main.cpp4
-rw-r--r--examples/quick/tableview/pixelator/doc/src/pixelator.qdoc6
-rw-r--r--examples/quick/tableview/pixelator/main.cpp4
-rw-r--r--examples/quick/tableview/pixelator/pixelator.pro4
-rw-r--r--examples/quick/touchinteraction/multipointtouch/bearwhack.qml12
-rw-r--r--examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml9
-rw-r--r--examples/quick/views/pathview/pathview-example.qml10
143 files changed, 2108 insertions, 1077 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/plugins.qmlproject b/examples/qml/qmlextensionplugins/plugins.qmlproject
index 771ab45b66..c2de5f5703 100644
--- a/examples/qml/qmlextensionplugins/plugins.qmlproject
+++ b/examples/qml/qmlextensionplugins/plugins.qmlproject
@@ -13,4 +13,6 @@ Project {
ImageFiles {
directory: "."
}
+
+ importPaths: [ "imports" ]
}
diff --git a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro
index 946626cce7..c074b8d671 100644
--- a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro
+++ b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro
@@ -1,25 +1,46 @@
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
+QMLTYPES_FILENAME = $$DESTDIR/plugins.qmltypes
+
+SOURCES += \
+ plugin.cpp \
+ timemodel.cpp
+
+HEADERS += \
+ timemodel.h
+
+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
+
+target.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME
+
+pluginfiles_copy.files = $$PLUGINFILES
+pluginfiles_copy.path = $$DESTDIR
+
+pluginfiles_install.files = $$PLUGINFILES $$OUT_PWD/$$DESTDIR/plugins.qmltypes
+pluginfiles_install.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME
-SOURCES += plugin.cpp
+qml_copy.files = plugins.qml plugins.qmlproject
+qml_copy.path = $$OUT_PWD
-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
+qml_install.files = plugins.qml plugins.qmlproject
+qml_install.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins
-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
+INSTALLS += target qml_install pluginfiles_install
+COPIES += qml_copy pluginfiles_copy
-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 dcfebc06ba..c84e9d9e5e 100644
--- a/examples/qml/referenceexamples/binding/happybirthdaysong.h
+++ b/examples/qml/referenceexamples/binding/happybirthdaysong.h
@@ -52,14 +52,17 @@
#include <QQmlPropertyValueSource>
#include <QQmlProperty>
+#include <qqml.h>
#include <QStringList>
+#include <qqml.h>
class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_INTERFACES(QQmlPropertyValueSource)
+ QML_ELEMENT
public:
HappyBirthdaySong(QObject *parent = nullptr);
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/animation/animation.qrc b/examples/quick/animation/animation.qrc
index d4e78c82f0..2d88c03007 100644
--- a/examples/quick/animation/animation.qrc
+++ b/examples/quick/animation/animation.qrc
@@ -9,6 +9,7 @@
<file>basics/color-animation.qml</file>
<file>basics/property-animation.qml</file>
<file>behaviors/behavior-example.qml</file>
+ <file>behaviors/FocusRect.qml</file>
<file>behaviors/SideRect.qml</file>
<file>behaviors/tvtennis.qml</file>
<file>behaviors/wigglytext.qml</file>
diff --git a/examples/quick/animation/behaviors/FocusRect.qml b/examples/quick/animation/behaviors/FocusRect.qml
new file mode 100644
index 0000000000..5188919606
--- /dev/null
+++ b/examples/quick/animation/behaviors/FocusRect.qml
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+ id: focusRect
+ property string text
+
+ x: 62
+ y: 75
+ width: 75
+ height: 50
+ radius: 6
+ border.width: 4
+ border.color: "white"
+ color: "firebrick"
+
+ // Set an 'elastic' behavior on the focusRect's x property.
+ Behavior on x {
+ NumberAnimation {
+ easing.type: Easing.OutElastic
+ easing.amplitude: 3.0
+ easing.period: 2.0
+ duration: 300
+ }
+ }
+
+ //! [0]
+ // Set an 'elastic' behavior on the focusRect's y property.
+ Behavior on y {
+ NumberAnimation {
+ easing.type: Easing.OutElastic
+ easing.amplitude: 3.0
+ easing.period: 2.0
+ duration: 300
+ }
+ }
+ //! [0]
+
+ Text {
+ id: focusText
+ text: focusRect.text
+ anchors.centerIn: parent
+ color: "white"
+ font.pixelSize: 16
+ font.bold: true
+
+ // Set a behavior on the focusText's x property:
+ // Set the opacity to 0, set the new text value, then set the opacity back to 1.
+ Behavior on text {
+ SequentialAnimation {
+ NumberAnimation {
+ target: focusText
+ property: "opacity"
+ to: 0
+ duration: 150
+ }
+ NumberAnimation {
+ target: focusText
+ property: "opacity"
+ to: 1
+ duration: 150
+ }
+ }
+ }
+ }
+}
diff --git a/examples/quick/animation/behaviors/SideRect.qml b/examples/quick/animation/behaviors/SideRect.qml
index 8b37a6a0ca..19c0528054 100644
--- a/examples/quick/animation/behaviors/SideRect.qml
+++ b/examples/quick/animation/behaviors/SideRect.qml
@@ -53,6 +53,7 @@ import QtQuick 2.0
Rectangle {
id: myRect
+ property FocusRect focusItem
property string text
width: 75; height: 50
@@ -64,9 +65,9 @@ Rectangle {
anchors.fill: parent
hoverEnabled: true
onEntered: {
- focusRect.x = myRect.x;
- focusRect.y = myRect.y;
- focusRect.text = myRect.text;
+ myRect.focusItem.x = myRect.x;
+ myRect.focusItem.y = myRect.y;
+ myRect.focusItem.text = myRect.text;
}
}
}
diff --git a/examples/quick/animation/behaviors/behavior-example.qml b/examples/quick/animation/behaviors/behavior-example.qml
index 1d07e6bb90..43ca31f185 100644
--- a/examples/quick/animation/behaviors/behavior-example.qml
+++ b/examples/quick/animation/behaviors/behavior-example.qml
@@ -64,67 +64,34 @@ Rectangle {
SideRect {
id: leftRect
+ focusItem: focusRect
anchors { verticalCenter: parent.verticalCenter; horizontalCenter: parent.left }
text: "Left"
}
SideRect {
id: rightRect
+ focusItem: focusRect
anchors { verticalCenter: parent.verticalCenter; horizontalCenter: parent.right }
text: "Right"
}
SideRect {
id: topRect
+ focusItem: focusRect
anchors { verticalCenter: parent.top; horizontalCenter: parent.horizontalCenter }
text: "Top"
}
SideRect {
id: bottomRect
+ focusItem: focusRect
anchors { verticalCenter: parent.bottom; horizontalCenter: parent.horizontalCenter }
text: "Bottom"
}
-
- Rectangle {
+ FocusRect {
id: focusRect
-
- property string text
-
- x: 62; y: 75; width: 75; height: 50
- radius: 6
- border.width: 4; border.color: "white"
- color: "firebrick"
-
- // Set an 'elastic' behavior on the focusRect's x property.
- Behavior on x {
- NumberAnimation { easing.type: Easing.OutElastic; easing.amplitude: 3.0; easing.period: 2.0; duration: 300 }
- }
-
- //! [0]
- // Set an 'elastic' behavior on the focusRect's y property.
- Behavior on y {
- NumberAnimation { easing.type: Easing.OutElastic; easing.amplitude: 3.0; easing.period: 2.0; duration: 300 }
- }
- //! [0]
-
- Text {
- id: focusText
- text: focusRect.text
- anchors.centerIn: parent
- color: "white"
- font.pixelSize: 16; font.bold: true
-
- // Set a behavior on the focusText's x property:
- // Set the opacity to 0, set the new text value, then set the opacity back to 1.
- Behavior on text {
- SequentialAnimation {
- NumberAnimation { target: focusText; property: "opacity"; to: 0; duration: 150 }
- NumberAnimation { target: focusText; property: "opacity"; to: 1; duration: 150 }
- }
- }
- }
}
}
}
diff --git a/examples/quick/animation/doc/src/animation.qdoc b/examples/quick/animation/doc/src/animation.qdoc
index 578fb4b849..97a574d768 100644
--- a/examples/quick/animation/doc/src/animation.qdoc
+++ b/examples/quick/animation/doc/src/animation.qdoc
@@ -60,7 +60,7 @@
\section1 Behaviors
\e Behaviors uses behaviors to move a rectangle to where you click.
- \snippet animation/behaviors/behavior-example.qml 0
+ \snippet animation/behaviors/FocusRect.qml 0
\section1 Wiggly Text
diff --git a/examples/quick/animation/easing/easing.qml b/examples/quick/animation/easing/easing.qml
index 6db5599a66..f443486141 100644
--- a/examples/quick/animation/easing/easing.qml
+++ b/examples/quick/animation/easing/easing.qml
@@ -48,6 +48,8 @@
**
****************************************************************************/
+import QtQml 2.15
+import QtQml.Models 2.15
import QtQuick 2.0
Rectangle {
@@ -107,9 +109,14 @@ Rectangle {
id: delegate
Item {
+ id: delegateInstance
+ required property string name;
+ required property int type;
+ required property color ballColor;
+
height: 56; width: window.width
- Text { text: name; anchors.centerIn: parent; color: "White" }
+ Text { text: parent.name; anchors.centerIn: parent; color: "White" }
Rectangle {
id: slot1; color: "#121212"; x: 30; height: 46; width: 46
@@ -137,12 +144,26 @@ Rectangle {
states : State {
name: "right"
- PropertyChanges { target: rect; x: window.width - 76; color: ballColor }
+ PropertyChanges {
+ target: rect;
+ x: window.width - 76;
+ color: delegateInstance.ballColor
+ }
}
transitions: Transition {
- NumberAnimation { properties: "x"; easing.type: type; easing.bezierCurve: getBezierCurve(name); duration: 1000 }
- ColorAnimation { properties: "color"; easing.type: type; easing.bezierCurve: getBezierCurve(name); duration: 1000 }
+ NumberAnimation {
+ properties: "x"
+ easing.type: delegateInstance.type
+ easing.bezierCurve: window.getBezierCurve(delegateInstance.name)
+ duration: 1000
+ }
+ ColorAnimation {
+ properties: "color"
+ easing.type: delegateInstance.type
+ easing.bezierCurve: window.getBezierCurve(delegateInstance.name)
+ duration: 1000
+ }
}
}
}
diff --git a/examples/quick/canvas/smile/smile.qml b/examples/quick/canvas/smile/smile.qml
index 880116726f..cde18d4d38 100644
--- a/examples/quick/canvas/smile/smile.qml
+++ b/examples/quick/canvas/smile/smile.qml
@@ -97,7 +97,6 @@ Item {
ctx.save();
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.translate(originX, originX);
- ctx.globalAlpha = canvas.alpha;
ctx.strokeStyle = canvas.strokeStyle;
ctx.fillStyle = canvas.fillStyle;
ctx.lineWidth = canvas.lineWidth;
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/draganddrop/draganddrop.qrc b/examples/quick/draganddrop/draganddrop.qrc
index 6d064f7722..df9fec51d2 100644
--- a/examples/quick/draganddrop/draganddrop.qrc
+++ b/examples/quick/draganddrop/draganddrop.qrc
@@ -5,5 +5,6 @@
<file>tiles/DropTile.qml</file>
<file>tiles/tiles.qml</file>
<file>views/gridview.qml</file>
+ <file>views/Icon.qml</file>
</qresource>
</RCC>
diff --git a/examples/quick/draganddrop/views/Icon.qml b/examples/quick/draganddrop/views/Icon.qml
new file mode 100644
index 0000000000..261d6d146a
--- /dev/null
+++ b/examples/quick/draganddrop/views/Icon.qml
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 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$
+**
+****************************************************************************/
+
+import QtQuick 2.14
+
+Rectangle {
+ id: icon
+ required property Item dragParent
+
+ property int visualIndex: 0
+ width: 72
+ height: 72
+ anchors {
+ horizontalCenter: parent.horizontalCenter
+ verticalCenter: parent.verticalCenter
+ }
+ radius: 3
+
+ Text {
+ anchors.centerIn: parent
+ color: "white"
+ text: parent.visualIndex
+ }
+
+ DragHandler {
+ id: dragHandler
+ }
+
+ Drag.active: dragHandler.active
+ Drag.source: icon
+ Drag.hotSpot.x: 36
+ Drag.hotSpot.y: 36
+
+ states: [
+ State {
+ when: dragHandler.active
+ ParentChange {
+ target: icon
+ parent: icon.dragParent
+ }
+
+ AnchorChanges {
+ target: icon
+ anchors.horizontalCenter: undefined
+ anchors.verticalCenter: undefined
+ }
+ }
+ ]
+}
diff --git a/examples/quick/draganddrop/views/gridview.qml b/examples/quick/draganddrop/views/gridview.qml
index 6c5bcef729..05bd48e7fa 100644
--- a/examples/quick/draganddrop/views/gridview.qml
+++ b/examples/quick/draganddrop/views/gridview.qml
@@ -48,8 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.12
-import QtQml.Models 2.1
+import QtQml 2.14
+import QtQuick 2.14
+import QtQml.Models 2.14
GridView {
id: root
@@ -94,54 +95,21 @@ GridView {
//! [1]
delegate: DropArea {
id: delegateRoot
+ required property color color;
width: 80; height: 80
- onEntered: visualModel.items.move(drag.source.visualIndex, icon.visualIndex)
+ onEntered: function(drag) {
+ visualModel.items.move((drag.source as Icon).visualIndex, icon.visualIndex)
+ }
+
property int visualIndex: DelegateModel.itemsIndex
- Binding { target: icon; property: "visualIndex"; value: visualIndex }
- Rectangle {
+ Icon {
id: icon
- property int visualIndex: 0
- width: 72; height: 72
- anchors {
- horizontalCenter: parent.horizontalCenter;
- verticalCenter: parent.verticalCenter
- }
- radius: 3
- color: model.color
-
- Text {
- anchors.centerIn: parent
- color: "white"
- text: parent.visualIndex
- }
-
- DragHandler {
- id: dragHandler
- }
-
- Drag.active: dragHandler.active
- Drag.source: icon
- Drag.hotSpot.x: 36
- Drag.hotSpot.y: 36
-
- states: [
- State {
- when: icon.Drag.active
- ParentChange {
- target: icon
- parent: root
- }
-
- AnchorChanges {
- target: icon
- anchors.horizontalCenter: undefined
- anchors.verticalCenter: undefined
- }
- }
- ]
+ dragParent: root
+ visualIndex: delegateRoot.visualIndex
+ color: delegateRoot.color
}
}
//! [1]
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/layouts/layouts.qml b/examples/quick/layouts/layouts.qml
index 48299f36aa..e56fecade9 100644
--- a/examples/quick/layouts/layouts.qml
+++ b/examples/quick/layouts/layouts.qml
@@ -53,6 +53,8 @@ import QtQuick.Controls 1.2
import QtQuick.Layouts 1.3
ApplicationWindow {
+ id: appWindow
+
visible: true
title: "Basic layouts"
property int margin: 11
@@ -64,7 +66,7 @@ ApplicationWindow {
ColumnLayout {
id: mainLayout
anchors.fill: parent
- anchors.margins: margin
+ anchors.margins: appWindow.margin
GroupBox {
id: rowBox
title: "Row layout"
@@ -135,8 +137,13 @@ ApplicationWindow {
id: stackRepeater
model: 5
Rectangle {
- color: Qt.hsla((0.5 + index)/stackRepeater.count, 0.3, 0.7, 1)
- Button { anchors.centerIn: parent; text: "Page " + (index + 1); onClicked: { stackLayout.advance() } }
+ required property int index
+ color: Qt.hsla((0.5 + index) / stackRepeater.count, 0.3, 0.7, 1)
+ Button {
+ anchors.centerIn: parent
+ text: "Page " + (parent.index + 1)
+ onClicked: { stackLayout.advance() }
+ }
}
}
}
diff --git a/examples/quick/localstorage/localstorage/Header.qml b/examples/quick/localstorage/localstorage/Header.qml
index b3807f6e40..e9446de55e 100644
--- a/examples/quick/localstorage/localstorage/Header.qml
+++ b/examples/quick/localstorage/localstorage/Header.qml
@@ -186,11 +186,11 @@ Item {
}
}
}
-
- MouseArea {
- anchors.fill: parent
- onClicked: dateInput.forceActiveFocus()
- }
}
}
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: dateInput.forceActiveFocus()
+ }
}
diff --git a/examples/quick/localstorage/localstorage/localstorage.qml b/examples/quick/localstorage/localstorage/localstorage.qml
index 434639db54..41f5cbd561 100644
--- a/examples/quick/localstorage/localstorage/localstorage.qml
+++ b/examples/quick/localstorage/localstorage/localstorage.qml
@@ -166,8 +166,8 @@ Window {
Component {
id: highlightBar
Rectangle {
- width: listView.currentItem.width
- height: listView.currentItem.height
+ width: listView.currentItem !== null ? listView.currentItem.width : implicitWidth
+ height: listView.currentItem !== null ? listView.currentItem.height : implicitHeight
color: "lightgreen"
}
}
diff --git a/examples/quick/quick-accessibility/content/Button.qml b/examples/quick/quick-accessibility/content/Button.qml
index fc9c19b789..7a86e31588 100644
--- a/examples/quick/quick-accessibility/content/Button.qml
+++ b/examples/quick/quick-accessibility/content/Button.qml
@@ -79,7 +79,6 @@ Rectangle {
Text {
id: buttonText
- text: parent.description
anchors.centerIn: parent
font.pixelSize: parent.height * .5
style: Text.Sunken
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/metaltextureimport/doc/src/metaltextureimport.qdoc b/examples/quick/scenegraph/metaltextureimport/doc/src/metaltextureimport.qdoc
index 2a584c26cc..55cbcd8f2e 100644
--- a/examples/quick/scenegraph/metaltextureimport/doc/src/metaltextureimport.qdoc
+++ b/examples/quick/scenegraph/metaltextureimport/doc/src/metaltextureimport.qdoc
@@ -29,7 +29,7 @@
\example scenegraph/metaltextureimport
\title Scene Graph - Metal Texture Import
\ingroup qtquickexamples
- \brief Shows how to use a texture created directly with Metal
+ \brief Shows how to use a texture created directly with Metal.
\image metaltextureimport-example.jpg
diff --git a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro
index 5b11606946..bbdfd358d3 100644
--- a/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro
+++ b/examples/quick/scenegraph/metaltextureimport/metaltextureimport.pro
@@ -1,4 +1,4 @@
-!macos: error("This example requires macOS")
+!macos:!ios: error("This example requires macOS or iOS")
QT += qml quick
@@ -6,7 +6,8 @@ HEADERS += metaltextureimport.h
SOURCES += metaltextureimport.mm main.cpp
RESOURCES += metaltextureimport.qrc
-LIBS += -framework Metal -framework AppKit
+LIBS += -framework Metal
+macos: LIBS += -framework AppKit
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metaltextureimport
INSTALLS += target
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/metalsquircle.mm b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm
index 5ca6daa01a..4844df0c70 100644
--- a/examples/quick/scenegraph/metalunderqml/metalsquircle.mm
+++ b/examples/quick/scenegraph/metalunderqml/metalsquircle.mm
@@ -349,10 +349,13 @@ void SquircleRenderer::init(int framesInFlight)
rpDesc.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOne;
rpDesc.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOne;
+#ifdef Q_OS_MACOS
if (m_device.depth24Stencil8PixelFormatSupported) {
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth24Unorm_Stencil8;
- } else {
+ } else
+#endif
+ {
rpDesc.depthAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
rpDesc.stencilAttachmentPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
}
diff --git a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro
index 9fd131fe1b..3b0489ecdf 100644
--- a/examples/quick/scenegraph/metalunderqml/metalunderqml.pro
+++ b/examples/quick/scenegraph/metalunderqml/metalunderqml.pro
@@ -1,12 +1,17 @@
-!macos: error("This example requires macOS")
+!macos:!ios: error("This example requires macOS or iOS")
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
-LIBS += -framework Metal -framework AppKit
+LIBS += -framework Metal
+macos: LIBS += -framework AppKit
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/metalunderqml
INSTALLS += target
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.cpp b/examples/quick/scenegraph/rendernode/customrenderitem.cpp
index e55cf0a2f4..aae91120a7 100644
--- a/examples/quick/scenegraph/rendernode/customrenderitem.cpp
+++ b/examples/quick/scenegraph/rendernode/customrenderitem.cpp
@@ -53,8 +53,9 @@
#include <QSGRendererInterface>
#include "openglrenderer.h"
+#ifdef Q_OS_MACOS
#include "metalrenderer.h"
-#include "d3d12renderer.h"
+#endif
#include "softwarerenderer.h"
//! [1]
@@ -101,14 +102,6 @@ QSGNode *CustomRenderItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *)
#endif
break;
- case QSGRendererInterface::Direct3D12: // ### Qt 6: remove
-#if QT_CONFIG(d3d12)
- if (!n)
- n = new D3D12RenderNode;
- static_cast<D3D12RenderNode *>(n)->sync(this);
-#endif
- break;
-
case QSGRendererInterface::Software:
if (!n)
n = new SoftwareRenderNode;
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/d3d12renderer.cpp b/examples/quick/scenegraph/rendernode/d3d12renderer.cpp
deleted file mode 100644
index e85811c089..0000000000
--- a/examples/quick/scenegraph/rendernode/d3d12renderer.cpp
+++ /dev/null
@@ -1,309 +0,0 @@
-/****************************************************************************
-**
-** 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 "d3d12renderer.h"
-#include <QQuickItem>
-#include <QQuickWindow>
-#include <QSGRendererInterface>
-#include <QFile>
-
-// ### Qt 6: remove
-
-#if QT_CONFIG(d3d12)
-
-D3D12RenderNode::~D3D12RenderNode()
-{
- releaseResources();
-}
-
-void D3D12RenderNode::releaseResources()
-{
- if (vbPtr) {
- vertexBuffer->Unmap(0, nullptr);
- vbPtr = nullptr;
- }
- if (cbPtr) {
- constantBuffer->Unmap(0, nullptr);
- cbPtr = nullptr;
- }
- constantBuffer = nullptr;
- vertexBuffer = nullptr;
- rootSignature = nullptr;
- pipelineState = nullptr;
- m_device = nullptr;
-}
-
-void D3D12RenderNode::init()
-{
- QSGRendererInterface *rif = m_window->rendererInterface();
- m_device = static_cast<ID3D12Device *>(rif->getResource(m_window, QSGRendererInterface::DeviceResource));
- Q_ASSERT(m_device);
-
- D3D12_ROOT_PARAMETER rootParameter;
- rootParameter.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
- rootParameter.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
- rootParameter.Descriptor.ShaderRegister = 0; // b0
- rootParameter.Descriptor.RegisterSpace = 0;
-
- D3D12_ROOT_SIGNATURE_DESC desc;
- desc.NumParameters = 1;
- desc.pParameters = &rootParameter;
- desc.NumStaticSamplers = 0;
- desc.pStaticSamplers = nullptr;
- desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
-
- ComPtr<ID3DBlob> signature;
- ComPtr<ID3DBlob> error;
- if (FAILED(D3D12SerializeRootSignature(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error))) {
- qWarning("Failed to serialize root signature");
- return;
- }
- if (FAILED(m_device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(),
- IID_PPV_ARGS(&rootSignature)))) {
- qWarning("Failed to create root signature");
- return;
- }
-
- D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
- { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
- { "COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 8, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 }
- };
-
- QFile f(QStringLiteral(":/scenegraph/rendernode/shader_vert.cso"));
- if (!f.open(QIODevice::ReadOnly)) {
- qWarning("Failed to open file with vertex shader bytecode");
- return;
- }
- QByteArray vshader_cso = f.readAll();
- f.close();
- f.setFileName(QStringLiteral(":/scenegraph/rendernode/shader_frag.cso"));
- if (!f.open(QIODevice::ReadOnly)) {
- qWarning("Failed to open file with fragment shader bytecode");
- return;
- }
- QByteArray fshader_cso = f.readAll();
- D3D12_SHADER_BYTECODE vshader;
- vshader.pShaderBytecode = vshader_cso.constData();
- vshader.BytecodeLength = vshader_cso.size();
- D3D12_SHADER_BYTECODE pshader;
- pshader.pShaderBytecode = fshader_cso.constData();
- pshader.BytecodeLength = fshader_cso.size();
-
- D3D12_RASTERIZER_DESC rastDesc = {};
- rastDesc.FillMode = D3D12_FILL_MODE_SOLID;
- rastDesc.CullMode = D3D12_CULL_MODE_BACK;
- rastDesc.FrontCounterClockwise = TRUE; // Vertices are given CCW
-
- // Enable color write and blending (premultiplied alpha). The latter is
- // needed because the example changes the item's opacity and we pass
- // inheritedOpacity() into the pixel shader. If that wasn't the case,
- // blending could have stayed disabled.
- const D3D12_RENDER_TARGET_BLEND_DESC premulBlendDesc = {
- TRUE, FALSE,
- D3D12_BLEND_ONE, D3D12_BLEND_INV_SRC_ALPHA, D3D12_BLEND_OP_ADD,
- D3D12_BLEND_ONE, D3D12_BLEND_INV_SRC_ALPHA, D3D12_BLEND_OP_ADD,
- D3D12_LOGIC_OP_NOOP,
- D3D12_COLOR_WRITE_ENABLE_ALL
- };
- D3D12_BLEND_DESC blendDesc = {};
- blendDesc.RenderTarget[0] = premulBlendDesc;
-
- D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
- psoDesc.InputLayout = { inputElementDescs, _countof(inputElementDescs) };
- psoDesc.pRootSignature = rootSignature.Get();
- psoDesc.VS = vshader;
- psoDesc.PS = pshader;
- psoDesc.RasterizerState = rastDesc;
- psoDesc.BlendState = blendDesc;
- // No depth. The correct stacking of the item is ensured by the projection matrix.
- // Note that this does not support clipping.
- // If clipping is desired, render() needs to set a different PSO
- // with stencil enabled whenever the RenderState indicates so.
- psoDesc.SampleMask = UINT_MAX;
- psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
- psoDesc.NumRenderTargets = 1;
- psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
- psoDesc.DSVFormat = DXGI_FORMAT_D24_UNORM_S8_UINT; // not in use due to !DepthEnable, but this would be the correct format otherwise
- // We are rendering on the default render target so if the QuickWindow/View
- // has requested samples > 0 then we have to follow suit.
- const uint samples = qMax(1, m_window->format().samples());
- psoDesc.SampleDesc.Count = samples;
- if (samples > 1) {
- D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS msaaInfo = {};
- msaaInfo.Format = psoDesc.RTVFormats[0];
- msaaInfo.SampleCount = samples;
- if (SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &msaaInfo, sizeof(msaaInfo)))) {
- if (msaaInfo.NumQualityLevels > 0)
- psoDesc.SampleDesc.Quality = msaaInfo.NumQualityLevels - 1;
- }
- }
-
- if (FAILED(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState)))) {
- qWarning("Failed to create graphics pipeline state");
- return;
- }
-
- const UINT vertexBufferSize = (2 + 3) * 3 * sizeof(float);
-
- D3D12_HEAP_PROPERTIES heapProp = {};
- heapProp.Type = D3D12_HEAP_TYPE_UPLOAD;
-
- D3D12_RESOURCE_DESC bufDesc;
- bufDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- bufDesc.Alignment = 0;
- bufDesc.Width = vertexBufferSize;
- bufDesc.Height = 1;
- bufDesc.DepthOrArraySize = 1;
- bufDesc.MipLevels = 1;
- bufDesc.Format = DXGI_FORMAT_UNKNOWN;
- bufDesc.SampleDesc.Count = 1;
- bufDesc.SampleDesc.Quality = 0;
- bufDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
- bufDesc.Flags = D3D12_RESOURCE_FLAG_NONE;
-
- if (FAILED(m_device->CreateCommittedResource(&heapProp, D3D12_HEAP_FLAG_NONE, &bufDesc,
- D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
- IID_PPV_ARGS(&vertexBuffer)))) {
- qWarning("Failed to create committed resource (vertex buffer)");
- return;
- }
-
- vertexBufferView.BufferLocation = vertexBuffer->GetGPUVirtualAddress();
- vertexBufferView.StrideInBytes = vertexBufferSize / 3;
- vertexBufferView.SizeInBytes = vertexBufferSize;
-
- bufDesc.Width = 256;
- if (FAILED(m_device->CreateCommittedResource(&heapProp, D3D12_HEAP_FLAG_NONE, &bufDesc,
- D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
- IID_PPV_ARGS(&constantBuffer)))) {
- qWarning("Failed to create committed resource (constant buffer)");
- return;
- }
-
- const D3D12_RANGE readRange = { 0, 0 };
- if (FAILED(vertexBuffer->Map(0, &readRange, reinterpret_cast<void **>(&vbPtr)))) {
- qWarning("Map failed");
- return;
- }
-
- if (FAILED(constantBuffer->Map(0, &readRange, reinterpret_cast<void **>(&cbPtr)))) {
- qWarning("Map failed (constant buffer)");
- return;
- }
-
- float *vp = reinterpret_cast<float *>(vbPtr);
- vp += 2;
- *vp++ = 1.0f; *vp++ = 0.0f; *vp++ = 0.0f;
- vp += 2;
- *vp++ = 0.0f; *vp++ = 1.0f; *vp++ = 0.0f;
- vp += 2;
- *vp++ = 0.0f; *vp++ = 0.0f; *vp++ = 1.0f;
-}
-
-void D3D12RenderNode::render(const RenderState *state)
-{
- if (!m_device)
- init();
-
- QSGRendererInterface *rif = m_window->rendererInterface();
- ID3D12GraphicsCommandList *commandList = static_cast<ID3D12GraphicsCommandList *>(
- rif->getResource(m_window, QSGRendererInterface::CommandListResource));
- Q_ASSERT(commandList);
-
- const int msize = 16 * sizeof(float);
- memcpy(cbPtr, matrix()->constData(), msize);
- memcpy(cbPtr + msize, state->projectionMatrix()->constData(), msize);
- const float opacity = inheritedOpacity();
- memcpy(cbPtr + 2 * msize, &opacity, sizeof(float));
-
- const QPointF p0(m_width - 1, m_height - 1);
- const QPointF p1(0, 0);
- const QPointF p2(0, m_height - 1);
-
- float *vp = reinterpret_cast<float *>(vbPtr);
- *vp++ = p0.x();
- *vp++ = p0.y();
- vp += 3;
- *vp++ = p1.x();
- *vp++ = p1.y();
- vp += 3;
- *vp++ = p2.x();
- *vp++ = p2.y();
-
- commandList->SetPipelineState(pipelineState.Get());
- commandList->SetGraphicsRootSignature(rootSignature.Get());
- commandList->SetGraphicsRootConstantBufferView(0, constantBuffer->GetGPUVirtualAddress());
- commandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- commandList->IASetVertexBuffers(0, 1, &vertexBufferView);
-
- commandList->DrawInstanced(3, 1, 0, 0);
-}
-
-// No need to reimplement changedStates() because no relevant commands are
-// added to the command list in render().
-
-QSGRenderNode::RenderingFlags D3D12RenderNode::flags() const
-{
- return BoundedRectRendering | DepthAwareRendering;
-}
-
-QRectF D3D12RenderNode::rect() const
-{
- return QRect(0, 0, m_width, m_height);
-}
-
-void D3D12RenderNode::sync(QQuickItem *item)
-{
- m_window = item->window();
- m_width = item->width();
- m_height = item->height();
-}
-
-#endif // d3d12
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/main.qml b/examples/quick/scenegraph/rendernode/main.qml
index 153a71e097..2c407796cf 100644
--- a/examples/quick/scenegraph/rendernode/main.qml
+++ b/examples/quick/scenegraph/rendernode/main.qml
@@ -143,7 +143,6 @@ Item {
var apiStr;
switch (api) {
case GraphicsInfo.OpenGL: apiStr = "OpenGL (direct)"; break;
- case GraphicsInfo.Direct3D12: apiStr = "Direct3D 12 (direct)"; break;
case GraphicsInfo.Software: apiStr = "Software (QPainter)"; break;
case GraphicsInfo.OpenGLRhi: apiStr = "OpenGL (RHI)"; break;
case GraphicsInfo.MetalRhi: apiStr = "Metal (RHI)"; break;
diff --git a/examples/quick/scenegraph/rendernode/rendernode.pro b/examples/quick/scenegraph/rendernode/rendernode.pro
index 897b0b1f08..4ae46de2a4 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
@@ -17,12 +21,6 @@ INSTALLS += target
OTHER_FILES += \
main.qml
-qtConfig(d3d12) {
- HEADERS += d3d12renderer.h
- SOURCES += d3d12renderer.cpp
- LIBS += -ld3d12
-}
-
macos {
HEADERS += metalrenderer.h
SOURCES += metalrenderer.mm
diff --git a/examples/quick/scenegraph/rendernode/rendernode.qrc b/examples/quick/scenegraph/rendernode/rendernode.qrc
index 5907eab62c..a93fd0270f 100644
--- a/examples/quick/scenegraph/rendernode/rendernode.qrc
+++ b/examples/quick/scenegraph/rendernode/rendernode.qrc
@@ -1,8 +1,6 @@
<RCC>
<qresource prefix="/scenegraph/rendernode">
<file>main.qml</file>
- <file>shader_vert.cso</file>
- <file>shader_frag.cso</file>
<file>metalshader.vert</file>
<file>metalshader.frag</file>
</qresource>
diff --git a/examples/quick/scenegraph/rendernode/shader_frag.cso b/examples/quick/scenegraph/rendernode/shader_frag.cso
deleted file mode 100644
index 686c6af3fc..0000000000
--- a/examples/quick/scenegraph/rendernode/shader_frag.cso
+++ /dev/null
Binary files differ
diff --git a/examples/quick/scenegraph/rendernode/shader_vert.cso b/examples/quick/scenegraph/rendernode/shader_vert.cso
deleted file mode 100644
index fa13be5160..0000000000
--- a/examples/quick/scenegraph/rendernode/shader_vert.cso
+++ /dev/null
Binary files differ
diff --git a/examples/quick/scenegraph/rendernode/softwarerenderer.cpp b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp
index bba364ac97..a0f288d575 100644
--- a/examples/quick/scenegraph/rendernode/softwarerenderer.cpp
+++ b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp
@@ -95,7 +95,7 @@ void SoftwareRenderNode::render(const RenderState *renderState)
QSGRenderNode::StateFlags SoftwareRenderNode::changedStates() const
{
- return nullptr;
+ return {};
}
QSGRenderNode::RenderingFlags SoftwareRenderNode::flags() const
diff --git a/examples/quick/scenegraph/scenegraph.pro b/examples/quick/scenegraph/scenegraph.pro
index 5fea3b974a..08ca18fa0c 100644
--- a/examples/quick/scenegraph/scenegraph.pro
+++ b/examples/quick/scenegraph/scenegraph.pro
@@ -16,7 +16,7 @@ SUBDIRS += \
rendernode \
threadedanimation
-macos {
+macos|ios {
SUBDIRS += \
metalunderqml \
metaltextureimport
@@ -27,7 +27,9 @@ win32 {
}
qtConfig(vulkan) {
- SUBDIRS += vulkanunderqml
+ SUBDIRS += \
+ vulkanunderqml \
+ vulkantextureimport
}
EXAMPLE_FILES += \
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/quick/scenegraph/simplematerial/simplematerialitem.h b/examples/quick/scenegraph/simplematerial/simplematerialitem.h
new file mode 100644
index 0000000000..5775ad097b
--- /dev/null
+++ b/examples/quick/scenegraph/simplematerial/simplematerialitem.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#ifndef SIMPLEMATERIALITEM_H
+#define SIMPLEMATERIALITEM_H
+
+#include <QtQuick/qquickitem.h>
+
+//! [8]
+class SimpleMaterialItem : public QQuickItem
+{
+ 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;
+
+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/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpg b/examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpg
new file mode 100644
index 0000000000..e7bbe62bf3
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/doc/images/vulkantextureimport-example.jpg
Binary files differ
diff --git a/examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc b/examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc
new file mode 100644
index 0000000000..334291f990
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/doc/src/vulkantextureimport.qdoc
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** 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.
+**
+** GNU Free Documentation License Usage
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file. Please review the following information to ensure
+** the GNU Free Documentation License version 1.3 requirements
+** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \example scenegraph/vulkantextureimport
+ \title Scene Graph - Vulkan Texture Import
+ \ingroup qtquickexamples
+ \brief Shows how to use a texture created directly with use a texture created directly withulkan.
+
+ \image vulkantextureimport-example.jpg
+
+
+ The Vulkan Texture Import example shows how an application can import and
+ use a
+ \l{https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkImage.html}
+ {VkImage} in the Qt Quick scene. This provides an alternative to the \l{Scene Graph -
+ Vulkan Under QML}{underlay}, overlay, or \l{Scene Graph - Custom Rendering
+ with QSGRenderNode}{render node} approaches when it comes to integrating
+ native Vulkan rendering.
+
+ This example is equivalent in most ways to the \l{Scene Graph - Metal Texture Import}{Metal Texture Import}
+ example. The Vulkan rendering code is taken from the \l{Scene Graph - Vulkan Under QML}{Vulkan Under QML} example.
+
+ */
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp b/examples/quick/scenegraph/vulkantextureimport/main.cpp
index 74d382ec57..1c42e87043 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp
+++ b/examples/quick/scenegraph/vulkantextureimport/main.cpp
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2019 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,24 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "chartsplugin.h"
-//![0]
-#include "piechart.h"
-#include "pieslice.h"
-#include <qqml.h>
-void ChartsPlugin::registerTypes(const char *uri)
+#include <QGuiApplication>
+#include <QtQuick/QQuickView>
+#include "vulkantextureimport.h"
+
+int main(int argc, char **argv)
{
- qmlRegisterTypesAndRevisions<PieChart, PieSlice>(uri, 1);
-}
+ QGuiApplication app(argc, argv);
+
+ qmlRegisterType<CustomTextureItem>("VulkanTextureImport", 1, 0, "CustomTextureItem");
-//![0]
+ QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi);
+ QQuickView view;
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+ view.setSource(QUrl("qrc:///scenegraph/vulkantextureimport/main.qml"));
+ view.resize(400, 400);
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/quick/scenegraph/vulkantextureimport/main.qml b/examples/quick/scenegraph/vulkantextureimport/main.qml
new file mode 100644
index 0000000000..91adf4c394
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/main.qml
@@ -0,0 +1,123 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+//! [1]
+import VulkanTextureImport 1.0
+//! [1]
+
+Rectangle {
+ gradient: Gradient {
+ GradientStop { position: 0; color: "firebrick" }
+ GradientStop { position: 1; color: "black" }
+ }
+
+ //! [2]
+ CustomTextureItem {
+ id: renderer
+ anchors.fill: parent
+ anchors.margins: 10
+
+ SequentialAnimation on t {
+ NumberAnimation { to: 1; duration: 2500; easing.type: Easing.InQuad }
+ NumberAnimation { to: 0; duration: 2500; easing.type: Easing.OutQuad }
+ loops: Animation.Infinite
+ running: true
+ }
+ //! [2]
+
+ transform: [
+ Rotation { id: rotation; axis.x: 0; axis.z: 0; axis.y: 1; angle: 0; origin.x: renderer.width / 2; origin.y: renderer.height / 2; },
+ Translate { id: txOut; x: -renderer.width / 2; y: -renderer.height / 2 },
+ Scale { id: scale; },
+ Translate { id: txIn; x: renderer.width / 2; y: renderer.height / 2 }
+ ]
+ }
+
+ SequentialAnimation {
+ PauseAnimation { duration: 5000 }
+ ParallelAnimation {
+ NumberAnimation { target: scale; property: "xScale"; to: 0.6; duration: 1000; easing.type: Easing.InOutBack }
+ NumberAnimation { target: scale; property: "yScale"; to: 0.6; duration: 1000; easing.type: Easing.InOutBack }
+ }
+ NumberAnimation { target: rotation; property: "angle"; to: 80; duration: 1000; easing.type: Easing.InOutCubic }
+ NumberAnimation { target: rotation; property: "angle"; to: -80; duration: 1000; easing.type: Easing.InOutCubic }
+ NumberAnimation { target: rotation; property: "angle"; to: 0; duration: 1000; easing.type: Easing.InOutCubic }
+ NumberAnimation { target: renderer; property: "opacity"; to: 0.1; duration: 1000; easing.type: Easing.InOutCubic }
+ PauseAnimation { duration: 1000 }
+ NumberAnimation { target: renderer; property: "opacity"; to: 1.0; duration: 1000; easing.type: Easing.InOutCubic }
+ ParallelAnimation {
+ NumberAnimation { target: scale; property: "xScale"; to: 1; duration: 1000; easing.type: Easing.InOutBack }
+ NumberAnimation { target: scale; property: "yScale"; to: 1; duration: 1000; easing.type: Easing.InOutBack }
+ }
+ running: true
+ loops: Animation.Infinite
+ }
+
+ Rectangle {
+ id: labelFrame
+ anchors.margins: -10
+ radius: 5
+ color: "white"
+ border.color: "black"
+ opacity: 0.5
+ anchors.fill: label
+ }
+
+ Text {
+ id: label
+ anchors.bottom: renderer.bottom
+ anchors.left: renderer.left
+ anchors.right: renderer.right
+ anchors.margins: 20
+ wrapMode: Text.WordWrap
+ text: "The squircle, using rendering code borrowed from the vulkanunderqml example, is rendered into a texture directly with Vulkan. The VkImage is then imported and used in a custom Qt Quick item."
+ }
+}
diff --git a/examples/quick/scenegraph/vulkantextureimport/squircle.frag.spv b/examples/quick/scenegraph/vulkantextureimport/squircle.frag.spv
new file mode 100644
index 0000000000..e4d13a871d
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/squircle.frag.spv
Binary files differ
diff --git a/examples/quick/scenegraph/vulkantextureimport/squircle.vert.spv b/examples/quick/scenegraph/vulkantextureimport/squircle.vert.spv
new file mode 100644
index 0000000000..5df94a47e4
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/squircle.vert.spv
Binary files differ
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp
new file mode 100644
index 0000000000..a4201c1dfa
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.cpp
@@ -0,0 +1,823 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 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 "vulkantextureimport.h"
+
+#include <QtGui/QScreen>
+#include <QtQuick/QQuickWindow>
+#include <QtQuick/QSGTextureProvider>
+#include <QtQuick/QSGSimpleTextureNode>
+
+#include <QVulkanInstance>
+#include <QVulkanFunctions>
+
+class CustomTextureNode : public QSGTextureProvider, public QSGSimpleTextureNode
+{
+ Q_OBJECT
+
+public:
+ CustomTextureNode(QQuickItem *item);
+ ~CustomTextureNode() override;
+
+ QSGTexture *texture() const override;
+
+ void sync();
+
+private slots:
+ void render();
+
+private:
+ enum Stage {
+ VertexStage,
+ FragmentStage
+ };
+ void prepareShader(Stage stage);
+ bool buildTexture(const QSize &size);
+ void freeTexture();
+ bool createRenderPass();
+ bool initialize();
+
+ QQuickItem *m_item;
+ QQuickWindow *m_window;
+ QSize m_size;
+ qreal m_dpr;
+
+ QByteArray m_vert;
+ QByteArray m_frag;
+
+ VkImage m_texture = VK_NULL_HANDLE;
+ VkDeviceMemory m_textureMemory = VK_NULL_HANDLE;
+ VkFramebuffer m_textureFramebuffer = VK_NULL_HANDLE;
+ VkImageView m_textureView = VK_NULL_HANDLE;
+
+ bool m_initialized = false;
+
+ float m_t;
+
+ VkPhysicalDevice m_physDev = VK_NULL_HANDLE;
+ VkDevice m_dev = VK_NULL_HANDLE;
+ QVulkanDeviceFunctions *m_devFuncs = nullptr;
+ QVulkanFunctions *m_funcs = nullptr;
+
+ VkBuffer m_vbuf = VK_NULL_HANDLE;
+ VkDeviceMemory m_vbufMem = VK_NULL_HANDLE;
+ VkBuffer m_ubuf = VK_NULL_HANDLE;
+ VkDeviceMemory m_ubufMem = VK_NULL_HANDLE;
+ VkDeviceSize m_allocPerUbuf = 0;
+
+ VkPipelineCache m_pipelineCache = VK_NULL_HANDLE;
+
+ VkPipelineLayout m_pipelineLayout = VK_NULL_HANDLE;
+ VkDescriptorSetLayout m_resLayout = VK_NULL_HANDLE;
+ VkPipeline m_pipeline = VK_NULL_HANDLE;
+
+ VkDescriptorPool m_descriptorPool = VK_NULL_HANDLE;
+ VkDescriptorSet m_ubufDescriptor = VK_NULL_HANDLE;
+
+ VkRenderPass m_renderPass = VK_NULL_HANDLE;
+};
+
+CustomTextureItem::CustomTextureItem()
+{
+ setFlag(ItemHasContents, true);
+}
+
+void CustomTextureItem::invalidateSceneGraph() // called on the render thread when the scenegraph is invalidated
+{
+ m_node = nullptr;
+}
+
+void CustomTextureItem::releaseResources() // called on the gui thread if the item is removed from scene
+{
+ m_node = nullptr;
+}
+
+QSGNode *CustomTextureItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *)
+{
+ CustomTextureNode *n = static_cast<CustomTextureNode *>(node);
+
+ if (!n && (width() <= 0 || height() <= 0))
+ return nullptr;
+
+ if (!n) {
+ m_node = new CustomTextureNode(this);
+ n = m_node;
+ }
+
+ m_node->sync();
+
+ n->setTextureCoordinatesTransform(QSGSimpleTextureNode::NoTransform);
+ n->setFiltering(QSGTexture::Linear);
+ n->setRect(0, 0, width(), height());
+
+ window()->update(); // ensure getting to beforeRendering() at some point
+
+ return n;
+}
+
+void CustomTextureItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+{
+ QQuickItem::geometryChanged(newGeometry, oldGeometry);
+
+ if (newGeometry.size() != oldGeometry.size())
+ update();
+}
+
+void CustomTextureItem::setT(qreal t)
+{
+ if (t == m_t)
+ return;
+
+ m_t = t;
+ emit tChanged();
+
+ update();
+}
+
+CustomTextureNode::CustomTextureNode(QQuickItem *item)
+ : m_item(item)
+{
+ m_window = m_item->window();
+ connect(m_window, &QQuickWindow::beforeRendering, this, &CustomTextureNode::render);
+ connect(m_window, &QQuickWindow::screenChanged, this, [this]() {
+ if (m_window->effectiveDevicePixelRatio() != m_dpr)
+ m_item->update();
+ });
+}
+
+CustomTextureNode::~CustomTextureNode()
+{
+ m_devFuncs->vkDestroyBuffer(m_dev, m_vbuf, nullptr);
+ m_devFuncs->vkDestroyBuffer(m_dev, m_ubuf, nullptr);
+ m_devFuncs->vkFreeMemory(m_dev, m_vbufMem, nullptr);
+ m_devFuncs->vkFreeMemory(m_dev, m_ubufMem, nullptr);
+
+ m_devFuncs->vkDestroyPipelineCache(m_dev, m_pipelineCache, nullptr);
+ m_devFuncs->vkDestroyPipelineLayout(m_dev, m_pipelineLayout, nullptr);
+ m_devFuncs->vkDestroyPipeline(m_dev, m_pipeline, nullptr);
+
+ m_devFuncs->vkDestroyRenderPass(m_dev, m_renderPass, nullptr);
+
+ m_devFuncs->vkDestroyDescriptorSetLayout(m_dev, m_resLayout, nullptr);
+ m_devFuncs->vkDestroyDescriptorPool(m_dev, m_descriptorPool, nullptr);
+
+ delete texture();
+ freeTexture();
+}
+
+QSGTexture *CustomTextureNode::texture() const
+{
+ return QSGSimpleTextureNode::texture();
+}
+
+static const float vertices[] = {
+ -1, -1,
+ 1, -1,
+ -1, 1,
+ 1, 1
+};
+
+const int UBUF_SIZE = 4;
+
+
+bool CustomTextureNode::buildTexture(const QSize &size)
+{
+ VkImageCreateInfo imageInfo;
+ memset(&imageInfo, 0, sizeof(imageInfo));
+ imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
+ imageInfo.flags = 0;
+ imageInfo.imageType = VK_IMAGE_TYPE_2D;
+ imageInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
+ imageInfo.extent.width = uint32_t(size.width());
+ imageInfo.extent.height = uint32_t(size.height());
+ imageInfo.extent.depth = 1;
+ imageInfo.mipLevels = 1;
+ imageInfo.arrayLayers = 1;
+ imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
+ imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
+ imageInfo.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
+
+ imageInfo.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
+ imageInfo.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+
+ VkImage image = VK_NULL_HANDLE;
+ if (m_devFuncs->vkCreateImage(m_dev, &imageInfo, nullptr, &image) != VK_SUCCESS) {
+ qCritical("VulkanWrapper: failed to create image!");
+ return false;
+ }
+
+ m_texture = image;
+
+ VkMemoryRequirements memReq;
+ m_devFuncs->vkGetImageMemoryRequirements(m_dev, image, &memReq);
+
+ quint32 memIndex = 0;
+ VkPhysicalDeviceMemoryProperties physDevMemProps;
+ m_window->vulkanInstance()->functions()->vkGetPhysicalDeviceMemoryProperties(m_physDev, &physDevMemProps);
+ for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) {
+ if (!(memReq.memoryTypeBits & (1 << i)))
+ continue;
+ memIndex = i;
+ }
+
+ VkMemoryAllocateInfo allocInfo = {
+ VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
+ nullptr,
+ memReq.size,
+ memIndex
+ };
+
+ VkResult err = m_devFuncs->vkAllocateMemory(m_dev, &allocInfo, nullptr, &m_textureMemory);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to allocate memory for linear image: %d", err);
+ return false;
+ }
+
+ err = m_devFuncs->vkBindImageMemory(m_dev, image, m_textureMemory, 0);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to bind linear image memory: %d", err);
+ return false;
+ }
+
+ VkImageViewCreateInfo viewInfo;
+ memset(&viewInfo, 0, sizeof(viewInfo));
+ viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+ viewInfo.image = image;
+ viewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
+ viewInfo.format = imageInfo.format;
+ viewInfo.components.r = VK_COMPONENT_SWIZZLE_R;
+ viewInfo.components.g = VK_COMPONENT_SWIZZLE_G;
+ viewInfo.components.b = VK_COMPONENT_SWIZZLE_B;
+ viewInfo.components.a = VK_COMPONENT_SWIZZLE_A;
+ viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ viewInfo.subresourceRange.baseMipLevel = 0;
+ viewInfo.subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
+ viewInfo.subresourceRange.baseArrayLayer = 0;
+ viewInfo.subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
+
+ err = m_devFuncs->vkCreateImageView(m_dev, &viewInfo, nullptr, &m_textureView);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to create render target image view: %d", err);
+ return false;
+ }
+
+ VkFramebufferCreateInfo fbInfo;
+ memset(&fbInfo, 0, sizeof(fbInfo));
+ fbInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
+ fbInfo.renderPass = m_renderPass;
+ fbInfo.attachmentCount = 1;
+ fbInfo.pAttachments = &m_textureView;
+ fbInfo.width = uint32_t(size.width());
+ fbInfo.height = uint32_t(size.height());
+ fbInfo.layers = 1;
+
+ err = m_devFuncs->vkCreateFramebuffer(m_dev, &fbInfo, nullptr, &m_textureFramebuffer);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to create framebuffer: %d", err);
+ return false;
+ }
+ return true;
+}
+
+void CustomTextureNode::freeTexture()
+{
+ if (m_texture) {
+ m_devFuncs->vkDestroyFramebuffer(m_dev, m_textureFramebuffer, nullptr);
+ m_textureFramebuffer = VK_NULL_HANDLE;
+ m_devFuncs->vkFreeMemory(m_dev, m_textureMemory, nullptr);
+ m_textureMemory = VK_NULL_HANDLE;
+ m_devFuncs->vkDestroyImageView(m_dev, m_textureView, nullptr);
+ m_textureView = VK_NULL_HANDLE;
+ m_devFuncs->vkDestroyImage(m_dev, m_texture, nullptr);
+ m_texture = VK_NULL_HANDLE;
+ }
+}
+
+
+
+static inline VkDeviceSize aligned(VkDeviceSize v, VkDeviceSize byteAlign)
+{
+ return (v + byteAlign - 1) & ~(byteAlign - 1);
+}
+
+bool CustomTextureNode::createRenderPass()
+{
+ const VkFormat vkformat = VK_FORMAT_R8G8B8A8_UNORM;
+ const VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
+ VkAttachmentDescription colorAttDesc;
+ memset(&colorAttDesc, 0, sizeof(colorAttDesc));
+ colorAttDesc.format = vkformat;
+ colorAttDesc.samples = samples;
+ colorAttDesc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
+ colorAttDesc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
+ colorAttDesc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ colorAttDesc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ colorAttDesc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ colorAttDesc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+
+ const VkAttachmentReference colorRef = { 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL };
+
+ VkSubpassDescription subpassDesc;
+ memset(&subpassDesc, 0, sizeof(subpassDesc));
+ subpassDesc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
+ subpassDesc.colorAttachmentCount = 1;
+ subpassDesc.pColorAttachments = &colorRef;
+ subpassDesc.pDepthStencilAttachment = nullptr;
+ subpassDesc.pResolveAttachments = nullptr;
+
+ VkRenderPassCreateInfo rpInfo;
+ memset(&rpInfo, 0, sizeof(rpInfo));
+ rpInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
+ rpInfo.attachmentCount = 1;
+ rpInfo.pAttachments = &colorAttDesc;
+ rpInfo.subpassCount = 1;
+ rpInfo.pSubpasses = &subpassDesc;
+
+ VkResult err = m_devFuncs->vkCreateRenderPass(m_dev, &rpInfo, nullptr, &m_renderPass);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to create renderpass: %d", err);
+ return false;
+ }
+
+ return true;
+}
+
+bool CustomTextureNode::initialize()
+{
+ const int framesInFlight = m_window->graphicsStateInfo().framesInFlight;
+ m_initialized = true;
+
+ QSGRendererInterface *rif = m_window->rendererInterface();
+ QVulkanInstance *inst = reinterpret_cast<QVulkanInstance *>(
+ rif->getResource(m_window, QSGRendererInterface::VulkanInstanceResource));
+ Q_ASSERT(inst && inst->isValid());
+
+ m_physDev = *static_cast<VkPhysicalDevice *>(rif->getResource(m_window, QSGRendererInterface::PhysicalDeviceResource));
+ m_dev = *static_cast<VkDevice *>(rif->getResource(m_window, QSGRendererInterface::DeviceResource));
+ Q_ASSERT(m_physDev && m_dev);
+
+ m_devFuncs = inst->deviceFunctions(m_dev);
+ m_funcs = inst->functions();
+ Q_ASSERT(m_devFuncs && m_funcs);
+
+ createRenderPass();
+
+ VkPhysicalDeviceProperties physDevProps;
+ m_funcs->vkGetPhysicalDeviceProperties(m_physDev, &physDevProps);
+
+ VkPhysicalDeviceMemoryProperties physDevMemProps;
+ m_funcs->vkGetPhysicalDeviceMemoryProperties(m_physDev, &physDevMemProps);
+
+ VkBufferCreateInfo bufferInfo;
+ memset(&bufferInfo, 0, sizeof(bufferInfo));
+ bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
+ bufferInfo.size = sizeof(vertices);
+ bufferInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
+ VkResult err = m_devFuncs->vkCreateBuffer(m_dev, &bufferInfo, nullptr, &m_vbuf);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create vertex buffer: %d", err);
+
+ VkMemoryRequirements memReq;
+ m_devFuncs->vkGetBufferMemoryRequirements(m_dev, m_vbuf, &memReq);
+ VkMemoryAllocateInfo allocInfo;
+ memset(&allocInfo, 0, sizeof(allocInfo));
+ allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
+ allocInfo.allocationSize = memReq.size;
+
+ uint32_t memTypeIndex = uint32_t(-1);
+ const VkMemoryType *memType = physDevMemProps.memoryTypes;
+ for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) {
+ if (memReq.memoryTypeBits & (1 << i)) {
+ if ((memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
+ && (memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
+ {
+ memTypeIndex = i;
+ break;
+ }
+ }
+ }
+ if (memTypeIndex == uint32_t(-1))
+ qFatal("Failed to find host visible and coherent memory type");
+
+ allocInfo.memoryTypeIndex = memTypeIndex;
+ err = m_devFuncs->vkAllocateMemory(m_dev, &allocInfo, nullptr, &m_vbufMem);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to allocate vertex buffer memory of size %u: %d", uint(allocInfo.allocationSize), err);
+
+ void *p = nullptr;
+ err = m_devFuncs->vkMapMemory(m_dev, m_vbufMem, 0, allocInfo.allocationSize, 0, &p);
+ if (err != VK_SUCCESS || !p)
+ qFatal("Failed to map vertex buffer memory: %d", err);
+ memcpy(p, vertices, sizeof(vertices));
+ m_devFuncs->vkUnmapMemory(m_dev, m_vbufMem);
+ err = m_devFuncs->vkBindBufferMemory(m_dev, m_vbuf, m_vbufMem, 0);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to bind vertex buffer memory: %d", err);
+
+ m_allocPerUbuf = aligned(UBUF_SIZE, physDevProps.limits.minUniformBufferOffsetAlignment);
+
+ bufferInfo.size = framesInFlight * m_allocPerUbuf;
+ bufferInfo.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
+ err = m_devFuncs->vkCreateBuffer(m_dev, &bufferInfo, nullptr, &m_ubuf);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create uniform buffer: %d", err);
+ m_devFuncs->vkGetBufferMemoryRequirements(m_dev, m_ubuf, &memReq);
+ memTypeIndex = -1;
+ for (uint32_t i = 0; i < physDevMemProps.memoryTypeCount; ++i) {
+ if (memReq.memoryTypeBits & (1 << i)) {
+ if ((memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
+ && (memType[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
+ {
+ memTypeIndex = i;
+ break;
+ }
+ }
+ }
+ if (memTypeIndex == uint32_t(-1))
+ qFatal("Failed to find host visible and coherent memory type");
+
+ allocInfo.allocationSize = qMax(memReq.size, framesInFlight * m_allocPerUbuf);
+ allocInfo.memoryTypeIndex = memTypeIndex;
+ err = m_devFuncs->vkAllocateMemory(m_dev, &allocInfo, nullptr, &m_ubufMem);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to allocate uniform buffer memory of size %u: %d", uint(allocInfo.allocationSize), err);
+
+ err = m_devFuncs->vkBindBufferMemory(m_dev, m_ubuf, m_ubufMem, 0);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to bind uniform buffer memory: %d", err);
+
+ // Now onto the pipeline.
+
+ VkPipelineCacheCreateInfo pipelineCacheInfo;
+ memset(&pipelineCacheInfo, 0, sizeof(pipelineCacheInfo));
+ pipelineCacheInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
+ err = m_devFuncs->vkCreatePipelineCache(m_dev, &pipelineCacheInfo, nullptr, &m_pipelineCache);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create pipeline cache: %d", err);
+
+ VkDescriptorSetLayoutBinding descLayoutBinding;
+ memset(&descLayoutBinding, 0, sizeof(descLayoutBinding));
+ descLayoutBinding.binding = 0;
+ descLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
+ descLayoutBinding.descriptorCount = 1;
+ descLayoutBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
+ VkDescriptorSetLayoutCreateInfo layoutInfo;
+ memset(&layoutInfo, 0, sizeof(layoutInfo));
+ layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
+ layoutInfo.bindingCount = 1;
+ layoutInfo.pBindings = &descLayoutBinding;
+ err = m_devFuncs->vkCreateDescriptorSetLayout(m_dev, &layoutInfo, nullptr, &m_resLayout);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create descriptor set layout: %d", err);
+
+ VkPipelineLayoutCreateInfo pipelineLayoutInfo;
+ memset(&pipelineLayoutInfo, 0, sizeof(pipelineLayoutInfo));
+ pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
+ pipelineLayoutInfo.setLayoutCount = 1;
+ pipelineLayoutInfo.pSetLayouts = &m_resLayout;
+ err = m_devFuncs->vkCreatePipelineLayout(m_dev, &pipelineLayoutInfo, nullptr, &m_pipelineLayout);
+ if (err != VK_SUCCESS)
+ qWarning("Failed to create pipeline layout: %d", err);
+
+ VkGraphicsPipelineCreateInfo pipelineInfo;
+ memset(&pipelineInfo, 0, sizeof(pipelineInfo));
+ pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
+
+ VkShaderModuleCreateInfo shaderInfo;
+ memset(&shaderInfo, 0, sizeof(shaderInfo));
+ shaderInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
+ shaderInfo.codeSize = m_vert.size();
+ shaderInfo.pCode = reinterpret_cast<const quint32 *>(m_vert.constData());
+ VkShaderModule vertShaderModule;
+ err = m_devFuncs->vkCreateShaderModule(m_dev, &shaderInfo, nullptr, &vertShaderModule);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create vertex shader module: %d", err);
+
+ shaderInfo.codeSize = m_frag.size();
+ shaderInfo.pCode = reinterpret_cast<const quint32 *>(m_frag.constData());
+ VkShaderModule fragShaderModule;
+ err = m_devFuncs->vkCreateShaderModule(m_dev, &shaderInfo, nullptr, &fragShaderModule);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create fragment shader module: %d", err);
+
+ VkPipelineShaderStageCreateInfo stageInfo[2];
+ memset(&stageInfo, 0, sizeof(stageInfo));
+ stageInfo[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ stageInfo[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
+ stageInfo[0].module = vertShaderModule;
+ stageInfo[0].pName = "main";
+ stageInfo[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ stageInfo[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
+ stageInfo[1].module = fragShaderModule;
+ stageInfo[1].pName = "main";
+ pipelineInfo.stageCount = 2;
+ pipelineInfo.pStages = stageInfo;
+
+ VkVertexInputBindingDescription vertexBinding = {
+ 0, // binding
+ 2 * sizeof(float), // stride
+ VK_VERTEX_INPUT_RATE_VERTEX
+ };
+ VkVertexInputAttributeDescription vertexAttr = {
+ 0, // location
+ 0, // binding
+ VK_FORMAT_R32G32_SFLOAT, // 'vertices' only has 2 floats per vertex
+ 0 // offset
+ };
+ VkPipelineVertexInputStateCreateInfo vertexInputInfo;
+ memset(&vertexInputInfo, 0, sizeof(vertexInputInfo));
+ vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
+ vertexInputInfo.vertexBindingDescriptionCount = 1;
+ vertexInputInfo.pVertexBindingDescriptions = &vertexBinding;
+ vertexInputInfo.vertexAttributeDescriptionCount = 1;
+ vertexInputInfo.pVertexAttributeDescriptions = &vertexAttr;
+ pipelineInfo.pVertexInputState = &vertexInputInfo;
+
+ VkDynamicState dynStates[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
+ VkPipelineDynamicStateCreateInfo dynamicInfo;
+ memset(&dynamicInfo, 0, sizeof(dynamicInfo));
+ dynamicInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
+ dynamicInfo.dynamicStateCount = 2;
+ dynamicInfo.pDynamicStates = dynStates;
+ pipelineInfo.pDynamicState = &dynamicInfo;
+
+ VkPipelineViewportStateCreateInfo viewportInfo;
+ memset(&viewportInfo, 0, sizeof(viewportInfo));
+ viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
+ viewportInfo.viewportCount = viewportInfo.scissorCount = 1;
+ pipelineInfo.pViewportState = &viewportInfo;
+
+ VkPipelineInputAssemblyStateCreateInfo iaInfo;
+ memset(&iaInfo, 0, sizeof(iaInfo));
+ iaInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
+ iaInfo.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
+ pipelineInfo.pInputAssemblyState = &iaInfo;
+
+ VkPipelineRasterizationStateCreateInfo rsInfo;
+ memset(&rsInfo, 0, sizeof(rsInfo));
+ rsInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
+ rsInfo.lineWidth = 1.0f;
+ pipelineInfo.pRasterizationState = &rsInfo;
+
+ VkPipelineMultisampleStateCreateInfo msInfo;
+ memset(&msInfo, 0, sizeof(msInfo));
+ msInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
+ msInfo.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
+ pipelineInfo.pMultisampleState = &msInfo;
+
+ VkPipelineDepthStencilStateCreateInfo dsInfo;
+ memset(&dsInfo, 0, sizeof(dsInfo));
+ dsInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
+ pipelineInfo.pDepthStencilState = &dsInfo;
+
+ // SrcAlpha, One
+ VkPipelineColorBlendStateCreateInfo blendInfo;
+ memset(&blendInfo, 0, sizeof(blendInfo));
+ blendInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
+ VkPipelineColorBlendAttachmentState blend;
+ memset(&blend, 0, sizeof(blend));
+ blend.blendEnable = true;
+ blend.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
+ blend.dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
+ blend.colorBlendOp = VK_BLEND_OP_ADD;
+ blend.srcAlphaBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
+ blend.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
+ blend.alphaBlendOp = VK_BLEND_OP_ADD;
+ blend.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT
+ | VK_COLOR_COMPONENT_A_BIT;
+ blendInfo.attachmentCount = 1;
+ blendInfo.pAttachments = &blend;
+ pipelineInfo.pColorBlendState = &blendInfo;
+
+ pipelineInfo.layout = m_pipelineLayout;
+
+ pipelineInfo.renderPass = m_renderPass;
+
+ err = m_devFuncs->vkCreateGraphicsPipelines(m_dev, m_pipelineCache, 1, &pipelineInfo, nullptr, &m_pipeline);
+
+ m_devFuncs->vkDestroyShaderModule(m_dev, vertShaderModule, nullptr);
+ m_devFuncs->vkDestroyShaderModule(m_dev, fragShaderModule, nullptr);
+
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create graphics pipeline: %d", err);
+
+ // Now just need some descriptors.
+ VkDescriptorPoolSize descPoolSizes[] = {
+ { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1 }
+ };
+ VkDescriptorPoolCreateInfo descPoolInfo;
+ memset(&descPoolInfo, 0, sizeof(descPoolInfo));
+ descPoolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
+ descPoolInfo.flags = 0; // won't use vkFreeDescriptorSets
+ descPoolInfo.maxSets = 1;
+ descPoolInfo.poolSizeCount = sizeof(descPoolSizes) / sizeof(descPoolSizes[0]);
+ descPoolInfo.pPoolSizes = descPoolSizes;
+ err = m_devFuncs->vkCreateDescriptorPool(m_dev, &descPoolInfo, nullptr, &m_descriptorPool);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to create descriptor pool: %d", err);
+
+ VkDescriptorSetAllocateInfo descAllocInfo;
+ memset(&descAllocInfo, 0, sizeof(descAllocInfo));
+ descAllocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
+ descAllocInfo.descriptorPool = m_descriptorPool;
+ descAllocInfo.descriptorSetCount = 1;
+ descAllocInfo.pSetLayouts = &m_resLayout;
+ err = m_devFuncs->vkAllocateDescriptorSets(m_dev, &descAllocInfo, &m_ubufDescriptor);
+ if (err != VK_SUCCESS)
+ qFatal("Failed to allocate descriptor set");
+
+ VkWriteDescriptorSet writeInfo;
+ memset(&writeInfo, 0, sizeof(writeInfo));
+ writeInfo.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
+ writeInfo.dstSet = m_ubufDescriptor;
+ writeInfo.dstBinding = 0;
+ writeInfo.descriptorCount = 1;
+ writeInfo.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
+ VkDescriptorBufferInfo bufInfo;
+ bufInfo.buffer = m_ubuf;
+ bufInfo.offset = 0; // dynamic offset is used so this is ignored
+ bufInfo.range = UBUF_SIZE;
+ writeInfo.pBufferInfo = &bufInfo;
+
+ m_devFuncs->vkUpdateDescriptorSets(m_dev, 1, &writeInfo, 0, nullptr);
+ return true;
+}
+
+void CustomTextureNode::sync()
+{
+ m_dpr = m_window->effectiveDevicePixelRatio();
+ const QSize newSize = m_window->size() * m_dpr;
+ bool needsNew = false;
+
+ if (!m_initialized) {
+ prepareShader(VertexStage);
+ prepareShader(FragmentStage);
+ initialize();
+ m_initialized = true;
+ }
+
+ if (!texture())
+ needsNew = true;
+
+ if (newSize != m_size) {
+ needsNew = true;
+ m_size = newSize;
+ }
+
+ if (needsNew) {
+ delete texture();
+ freeTexture();
+ buildTexture(m_size);
+ QSGTexture *wrapper = m_window->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture,
+ &m_texture,
+ VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
+ m_size);
+ setTexture(wrapper);
+ }
+
+ m_t = float(static_cast<CustomTextureItem *>(m_item)->t());
+}
+
+void CustomTextureNode::render()
+{
+ if (!m_initialized)
+ return;
+
+ VkResult err = VK_SUCCESS;
+
+ uint currentFrameSlot = m_window->graphicsStateInfo().currentFrameSlot;
+ VkDeviceSize ubufOffset = currentFrameSlot * m_allocPerUbuf;
+ void *p = nullptr;
+ err = m_devFuncs->vkMapMemory(m_dev, m_ubufMem, ubufOffset, m_allocPerUbuf, 0, &p);
+ if (err != VK_SUCCESS || !p)
+ qFatal("Failed to map uniform buffer memory: %d", err);
+ float t = m_t;
+ memcpy(p, &t, 4);
+ m_devFuncs->vkUnmapMemory(m_dev, m_ubufMem);
+
+ VkClearValue clearColor = {{ {0, 0, 0, 1} }};
+
+ VkRenderPassBeginInfo rpBeginInfo = {};
+ rpBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
+ rpBeginInfo.renderPass = m_renderPass;
+ rpBeginInfo.framebuffer = m_textureFramebuffer;
+ rpBeginInfo.renderArea.extent.width = m_size.width();
+ rpBeginInfo.renderArea.extent.height = m_size.height();
+ rpBeginInfo.clearValueCount = 1;
+ rpBeginInfo.pClearValues = &clearColor;
+
+ QSGRendererInterface *rif = m_window->rendererInterface();
+ VkCommandBuffer cmdBuf = *reinterpret_cast<VkCommandBuffer *>(
+ rif->getResource(m_window, QSGRendererInterface::CommandListResource));
+
+ m_devFuncs->vkCmdBeginRenderPass(cmdBuf, &rpBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
+
+ m_devFuncs->vkCmdBindPipeline(cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipeline);
+
+ VkDeviceSize vbufOffset = 0;
+ m_devFuncs->vkCmdBindVertexBuffers(cmdBuf, 0, 1, &m_vbuf, &vbufOffset);
+
+ uint32_t dynamicOffset = m_allocPerUbuf * currentFrameSlot;
+ m_devFuncs->vkCmdBindDescriptorSets(cmdBuf, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1,
+ &m_ubufDescriptor, 1, &dynamicOffset);
+
+ VkViewport vp = { 0, 0, float(m_size.width()), float(m_size.height()), 0.0f, 1.0f };
+ m_devFuncs->vkCmdSetViewport(cmdBuf, 0, 1, &vp);
+ VkRect2D scissor = { { 0, 0 }, { uint32_t(m_size.width()), uint32_t(m_size.height()) } };
+ m_devFuncs->vkCmdSetScissor(cmdBuf, 0, 1, &scissor);
+
+ m_devFuncs->vkCmdDraw(cmdBuf, 4, 1, 0, 0);
+ m_devFuncs->vkCmdEndRenderPass(cmdBuf);
+
+ // Memory barrier before the texture can be used as a source.
+ // Since we are not using a sub-pass, we have to do this explicitly.
+
+ VkImageMemoryBarrier imageTransitionBarrier = {};
+ imageTransitionBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
+ imageTransitionBarrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
+ imageTransitionBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
+ imageTransitionBarrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ imageTransitionBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
+ imageTransitionBarrier.image = m_texture;
+ imageTransitionBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ imageTransitionBarrier.subresourceRange.levelCount = imageTransitionBarrier.subresourceRange.layerCount = 1;
+
+ m_devFuncs->vkCmdPipelineBarrier(cmdBuf,
+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
+ VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
+ 0, 0, nullptr, 0, nullptr,
+ 1, &imageTransitionBarrier);
+}
+
+void CustomTextureNode::prepareShader(Stage stage)
+{
+ QString filename;
+ if (stage == VertexStage) {
+ filename = QLatin1String(":/scenegraph/vulkantextureimport/squircle.vert.spv");
+ } else {
+ Q_ASSERT(stage == FragmentStage);
+ filename = QLatin1String(":/scenegraph/vulkantextureimport/squircle.frag.spv");
+ }
+ QFile f(filename);
+ if (!f.open(QIODevice::ReadOnly))
+ qFatal("Failed to read shader %s", qPrintable(filename));
+
+ const QByteArray contents = f.readAll();
+
+ if (stage == VertexStage) {
+ m_vert = contents;
+ Q_ASSERT(!m_vert.isEmpty());
+ } else {
+ m_frag = contents;
+ Q_ASSERT(!m_frag.isEmpty());
+ }
+}
+
+#include "vulkantextureimport.moc"
diff --git a/examples/quick/scenegraph/rendernode/d3d12renderer.h b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h
index 7186b72c04..f604faf66f 100644
--- a/examples/quick/scenegraph/rendernode/d3d12renderer.h
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.h
@@ -1,9 +1,9 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
-** This file is part of the examples of the Qt Toolkit.
+** This file is part of the demonstration applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
@@ -48,48 +48,41 @@
**
****************************************************************************/
-#ifndef D3D12RENDERER_H
-#define D3D12RENDERER_H
+#ifndef VULKANTEXTUREIMPORT_H
+#define VULKANTEXTUREIMPORT_H
-#include <qsgrendernode.h>
-#include <QQuickItem>
+#include <QtQuick/QQuickItem>
-#if QT_CONFIG(d3d12)
+class CustomTextureNode;
-#include <d3d12.h>
-#include <wrl/client.h>
-
-using namespace Microsoft::WRL;
-
-class D3D12RenderNode : public QSGRenderNode
+//! [1]
+class CustomTextureItem : public QQuickItem
{
+ Q_OBJECT
+ Q_PROPERTY(qreal t READ t WRITE setT NOTIFY tChanged)
+
public:
- ~D3D12RenderNode();
+ CustomTextureItem();
- void render(const RenderState *state) override;
- void releaseResources() override;
- RenderingFlags flags() const override;
- QRectF rect() const override;
+ qreal t() const { return m_t; }
+ void setT(qreal t);
- void sync(QQuickItem *item);
+signals:
+ void tChanged();
-private:
- void init();
+protected:
+ QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
+ void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
- QQuickWindow *m_window = nullptr;
- int m_width = 0;
- int m_height = 0;
+private slots:
+ void invalidateSceneGraph();
- ID3D12Device *m_device = nullptr;
- ComPtr<ID3D12PipelineState> pipelineState;
- ComPtr<ID3D12RootSignature> rootSignature;
- ComPtr<ID3D12Resource> vertexBuffer;
- ComPtr<ID3D12Resource> constantBuffer;
- D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
- quint8 *vbPtr = nullptr;
- quint8 *cbPtr = nullptr;
-};
+private:
+ void releaseResources() override;
-#endif // d3d12
+ CustomTextureNode *m_node = nullptr;
+ qreal m_t = 0;
+};
+//! [1]
-#endif
+#endif // VULKANTEXTUREIMPORT_H
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro
new file mode 100644
index 0000000000..f2f78a6ed3
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.pro
@@ -0,0 +1,12 @@
+!qtConfig(vulkan): error("This example requires Qt built with Vulkan support")
+
+QT += qml quick
+
+HEADERS += vulkantextureimport.h
+SOURCES += vulkantextureimport.cpp main.cpp
+RESOURCES += vulkantextureimport.qrc
+
+
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/vulkantextureimport
+INSTALLS += target
diff --git a/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc
new file mode 100644
index 0000000000..a1aec6c950
--- /dev/null
+++ b/examples/quick/scenegraph/vulkantextureimport/vulkantextureimport.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/scenegraph/vulkantextureimport">
+ <file>main.qml</file>
+ <file>squircle.vert.spv</file>
+ <file>squircle.frag.spv</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/blur.frag b/examples/quick/shadereffects/content/shaders/+hlsl/blur.frag
deleted file mode 100644
index 481a238d2a..0000000000
--- a/examples/quick/shadereffects/content/shaders/+hlsl/blur.frag
+++ /dev/null
@@ -1,18 +0,0 @@
-cbuffer ConstantBuffer : register(b0)
-{
- float4x4 qt_Matrix;
- float qt_Opacity;
- float2 delta;
-};
-
-Texture2D source : register(t0);
-SamplerState sourceSampler : register(s0);
-
-float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET
-{
- return (0.0538 * source.Sample(sourceSampler, coord - 3.182 * delta)
- + 0.3229 * source.Sample(sourceSampler, coord - 1.364 * delta)
- + 0.2466 * source.Sample(sourceSampler, coord)
- + 0.3229 * source.Sample(sourceSampler, coord + 1.364 * delta)
- + 0.0538 * source.Sample(sourceSampler, coord + 3.182 * delta)) * qt_Opacity;
-}
diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/colorize.frag b/examples/quick/shadereffects/content/shaders/+hlsl/colorize.frag
deleted file mode 100644
index d6e65b6b10..0000000000
--- a/examples/quick/shadereffects/content/shaders/+hlsl/colorize.frag
+++ /dev/null
@@ -1,17 +0,0 @@
-cbuffer ConstantBuffer : register(b0)
-{
- float4x4 qt_Matrix;
- float qt_Opacity;
- float4 tint;
-};
-
-Texture2D source : register(t0);
-SamplerState sourceSampler : register(s0);
-
-float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET
-{
- float4 c = source.Sample(sourceSampler, coord);
- float lo = min(min(c.x, c.y), c.z);
- float hi = max(max(c.x, c.y), c.z);
- return float4(lerp(float3(lo, lo, lo), float3(hi, hi, hi), tint.xyz), c.w) * qt_Opacity;
-}
diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/genie.vert b/examples/quick/shadereffects/content/shaders/+hlsl/genie.vert
deleted file mode 100644
index 40876e7996..0000000000
--- a/examples/quick/shadereffects/content/shaders/+hlsl/genie.vert
+++ /dev/null
@@ -1,31 +0,0 @@
-cbuffer ConstantBuffer : register(b0)
-{
- float4x4 qt_Matrix;
- float qt_Opacity;
- float bend;
- float minimize;
- float side;
- float width;
- float height;
-};
-
-struct PSInput
-{
- float4 position : SV_POSITION;
- float2 coord : TEXCOORD0;
-};
-
-PSInput main(float4 position : POSITION, float2 coord : TEXCOORD0)
-{
- PSInput result;
- result.coord = coord;
-
- float4 pos = position;
- pos.y = lerp(position.y, height, minimize);
- float t = pos.y / height;
- t = (3.0 - 2.0 * t) * t * t;
- pos.x = lerp(position.x, side * width, t * bend);
- result.position = mul(qt_Matrix, pos);
-
- return result;
-}
diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/outline.frag b/examples/quick/shadereffects/content/shaders/+hlsl/outline.frag
deleted file mode 100644
index b6e7e51f35..0000000000
--- a/examples/quick/shadereffects/content/shaders/+hlsl/outline.frag
+++ /dev/null
@@ -1,21 +0,0 @@
-cbuffer ConstantBuffer : register(b0)
-{
- float4x4 qt_Matrix;
- float qt_Opacity;
- float2 delta;
-};
-
-Texture2D source : register(t0);
-SamplerState sourceSampler : register(s0);
-
-float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET
-{
- float4 tl = source.Sample(sourceSampler, coord - delta);
- float4 tr = source.Sample(sourceSampler, coord + float2(delta.x, -delta.y));
- float4 bl = source.Sample(sourceSampler, coord - float2(delta.x, -delta.y));
- float4 br = source.Sample(sourceSampler, coord + delta);
- float4 gx = (tl + bl) - (tr + br);
- float4 gy = (tl + tr) - (bl + br);
- return float4(0.0, 0.0, 0.0,
- clamp(dot(sqrt(gx * gx + gy * gy), float4(1.0, 1.0, 1.0, 1.0)), 0.0, 1.0) * qt_Opacity);
-}
diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/shadow.frag b/examples/quick/shadereffects/content/shaders/+hlsl/shadow.frag
deleted file mode 100644
index a86a25e007..0000000000
--- a/examples/quick/shadereffects/content/shaders/+hlsl/shadow.frag
+++ /dev/null
@@ -1,20 +0,0 @@
-cbuffer ConstantBuffer : register(b0)
-{
- float4x4 qt_Matrix;
- float qt_Opacity;
- float2 offset;
- float2 delta;
- float darkness;
-};
-
-Texture2D source : register(t0);
-SamplerState sourceSampler : register(s0);
-Texture2D shadow : register(t1);
-SamplerState shadowSampler : register(s1);
-
-float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET
-{
- float4 fg = source.Sample(sourceSampler, coord);
- float4 bg = shadow.Sample(shadowSampler, coord + delta);
- return (fg + float4(0.0, 0.0, 0.0, darkness * bg.a) * (1.0 - fg.a)) * qt_Opacity;
-}
diff --git a/examples/quick/shadereffects/content/shaders/+hlsl/wobble.frag b/examples/quick/shadereffects/content/shaders/+hlsl/wobble.frag
deleted file mode 100644
index c28612a2fd..0000000000
--- a/examples/quick/shadereffects/content/shaders/+hlsl/wobble.frag
+++ /dev/null
@@ -1,17 +0,0 @@
-cbuffer ConstantBuffer : register(b0)
-{
- float4x4 qt_Matrix;
- float qt_Opacity;
- float amplitude;
- float frequency;
- float time;
-};
-
-Texture2D source : register(t0);
-SamplerState sourceSampler : register(s0);
-
-float4 main(float4 position : SV_POSITION, float2 coord : TEXCOORD0) : SV_TARGET
-{
- float2 p = sin(time + frequency * coord);
- return source.Sample(sourceSampler, coord + amplitude * float2(p.y, -p.x)) * qt_Opacity;
-}
diff --git a/examples/quick/shadereffects/doc/src/shadereffects.qdoc b/examples/quick/shadereffects/doc/src/shadereffects.qdoc
index d35989c262..d217c956ad 100644
--- a/examples/quick/shadereffects/doc/src/shadereffects.qdoc
+++ b/examples/quick/shadereffects/doc/src/shadereffects.qdoc
@@ -59,21 +59,6 @@
Direct 3D, or OpenGL. Qt automatically selects the file under the \c qsb
selector, for example \c{shaders/+qsb/wobble.frag}, when present.
- On the traditional code path, which can mean using OpenGL or Direct3D 12,
- file selectors are used to select the correct variant at runtime. Based on
- the Qt Quick backend in use, Qt will automatically select either
- \c{shaders/wobble.frag} with the GLSL source code or
- \c{shaders/+hlsl/wobble.frag} with the HLSL source code.
-
- \note For simplicity shader source code is used in all variants of the
- files. However, with the Direct3D backend of Qt Quick pre-compiled shaders
- are also supported. For example, try the following commands in the
- \c{content/shaders/+hlsl} directory: \c{move wobble.frag wobble.frag.src}
- followed by \c{fxc /E main /T ps_5_0 /Fo wobble.frag wobble.frag.src}. Now
- \c wobble.frag contains Direct3D bytecode and that is what gets shipped
- with the application instead of the shader source. Further changes are not
- necessary, the application will function like before.
-
You can use any custom property on the ShaderEffect in your shader. This
makes animated shader code very easy:
\snippet shadereffects/shadereffects.qml properties
diff --git a/examples/quick/shadereffects/shadereffects.qrc b/examples/quick/shadereffects/shadereffects.qrc
index 762ad0d037..72ad2d9054 100644
--- a/examples/quick/shadereffects/shadereffects.qrc
+++ b/examples/quick/shadereffects/shadereffects.qrc
@@ -5,22 +5,16 @@
<file>content/qt-logo.png</file>
<file>content/Slider.qml</file>
<file>content/shaders/wobble.frag</file>
- <file>content/shaders/+hlsl/wobble.frag</file>
<file>content/shaders/+qsb/wobble.frag</file>
<file>content/shaders/blur.frag</file>
- <file>content/shaders/+hlsl/blur.frag</file>
<file>content/shaders/+qsb/blur.frag</file>
<file>content/shaders/shadow.frag</file>
- <file>content/shaders/+hlsl/shadow.frag</file>
<file>content/shaders/+qsb/shadow.frag</file>
<file>content/shaders/outline.frag</file>
- <file>content/shaders/+hlsl/outline.frag</file>
<file>content/shaders/+qsb/outline.frag</file>
<file>content/shaders/colorize.frag</file>
- <file>content/shaders/+hlsl/colorize.frag</file>
<file>content/shaders/+qsb/colorize.frag</file>
<file>content/shaders/genie.vert</file>
- <file>content/shaders/+hlsl/genie.vert</file>
<file>content/shaders/+qsb/genie.vert</file>
</qresource>
</RCC>
diff --git a/examples/quick/shared/FlickrRssModel.qml b/examples/quick/shared/FlickrRssModel.qml
index cee4022bf0..5f88fabcae 100644
--- a/examples/quick/shared/FlickrRssModel.qml
+++ b/examples/quick/shared/FlickrRssModel.qml
@@ -63,6 +63,12 @@ ListModel {
var xhr = new XMLHttpRequest;
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
+
+ if (xhr.status !== 200) {
+ console.log("Failed to get images from flickr. status code: " + xhr.status);
+ return;
+ }
+
var jsonText = xhr.responseText;
var objArray = JSON.parse(jsonText.replace(/\'/g,"'"))
if (objArray.errors !== undefined)
diff --git a/examples/quick/shared/SimpleLauncherDelegate.qml b/examples/quick/shared/SimpleLauncherDelegate.qml
index 75aecf262c..7f07dea52a 100644
--- a/examples/quick/shared/SimpleLauncherDelegate.qml
+++ b/examples/quick/shared/SimpleLauncherDelegate.qml
@@ -61,12 +61,12 @@ Rectangle {
GradientStop {
position: 0
Behavior on color {ColorAnimation { duration: 100 }}
- color: button.pressed ? "#e0e0e0" : "#fff"
+ color: tapHandler.pressed ? "#e0e0e0" : "#fff"
}
GradientStop {
position: 1
Behavior on color {ColorAnimation { duration: 100 }}
- color: button.pressed ? "#e0e0e0" : button.containsMouse ? "#f5f5f5" : "#eee"
+ color: tapHandler.pressed ? "#e0e0e0" : button.containsMouse ? "#f5f5f5" : "#eee"
}
}
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 a34456ff0b..188f55ebc3 100644
--- a/examples/quick/tableview/pixelator/pixelator.pro
+++ b/examples/quick/tableview/pixelator/pixelator.pro
@@ -6,6 +6,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
diff --git a/examples/quick/touchinteraction/multipointtouch/bearwhack.qml b/examples/quick/touchinteraction/multipointtouch/bearwhack.qml
index 49bd0b9db8..90c1a66891 100644
--- a/examples/quick/touchinteraction/multipointtouch/bearwhack.qml
+++ b/examples/quick/touchinteraction/multipointtouch/bearwhack.qml
@@ -87,7 +87,7 @@ Item {
running: !startScreen.visible
}
- property int score: 0
+ property int score: particleSystem.score
Text {
anchors.right: parent.right
@@ -96,11 +96,13 @@ Item {
color: "white"
function padded(num) {
var ret = num.toString();
- while (ret.length < 6)
- ret = "0" + ret;
- return ret;
+
+ if (ret >= 0)
+ return ret.padStart(6, "0");
+ else
+ return "-" + ret.substr(1).padStart(6, "0");
}
- text: "Score: " + padded(score)
+ text: "Score: " + padded(root.score)
}
MultiPointTouchArea {
anchors.fill: parent
diff --git a/examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml b/examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml
index 3db9eaf1e5..8da5949a1b 100644
--- a/examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml
+++ b/examples/quick/touchinteraction/multipointtouch/content/BearWhackParticleSystem.qml
@@ -52,6 +52,9 @@ import QtQuick.Particles 2.0
ParticleSystem {
id: particleSystem
+
+ property int score
+
function explode(x,y) {
fireEmitter.burst(100,x,y);
}
@@ -116,13 +119,13 @@ ParticleSystem {
once: true
y: parent.height - 32
groups: "bears"
- onAffectParticles: {
+ onAffectParticles: function(particles) {
for (var i=0;i<particles.length; i++) {
if (particles[i].animationIndex != 0) {
- score++;
+ particleSystem.score++;
bloodEmitter.burst(100, particles[i].x, particles[i].y);
} else {
- score--;
+ particleSystem.score--;
heartEmitter.burst(100, particles[i].x, particles[i].y);
}
particles[i].update = 1.0;
diff --git a/examples/quick/views/pathview/pathview-example.qml b/examples/quick/views/pathview/pathview-example.qml
index a70bf1b656..e42117dfae 100644
--- a/examples/quick/views/pathview/pathview-example.qml
+++ b/examples/quick/views/pathview/pathview-example.qml
@@ -71,19 +71,23 @@ Rectangle {
width: 100; height: 100
scale: PathView.iconScale
+ required property string name
+ required property string icon
+ required property int index
+
Image {
id: myIcon
y: 20; anchors.horizontalCenter: parent.horizontalCenter
- source: icon
+ source: parent.icon
}
Text {
anchors { top: myIcon.bottom; horizontalCenter: parent.horizontalCenter }
- text: name
+ text: parent.name
}
MouseArea {
anchors.fill: parent
- onClicked: view.currentIndex = index
+ onClicked: view.currentIndex = parent.index
}
}
}