Merge remote-tracking branch 'origin/dev' into wip/cmake

Change-Id: I0c5b939c70bdb91ccdf7068784308416dcaa5736
This commit is contained in:
Leander Beernaert 2020-01-16 16:25:06 +01:00
commit 1d333d3375
830 changed files with 107047 additions and 35708 deletions

View File

@ -1,51 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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 Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <d3d12.h>
#include <dxgi1_4.h>
#include <wrl/client.h>
using namespace Microsoft::WRL;
int main(int, char **)
{
ID3D12Device *dev = 0;
return 0;
}

View File

@ -1,4 +0,0 @@
SOURCES = d3d12.cpp
CONFIG -= qt dylib
CONFIG += console
LIBS += -ldxgi -ld3d12 -ld3dcompiler -ldcomp

372
dist/changes-5.14.0 vendored Normal file
View File

@ -0,0 +1,372 @@
Qt 5.14 introduces many new features and improvements as well as bugfixes
over the 5.13.x series. For more details, refer to the online documentation
included in this distribution. The documentation is also available online:
https://doc.qt.io/qt-5/index.html
The Qt version 5.14 series is binary compatible with the 5.13.x series.
Applications compiled for 5.13 will continue to run with 5.14.
Some of the changes listed in this file include issue tracking numbers
corresponding to tasks in the Qt Bug Tracker:
https://bugreports.qt.io/
Each of these identifiers can be entered in the bug tracker to obtain more
information about a particular change.
****************************************************************************
* QtQml *
****************************************************************************
- On Android, QML plugins are loaded directly from the APK libs dir and
use qrc:/android_rcc_bundle/qml to search for QML files.
- [QTBUG-38913] Added ability to import static qml plugins with CMake
builds using the new QT5_IMPORT_QML_PLUGINS function.
- The NaN obtained by Math.pow(+/-1, +/-infinity) and
(+/-1)**(+/-infinity) is now quiet rather than signalling.
- It is now possible to specify types for method parameters and their
return value in QML (basic and object types), using TypeScript-like
syntax with a colon separator. The syntax for QML declared signals
supports the same style.
- QML Binding elements now support restoring previous values
of the bound property when the binding is disabled. This will be the
default behavior in Qt 6.0. Reliance on the old behavior of only
restoring binding, not literal values will results in a warning beginning
with Qt 5.15.
- The regular expression engine was updated, causing somewhat better
compliance with the ECMAScript specification.
- [QTBUG-74190] Fixed a crash due to combination of aggressive GC with logging.
Also, the qt.qml.gc.* logging rules don't produce false warnings about huge
amounts of lost memory anymore.
- [QTBUG-75007] Usage of singletons from QML engines in different threads
does not cause race conditions anymore.
- The JIT compiler is now a configurable feature. You can pass
-no-feature-qml-jit to configure in order to skip it, or -feature-qml-jit
in order to build it for platforms where it's disabled by default, e.g.
iOS and tvOS.
- [QTBUG-49080][QTBUG-78955] You can now interrupt a QJSEngine running a
JavaScript program by setting its isInterrupted flag from a different thread.
- qmlscene will not run into an infinite loop anymore if you pass a QML
document without any executable code.
- You can configure the maximum sizes of the JavaScript and the garbage
collector stacks now, using the QV4_JS_MAX_STACK_SIZE and
QV4_GC_MAX_STACK_SIZE environment variables.
- [QTBUG-76346] Context properties carrying QObjects are automatically
reset when the objects are destroyed now.
- [QTBUG-40487] You can now use Component properties in Binding elements.
- [QTBUG-76932] Changing sourceComponent in a Loader does not delete
C++-owned objects anymore.
- qmllint can now check for unqualified access to to properties of the
root object and undeclared signal parameters.
- [QTBUG-77096] You can use generator functions in QML components now.
- You can and should use plain JavaScript functions as signal handlers in
Connections elements now. This avoids the overhead of the custom parser
that otherwise needs to run for each Connections element, and forces you
to specify the signal parameters you are going to use.
- You can pass a set of initial properties to QQmlApplicationEngine,
QQmlComponent, and QQuickView now. Those will be used as defaults in any
subsequent instantiation of top-level QML objects.
- Anonymous types should be registered via the new qmlRegisterAnonymousType()
function now, rather than via the parameter-less qmlRegisterType(). That
is, you should specify a URI and a major version for your type.
- [QTBUG-74087] The QML parser can parse more complex JavaScript code now
without overflowing the stack. This allows for deeper list nesting in QML.
- [QTBUG-76021] instanceof does not confuse derived types with no additional
properties with their parent types anymore.
- [QTBUG-78943] Binding elements will not randomly convert strings to other
types anymore.
- [QTBUG-48150] You can use aliases of "depth" 2 now. That is, something like
"property alias topMargin: myItem.anchors.topMargin" works now.
- [QTBUG-78325] The "color" type has a property "valid" now.
- [QTBUG-78044] The qmlprofiler command line tool's interactive mode is more
stable now.
- [QTBUG-48809] Fixed a warning about non-relative paths in qmldir files.
We now permit the use of resource urls in qmldir files to allow a plugin
to include its .qml files in resources, optionally compiled ahead of time.
- [QTBUG-79614] QQmlProperty now handles reads of QQmlPropertyMap correctly.
- [QTBUG-79443] In the debugger, we now avoid loading cache files, so that
JavaScript breakpoints keep working after the first run.
- [QTBUG-55259] qmlimportscanner now scans resources in qrc files.
- [QTBUG-78486] Calling a function with 14 arguments no longer crashes.
- [QTBUG-78721] Fixed handling of properties with interface type in bindings.
- [QTBUG-71078] Increased the QML loader thread's stack size to avoid problems
parsing deeply nested QML/JS files on some platforms.
- [QTBUG-72442] Fixed float value binding to an integer (including NaN values).
- [QTBUG-78566] A warning is emitted when overriding a declared Binding from
elsewhere. The Binding stays active and updates the target property again
on the next change.
- [QTBUG-77027] Fixed nullptr handling in Binding.
- [QTBUG-78859] Fixed a property cache memory leak.
- [QTBUG-78865] Fixed a memory leak due to declaring unused scripts in
qmldir files.
- [QTBUG-78706] Fixed inconsistent daylight saving time behavior by
converting QTime to V4 Date on a date with no DST in force.
- [QTBUG-78098] QQmlTypeLoader now prevents more trivial cycles.
- [QTBUG-77751] Fixed the translation context in Qt.include()d JS files.
- [QTBUG-76514] Avoid duplicate singleton creation.
- [QTBUG-77237] Using an enum in a switch statement performs much better.
- [QTBUG-76866] Fixed a crash due to inconsistency between
isValueType() and valueType()'s return value.
- [QTBUG-77954] Semicolon is always allowed after property declaration.
- [QTBUG-73512] Fixed a bug with use of resource paths in
QQmlEngine::setImportPathList().
- [QTBUG-76303] When converting from number to string, we now keep
double precision if the number of significant digits exceeds six, so that
precision isn't lost if the string is converted back to a number.
- [QTBUG-76838] Binding.when is stored as boolean to support primitive values.
- [QTBUG-76033] Fixed several bugs in frozen(), sealed(), nonExtensible()
and propertiesFrozen().
- [QTBUG-75983] Fixed a crash in XMLHttpRequest::open().
- [QTBUG-49975] Warn rather than crashing in case of invalid top-level
parallel states.
- [QTBUG-73786] We now filter out duplicate entries in Object.keys().
- [QTBUG-73491] Added QQmlInstanceModel::variantValue() to enable ComboBox.valueRole.
- [QTBUG-74348] Fixed memory leaks due to value type provider deletion order.
- There are two new functions to register singleton types and help you to
get rid of context properties:
* qmlRegisterSingletonType() has an overload taking a std::function now,
instead of a bare function pointer. Therefore, you can capture context
now when creating singletons.
* qmlRegisterSingletonInstance() directly passes a single instance of the
type to be used in all QML engines. No QML engine assumes ownership of
such a singleton and any concurrent access has to be handled by the
object itself.
- qml Runtime tool:
* [QTBUG-53557] The QML Runtime tool now accepts command-line arguments
in double-dash GNU style as well as the old single-dash style.
* [QTBUG-53557] The QML Runtime tool now has default behavior matching
qmlscene when the root QML object is an Item: it will be wrapped in a
Window which will resize the Item when the Window is resized. But you
can alternatively use the --config resizeToItem option, resulting in
the same behavior as qmlscene --resizeToRoot: resizing the root Item
programmatically causes the wrapping Window to be resized. Behavior
can still be customized in other ways using the --config option with
an external QML configuration file.
* The QML Runtime tool --quiet option now disables categorized logging
in addition to qDebug, qInfo, qWarning and qFatal, except for some
early QPA-level categorized logging that occurs during application
construction. You can still override specific categories by setting
QT_LOGGING_CONF or QT_LOGGING_RULES.
* [QTBUG-78828] Fixed a crash at exit when the qmldebugger channel is
connected.
- qmlplugindump:
* [QTBUG-78745] If given a "--strict" argument, qmlplugindump will check
the URI as exact match; whereas by default it will ignore the given
major version, as before.
* [QTBUG-78744] qmlplugindump no longer ignores base classes of QML files
registered as components.
- Important Behavior Changes:
* QRegularExpression is now supported the same way QRegExp was in QML.
QJSValue::toVariant() creates a QRegularExpression variant rather than
a QRegExp one from a JavaScript regular expression now.
* The accidentally exported function qmlRegisterBaseTypes() was removed.
* QJSEngine::toScriptValue will now return correct JavaScript objects in
more cases, for example, for gadget types like QPointF.
* QJSEngine::toScriptValue now uses the same behavior as the rest of the
engine when building JavaScript values, which will cause the types of
some returned JavaScript objects to change. For instance, string lists
are now returned as sequence objects, not array objects, and QChar now
constructs a JavaScript string.
* [QTBUG-75176] Attached properties are internally not identified by
integer IDs anymore, but rather by the functions used to produce them.
Using the integer indexes is a bad idea because the same metatype can
be registered as several different QML types and the integer IDs refer
to the QML types. Therefore, qmlAttachedPropertiesObjectById() and the
overload of qmlAttachedPropertiesObject() taking an integer ID are
deprecated.
* We expect QMetaObject revisions and import minor versions to be equal.
That is, when registering a revision X of a metaobject as QML type for
a version Y.Z of your module, X should equal Z. This is not enforced,
yet, but future versions of Qt will build on this assumption.
****************************************************************************
* QtQuick *
****************************************************************************
- Qt Quick is now able to render via Vulkan, Metal, and Direct 3D 11. The
new rendering path is currently a preview feature and has to be opted-in
to explicitly.
- Drag and Drop:
* [QTBUG-30305] When DropAreas intersect, the higher z-order item now
steals the drop.
* [QTBUG-72045] Fixed a crash when using an image provider url with Drag.
- DelegateModel:
* [QTBUG-63477] DelegateModel.delegate is now a notifying property,
and an Item View with model: DelegateModel { } is now refilled when
the delegate is changed.
- Event Handlers:
* Added WheelHandler, which handles mouse wheel rotation by modifying
arbitrary Item properties.
* [QTBUG-75661] Added DragHandler.snapMode which can be used to configure
conditions under which the dragged item is snapped to the cursor. The
default mode is SnapAuto. The old behavior can be obtained through the
SnapIfPressedOutsideTarget mode.
- Image:
* [QTBUG-77506] Image and BorderImage now have currentFrame and
frameCount properties which can be used to step through the frames of
multi-page image formats such as TIFF, WEBP and ICO (and PDF in the
future).
* [QTBUG-55027] Any URL interceptor is applied to the source binding.
* [QTBUG-76527] ImageProvider is kept alive while in use.
- FolderListModel:
* update the values of some properties when setting new values to them
- Layouts:
* [QTBUG-67204] GridLayout now warns rather than asserting when an
invalid row or column is specified.
* [QTBUG-79359] GridLayout now emits appropriate signals for
layoutDirection, columnSpacing, and rowSpacing changes.
- ListModel:
* [QTBUG-63569] We now emit a warning if an object with an undefined or
null member is added.
* [QTBUG-79083] JSON.stringify(model.get(i)) now works correctly when the
row contains a nested list model.
- Loader:
* [QTBUG-79435] Loader now clears all initial properties when changing source.
- MouseArea:
* [QTBUG-75993] mouseX and mouseY will now be synchronized after dragging
the target item.
* [QTBUG-77983] The containsMouse property will not become true when an
invisible mousearea become visible, if the enabled property is false or
its parent item is not enabled.
- MultiPointTouchArea:
* [QTBUG-77142] When a stationary touchpoint contains some "interesting"
property change (pressure or velocity, so far), it is delivered normally,
and MultiPointTouchArea will react to that.
- Particles:
* [QTBUG-54673] Fixed image particle flickering due to dynamic creation
of Emitter objects.
- Path and Shapes:
* Added Path.scale property to scale a path prior to rendering via
Shape or to scale the movement in PathView. The width and height
can be different, to achieve anisotropic scaling.
* Added PathPolyline, to render an array, list or vector of QPointF,
or a single QPolygonF.
* Added PathMultiLine, to render an array, list or vector of
polylines or QPolygonF.
* Exposed QQuickPath::pointAtPercent as invokable in QML.
* [QTBUG-77332] Fixed incorrect colors when shapes change scene.
- PathView:
* [QTBUG-77173] When the mouse is pressed while PathView is already moving,
PathView now grabs rather than allowing the delegate to handle it. The
position will then snap to the nearest delegate on release, as usual.
* [QTBUG-77173] If the user drags quickly, pauses, and then releases,
the calculated velocity is reduced according to a linear decay model
up to 50ms (and zero after that), to prevent excessive movement when
the user intended the pause to stop the movement.
- TableView:
* [QTBUG-79395] forceLayout() now rebuilds the table if the size of the
model has changed, to avoid a crash.
- Text:
* Markdown (GitHub dialect by default) is now a supported format, when
textFormat: Text.MarkdownText is declared. All features such as
hyperlinks, images, tables, lists, checklists, etc. are supported.
- TextEdit:
* Markdown (GitHub dialect by default) is now a supported format, when
textFormat: TextEdit.MarkdownText is declared. If it contains checkboxes,
the user can click on them to toggle the states.
* [QTBUG-14769][QTBUG-50482] The mouse cursor is now IBeamCursor by default,
or PointingHandCursor when the mouse is hovering over a checkbox or a
hyperlink. However this can be overridden in C++.
* [QTBUG-74745] Fixed overlapping text after line deletion.
- TextInput:
* [QTBUG-77814] Fixed text selection logic after insert() and remove().
- [QTBUG-79573] Fixed application deadlock when an item is reparented
to contentItem in a user-defined windowChanged handler, e.g. on exit.
- [QTBUG-78304] A ShortCutOverride event is now sent even when receiving a
non-spontaneous key press (e.g. from sendEvent()), so that Shortcut reacts.
- [QTBUG-76749] Fixed a crash when using an animation while destroying an item.
****************************************************************************
* Qt Labs Animation *
****************************************************************************
- Added the BoundaryRule QML type, a PropertyValueInterceptor that
restricts the range of values a numeric property can have, applies
"resistance" when the value is overshooting, and provides the ability to
animate it back within range. This is especially useful in combination
with WheelHandler to limit its range of motion or adjustment.
****************************************************************************
* Qt Labs QML Models *
****************************************************************************
- Added the TableModel QML type, a JavaScript-based model for the new
TableView.

View File

@ -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

View File

@ -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]

View File

@ -13,4 +13,6 @@ Project {
ImageFiles {
directory: "."
}
importPaths: [ "imports" ]
}

View File

@ -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
SOURCES += \
plugin.cpp \
timemodel.cpp
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
HEADERS += \
timemodel.h
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
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
INSTALLS += target qml pluginfiles
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
qml_copy.files = plugins.qml plugins.qmlproject
qml_copy.path = $$OUT_PWD
qml_install.files = plugins.qml plugins.qmlproject
qml_install.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins
INSTALLS += target qml_install pluginfiles_install
COPIES += qml_copy pluginfiles_copy
OTHER_FILES += $$PLUGINFILES plugins.qml
CONFIG += install_ok # Do not cargo-cult this!

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the demonstration applications of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
@ -48,34 +48,51 @@
**
****************************************************************************/
import QtQuick 2.0
#include "timemodel.h"
Item {
Text {
id: text1
anchors.top: parent.top
text: "árvíztűrő tükörfúrógép\nÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP"
}
Text {
anchors.bottom: parent.bottom
text: "the quick brown fox jumps over the lazy dog\nTHE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
color: "red"
}
Text {
anchors.centerIn: parent
text: "rotate rotate rotate"
font.bold: true
font.pointSize: 20
color: "green"
NumberAnimation on rotation { from: 0; to: 360; duration: 2000; loops: Animation.Infinite; }
}
int TimeModel::instances=0;
MinuteTimer *TimeModel::timer=nullptr;
Row {
anchors.top: text1.bottom
anchors.margins: 10
Text { font.pointSize: 24; text: "Normal" }
Text { font.pointSize: 24; text: "Raised"; style: Text.Raised; styleColor: "#AAAAAA" }
Text { font.pointSize: 24; text: "Outline"; style: Text.Outline; styleColor: "red" }
Text { font.pointSize: 24; text: "Sunken"; style: Text.Sunken; styleColor: "#AAAAAA" }
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();
}
}

View File

@ -3,7 +3,7 @@
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the demonstration applications of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
@ -48,46 +48,64 @@
**
****************************************************************************/
import QtQuick 2.0
#ifndef TIMEMODEL_H
#define TIMEMODEL_H
Item {
focus: true
#include <QtQml/qqml.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qbasictimer.h>
#include <QtCore/qcoreapplication.h>
Loader {
anchors.fill: parent
id: loader
}
// Implements a "TimeModel" class with hour and minute properties
// that change on-the-minute yet efficiently sleep the rest
// of the time.
Keys.onPressed: {
if (event.key === Qt.Key_S)
loader.source = "";
class MinuteTimer : public QObject
{
Q_OBJECT
public:
MinuteTimer(QObject *parent) : QObject(parent) {}
if (event.key === Qt.Key_R)
loader.source = "qrc:/Rects.qml";
if (event.key === Qt.Key_4)
loader.source = "qrc:/LotsOfRects.qml";
void start();
void stop();
if (event.key === Qt.Key_I)
loader.source = "qrc:/Images.qml";
if (event.key === Qt.Key_5)
loader.source = "qrc:/LotsOfImages.qml";
int hour() const { return time.hour(); }
int minute() const { return time.minute(); }
if (event.key === Qt.Key_T)
loader.source = "qrc:/Text.qml";
signals:
void timeChanged();
if (event.key === Qt.Key_A)
loader.source = "qrc:/Animators.qml";
protected:
void timerEvent(QTimerEvent *) override;
if (event.key === Qt.Key_L)
loader.source = "qrc:/Layers.qml";
private:
QTime time;
QBasicTimer timer;
};
if (event.key === Qt.Key_E)
loader.source = "qrc:/Effects.qml";
//![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]
if (event.key === Qt.Key_P)
loader.source = "qrc:/Painter.qml";
public:
TimeModel(QObject *parent=nullptr);
~TimeModel() override;
if (event.key === Qt.Key_G)
helper.testGrab()
}
}
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

View File

@ -1,4 +1,8 @@
QT = core qml
CONFIG += qmltypes
QML_IMPORT_NAME = People
QML_IMPORT_MAJOR_VERSION = 1
SOURCES += main.cpp \
person.cpp

View File

@ -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"));

View File

@ -1,4 +1,8 @@
QT += qml
CONFIG += qmltypes
QML_IMPORT_NAME = People
QML_IMPORT_MAJOR_VERSION = 1
SOURCES += main.cpp \
person.cpp \

View File

@ -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());

View File

@ -1,5 +1,9 @@
QT += qml
CONFIG += qmltypes
QML_IMPORT_NAME = People
QML_IMPORT_MAJOR_VERSION = 1
SOURCES += main.cpp \
person.cpp \
birthdayparty.cpp \

View File

@ -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);

View File

@ -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"));

View File

@ -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);

View File

@ -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

View File

@ -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());

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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());

View File

@ -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

View File

@ -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

View File

@ -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"));

View File

@ -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);

View File

@ -1,5 +1,9 @@
QT += qml
CONFIG += qmltypes
QML_IMPORT_NAME = People
QML_IMPORT_MAJOR_VERSION = 1
SOURCES += main.cpp \
person.cpp \
birthdayparty.cpp

View File

@ -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());

View File

@ -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);

View File

@ -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());

View File

@ -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

View File

@ -67,6 +67,7 @@ class BirthdayParty : public QObject
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
// ![2]
// ![3]
QML_ELEMENT
public:
BirthdayParty(QObject *parent = nullptr);

View File

@ -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());

View File

@ -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

View File

@ -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());

View File

@ -1,5 +1,9 @@
QT += qml
CONFIG += qmltypes
QML_IMPORT_NAME = People
QML_IMPORT_MAJOR_VERSION = 1
SOURCES += main.cpp \
person.cpp \
birthdayparty.cpp

View File

@ -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);

View File

@ -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());

View File

@ -1,5 +1,9 @@
QT += qml
CONFIG += qmltypes
QML_IMPORT_NAME = People
QML_IMPORT_MAJOR_VERSION = 1
SOURCES += main.cpp \
person.cpp \
birthdayparty.cpp \

View File

@ -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

View File

@ -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"));

View File

@ -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

View File

@ -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"));

View File

@ -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

View File

@ -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"));

View File

@ -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 \

View File

@ -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"));

View File

@ -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 \

View File

@ -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"));

View File

@ -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]

View File

@ -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/Charts
DESTPATH=$$[QT_INSTALL_EXAMPLES]/qml/tutorials/extending-qml/chapter6-plugins/$$QML_IMPORT_NAME
copy_qmltypes.files = $$OUT_PWD/plugins.qmltypes
copy_qmltypes.path = $$DESTDIR
COPIES += copy_qmltypes
target.path=$$DESTPATH
qmldir.files=$$PWD/qmldir

View File

@ -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>

View File

@ -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 demonstration applications of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
@ -48,60 +48,68 @@
**
****************************************************************************/
import QtQuick 2.3
import QtQuick 2.0
Item {
Rectangle {
width: 100
height: 100
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: "red"
NumberAnimation on rotation { from: 0; to: 360; duration: 2000; loops: Animation.Infinite; }
}
color: "white"
font.pixelSize: 16
font.bold: true
Image {
id: im
source: "qrc:/qt.png"
mipmap: true
// changing the mipmap property results in the creation of a brand new
// texture resource. enable the following to test.
// Timer {
// interval: 2000
// onTriggered: im.mipmap = false
// running: true
// }
SequentialAnimation on scale {
loops: Animation.Infinite
NumberAnimation {
from: 1.0
to: 4.0
duration: 2000
}
NumberAnimation {
from: 4.0
to: 0.1
duration: 3000
}
NumberAnimation {
from: 0.1
to: 1.0
duration: 1000
// 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
}
}
}
Image {
anchors.centerIn: parent
source: "qrc:/face-smile.png"
}
}
Image {
source: "qrc:/face-smile.png"
anchors.bottom: parent.bottom
anchors.right: parent.right
antialiasing: true
NumberAnimation on rotation { from: 0; to: 360; duration: 2000; loops: Animation.Infinite; }
}
}

View File

@ -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;
}
}
}

View File

@ -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 }
}
}
}
}
}
}

View File

@ -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

View File

@ -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
}
}
}
}

View File

@ -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;

View File

@ -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();

View File

@ -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 \

View File

@ -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)
};

View File

@ -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

View File

@ -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>

View File

@ -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 demonstration applications of the Qt Toolkit.
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
@ -48,47 +48,49 @@
**
****************************************************************************/
import QtQuick 2.0
import Stuff 1.0
import QtQuick 2.14
Item {
ListModel {
id: balloonModel
ListElement {
balloonWidth: 200
}
ListElement {
balloonWidth: 120
}
ListElement {
balloonWidth: 120
}
ListElement {
balloonWidth: 120
}
ListElement {
balloonWidth: 120
}
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
}
ListView {
anchors.fill: parent
anchors.margins: 10
id: balloonView
model: balloonModel
spacing: 5
delegate: TextBalloon {
anchors.right: index % 2 == 0 ? undefined : parent.right
height: 60
rightAligned: index % 2 == 0 ? false : true
width: balloonWidth
innerAnim: model.index === 1
NumberAnimation on width {
from: 200
to: 300
duration: 5000
running: model.index === 0
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
}
}
}
]
}

View File

@ -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]

View File

@ -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);
}
};

View File

@ -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);

View File

@ -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() }
}
}
}
}

View File

@ -186,11 +186,11 @@ Item {
}
}
}
MouseArea {
anchors.fill: parent
onClicked: dateInput.forceActiveFocus()
}
}
}
MouseArea {
anchors.fill: parent
onClicked: dateInput.forceActiveFocus()
}
}

View File

@ -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"
}
}

View File

@ -79,7 +79,6 @@ Rectangle {
Text {
id: buttonText
text: parent.description
anchors.centerIn: parent
font.pixelSize: parent.height * .5
style: Text.Sunken

View File

@ -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);

View File

@ -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 \

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -1,6 +1,10 @@
TARGET = customgeometry
QT += quick
CONFIG += qmltypes
QML_IMPORT_NAME = CustomGeometry
QML_IMPORT_MAJOR_VERSION = 1
SOURCES += \
main.cpp \
beziercurve.cpp

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -56,8 +56,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
qmlRegisterTypesAndRevisions<D3D11Squircle>("D3D11UnderQML", 1);
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Direct3D11Rhi);
QQuickView view;

View File

@ -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

View File

@ -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"));

View File

@ -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 \

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -56,8 +56,6 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
qmlRegisterTypesAndRevisions<MetalSquircle>("MetalUnderQML", 1);
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);
QQuickView view;

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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"));

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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");

View File

@ -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;

Some files were not shown because too many files have changed in this diff Show More