Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: src/imports/folderlistmodel/plugin.cpp src/imports/layouts/plugin.cpp src/imports/localstorage/plugin.cpp src/imports/models/plugin.cpp src/imports/particles/plugin.cpp src/imports/qtqml/plugin.cpp src/imports/qtquick2/plugin.cpp src/imports/shapes/plugin.cpp src/imports/statemachine/plugin.cpp src/imports/testlib/main.cpp src/imports/wavefrontmesh/plugin.cpp src/imports/window/plugin.cpp src/imports/workerscript/plugin.cpp src/qml/jsruntime/qv4sequenceobject.cpp src/qml/qml/qqmlengine.cpp src/qmlmodels/qqmlmodelsmodule.cpp src/qmlmodels/qqmlmodelsmodule_p.h src/qmlworkerscript/qqmlworkerscriptmodule.cpp src/qmlworkerscript/qqmlworkerscriptmodule_p.h src/quick/items/qquickitemsmodule.cpp Change-Id: I5f1fbc3d00e8f583d2c89afc5389de84d68633a7
This commit is contained in:
commit
8a22c92b55
|
@ -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.
|
|
@ -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
|
The Person class implementation is quite basic. The property accessors simply
|
||||||
return members of the object instance.
|
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
|
\section1 Running the Example
|
||||||
|
|
||||||
The main.cpp file in the example includes a simple shell application that
|
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
|
\l {Registering Extension Objects}{extension object} to a \l QLineEdit without modifying or
|
||||||
subclassing it.
|
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:
|
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
|
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
|
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.
|
and other types can be coerced to it. This is what the QML_UNCREATABLE macro
|
||||||
|
does.
|
||||||
\snippet referenceexamples/coercion/main.cpp 0
|
|
||||||
|
|
||||||
\section2 Define Boy and Girl
|
\section2 Define Boy and Girl
|
||||||
|
|
||||||
|
|
|
@ -49,117 +49,13 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QtQml/QQmlExtensionPlugin>
|
#include <QtQml/QQmlExtensionPlugin>
|
||||||
#include <QtQml/qqml.h>
|
|
||||||
#include <qdebug.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]
|
//![plugin]
|
||||||
class QExampleQmlPlugin : public QQmlExtensionPlugin
|
class QExampleQmlPlugin : public QQmlEngineExtensionPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
|
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
|
||||||
|
|
||||||
public:
|
|
||||||
void registerTypes(const char *uri) override
|
|
||||||
{
|
|
||||||
Q_ASSERT(uri == QLatin1String("TimeExample"));
|
|
||||||
qmlRegisterTypesAndRevisions<TimeModel>(uri, 1);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
//![plugin]
|
//![plugin]
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,37 @@
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
CONFIG += plugin
|
CONFIG += plugin qmltypes
|
||||||
QT += qml
|
QT += qml
|
||||||
|
|
||||||
DESTDIR = imports/TimeExample
|
QML_IMPORT_NAME = TimeExample
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
|
DESTDIR = imports/$$QML_IMPORT_NAME
|
||||||
TARGET = qmlqtimeexampleplugin
|
TARGET = qmlqtimeexampleplugin
|
||||||
|
|
||||||
SOURCES += plugin.cpp
|
SOURCES += \
|
||||||
|
plugin.cpp \
|
||||||
|
timemodel.cpp
|
||||||
|
|
||||||
pluginfiles.files += \
|
HEADERS += \
|
||||||
imports/TimeExample/qmldir \
|
timemodel.h
|
||||||
imports/TimeExample/center.png \
|
|
||||||
imports/TimeExample/clock.png \
|
PLUGINFILES = \
|
||||||
imports/TimeExample/Clock.qml \
|
imports/$$QML_IMPORT_NAME/qmldir \
|
||||||
imports/TimeExample/hour.png \
|
imports/$$QML_IMPORT_NAME/center.png \
|
||||||
imports/TimeExample/minute.png
|
imports/$$QML_IMPORT_NAME/clock.png \
|
||||||
|
imports/$$QML_IMPORT_NAME/Clock.qml \
|
||||||
|
imports/$$QML_IMPORT_NAME/hour.png \
|
||||||
|
imports/$$QML_IMPORT_NAME/minute.png
|
||||||
|
|
||||||
|
pluginfiles.files += $$PLUGINFILES
|
||||||
|
|
||||||
qml.files = plugins.qml
|
qml.files = plugins.qml
|
||||||
qml.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins
|
qml.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins
|
||||||
target.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/TimeExample
|
target.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME
|
||||||
pluginfiles.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/TimeExample
|
pluginfiles.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME
|
||||||
|
|
||||||
INSTALLS += target qml pluginfiles
|
INSTALLS += target qml pluginfiles
|
||||||
|
|
||||||
|
OTHER_FILES += $$PLUGINFILES plugins.qml
|
||||||
|
|
||||||
CONFIG += install_ok # Do not cargo-cult this!
|
CONFIG += install_ok # Do not cargo-cult this!
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
|
@ -1,4 +1,8 @@
|
||||||
QT = core qml
|
QT = core qml
|
||||||
|
CONFIG += qmltypes
|
||||||
|
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp
|
person.cpp
|
||||||
|
|
|
@ -56,9 +56,6 @@
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
//![0]
|
|
||||||
qmlRegisterTypesAndRevisions<Person>("People", 1);
|
|
||||||
//![0]
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
QT += qml
|
QT += qml
|
||||||
|
CONFIG += qmltypes
|
||||||
|
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp \
|
person.cpp \
|
||||||
|
|
|
@ -58,10 +58,6 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<BirthdayPartyAttached,
|
|
||||||
BirthdayParty, ShoeDescription,
|
|
||||||
Person, Boy, Girl>("People", 1);
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml
|
QT += qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp \
|
person.cpp \
|
||||||
birthdayparty.cpp \
|
birthdayparty.cpp \
|
||||||
|
|
|
@ -52,14 +52,17 @@
|
||||||
|
|
||||||
#include <QQmlPropertyValueSource>
|
#include <QQmlPropertyValueSource>
|
||||||
#include <QQmlProperty>
|
#include <QQmlProperty>
|
||||||
|
#include <qqml.h>
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <qqml.h>
|
||||||
|
|
||||||
class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource
|
class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||||
Q_INTERFACES(QQmlPropertyValueSource)
|
Q_INTERFACES(QQmlPropertyValueSource)
|
||||||
|
QML_ELEMENT
|
||||||
public:
|
public:
|
||||||
HappyBirthdaySong(QObject *parent = nullptr);
|
HappyBirthdaySong(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,6 @@
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
qmlRegisterTypesAndRevisions<BirthdayPartyAttached, BirthdayParty, HappyBirthdaySong,
|
|
||||||
ShoeDescription, Person, Boy, Girl>("People", 1);
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
|
|
|
@ -60,6 +60,7 @@ class BirthdayParty : public QObject
|
||||||
// ![0]
|
// ![0]
|
||||||
Q_PROPERTY(Person *host READ host WRITE setHost)
|
Q_PROPERTY(Person *host READ host WRITE setHost)
|
||||||
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
||||||
|
QML_ELEMENT
|
||||||
// ![0]
|
// ![0]
|
||||||
public:
|
public:
|
||||||
BirthdayParty(QObject *parent = nullptr);
|
BirthdayParty(QObject *parent = nullptr);
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT = core qml
|
QT = core qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp \
|
person.cpp \
|
||||||
birthdayparty.cpp
|
birthdayparty.cpp
|
||||||
|
|
|
@ -58,10 +58,6 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
//![0]
|
|
||||||
qmlRegisterTypesAndRevisions<BirthdayParty, Person, Boy, Girl>("People", 1);
|
|
||||||
//![0]
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
|
@ -59,7 +59,8 @@ class Person : public QObject
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
Q_PROPERTY(QString name READ name WRITE setName)
|
||||||
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
|
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
|
||||||
//![0]
|
//![0]
|
||||||
QML_ANONYMOUS
|
QML_ELEMENT
|
||||||
|
QML_UNCREATABLE("Person is an abstract base class.")
|
||||||
//![0]
|
//![0]
|
||||||
public:
|
public:
|
||||||
Person(QObject *parent = nullptr);
|
Person(QObject *parent = nullptr);
|
||||||
|
|
|
@ -61,6 +61,7 @@ class BirthdayParty : public QObject
|
||||||
Q_PROPERTY(Person *host READ host WRITE setHost)
|
Q_PROPERTY(Person *host READ host WRITE setHost)
|
||||||
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
||||||
Q_CLASSINFO("DefaultProperty", "guests")
|
Q_CLASSINFO("DefaultProperty", "guests")
|
||||||
|
QML_ELEMENT
|
||||||
public:
|
public:
|
||||||
BirthdayParty(QObject *parent = nullptr);
|
BirthdayParty(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT = core qml
|
QT = core qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp \
|
person.cpp \
|
||||||
birthdayparty.cpp
|
birthdayparty.cpp
|
||||||
|
|
|
@ -58,8 +58,6 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<BirthdayParty, Person, Boy, Girl>("People", 1);
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml widgets
|
QT += qml widgets
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
lineedit.cpp
|
lineedit.cpp
|
||||||
HEADERS += lineedit.h
|
HEADERS += lineedit.h
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
#define LINEEDIT_H
|
#define LINEEDIT_H
|
||||||
|
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
|
#include <qqml.h>
|
||||||
|
|
||||||
class LineEditExtension : public QObject
|
class LineEditExtension : public QObject
|
||||||
{
|
{
|
||||||
|
@ -80,4 +81,14 @@ private:
|
||||||
QLineEdit *m_lineedit;
|
QLineEdit *m_lineedit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ![0]
|
||||||
|
struct QLineEditForeign
|
||||||
|
{
|
||||||
|
Q_GADGET
|
||||||
|
QML_FOREIGN(QLineEdit)
|
||||||
|
QML_ELEMENT
|
||||||
|
QML_EXTENDED(LineEditExtension)
|
||||||
|
};
|
||||||
|
// ![0]
|
||||||
|
|
||||||
#endif // LINEEDIT_H
|
#endif // LINEEDIT_H
|
||||||
|
|
|
@ -58,10 +58,6 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
// ![0]
|
|
||||||
qmlRegisterExtendedType<QLineEdit, LineEditExtension>("People", 1,0, "QLineEdit");
|
|
||||||
// ![0]
|
|
||||||
|
|
||||||
// ![1]
|
// ![1]
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
|
|
|
@ -60,6 +60,7 @@ class BirthdayParty : public QObject
|
||||||
Q_PROPERTY(Person *host READ host WRITE setHost)
|
Q_PROPERTY(Person *host READ host WRITE setHost)
|
||||||
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
||||||
Q_CLASSINFO("DefaultProperty", "guests")
|
Q_CLASSINFO("DefaultProperty", "guests")
|
||||||
|
QML_ELEMENT
|
||||||
public:
|
public:
|
||||||
BirthdayParty(QObject *parent = nullptr);
|
BirthdayParty(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml
|
QT += qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp \
|
person.cpp \
|
||||||
birthdayparty.cpp
|
birthdayparty.cpp
|
||||||
|
|
|
@ -58,8 +58,6 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<BirthdayParty, ShoeDescription, Person, Boy, Girl>("People", 1);
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
|
@ -59,6 +59,7 @@ class BirthdayParty : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(Person *host READ host WRITE setHost)
|
Q_PROPERTY(Person *host READ host WRITE setHost)
|
||||||
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
||||||
|
QML_ELEMENT
|
||||||
public:
|
public:
|
||||||
BirthdayParty(QObject *parent = nullptr);
|
BirthdayParty(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,6 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<BirthdayParty, Person>("People", 1);
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT = core qml
|
QT = core qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp \
|
person.cpp \
|
||||||
birthdayparty.cpp
|
birthdayparty.cpp
|
||||||
|
|
|
@ -67,6 +67,7 @@ class BirthdayParty : public QObject
|
||||||
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
Q_PROPERTY(QQmlListProperty<Person> guests READ guests)
|
||||||
// ![2]
|
// ![2]
|
||||||
// ![3]
|
// ![3]
|
||||||
|
QML_ELEMENT
|
||||||
public:
|
public:
|
||||||
BirthdayParty(QObject *parent = nullptr);
|
BirthdayParty(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,6 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
//![register list]
|
|
||||||
qmlRegisterTypesAndRevisions<BirthdayParty, Person>("People", 1);
|
|
||||||
//![register list]
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT = core qml
|
QT = core qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp \
|
person.cpp \
|
||||||
birthdayparty.cpp
|
birthdayparty.cpp
|
||||||
|
|
|
@ -58,9 +58,6 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<BirthdayPartyAttached, BirthdayParty, ShoeDescription,
|
|
||||||
Person, Boy, Girl>("People", 1);
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml
|
QT += qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp \
|
person.cpp \
|
||||||
birthdayparty.cpp
|
birthdayparty.cpp
|
||||||
|
|
|
@ -64,6 +64,7 @@ class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource
|
||||||
// ![0]
|
// ![0]
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
Q_PROPERTY(QString name READ name WRITE setName)
|
||||||
// ![1]
|
// ![1]
|
||||||
|
QML_ELEMENT
|
||||||
public:
|
public:
|
||||||
HappyBirthdaySong(QObject *parent = nullptr);
|
HappyBirthdaySong(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|
|
@ -59,9 +59,6 @@ int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<BirthdayPartyAttached, BirthdayParty, HappyBirthdaySong,
|
|
||||||
ShoeDescription, Person, Boy, Girl>("People", 1);
|
|
||||||
|
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
QQmlComponent component(&engine, QUrl("qrc:example.qml"));
|
||||||
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
auto *party = qobject_cast<BirthdayParty *>(component.create());
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml
|
QT += qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = People
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
person.cpp \
|
person.cpp \
|
||||||
birthdayparty.cpp \
|
birthdayparty.cpp \
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = Charts
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += piechart.h
|
HEADERS += piechart.h
|
||||||
SOURCES += piechart.cpp \
|
SOURCES += piechart.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
|
@ -56,8 +56,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<PieChart>("Charts", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:///app.qml"));
|
view.setSource(QUrl("qrc:///app.qml"));
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = Charts
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += piechart.h
|
HEADERS += piechart.h
|
||||||
SOURCES += piechart.cpp \
|
SOURCES += piechart.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
|
@ -56,8 +56,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<PieChart>("Charts", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:///app.qml"));
|
view.setSource(QUrl("qrc:///app.qml"));
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = Charts
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += piechart.h
|
HEADERS += piechart.h
|
||||||
SOURCES += piechart.cpp \
|
SOURCES += piechart.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
|
@ -56,8 +56,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<PieChart>("Charts", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:///app.qml"));
|
view.setSource(QUrl("qrc:///app.qml"));
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = Charts
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += piechart.h \
|
HEADERS += piechart.h \
|
||||||
pieslice.h
|
pieslice.h
|
||||||
SOURCES += piechart.cpp \
|
SOURCES += piechart.cpp \
|
||||||
|
|
|
@ -59,10 +59,6 @@ int main(int argc, char *argv[])
|
||||||
//![0]
|
//![0]
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
//![1]
|
|
||||||
qmlRegisterTypesAndRevisions<PieChart, PieSlice>("Charts", 1);
|
|
||||||
//![1]
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:///app.qml"));
|
view.setSource(QUrl("qrc:///app.qml"));
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = Charts
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += piechart.h \
|
HEADERS += piechart.h \
|
||||||
pieslice.h
|
pieslice.h
|
||||||
SOURCES += piechart.cpp \
|
SOURCES += piechart.cpp \
|
||||||
|
|
|
@ -57,8 +57,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<PieChart, PieSlice>("Charts", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:///app.qml"));
|
view.setSource(QUrl("qrc:///app.qml"));
|
||||||
|
|
|
@ -53,13 +53,10 @@
|
||||||
//![0]
|
//![0]
|
||||||
#include <QQmlExtensionPlugin>
|
#include <QQmlExtensionPlugin>
|
||||||
|
|
||||||
class ChartsPlugin : public QQmlExtensionPlugin
|
class ChartsPlugin : public QQmlEngineExtensionPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
|
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
|
||||||
|
|
||||||
public:
|
|
||||||
void registerTypes(const char *uri);
|
|
||||||
};
|
};
|
||||||
//![0]
|
//![0]
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
CONFIG += plugin
|
CONFIG += plugin qmltypes
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
DESTDIR = ../Charts
|
QML_IMPORT_NAME = Charts
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
|
DESTDIR = ../$$QML_IMPORT_NAME
|
||||||
TARGET = $$qtLibraryTarget(chartsplugin)
|
TARGET = $$qtLibraryTarget(chartsplugin)
|
||||||
|
|
||||||
HEADERS += piechart.h \
|
HEADERS += piechart.h \
|
||||||
|
@ -10,10 +13,13 @@ HEADERS += piechart.h \
|
||||||
chartsplugin.h
|
chartsplugin.h
|
||||||
|
|
||||||
SOURCES += piechart.cpp \
|
SOURCES += piechart.cpp \
|
||||||
pieslice.cpp \
|
pieslice.cpp
|
||||||
chartsplugin.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
|
target.path=$$DESTPATH
|
||||||
qmldir.files=$$PWD/qmldir
|
qmldir.files=$$PWD/qmldir
|
||||||
|
|
|
@ -53,14 +53,11 @@
|
||||||
|
|
||||||
#include "maskedmousearea.h"
|
#include "maskedmousearea.h"
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc,argv);
|
QGuiApplication app(argc,argv);
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<MaskedMouseArea>("Example", 1);
|
|
||||||
|
|
||||||
view.setSource(QUrl("qrc:///customitems/maskedmousearea/maskedmousearea.qml"));
|
view.setSource(QUrl("qrc:///customitems/maskedmousearea/maskedmousearea.qml"));
|
||||||
view.show();
|
view.show();
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
|
@ -2,6 +2,10 @@ TEMPLATE = app
|
||||||
|
|
||||||
QT += quick qml
|
QT += quick qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = Example
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += maskedmousearea.h
|
HEADERS += maskedmousearea.h
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
|
|
|
@ -52,13 +52,8 @@
|
||||||
|
|
||||||
#include "../textballoon.h"
|
#include "../textballoon.h"
|
||||||
|
|
||||||
class TextBalloonPlugin : public QQmlExtensionPlugin
|
class TextBalloonPlugin : public QQmlEngineExtensionPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
|
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
|
||||||
public:
|
|
||||||
void registerTypes(const char *uri)
|
|
||||||
{
|
|
||||||
qmlRegisterTypesAndRevisions<TextBalloon>(uri, 1);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,21 +1,25 @@
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
CONFIG += plugin
|
CONFIG += plugin qmltypes
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
QML_IMPORT_NAME = TextBalloonPlugin
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
TARGET = qmltextballoonplugin
|
TARGET = qmltextballoonplugin
|
||||||
|
|
||||||
HEADERS += TextBalloonPlugin/plugin.h \
|
HEADERS += \
|
||||||
|
TextBalloonPlugin/plugin.h \
|
||||||
textballoon.h
|
textballoon.h
|
||||||
|
|
||||||
SOURCES += textballoon.cpp
|
SOURCES += textballoon.cpp
|
||||||
|
|
||||||
RESOURCES += painteditem.qrc
|
RESOURCES += painteditem.qrc
|
||||||
|
|
||||||
DESTDIR = TextBalloonPlugin
|
DESTDIR = $$QML_IMPORT_NAME
|
||||||
|
|
||||||
target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/TextBalloonPlugin
|
target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME
|
||||||
qmldir.files = TextBalloonPlugin/qmldir
|
qmldir.files = $$QML_IMPORT_NAME/qmldir
|
||||||
qmldir.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/TextBalloonPlugin
|
qmldir.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME
|
||||||
|
|
||||||
INSTALLS += qmldir target
|
INSTALLS += qmldir target
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,6 @@
|
||||||
<file>tiles/DropTile.qml</file>
|
<file>tiles/DropTile.qml</file>
|
||||||
<file>tiles/tiles.qml</file>
|
<file>tiles/tiles.qml</file>
|
||||||
<file>views/gridview.qml</file>
|
<file>views/gridview.qml</file>
|
||||||
|
<file>views/Icon.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -48,8 +48,9 @@
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
import QtQuick 2.12
|
import QtQml 2.14
|
||||||
import QtQml.Models 2.1
|
import QtQuick 2.14
|
||||||
|
import QtQml.Models 2.14
|
||||||
|
|
||||||
GridView {
|
GridView {
|
||||||
id: root
|
id: root
|
||||||
|
@ -94,54 +95,21 @@ GridView {
|
||||||
//! [1]
|
//! [1]
|
||||||
delegate: DropArea {
|
delegate: DropArea {
|
||||||
id: delegateRoot
|
id: delegateRoot
|
||||||
|
required property color color;
|
||||||
|
|
||||||
width: 80; height: 80
|
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
|
property int visualIndex: DelegateModel.itemsIndex
|
||||||
Binding { target: icon; property: "visualIndex"; value: visualIndex }
|
|
||||||
|
|
||||||
Rectangle {
|
Icon {
|
||||||
id: icon
|
id: icon
|
||||||
property int visualIndex: 0
|
dragParent: root
|
||||||
width: 72; height: 72
|
visualIndex: delegateRoot.visualIndex
|
||||||
anchors {
|
color: delegateRoot.color
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [1]
|
//! [1]
|
||||||
|
|
|
@ -90,22 +90,16 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ImageProviderExtensionPlugin : public QQmlExtensionPlugin
|
class ImageProviderExtensionPlugin : public QQmlEngineExtensionPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
|
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
|
||||||
public:
|
public:
|
||||||
void registerTypes(const char *uri) override
|
|
||||||
{
|
|
||||||
Q_UNUSED(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializeEngine(QQmlEngine *engine, const char *uri) override
|
void initializeEngine(QQmlEngine *engine, const char *uri) override
|
||||||
{
|
{
|
||||||
Q_UNUSED(uri);
|
Q_UNUSED(uri);
|
||||||
engine->addImageProvider("colors", new ColorImageProvider);
|
engine->addImageProvider("colors", new ColorImageProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -128,16 +128,11 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ImageProviderExtensionPlugin : public QQmlExtensionPlugin
|
class ImageProviderExtensionPlugin : public QQmlEngineExtensionPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
|
Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid)
|
||||||
public:
|
public:
|
||||||
void registerTypes(const char *uri) override
|
|
||||||
{
|
|
||||||
Q_UNUSED(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializeEngine(QQmlEngine *engine, const char *uri) override
|
void initializeEngine(QQmlEngine *engine, const char *uri) override
|
||||||
{
|
{
|
||||||
Q_UNUSED(uri);
|
Q_UNUSED(uri);
|
||||||
|
|
|
@ -86,8 +86,6 @@ MainWindow::MainWindow(bool transparency, bool noRenderAlpha)
|
||||||
m_labelStatus = new QLabel;
|
m_labelStatus = new QLabel;
|
||||||
layout->addWidget(m_labelStatus);
|
layout->addWidget(m_labelStatus);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<FbItem>("fbitem", 1);
|
|
||||||
|
|
||||||
QWidget *quickContainer = new QWidget;
|
QWidget *quickContainer = new QWidget;
|
||||||
layout->addWidget(quickContainer);
|
layout->addWidget(quickContainer);
|
||||||
layout->setStretchFactor(quickContainer, 8);
|
layout->setStretchFactor(quickContainer, 8);
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
TARGET = qquickviewcomparison
|
TARGET = qquickviewcomparison
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = fbitem
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
QT += quick widgets quickwidgets
|
QT += quick widgets quickwidgets
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
|
|
|
@ -214,8 +214,6 @@ int main(int argc, char **argv)
|
||||||
optMultipleSample = parser.isSet(multipleSampleOption);
|
optMultipleSample = parser.isSet(multipleSampleOption);
|
||||||
optCoreProfile = parser.isSet(coreProfileOption);
|
optCoreProfile = parser.isSet(coreProfileOption);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<FbItem>("QuickWidgetExample", 1);
|
|
||||||
|
|
||||||
MainWindow mainWindow;
|
MainWindow mainWindow;
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ QT += core gui quick widgets quickwidgets
|
||||||
TARGET = quickwidget
|
TARGET = quickwidget
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = QuickWidgetExample
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp fbitem.cpp
|
SOURCES += main.cpp fbitem.cpp
|
||||||
HEADERS += fbitem.h
|
HEADERS += fbitem.h
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,9 @@ class BezierCurve : public QQuickItem
|
||||||
Q_PROPERTY(QPointF p4 READ p4 WRITE setP4 NOTIFY p4Changed)
|
Q_PROPERTY(QPointF p4 READ p4 WRITE setP4 NOTIFY p4Changed)
|
||||||
|
|
||||||
Q_PROPERTY(int segmentCount READ segmentCount WRITE setSegmentCount NOTIFY segmentCountChanged)
|
Q_PROPERTY(int segmentCount READ segmentCount WRITE setSegmentCount NOTIFY segmentCountChanged)
|
||||||
|
//! [3]
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
//! [3]
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BezierCurve(QQuickItem *parent = 0);
|
BezierCurve(QQuickItem *parent = 0);
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
TARGET = customgeometry
|
TARGET = customgeometry
|
||||||
QT += quick
|
QT += quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = CustomGeometry
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
beziercurve.cpp
|
beziercurve.cpp
|
||||||
|
|
|
@ -169,11 +169,16 @@
|
||||||
\snippet scenegraph/customgeometry/main.cpp 1
|
\snippet scenegraph/customgeometry/main.cpp 1
|
||||||
|
|
||||||
The application is a straightforward QML application, with a
|
The application is a straightforward QML application, with a
|
||||||
QGuiApplication and a QQuickView that we pass a .qml file. To make
|
QGuiApplication and a QQuickView that we pass a .qml file.
|
||||||
use of the BezierCurve item, we need to register it in the QML
|
|
||||||
engine, using the qmlRegisterType() function. We give it the name
|
\snippet scenegraph/customgeometry/beziercurve.h 3
|
||||||
BezierCurve and make it part of the \c {CustomGeometry 1.0}
|
|
||||||
module.
|
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
|
As the bezier curve is drawn using GL_LINE_STRIP, we specify that
|
||||||
the view should be multisampled to get antialiasing. This is not
|
the view should be multisampled to get antialiasing. This is not
|
||||||
|
|
|
@ -58,8 +58,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<BezierCurve>("CustomGeometry", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
QSurfaceFormat format = view.format();
|
QSurfaceFormat format = view.format();
|
||||||
format.setSamples(16);
|
format.setSamples(16);
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = D3D11UnderQML
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += d3d11squircle.h
|
HEADERS += d3d11squircle.h
|
||||||
SOURCES += d3d11squircle.cpp main.cpp
|
SOURCES += d3d11squircle.cpp main.cpp
|
||||||
RESOURCES += d3d11underqml.qrc
|
RESOURCES += d3d11underqml.qrc
|
||||||
|
|
|
@ -56,8 +56,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<D3D11Squircle>("D3D11UnderQML", 1);
|
|
||||||
|
|
||||||
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Direct3D11Rhi);
|
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Direct3D11Rhi);
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = SceneGraphRendering
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += fboinsgrenderer.h
|
HEADERS += fboinsgrenderer.h
|
||||||
SOURCES += fboinsgrenderer.cpp main.cpp
|
SOURCES += fboinsgrenderer.cpp main.cpp
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<FboInSGRenderer>("SceneGraphRendering", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:///scenegraph/fboitem/main.qml"));
|
view.setSource(QUrl("qrc:///scenegraph/fboitem/main.qml"));
|
||||||
|
|
|
@ -4,6 +4,10 @@ TARGET = graph
|
||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = Graph
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
graph.cpp \
|
graph.cpp \
|
||||||
noisynode.cpp \
|
noisynode.cpp \
|
||||||
|
|
|
@ -58,8 +58,6 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QGuiApplication a(argc, argv);
|
QGuiApplication a(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<Graph>("Graph", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.resize(800, 400);
|
view.resize(800, 400);
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
|
|
|
@ -56,8 +56,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<MetalSquircle>("MetalUnderQML", 1);
|
|
||||||
|
|
||||||
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);
|
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = MetalUnderQML
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += metalsquircle.h
|
HEADERS += metalsquircle.h
|
||||||
SOURCES += metalsquircle.mm main.cpp
|
SOURCES += metalsquircle.mm main.cpp
|
||||||
RESOURCES += metalunderqml.qrc
|
RESOURCES += metalunderqml.qrc
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
|
|
||||||
First of all, we need an object we can expose to QML. This is a
|
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().
|
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
|
\snippet scenegraph/openglunderqml/squircle.h 1
|
||||||
|
|
||||||
|
@ -145,9 +146,7 @@
|
||||||
\snippet scenegraph/openglunderqml/main.cpp 1
|
\snippet scenegraph/openglunderqml/main.cpp 1
|
||||||
|
|
||||||
The application's \c main() function instantiates a QQuickView and
|
The application's \c main() function instantiates a QQuickView and
|
||||||
launches the \c main.qml file. The only thing worth noting is that
|
launches the \c main.qml file.
|
||||||
we export the \c Squircle class to QML using the \l
|
|
||||||
qmlRegisterType() macro.
|
|
||||||
|
|
||||||
\snippet scenegraph/openglunderqml/main.qml 1
|
\snippet scenegraph/openglunderqml/main.qml 1
|
||||||
|
|
||||||
|
|
|
@ -59,8 +59,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<Squircle>("OpenGLUnderQML", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:///scenegraph/openglunderqml/main.qml"));
|
view.setSource(QUrl("qrc:///scenegraph/openglunderqml/main.qml"));
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = OpenGLUnderQML
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += squircle.h
|
HEADERS += squircle.h
|
||||||
SOURCES += squircle.cpp main.cpp
|
SOURCES += squircle.cpp main.cpp
|
||||||
RESOURCES += openglunderqml.qrc
|
RESOURCES += openglunderqml.qrc
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
|
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
//! [0]
|
||||||
class CustomRenderItem : public QQuickItem
|
class CustomRenderItem : public QQuickItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -62,5 +63,6 @@ public:
|
||||||
CustomRenderItem(QQuickItem *parent = nullptr);
|
CustomRenderItem(QQuickItem *parent = nullptr);
|
||||||
QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override;
|
QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *) override;
|
||||||
};
|
};
|
||||||
|
//! [0]
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
|
|
||||||
Let's go through the most important parts of the code:
|
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.
|
Our custom QML type is implemented in the class CustomRenderItem.
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
//! [1]
|
|
||||||
qmlRegisterTypesAndRevisions<CustomRenderItem>("SceneGraphRendering", 2);
|
|
||||||
//! [1]
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
|
|
||||||
QCoreApplication::setApplicationName("Qt Scene Graph Render Node Example");
|
QCoreApplication::setApplicationName("Qt Scene Graph Render Node Example");
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = SceneGraphRendering
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 2
|
||||||
|
|
||||||
HEADERS += customrenderitem.h \
|
HEADERS += customrenderitem.h \
|
||||||
openglrenderer.h \
|
openglrenderer.h \
|
||||||
softwarerenderer.h
|
softwarerenderer.h
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
material state is what we assign to each individual node; in this
|
material state is what we assign to each individual node; in this
|
||||||
case to give them different colors.
|
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
|
The first thing we do when creating custom materials with the
|
||||||
simplified scheme is to create a state class. In this case 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
|
compare function which the scene graph can use to reorder the node
|
||||||
rendering.
|
rendering.
|
||||||
|
|
||||||
\snippet scenegraph/simplematerial/simplematerial.cpp 2
|
\snippet scenegraph/simplematerial/simplematerialitem.cpp 2
|
||||||
|
|
||||||
Next we define the material shader, by subclassing a template
|
Next we define the material shader, by subclassing a template
|
||||||
instantiation of \l QSGSimpleMaterialShader with our \c State.
|
instantiation of \l QSGSimpleMaterialShader with our \c State.
|
||||||
|
@ -74,21 +74,21 @@
|
||||||
classes. Using the same \c State class in multiple shaders will
|
classes. Using the same \c State class in multiple shaders will
|
||||||
will lead to undefined behavior.
|
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
|
Next comes the declaration of the shader source code, where we
|
||||||
define a vertex and fragment shader. The simple material assumes
|
define a vertex and fragment shader. The simple material assumes
|
||||||
the presence of \c qt_Matrix in the vertex shader and \c
|
the presence of \c qt_Matrix in the vertex shader and \c
|
||||||
qt_Opacity in the fragment shader.
|
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
|
We reimplement the \c attributes function to return the name of
|
||||||
the \c aVertex and \c aTexCoord attributes. These attributes
|
the \c aVertex and \c aTexCoord attributes. These attributes
|
||||||
will be mapped to attribute indices 0 and 1 in the node's
|
will be mapped to attribute indices 0 and 1 in the node's
|
||||||
geometry.
|
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
|
Uniforms can be accessed either by name or by index, where index
|
||||||
is faster than name. We reimplement the \c resolveUniforms()
|
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
|
to worry about resolving \c qt_Opacity or \c qt_Matrix as these
|
||||||
are handled by the baseclass.
|
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
|
The \c updateState() function is called once for every unique
|
||||||
state and we use it to update the shader program with the current
|
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()
|
use case, where all the colors are different, the updateState()
|
||||||
function will be called once for every node.
|
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
|
The \c ColorNode class is supposed to draw something, so it needs
|
||||||
to be a subclass of \l QSGGeometryNode.
|
to be a subclass of \l QSGGeometryNode.
|
||||||
|
@ -129,12 +129,13 @@
|
||||||
Finally, we tell the node to take ownership of the material, so we
|
Finally, we tell the node to take ownership of the material, so we
|
||||||
do not have to explicitly memory-manage it.
|
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,
|
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
|
Whenever the Item has changed graphically, the \l
|
||||||
QQuickItem::updatePaintNode() function is called.
|
QQuickItem::updatePaintNode() function is called.
|
||||||
|
@ -159,9 +160,8 @@
|
||||||
|
|
||||||
\snippet scenegraph/simplematerial/simplematerial.cpp 11
|
\snippet scenegraph/simplematerial/simplematerial.cpp 11
|
||||||
|
|
||||||
The \c main() function of the application adds the custom QML type
|
The \c main() function of the application opens up a \l QQuickView
|
||||||
using \l qmlRegisterType() and opens up a \l QQuickView with our
|
with our QML file.
|
||||||
QML file.
|
|
||||||
|
|
||||||
\snippet scenegraph/simplematerial/main.qml 1
|
\snippet scenegraph/simplematerial/main.qml 1
|
||||||
|
|
||||||
|
|
|
@ -49,163 +49,13 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <qguiapplication.h>
|
#include <qguiapplication.h>
|
||||||
|
|
||||||
#include <qsgmaterial.h>
|
|
||||||
#include <qsgnode.h>
|
|
||||||
|
|
||||||
#include <qquickitem.h>
|
|
||||||
#include <qquickview.h>
|
#include <qquickview.h>
|
||||||
|
|
||||||
#include <qsgsimplerectnode.h>
|
//! [11]
|
||||||
|
|
||||||
#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]
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<Item>("SimpleMaterial", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:///scenegraph/simplematerial/main.qml"));
|
view.setSource(QUrl("qrc:///scenegraph/simplematerial/main.qml"));
|
||||||
|
@ -213,6 +63,4 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "simplematerial.moc"
|
|
||||||
//! [11]
|
//! [11]
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
|
|
||||||
QT += quick
|
QT += quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = SimpleMaterial
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
simplematerial.cpp
|
simplematerial.cpp \
|
||||||
|
simplematerialitem.cpp
|
||||||
RESOURCES += simplematerial.qrc
|
RESOURCES += simplematerial.qrc
|
||||||
|
|
||||||
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial
|
target.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial
|
||||||
|
@ -10,3 +15,6 @@ qml.files = main.qml
|
||||||
qml.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial
|
qml.path = $$[QT_INSTALL_EXAMPLES]/quick/scenegraph/simplematerial
|
||||||
|
|
||||||
INSTALLS += target qml
|
INSTALLS += target qml
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
simplematerialitem.h
|
||||||
|
|
|
@ -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]
|
|
@ -1,9 +1,9 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2017 The Qt Company Ltd.
|
** Copyright (C) 2016 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** 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$
|
** $QT_BEGIN_LICENSE:BSD$
|
||||||
** Commercial License Usage
|
** Commercial License Usage
|
||||||
|
@ -47,16 +47,36 @@
|
||||||
** $QT_END_LICENSE$
|
** $QT_END_LICENSE$
|
||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "chartsplugin.h"
|
|
||||||
//![0]
|
|
||||||
#include "piechart.h"
|
|
||||||
#include "pieslice.h"
|
|
||||||
#include <qqml.h>
|
|
||||||
|
|
||||||
void ChartsPlugin::registerTypes(const char *uri)
|
#ifndef SIMPLEMATERIALITEM_H
|
||||||
|
#define SIMPLEMATERIALITEM_H
|
||||||
|
|
||||||
|
#include <QtQuick/qquickitem.h>
|
||||||
|
|
||||||
|
//! [8]
|
||||||
|
class SimpleMaterialItem : public QQuickItem
|
||||||
{
|
{
|
||||||
qmlRegisterTypesAndRevisions<PieChart, PieSlice>(uri, 1);
|
Q_OBJECT
|
||||||
}
|
|
||||||
|
|
||||||
//![0]
|
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
|
|
@ -70,7 +70,6 @@ int main(int argc, char **argv)
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<ThreadRenderer>("SceneGraphRendering", 1);
|
|
||||||
int execReturn = 0;
|
int execReturn = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,10 @@ QT += quick
|
||||||
# To make threaded gl check...
|
# To make threaded gl check...
|
||||||
QT += core-private gui-private
|
QT += core-private gui-private
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = SceneGraphRendering
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += threadrenderer.h
|
HEADERS += threadrenderer.h
|
||||||
SOURCES += threadrenderer.cpp main.cpp
|
SOURCES += threadrenderer.cpp main.cpp
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<Spinner>("Spinner", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setSource(QUrl("qrc:///scenegraph/threadedanimation/main.qml"));
|
view.setSource(QUrl("qrc:///scenegraph/threadedanimation/main.qml"));
|
||||||
view.show();
|
view.show();
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = Spinner
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += spinner.h
|
HEADERS += spinner.h
|
||||||
SOURCES += spinner.cpp main.cpp
|
SOURCES += spinner.cpp main.cpp
|
||||||
RESOURCES += threadedanimation.qrc
|
RESOURCES += threadedanimation.qrc
|
||||||
|
|
|
@ -58,8 +58,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
qmlRegisterTypesAndRevisions<XorBlender>("SceneGraphRendering", 1);
|
|
||||||
|
|
||||||
QQuickView view;
|
QQuickView view;
|
||||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||||
view.setSource(QUrl("qrc:///scenegraph/twotextureproviders/main.qml"));
|
view.setSource(QUrl("qrc:///scenegraph/twotextureproviders/main.qml"));
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
QT += qml quick
|
QT += qml quick
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = SceneGraphRendering
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
HEADERS += xorblender.h
|
HEADERS += xorblender.h
|
||||||
SOURCES += xorblender.cpp main.cpp
|
SOURCES += xorblender.cpp main.cpp
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,6 @@
|
||||||
the view should be scrolled to.
|
the view should be scrolled to.
|
||||||
|
|
||||||
\snippet tableview/gameoflife/main.qml model
|
\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
|
\section1 The C++ Model
|
||||||
|
|
||||||
|
@ -61,7 +58,8 @@
|
||||||
used as the model of our TableView component. Therefore, it needs to
|
used as the model of our TableView component. Therefore, it needs to
|
||||||
implement some functions so the TableView component can interact with
|
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
|
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
|
\snippet tableview/gameoflife/gameoflifemodel.cpp modelsize
|
||||||
Here, the \c rowCount and \c columnCount methods are implemented so
|
Here, the \c rowCount and \c columnCount methods are implemented so
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
QT += quick qml
|
QT += quick qml
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = GameOfLifeModel
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
gameoflifemodel.cpp
|
gameoflifemodel.cpp
|
||||||
|
|
|
@ -58,10 +58,6 @@ int main(int argc, char *argv[])
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
|
||||||
//! [registertype]
|
|
||||||
qmlRegisterTypesAndRevisions<GameOfLifeModel>("GameOfLifeModel", 1);
|
|
||||||
//! [registertype]
|
|
||||||
|
|
||||||
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||||
if (engine.rootObjects().isEmpty())
|
if (engine.rootObjects().isEmpty())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
TableView.
|
TableView.
|
||||||
We use the \l{The Property System}{Qt Property System} and a source property
|
We use the \l{The Property System}{Qt Property System} and a source property
|
||||||
as \c QString to set the path of the image.
|
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
|
\snippet tableview/pixelator/imagemodel.cpp setsource
|
||||||
|
|
||||||
|
@ -59,11 +60,6 @@
|
||||||
When we call this function with the display role, we return the pixel's
|
When we call this function with the display role, we return the pixel's
|
||||||
gray value.
|
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
|
\snippet tableview/pixelator/main.qml pixelcomponent
|
||||||
|
|
||||||
Each pixel in the \c TableView is displayed via a delegate component.
|
Each pixel in the \c TableView is displayed via a delegate component.
|
||||||
|
|
|
@ -59,10 +59,6 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
|
||||||
//! [registertype]
|
|
||||||
qmlRegisterTypesAndRevisions<ImageModel>("ImageModel", 1);
|
|
||||||
//! [registertype]
|
|
||||||
|
|
||||||
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||||
if (engine.rootObjects().isEmpty())
|
if (engine.rootObjects().isEmpty())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -5,6 +5,10 @@ HEADERS += imagemodel.h
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
imagemodel.cpp
|
imagemodel.cpp
|
||||||
|
|
||||||
|
CONFIG += qmltypes
|
||||||
|
QML_IMPORT_NAME = ImageModel
|
||||||
|
QML_IMPORT_MAJOR_VERSION = 1
|
||||||
|
|
||||||
RESOURCES += qt.png main.qml
|
RESOURCES += qt.png main.qml
|
||||||
|
|
||||||
target.path = $$[QT_INSTALL_EXAMPLES]/quick/tableview/pixelator
|
target.path = $$[QT_INSTALL_EXAMPLES]/quick/tableview/pixelator
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
#include <QtQml/private/qtqmlglobal_p.h>
|
#include <QtQml/private/qtqmlglobal_p.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#if __cplusplus > 201402L && QT_HAS_INCLUDE(<optional>)
|
#if __cplusplus > 201402L && __has_include(<optional>)
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,5 @@ HEADERS += qquickfolderlistmodel.h \
|
||||||
fileproperty_p.h \
|
fileproperty_p.h \
|
||||||
fileinfothread_p.h
|
fileinfothread_p.h
|
||||||
|
|
||||||
|
CONFIG += qmltypes install_qmltypes
|
||||||
load(qml_plugin)
|
load(qml_plugin)
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue