aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dist/changes-5.13.263
-rw-r--r--examples/qml/xmlhttprequest/Get.qml2
-rw-r--r--examples/quick/scenegraph/fboitem/fboitem.qrc2
-rw-r--r--examples/quick/scenegraph/fboitem/main.qml15
-rw-r--r--examples/quick/scenegraph/fboitem/shaders/+qsb/checker.fragbin0 -> 1615 bytes
-rw-r--r--examples/quick/scenegraph/fboitem/shaders/checker.frag14
-rw-r--r--examples/quick/scenegraph/fboitem/shaders/checker_rhi.frag22
-rw-r--r--examples/quick/scenegraph/twotextureproviders/main.qml17
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/+qsb/checker.fragbin0 -> 1824 bytes
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.fragbin0 -> 1941 bytes
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vertbin0 -> 1815 bytes
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/checker.frag14
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/checker_rhi.frag25
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/xorblender.frag12
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/xorblender.vert12
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.frag20
-rw-r--r--examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.vert19
-rw-r--r--examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc8
-rw-r--r--examples/quick/scenegraph/twotextureproviders/xorblender.cpp220
-rw-r--r--examples/quick/text/styledtext-layout.qml19
-rw-r--r--examples/quick/views/doc/src/views.qdoc16
-rw-r--r--src/imports/labsmodels/labsmodels.pro20
-rw-r--r--src/imports/labsmodels/plugin.cpp16
-rw-r--r--src/imports/labsmodels/qqmldelegatecomponent.cpp (renamed from src/qmlmodels/qqmldelegatecomponent.cpp)16
-rw-r--r--src/imports/labsmodels/qqmldelegatecomponent_p.h (renamed from src/qmlmodels/qqmldelegatecomponent_p.h)35
-rw-r--r--src/imports/labsmodels/qqmltablemodel.cpp (renamed from src/qmlmodels/qqmltablemodel.cpp)0
-rw-r--r--src/imports/labsmodels/qqmltablemodel_p.h (renamed from src/qmlmodels/qqmltablemodel_p.h)5
-rw-r--r--src/imports/labsmodels/qqmltablemodelcolumn.cpp (renamed from src/qmlmodels/qqmltablemodelcolumn.cpp)0
-rw-r--r--src/imports/labsmodels/qqmltablemodelcolumn_p.h (renamed from src/qmlmodels/qqmltablemodelcolumn_p.h)2
-rw-r--r--src/imports/layouts/qquicklinearlayout.cpp6
-rw-r--r--src/imports/qtqml/qmldir7
-rw-r--r--src/imports/qtqml/qtqml.pro11
-rw-r--r--src/imports/testlib/TestCase.qml2
-rw-r--r--src/imports/window/plugin.cpp10
-rw-r--r--src/imports/window/plugin.h121
-rw-r--r--src/imports/window/window.pro3
-rw-r--r--src/particles/qquickimageparticle.cpp18
-rw-r--r--src/particles/qquickimageparticle_p.h1
-rw-r--r--src/qml/common/qqmlapiversion_p.h2
-rw-r--r--src/qml/common/qv4compileddata_p.h1
-rw-r--r--src/qml/compiler/qqmlirbuilder.cpp8
-rw-r--r--src/qml/compiler/qqmlirbuilder_p.h18
-rw-r--r--src/qml/compiler/qv4instr_moth_p.h2
-rw-r--r--src/qml/doc/images/cpp-qml-integration-flowchart.odgbin15028 -> 15311 bytes
-rw-r--r--src/qml/doc/images/cpp-qml-integration-flowchart.pngbin80498 -> 64865 bytes
-rw-r--r--src/qml/doc/src/external-resources.qdoc2
-rw-r--r--src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc20
-rw-r--r--src/qml/jit/qv4assemblercommon.cpp19
-rw-r--r--src/qml/jit/qv4assemblercommon_p.h6
-rw-r--r--src/qml/jit/qv4baselineassembler.cpp62
-rw-r--r--src/qml/jit/qv4baselineassembler_p.h13
-rw-r--r--src/qml/jsruntime/qv4arrayobject.cpp72
-rw-r--r--src/qml/jsruntime/qv4executablecompilationunit.cpp10
-rw-r--r--src/qml/jsruntime/qv4executablecompilationunit_p.h5
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp4
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp127
-rw-r--r--src/qml/jsruntime/qv4runtimeapi_p.h2
-rw-r--r--src/qml/jsruntime/qv4scopedvalue_p.h2
-rw-r--r--src/qml/jsruntime/qv4sequenceobject.cpp20
-rw-r--r--src/qml/jsruntime/qv4sparsearray.cpp2
-rw-r--r--src/qml/jsruntime/qv4sparsearray_p.h2
-rw-r--r--src/qml/jsruntime/qv4stackframe_p.h2
-rw-r--r--src/qml/jsruntime/qv4typedarray.cpp55
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp2
-rw-r--r--src/qml/qml/ftw/qflagpointer_p.h16
-rw-r--r--src/qml/qml/ftw/qqmlthread.cpp3
-rw-r--r--src/qml/qml/qml.pri2
-rw-r--r--src/qml/qml/qqmlbinding.cpp5
-rw-r--r--src/qml/qml/qqmlcomponent.cpp1
-rw-r--r--src/qml/qml/qqmlcontext.cpp3
-rw-r--r--src/qml/qml/qqmlengine.cpp8
-rw-r--r--src/qml/qml/qqmlextensioninterface.h11
-rw-r--r--src/qml/qml/qqmlextensionplugin.cpp56
-rw-r--r--src/qml/qml/qqmlextensionplugin.h13
-rw-r--r--src/qml/qml/qqmlimport.cpp124
-rw-r--r--src/qml/qml/qqmlimport_p.h10
-rw-r--r--src/qml/qml/qqmlincubator.cpp35
-rw-r--r--src/qml/qml/qqmlincubator.h5
-rw-r--r--src/qml/qml/qqmlmetatype.cpp98
-rw-r--r--src/qml/qml/qqmlmetatype_p.h17
-rw-r--r--src/qml/qml/qqmlmetatypedata.cpp10
-rw-r--r--src/qml/qml/qqmlmetatypedata_p.h4
-rw-r--r--src/qml/qml/qqmlmoduleregistration.cpp54
-rw-r--r--src/qml/qml/qqmlmoduleregistration.h58
-rw-r--r--src/qml/qml/qqmlnotifier.cpp4
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp140
-rw-r--r--src/qml/qml/qqmlobjectcreator_p.h15
-rw-r--r--src/qml/qml/qqmlprivate.h2
-rw-r--r--src/qml/qml/qqmlproperty.cpp24
-rw-r--r--src/qml/qml/qqmlpropertycachecreator.cpp16
-rw-r--r--src/qml/qml/qqmlpropertycachecreator_p.h48
-rw-r--r--src/qml/qml/qqmlpropertyvalidator.cpp4
-rw-r--r--src/qml/qml/qqmlscriptblob.cpp4
-rw-r--r--src/qml/qml/qqmltypecompiler.cpp7
-rw-r--r--src/qml/qml/qqmltypecompiler_p.h2
-rw-r--r--src/qml/qml/qqmltypedata.cpp42
-rw-r--r--src/qml/qml/qqmltypedata_p.h12
-rw-r--r--src/qml/qml/qqmltypeloader.cpp108
-rw-r--r--src/qml/qml/qqmltypeloader_p.h6
-rw-r--r--src/qml/qml/qqmltypeloaderthread.cpp17
-rw-r--r--src/qml/qml/qqmltypeloaderthread_p.h5
-rw-r--r--src/qml/qml/qqmltypenamecache.cpp4
-rw-r--r--src/qml/qml/qqmltypewrapper.cpp2
-rw-r--r--src/qml/qml/qqmlvme_p.h43
-rw-r--r--src/qml/types/qqmlbind.cpp29
-rw-r--r--src/qmlmodels/qmlmodels.pro12
-rw-r--r--src/qmlmodels/qqmlabstractdelegatecomponent.cpp61
-rw-r--r--src/qmlmodels/qqmlabstractdelegatecomponent_p.h85
-rw-r--r--src/qmlmodels/qqmladaptormodel.cpp7
-rw-r--r--src/qmlmodels/qqmldelegatemodel.cpp2
-rw-r--r--src/qmlmodels/qqmlmodelsmodule.cpp21
-rw-r--r--src/qmlmodels/qqmlobjectmodel.cpp7
-rw-r--r--src/qmlmodels/qqmltableinstancemodel.cpp2
-rw-r--r--src/qmltest/quicktestevent.cpp2
-rw-r--r--src/qmltyperegistrar/qmltyperegistrar.cpp410
-rw-r--r--src/qmltyperegistrar/qmltyperegistrar.pro32
-rw-r--r--src/qmltyperegistrar/qmltypes.prf95
-rw-r--r--src/qmltyperegistrar/qmltypesclassdescription.cpp161
-rw-r--r--src/qmltyperegistrar/qmltypesclassdescription.h58
-rw-r--r--src/qmltyperegistrar/qmltypescreator.cpp357
-rw-r--r--src/qmltyperegistrar/qmltypescreator.h68
-rw-r--r--src/quick/doc/src/examples.qdoc1
-rw-r--r--src/quick/items/qquickanimatedsprite.cpp64
-rw-r--r--src/quick/items/qquickanimatedsprite_p.h11
-rw-r--r--src/quick/items/qquickanimatedsprite_p_p.h5
-rw-r--r--src/quick/items/qquickdrag.cpp2
-rw-r--r--src/quick/items/qquickevents.cpp10
-rw-r--r--src/quick/items/qquickevents_p_p.h4
-rw-r--r--src/quick/items/qquickframebufferobject.cpp30
-rw-r--r--src/quick/items/qquickframebufferobject.h3
-rw-r--r--src/quick/items/qquickitem.cpp28
-rw-r--r--src/quick/items/qquickitemview.cpp34
-rw-r--r--src/quick/items/qquickitemview_p_p.h2
-rw-r--r--src/quick/items/qquicklistview.cpp10
-rw-r--r--src/quick/items/qquickloader.cpp3
-rw-r--r--src/quick/items/qquickscreen_p.h14
-rw-r--r--src/quick/items/qquicktext.cpp79
-rw-r--r--src/quick/items/qquicktext_p.h6
-rw-r--r--src/quick/items/qquicktext_p_p.h2
-rw-r--r--src/quick/items/qquicktextedit.cpp9
-rw-r--r--src/quick/items/qquicktextinput.cpp4
-rw-r--r--src/quick/items/qquickwindow.cpp59
-rw-r--r--src/quick/items/qquickwindow.h3
-rw-r--r--src/quick/items/qquickwindowmodule.cpp14
-rw-r--r--src/quick/items/qquickwindowmodule_p.h8
-rw-r--r--src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp12
-rw-r--r--src/quick/scenegraph/qsgrhitextureglyphcache_p.h6
-rw-r--r--src/quick/scenegraph/qsgthreadedrenderloop.cpp4
-rw-r--r--src/quick/scenegraph/util/qsgopenglatlastexture.cpp12
-rw-r--r--src/quick/util/qquickimageprovider.cpp2
-rw-r--r--src/quickwidgets/qquickwidget.cpp4
-rw-r--r--src/src.pro6
-rw-r--r--tests/auto/qml/debugger/qqmldebugjs/data/quit.js4
-rw-r--r--tests/auto/qml/debugger/qqmldebugjs/data/quitInJS.qml41
-rw-r--r--tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp48
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp1
-rw-r--r--tests/auto/qml/qmlcachegen/data/parameterAdjustment.qml7
-rw-r--r--tests/auto/qml/qmlcachegen/qmlcachegen.pro3
-rw-r--r--tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp10
-rw-r--r--tests/auto/qml/qmllint/data/esmodule.mjs2
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp1
-rw-r--r--tests/auto/qml/qmlmin/tst_qmlmin.cpp1
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/Imports/Derived.qml6
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro2
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes10
-rw-r--r--tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir1
-rw-r--r--tests/auto/qml/qqmlbinding/data/nanPropertyToInt.qml14
-rw-r--r--tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp11
-rw-r--r--tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp25
-rw-r--r--tests/auto/qml/qqmldelegatemodel/data/abstractItemModel.qml37
-rw-r--r--tests/auto/qml/qqmldelegatemodel/data/integerModel.qml35
-rw-r--r--tests/auto/qml/qqmldelegatemodel/data/listModel.qml45
-rw-r--r--tests/auto/qml/qqmldelegatemodel/qqmldelegatemodel.pro13
-rw-r--r--tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp139
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp8
-rw-r--r--tests/auto/qml/qqmlimport/tst_qqmlimport.cpp21
-rw-r--r--tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp66
-rw-r--r--tests/auto/qml/qqmlitemmodels/qtestmodel.h2
-rw-r--r--tests/auto/qml/qqmllanguage/data/SelfInstantiation.errors.txt1
-rw-r--r--tests/auto/qml/qqmllanguage/data/SelfInstantiation.qml5
-rw-r--r--tests/auto/qml/qqmllanguage/data/SelfReference.qml8
-rw-r--r--tests/auto/qml/qqmllanguage/data/alias.14.errors.txt1
-rw-r--r--tests/auto/qml/qqmllanguage/data/alias.18.errors.txt1
-rw-r--r--tests/auto/qml/qqmllanguage/data/alias.18.qml9
-rw-r--r--tests/auto/qml/qqmllanguage/data/fuzzed.2.qmlbin404 -> 404 bytes
-rw-r--r--tests/auto/qml/qqmllanguage/data/fuzzed.3.errors.txt2
-rw-r--r--tests/auto/qml/qqmllanguage/data/fuzzed.3.qmlbin0 -> 4777 bytes
-rw-r--r--tests/auto/qml/qqmllanguage/data/objectValueTypeProperty.errors.txt2
-rw-r--r--tests/auto/qml/qqmllanguage/data/selfreferencingsingletonmodule/TestSingleton.qml7
-rw-r--r--tests/auto/qml/qqmllanguage/data/selfreferencingsingletonmodule/qmldir1
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp93
-rw-r--r--tests/auto/qml/qqmlproperty/data/interfaceBinding.qml27
-rw-r--r--tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp100
-rw-r--r--tests/auto/qml/qqmltablemodel/qqmltablemodel.pro2
-rw-r--r--tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp28
-rw-r--r--tests/auto/qml/qqmltypeloader/data/declarativeCppType.qml6
-rw-r--r--tests/auto/qml/qqmltypeloader/declarativetesttype.h44
-rw-r--r--tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp21
-rw-r--r--tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro8
-rw-r--r--tests/auto/quick/qquickanimatedsprite/data/finishBehavior.qml18
-rw-r--r--tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp63
-rw-r--r--tests/auto/quick/qquickdrag/tst_qquickdrag.cpp25
-rw-r--r--tests/auto/quick/qquickitem/data/setParentInWindowChange.qml12
-rw-r--r--tests/auto/quick/qquickitem/tst_qquickitem.cpp8
-rw-r--r--tests/auto/quick/qquickitem2/tst_qquickitem.cpp6
-rw-r--r--tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml54
-rw-r--r--tests/auto/quick/qquickloader/data/CacheClearTest.qml4
-rw-r--r--tests/auto/quick/qquickloader/data/initialPropertyValues.11.qml20
-rw-r--r--tests/auto/quick/qquickloader/tst_qquickloader.cpp5
-rw-r--r--tests/auto/quick/qquicktext/data/lineLayout.qml9
-rw-r--r--tests/auto/quick/qquicktext/data/lineLayoutImplicitWidth.qml80
-rw-r--r--tests/auto/quick/qquicktext/tst_qquicktext.cpp56
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp24
-rw-r--r--tests/auto/quick/qquicktextinput/data/qtbug77841.qml22
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp42
-rw-r--r--tests/auto/quick/quick.pro2
-rw-r--r--tools/qmlcachegen/qmlcachegen.pro8
-rw-r--r--tools/qmlimportscanner/main.cpp11
-rw-r--r--tools/qmlimportscanner/qmlimportscanner.pro1
-rw-r--r--tools/qmllint/findunqualified.cpp2
-rw-r--r--tools/qmllint/main.cpp6
-rw-r--r--tools/qmlmin/main.cpp2
-rw-r--r--tools/qmlplugindump/main.cpp68
-rw-r--r--tools/qmlplugindump/qmlplugindump.pro10
-rw-r--r--tools/shared/qmlstreamwriter.cpp (renamed from tools/qmlplugindump/qmlstreamwriter.cpp)0
-rw-r--r--tools/shared/qmlstreamwriter.h (renamed from tools/qmlplugindump/qmlstreamwriter.h)0
-rw-r--r--tools/shared/resourcefilemapper.cpp (renamed from tools/qmlcachegen/resourcefilemapper.cpp)7
-rw-r--r--tools/shared/resourcefilemapper.h (renamed from tools/qmlcachegen/resourcefilemapper.h)6
-rw-r--r--tools/shared/shared.pri9
229 files changed, 4656 insertions, 972 deletions
diff --git a/dist/changes-5.13.2 b/dist/changes-5.13.2
new file mode 100644
index 0000000000..6936f38721
--- /dev/null
+++ b/dist/changes-5.13.2
@@ -0,0 +1,63 @@
+Qt 5.13.2 is a bug-fix release. It maintains both forward and backward
+compatibility (source and binary) with Qt 5.13.0 through 5.13.1.
+
+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.13 series is binary compatible with the 5.12.x series.
+Applications compiled for 5.12 will continue to run with 5.13.
+
+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 *
+****************************************************************************
+
+ - [QTBUG-77761] EcmaScript modules are loaded correctly now when using the
+ Qt Quick Compiler.
+ - [QTBUG-74087] Various JavaScript list-like constructs are parsed
+ iteratively rather than recursively now, avoiding stack overflows.
+ - [QTBUG-78554] Exceptions thrown from a promise's resolve or reject
+ handler are forwarded correctly now.
+ - [QTBUG-78996] MakeDay() and getDay() now behave more correctly.
+
+****************************************************************************
+* QtQuick *
+****************************************************************************
+
+ - [QTBUG-79084] The QQuickWindow::afterAnimating signal is now emitted
+ properly when using QQuickRenderControl.
+ - [QTBUG-79011] Fix an odd 1px offset when rendering an Image with
+ fillMode: PreserveAspectFit.
+ - [QTBUG-78468] Fixed the hanging native pictures dialog on iOS.
+
+ - Item Views:
+
+ * [QTBUG-77074] Fixed a bug when TableView columnWidthProvider calculates
+ the widths of columns after a previously-hidden row is shown again.
+ * [QTBUG-77173] If you click or tap a PathView while it's moving,
+ it will come to rest with the nearest delegate aligned properly.
+ * [QTBUG-77418] ListView highlightRangeMode works correctly after
+ currentIndex is changed.
+
+ - Text:
+
+ * If the alpha of a text background is 0, the background rectangle node
+ is now omitted from the scene graph.
+ * [QTBUG-77389] Fixed TextEdit paragraph-selection triple click feature.
+
+ - OpenVG rendering:
+
+ * [QTBUG-77019] Fixed sprites leaking textures.
+ * [QTBUG-76526] Fixed per-frame delivery of touch events.
+ * [QTBUG-76806] The sceneGraphInitialized and sceneGraphInvalidated
+ signals are now emitted properly.
+ * [QTBUG-76589] Fixed rendering of non-affine transformed rectangles.
diff --git a/examples/qml/xmlhttprequest/Get.qml b/examples/qml/xmlhttprequest/Get.qml
index 1a35d32666..96cec2a99d 100644
--- a/examples/qml/xmlhttprequest/Get.qml
+++ b/examples/qml/xmlhttprequest/Get.qml
@@ -58,7 +58,7 @@ GetForm
mouseArea.onClicked: Utils.makeRequest()
- button.border.width: button.pressed ? 2 : 1
+ button.border.width: mouseArea.pressed ? 2 : 1
text.text: "Request data.xml"
}
diff --git a/examples/quick/scenegraph/fboitem/fboitem.qrc b/examples/quick/scenegraph/fboitem/fboitem.qrc
index 9d9db70654..eeb5c36afd 100644
--- a/examples/quick/scenegraph/fboitem/fboitem.qrc
+++ b/examples/quick/scenegraph/fboitem/fboitem.qrc
@@ -1,5 +1,7 @@
<RCC>
<qresource prefix="/scenegraph/fboitem">
<file>main.qml</file>
+ <file>shaders/checker.frag</file>
+ <file>shaders/+qsb/checker.frag</file>
</qresource>
</RCC>
diff --git a/examples/quick/scenegraph/fboitem/main.qml b/examples/quick/scenegraph/fboitem/main.qml
index 92fa99e847..1f1829deda 100644
--- a/examples/quick/scenegraph/fboitem/main.qml
+++ b/examples/quick/scenegraph/fboitem/main.qml
@@ -67,20 +67,7 @@ Item {
property size pixelSize: Qt.size(width / tileSize, height / tileSize);
- fragmentShader:
- "
- uniform lowp vec4 color1;
- uniform lowp vec4 color2;
- uniform highp vec2 pixelSize;
- varying highp vec2 qt_TexCoord0;
- void main() {
- highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
- if (tc.x != tc.y)
- gl_FragColor = color1;
- else
- gl_FragColor = color2;
- }
- "
+ fragmentShader: "qrc:/scenegraph/fboitem/shaders/checker.frag"
}
Renderer {
diff --git a/examples/quick/scenegraph/fboitem/shaders/+qsb/checker.frag b/examples/quick/scenegraph/fboitem/shaders/+qsb/checker.frag
new file mode 100644
index 0000000000..5037899d19
--- /dev/null
+++ b/examples/quick/scenegraph/fboitem/shaders/+qsb/checker.frag
Binary files differ
diff --git a/examples/quick/scenegraph/fboitem/shaders/checker.frag b/examples/quick/scenegraph/fboitem/shaders/checker.frag
new file mode 100644
index 0000000000..044b3bad58
--- /dev/null
+++ b/examples/quick/scenegraph/fboitem/shaders/checker.frag
@@ -0,0 +1,14 @@
+uniform lowp vec4 color1;
+uniform lowp vec4 color2;
+uniform highp vec2 pixelSize;
+
+varying highp vec2 qt_TexCoord0;
+
+void main()
+{
+ highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
+ if (tc.x != tc.y)
+ gl_FragColor = color1;
+ else
+ gl_FragColor = color2;
+}
diff --git a/examples/quick/scenegraph/fboitem/shaders/checker_rhi.frag b/examples/quick/scenegraph/fboitem/shaders/checker_rhi.frag
new file mode 100644
index 0000000000..1e4131d026
--- /dev/null
+++ b/examples/quick/scenegraph/fboitem/shaders/checker_rhi.frag
@@ -0,0 +1,22 @@
+#version 440
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float qt_Opacity;
+
+ vec4 color1;
+ vec4 color2;
+ vec2 pixelSize;
+} ubuf;
+
+layout(location = 0) in vec2 qt_TexCoord0;
+layout(location = 0) out vec4 fragColor;
+
+void main()
+{
+ vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * ubuf.pixelSize));
+ if (tc.x != tc.y)
+ fragColor = ubuf.color1;
+ else
+ fragColor = ubuf.color2;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/main.qml b/examples/quick/scenegraph/twotextureproviders/main.qml
index 296df766a1..b9e516f4b7 100644
--- a/examples/quick/scenegraph/twotextureproviders/main.qml
+++ b/examples/quick/scenegraph/twotextureproviders/main.qml
@@ -64,20 +64,9 @@ Item {
property size pixelSize: Qt.size(width / tileSize, height / tileSize);
- fragmentShader:
- "
- uniform lowp vec4 color1;
- uniform lowp vec4 color2;
- uniform highp vec2 pixelSize;
- varying highp vec2 qt_TexCoord0;
- void main() {
- highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
- if (tc.x != tc.y)
- gl_FragColor = color1;
- else
- gl_FragColor = color2;
- }
- "
+ // Will automatically pick either checker.frag or +qsb/checker.frag
+ // thanks to file selectors.
+ fragmentShader: "qrc:/scenegraph/twotextureproviders/shaders/checker.frag"
}
width: 320
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/checker.frag b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/checker.frag
new file mode 100644
index 0000000000..edcfad488b
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/checker.frag
Binary files differ
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.frag b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.frag
new file mode 100644
index 0000000000..7a5280ba08
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.frag
Binary files differ
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vert b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vert
new file mode 100644
index 0000000000..d643c7be6a
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vert
Binary files differ
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/checker.frag b/examples/quick/scenegraph/twotextureproviders/shaders/checker.frag
new file mode 100644
index 0000000000..044b3bad58
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/checker.frag
@@ -0,0 +1,14 @@
+uniform lowp vec4 color1;
+uniform lowp vec4 color2;
+uniform highp vec2 pixelSize;
+
+varying highp vec2 qt_TexCoord0;
+
+void main()
+{
+ highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
+ if (tc.x != tc.y)
+ gl_FragColor = color1;
+ else
+ gl_FragColor = color2;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/checker_rhi.frag b/examples/quick/scenegraph/twotextureproviders/shaders/checker_rhi.frag
new file mode 100644
index 0000000000..0932bc8c37
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/checker_rhi.frag
@@ -0,0 +1,25 @@
+#version 440
+
+layout(location = 0) in vec2 qt_TexCoord0;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+ // preamble as required by ShaderEffect
+ mat4 qt_Matrix;
+ float qt_Opacity;
+
+ // our custom members, connected automatically to QML object properties
+ vec4 color1;
+ vec4 color2;
+ vec2 pixelSize;
+} ubuf;
+
+void main()
+{
+ vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * ubuf.pixelSize));
+ if (tc.x != tc.y)
+ fragColor = ubuf.color1;
+ else
+ fragColor = ubuf.color2;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.frag b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.frag
new file mode 100644
index 0000000000..f67735312d
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.frag
@@ -0,0 +1,12 @@
+uniform lowp float qt_Opacity;
+uniform lowp sampler2D uSource1;
+uniform lowp sampler2D uSource2;
+
+varying highp vec2 vTexCoord;
+
+void main()
+{
+ lowp vec4 p1 = texture2D(uSource1, vTexCoord);
+ lowp vec4 p2 = texture2D(uSource2, vTexCoord);
+ gl_FragColor = (p1 * (1.0 - p2.a) + p2 * (1.0 - p1.a)) * qt_Opacity;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.vert b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.vert
new file mode 100644
index 0000000000..ac9f1364d6
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender.vert
@@ -0,0 +1,12 @@
+attribute highp vec4 aVertex;
+attribute highp vec2 aTexCoord;
+
+uniform highp mat4 qt_Matrix;
+
+varying highp vec2 vTexCoord;
+
+void main()
+{
+ gl_Position = qt_Matrix * aVertex;
+ vTexCoord = aTexCoord;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.frag b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.frag
new file mode 100644
index 0000000000..bc68160c1f
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.frag
@@ -0,0 +1,20 @@
+#version 440
+
+layout(location = 0) in vec2 vTexCoord;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float qt_Opacity;
+} ubuf;
+
+layout(binding = 1) uniform sampler2D uSource1;
+layout(binding = 2) uniform sampler2D uSource2;
+
+void main()
+{
+ lowp vec4 p1 = texture(uSource1, vTexCoord);
+ lowp vec4 p2 = texture(uSource2, vTexCoord);
+ fragColor = (p1 * (1.0 - p2.a) + p2 * (1.0 - p1.a)) * ubuf.qt_Opacity;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.vert b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.vert
new file mode 100644
index 0000000000..41000bde04
--- /dev/null
+++ b/examples/quick/scenegraph/twotextureproviders/shaders/xorblender_rhi.vert
@@ -0,0 +1,19 @@
+#version 440
+
+layout(location = 0) in vec4 aVertex;
+layout(location = 1) in vec2 aTexCoord;
+
+layout(location = 0) out vec2 vTexCoord;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 qt_Matrix;
+ float qt_Opacity;
+} ubuf;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ gl_Position = ubuf.qt_Matrix * aVertex;
+ vTexCoord = aTexCoord;
+}
diff --git a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc
index 1424333ce5..8022a77a1e 100644
--- a/examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc
+++ b/examples/quick/scenegraph/twotextureproviders/twotextureproviders.qrc
@@ -1,5 +1,13 @@
<RCC>
<qresource prefix="/scenegraph/twotextureproviders">
<file>main.qml</file>
+
+ <file>shaders/checker.frag</file>
+ <file>shaders/xorblender.vert</file>
+ <file>shaders/xorblender.frag</file>
+
+ <file>shaders/+qsb/checker.frag</file>
+ <file>shaders/+qsb/xorblender.vert</file>
+ <file>shaders/+qsb/xorblender.frag</file>
</qresource>
</RCC>
diff --git a/examples/quick/scenegraph/twotextureproviders/xorblender.cpp b/examples/quick/scenegraph/twotextureproviders/xorblender.cpp
index 8d7597addf..d5881b9adc 100644
--- a/examples/quick/scenegraph/twotextureproviders/xorblender.cpp
+++ b/examples/quick/scenegraph/twotextureproviders/xorblender.cpp
@@ -55,7 +55,7 @@
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLFunctions>
-#include <QtQuick/QSGSimpleMaterial>
+#include <QtQuick/QSGMaterial>
#include <QtQuick/QSGTexture>
#include <QtQuick/QSGGeometryNode>
#include <QtQuick/QSGTextureProvider>
@@ -67,64 +67,170 @@
* a custom material.
*/
-struct XorBlendState {
- QSGTexture *texture1;
- QSGTexture *texture2;
+class XorBlendMaterial : public QSGMaterial
+{
+public:
+ XorBlendMaterial();
+ QSGMaterialType *type() const override;
+ QSGMaterialShader *createShader() const override;
+ int compare(const QSGMaterial *other) const override;
+
+ struct {
+ QSGTexture *texture1 = nullptr;
+ QSGTexture *texture2 = nullptr;
+ } state;
};
-class XorBlendShader : public QSGSimpleMaterialShader<XorBlendState>
+class XorBlendShader : public QSGMaterialShader // for when the scenegraph is using OpenGL directly
{
- QSG_DECLARE_SIMPLE_SHADER(XorBlendShader, XorBlendState)
public:
+ XorBlendShader();
+ void initialize() override;
+ char const *const *attributeNames() const override;
+ void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
- 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 vTexCoord; \n"
- "void main() { \n"
- " gl_Position = qt_Matrix * aVertex; \n"
- " vTexCoord = aTexCoord; \n"
- "}";
- }
+private:
+ int m_matrix_id;
+ int m_opacity_id;
+};
- const char *fragmentShader() const override {
- return
- "uniform lowp float qt_Opacity; \n"
- "uniform lowp sampler2D uSource1; \n"
- "uniform lowp sampler2D uSource2; \n"
- "varying highp vec2 vTexCoord; \n"
- "void main() { \n"
- " lowp vec4 p1 = texture2D(uSource1, vTexCoord); \n"
- " lowp vec4 p2 = texture2D(uSource2, vTexCoord); \n"
- " gl_FragColor = (p1 * (1.0 - p2.a) + p2 * (1.0 - p1.a)) * qt_Opacity; \n"
- "}";
- }
+class XorBlendRhiShader : public QSGMaterialRhiShader // for when the scenegraph is using QRhi
+{
+public:
+ XorBlendRhiShader();
+ bool updateUniformData(RenderState &state,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+ void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
+};
+
+XorBlendMaterial::XorBlendMaterial()
+{
+ setFlag(SupportsRhiShader);
+ setFlag(Blending);
+}
+
+QSGMaterialShader *XorBlendMaterial::createShader() const
+{
+ if (flags().testFlag(RhiShaderWanted))
+ return new XorBlendRhiShader;
+ else
+ return new XorBlendShader;
+}
+
+QSGMaterialType *XorBlendMaterial::type() const
+{
+ static QSGMaterialType type;
+ return &type;
+}
+
+int XorBlendMaterial::compare(const QSGMaterial *o) const
+{
+ Q_ASSERT(o && type() == o->type());
+ const XorBlendMaterial *other = static_cast<const XorBlendMaterial *>(o);
+
+ if (!state.texture1 || !other->state.texture1)
+ return state.texture1 ? 1 : -1;
+
+ if (!state.texture2 || !other->state.texture2)
+ return state.texture2 ? -1 : 1;
+
+ if (int diff = state.texture1->comparisonKey() - other->state.texture1->comparisonKey())
+ return diff;
+
+ if (int diff = state.texture2->comparisonKey() - other->state.texture2->comparisonKey())
+ return diff;
- QList<QByteArray> attributes() const override {
- return QList<QByteArray>() << "aVertex" << "aTexCoord";
+ return 0;
+}
+
+XorBlendShader::XorBlendShader()
+{
+ setShaderSourceFile(QOpenGLShader::Vertex, QLatin1String(":/scenegraph/twotextureproviders/shaders/xorblender.vert"));
+ setShaderSourceFile(QOpenGLShader::Fragment, QLatin1String(":/scenegraph/twotextureproviders/shaders/xorblender.frag"));
+}
+
+void XorBlendShader::initialize()
+{
+ m_matrix_id = program()->uniformLocation("qt_Matrix");
+ m_opacity_id = program()->uniformLocation("qt_Opacity");
+ // The texture units never change, only the textures we bind to them so
+ // we set these once and for all here.
+ program()->setUniformValue("uSource1", 0); // GL_TEXTURE0
+ program()->setUniformValue("uSource2", 1); // GL_TEXTURE1
+}
+
+char const *const *XorBlendShader::attributeNames() const
+{
+ static char const *const attr[] = { "aVertex", "aTexCoord", nullptr };
+ return attr;
+}
+
+void XorBlendShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
+{
+ XorBlendMaterial *material = static_cast<XorBlendMaterial *>(newEffect);
+
+ if (state.isMatrixDirty())
+ program()->setUniformValue(m_matrix_id, state.combinedMatrix());
+
+ if (state.isOpacityDirty())
+ program()->setUniformValue(m_opacity_id, state.opacity());
+
+ QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
+ // We bind the textures in inverse order so that we leave the updateState
+ // function with GL_TEXTURE0 as the active texture unit. This is maintain
+ // the "contract" that updateState should not mess up the GL state beyond
+ // what is needed for this material.
+ f->glActiveTexture(GL_TEXTURE1);
+ material->state.texture2->bind();
+ f->glActiveTexture(GL_TEXTURE0);
+ material->state.texture1->bind();
+}
+
+XorBlendRhiShader::XorBlendRhiShader()
+{
+ setShaderFileName(VertexStage, QLatin1String(":/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vert"));
+ setShaderFileName(FragmentStage, QLatin1String(":/scenegraph/twotextureproviders/shaders/+qsb/xorblender.frag"));
+}
+
+bool XorBlendRhiShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *)
+{
+ bool changed = false;
+ QByteArray *buf = state.uniformData();
+ Q_ASSERT(buf->size() >= 68);
+
+ if (state.isMatrixDirty()) {
+ const QMatrix4x4 m = state.combinedMatrix();
+ memcpy(buf->data(), m.constData(), 64);
+ changed = true;
}
- void updateState(const XorBlendState *state, const XorBlendState *) override {
- QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
- // We bind the textures in inverse order so that we leave the updateState
- // function with GL_TEXTURE0 as the active texture unit. This is maintain
- // the "contract" that updateState should not mess up the GL state beyond
- // what is needed for this material.
- f->glActiveTexture(GL_TEXTURE1);
- state->texture2->bind();
- f->glActiveTexture(GL_TEXTURE0);
- state->texture1->bind();
+ if (state.isOpacityDirty()) {
+ const float opacity = state.opacity();
+ memcpy(buf->data() + 64, &opacity, 4);
+ changed = true;
}
- void resolveUniforms() override {
- // The texture units never change, only the texturess we bind to them so
- // we set these once and for all here.
- program()->setUniformValue("uSource1", 0); // GL_TEXTURE0
- program()->setUniformValue("uSource2", 1); // GL_TEXTURE1
+ return changed;
+}
+
+void XorBlendRhiShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
+ QSGMaterial *newMaterial, QSGMaterial *)
+{
+ Q_UNUSED(state);
+
+ XorBlendMaterial *mat = static_cast<XorBlendMaterial *>(newMaterial);
+ switch (binding) { // the binding for the sampler2Ds in the fragment shader
+ case 1:
+ *texture = mat->state.texture1;
+ break;
+ case 2:
+ *texture = mat->state.texture2;
+ break;
+ default:
+ return;
}
-};
+}
/* The rendering is split into two nodes. The top-most node is not actually
* rendering anything, but is responsible for managing the texture providers.
@@ -148,10 +254,7 @@ public:
setFlag(QSGNode::UsePreprocess, true);
// Set up material so it is all set for later..
- m_material = XorBlendShader::createMaterial();
- m_material->state()->texture1 = nullptr;
- m_material->state()->texture2 = nullptr;
- m_material->setFlag(QSGMaterial::Blending);
+ m_material = new XorBlendMaterial;
m_node.setMaterial(m_material);
m_node.setFlag(QSGNode::OwnsMaterial);
@@ -166,25 +269,24 @@ public:
}
void preprocess() override {
- XorBlendState *state = m_material->state();
// Update the textures from the providers, calling into QSGDynamicTexture if required
if (m_provider1) {
- state->texture1 = m_provider1->texture();
- if (QSGDynamicTexture *dt1 = qobject_cast<QSGDynamicTexture *>(state->texture1))
+ m_material->state.texture1 = m_provider1->texture();
+ if (QSGDynamicTexture *dt1 = qobject_cast<QSGDynamicTexture *>(m_material->state.texture1))
dt1->updateTexture();
}
if (m_provider2) {
- state->texture2 = m_provider2->texture();
- if (QSGDynamicTexture *dt2 = qobject_cast<QSGDynamicTexture *>(state->texture2))
+ m_material->state.texture2 = m_provider2->texture();
+ if (QSGDynamicTexture *dt2 = qobject_cast<QSGDynamicTexture *>(m_material->state.texture2))
dt2->updateTexture();
}
// Remove node from the scene graph if it is there and either texture is missing...
- if (m_node.parent() && (!state->texture1 || !state->texture2))
+ if (m_node.parent() && (!m_material->state.texture1 || !m_material->state.texture2))
removeChildNode(&m_node);
// Add it if it is not already there and both textures are present..
- else if (!m_node.parent() && state->texture1 && state->texture2)
+ else if (!m_node.parent() && m_material->state.texture1 && m_material->state.texture2)
appendChildNode(&m_node);
}
@@ -206,7 +308,7 @@ public slots:
private:
QRectF m_rect;
- QSGSimpleMaterial<XorBlendState> *m_material;
+ XorBlendMaterial *m_material;
QSGGeometryNode m_node;
QPointer<QSGTextureProvider> m_provider1;
QPointer<QSGTextureProvider> m_provider2;
diff --git a/examples/quick/text/styledtext-layout.qml b/examples/quick/text/styledtext-layout.qml
index fe7b40b89b..631a37b493 100644
--- a/examples/quick/text/styledtext-layout.qml
+++ b/examples/quick/text/styledtext-layout.qml
@@ -78,8 +78,27 @@ Rectangle {
line.y -= height - margin
line.x = width / 2 + margin
}
+
+ if (line.isLast) {
+ lastLineMarker.x = line.x + line.implicitWidth
+ lastLineMarker.y = line.y + (line.height - lastLineMarker.height) / 2
+ }
}
//! [layout]
+
+ Rectangle {
+ id: lastLineMarker
+ color: "#44cccccc"
+ width: theEndText.width + margin
+ height: theEndText.height + margin
+
+ Text {
+ id: theEndText
+ text: "THE\nEND"
+ anchors.centerIn: parent
+ font.pixelSize: myText.font.pixelSize / 2
+ }
+ }
}
}
diff --git a/examples/quick/views/doc/src/views.qdoc b/examples/quick/views/doc/src/views.qdoc
index 16237a68e0..3e23f7657a 100644
--- a/examples/quick/views/doc/src/views.qdoc
+++ b/examples/quick/views/doc/src/views.qdoc
@@ -39,13 +39,13 @@
\include examples-run.qdocinc
- \section1 GridView and PathView
+ \section1 Using GridView and PathView
\e GridView and \e PathView demonstrate usage of these types to display
views.
\snippet views/gridview/gridview-example.qml 0
- \section1 Dynamic List
+ \section1 Using Dynamic List
\e{Dynamic List} demonstrates animation of runtime additions and removals to
a \l ListView.
@@ -66,12 +66,12 @@
\snippet views/listview/expandingdelegates.qml 2
\snippet views/listview/expandingdelegates.qml 3
- \section1 Highlight
+ \section1 Using Highlight
\e Highlight demonstrates adding a custom highlight to a ListView.
\snippet views/listview/highlight.qml 0
- \section1 Highlight Ranges
+ \section1 Using Highlight Ranges
\e{Highlight Ranges} shows the three different highlight range modes of
ListView.
@@ -79,13 +79,13 @@
\snippet views/listview/highlightranges.qml 1
\snippet views/listview/highlightranges.qml 2
- \section1 Sections
+ \section1 Using Sections
\e Sections demonstrates the various section headers and footers available
to \l ListView.
\snippet views/listview/sections.qml 0
- \section1 Packages
+ \section1 Using Packages
\e Packages use the \l [QML]{Package} type to transition delegates between
two views.
@@ -100,13 +100,13 @@
\snippet views/package/view.qml 0
- \section1 ObjectModel
+ \section1 Using ObjectModel
\e ObjectModel uses an ObjectModel for the model instead of a \l ListModel.
\snippet views/objectmodel/objectmodel.qml 0
- \section1 Display Margins
+ \section1 Using Display Margins
\e{Display Margins} uses delegates to display items and implements a simple
header and footer components.
diff --git a/src/imports/labsmodels/labsmodels.pro b/src/imports/labsmodels/labsmodels.pro
index 5ef2ad76f6..c35e5f963d 100644
--- a/src/imports/labsmodels/labsmodels.pro
+++ b/src/imports/labsmodels/labsmodels.pro
@@ -3,9 +3,27 @@ TARGET = labsmodelsplugin
TARGETPATH = Qt/labs/qmlmodels
IMPORT_VERSION = 1.0
+QT = qml-private qmlmodels-private
+
SOURCES += \
plugin.cpp
-QT = qml-private qmlmodels-private
+qtConfig(qml-table-model) {
+ SOURCES += \
+ $$PWD/qqmltablemodel.cpp \
+ $$PWD/qqmltablemodelcolumn.cpp
+
+ HEADERS += \
+ $$PWD/qqmltablemodel_p.h \
+ $$PWD/qqmltablemodelcolumn_p.h
+}
+
+qtConfig(qml-delegate-model) {
+ SOURCES += \
+ qqmldelegatecomponent.cpp
+
+ HEADERS += \
+ qqmldelegatecomponent_p.h
+}
load(qml_plugin)
diff --git a/src/imports/labsmodels/plugin.cpp b/src/imports/labsmodels/plugin.cpp
index cebc1dc920..f1d1dd20b0 100644
--- a/src/imports/labsmodels/plugin.cpp
+++ b/src/imports/labsmodels/plugin.cpp
@@ -42,6 +42,14 @@
#include <private/qqmlmodelsmodule_p.h>
+#if QT_CONFIG(qml_table_model)
+#include "qqmltablemodel_p.h"
+#include "qqmltablemodelcolumn_p.h"
+#endif
+#if QT_CONFIG(qml_delegate_model)
+#include "qqmldelegatecomponent_p.h"
+#endif
+
QT_BEGIN_NAMESPACE
/*!
@@ -70,7 +78,13 @@ public:
void registerTypes(const char *uri) override
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.qmlmodels"));
- QQmlModelsModule::defineLabsModule();
+
+#if QT_CONFIG(qml_delegate_model)
+ qmlRegisterTypesAndRevisions<QQmlDelegateChooser, QQmlDelegateChoice>(uri, 1);
+#endif
+#if QT_CONFIG(qml_table_model)
+ qmlRegisterTypesAndRevisions<QQmlTableModel, QQmlTableModelColumn>(uri, 1);
+#endif
qmlRegisterModule(uri, 1, 0);
}
diff --git a/src/qmlmodels/qqmldelegatecomponent.cpp b/src/imports/labsmodels/qqmldelegatecomponent.cpp
index cc3b38ec93..b3c9afbb97 100644
--- a/src/qmlmodels/qqmldelegatecomponent.cpp
+++ b/src/imports/labsmodels/qqmldelegatecomponent.cpp
@@ -42,22 +42,6 @@
QT_BEGIN_NAMESPACE
-QQmlAbstractDelegateComponent::QQmlAbstractDelegateComponent(QObject *parent)
- : QQmlComponent(parent)
-{
-}
-
-QQmlAbstractDelegateComponent::~QQmlAbstractDelegateComponent()
-{
-}
-
-QVariant QQmlAbstractDelegateComponent::value(QQmlAdaptorModel *adaptorModel, int row, int column, const QString &role) const
-{
- if (!adaptorModel)
- return QVariant();
- return adaptorModel->value(adaptorModel->indexAt(row, column), role);
-}
-
/*!
\qmltype DelegateChoice
\instantiates QQmlDelegateChoice
diff --git a/src/qmlmodels/qqmldelegatecomponent_p.h b/src/imports/labsmodels/qqmldelegatecomponent_p.h
index 86ad04d2e3..4c39dc0d0a 100644
--- a/src/qmlmodels/qqmldelegatecomponent_p.h
+++ b/src/imports/labsmodels/qqmldelegatecomponent_p.h
@@ -51,40 +51,15 @@
// We mean it.
//
-#include <private/qtqmlmodelsglobal_p.h>
-#include <qqmlcomponent.h>
+#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
+#include <QtQmlModels/private/qqmlabstractdelegatecomponent_p.h>
+#include <QtQml/qqmlcomponent.h>
QT_REQUIRE_CONFIG(qml_delegate_model);
QT_BEGIN_NAMESPACE
-// TODO: consider making QQmlAbstractDelegateComponent public API
-class QQmlAbstractDelegateComponentPrivate;
-class QQmlAdaptorModel;
-class Q_QMLMODELS_PRIVATE_EXPORT QQmlAbstractDelegateComponent : public QQmlComponent
-{
- Q_OBJECT
- QML_NAMED_ELEMENT(AbstractDelegateComponent)
- QML_UNCREATABLE("Cannot create instance of abstract class AbstractDelegateComponent.")
-
-public:
- QQmlAbstractDelegateComponent(QObject *parent = nullptr);
- ~QQmlAbstractDelegateComponent() override;
-
- virtual QQmlComponent *delegate(QQmlAdaptorModel *adaptorModel, int row, int column = 0) const = 0;
-
-signals:
- void delegateChanged();
-
-protected:
- QVariant value(QQmlAdaptorModel *adaptorModel,int row, int column, const QString &role) const;
-
-private:
- Q_DECLARE_PRIVATE(QQmlAbstractDelegateComponent)
- Q_DISABLE_COPY(QQmlAbstractDelegateComponent)
-};
-
-class Q_QMLMODELS_PRIVATE_EXPORT QQmlDelegateChoice : public QObject
+class QQmlDelegateChoice : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
@@ -124,7 +99,7 @@ private:
QQmlComponent *m_delegate = nullptr;
};
-class Q_QMLMODELS_PRIVATE_EXPORT QQmlDelegateChooser : public QQmlAbstractDelegateComponent
+class QQmlDelegateChooser : public QQmlAbstractDelegateComponent
{
Q_OBJECT
Q_PROPERTY(QString role READ role WRITE setRole NOTIFY roleChanged)
diff --git a/src/qmlmodels/qqmltablemodel.cpp b/src/imports/labsmodels/qqmltablemodel.cpp
index f190ad86b1..f190ad86b1 100644
--- a/src/qmlmodels/qqmltablemodel.cpp
+++ b/src/imports/labsmodels/qqmltablemodel.cpp
diff --git a/src/qmlmodels/qqmltablemodel_p.h b/src/imports/labsmodels/qqmltablemodel_p.h
index 4b667e1073..6bf3e6df19 100644
--- a/src/qmlmodels/qqmltablemodel_p.h
+++ b/src/imports/labsmodels/qqmltablemodel_p.h
@@ -51,11 +51,12 @@
// We mean it.
//
+#include "qqmltablemodelcolumn_p.h"
+
#include <QtCore/QObject>
#include <QtCore/QAbstractTableModel>
#include <QtQml/qqml.h>
#include <QtQmlModels/private/qtqmlmodelsglobal_p.h>
-#include <QtQmlModels/private/qqmltablemodelcolumn_p.h>
#include <QtQml/QJSValue>
#include <QtQml/QQmlListProperty>
@@ -63,7 +64,7 @@ QT_REQUIRE_CONFIG(qml_table_model);
QT_BEGIN_NAMESPACE
-class Q_QMLMODELS_PRIVATE_EXPORT QQmlTableModel : public QAbstractTableModel, public QQmlParserStatus
+class QQmlTableModel : public QAbstractTableModel, public QQmlParserStatus
{
Q_OBJECT
Q_PROPERTY(int columnCount READ columnCount NOTIFY columnCountChanged FINAL)
diff --git a/src/qmlmodels/qqmltablemodelcolumn.cpp b/src/imports/labsmodels/qqmltablemodelcolumn.cpp
index 93da0642de..93da0642de 100644
--- a/src/qmlmodels/qqmltablemodelcolumn.cpp
+++ b/src/imports/labsmodels/qqmltablemodelcolumn.cpp
diff --git a/src/qmlmodels/qqmltablemodelcolumn_p.h b/src/imports/labsmodels/qqmltablemodelcolumn_p.h
index 33f32ccb68..a18f21ab4f 100644
--- a/src/qmlmodels/qqmltablemodelcolumn_p.h
+++ b/src/imports/labsmodels/qqmltablemodelcolumn_p.h
@@ -60,7 +60,7 @@ QT_REQUIRE_CONFIG(qml_table_model);
QT_BEGIN_NAMESPACE
-class Q_QMLMODELS_PRIVATE_EXPORT QQmlTableModelColumn : public QObject
+class QQmlTableModelColumn : public QObject
{
Q_OBJECT
Q_PROPERTY(QJSValue display READ display WRITE setDisplay NOTIFY displayChanged FINAL)
diff --git a/src/imports/layouts/qquicklinearlayout.cpp b/src/imports/layouts/qquicklinearlayout.cpp
index af7b1b7340..c6c9685ae2 100644
--- a/src/imports/layouts/qquicklinearlayout.cpp
+++ b/src/imports/layouts/qquicklinearlayout.cpp
@@ -283,8 +283,11 @@ Qt::LayoutDirection QQuickGridLayoutBase::layoutDirection() const
void QQuickGridLayoutBase::setLayoutDirection(Qt::LayoutDirection dir)
{
Q_D(QQuickGridLayoutBase);
+ if (d->m_layoutDirection == dir)
+ return;
d->m_layoutDirection = dir;
invalidate();
+ emit layoutDirectionChanged();
}
Qt::LayoutDirection QQuickGridLayoutBase::effectiveLayoutDirection() const
@@ -524,6 +527,7 @@ void QQuickGridLayout::setColumnSpacing(qreal spacing)
d->engine.setSpacing(spacing, Qt::Horizontal);
invalidate();
+ emit columnSpacingChanged();
}
/*!
@@ -546,6 +550,7 @@ void QQuickGridLayout::setRowSpacing(qreal spacing)
d->engine.setSpacing(spacing, Qt::Vertical);
invalidate();
+ emit rowSpacingChanged();
}
/*!
@@ -817,6 +822,7 @@ void QQuickLinearLayout::setSpacing(qreal space)
d->engine.setSpacing(space, Qt::Horizontal | Qt::Vertical);
invalidate();
+ emit spacingChanged();
}
void QQuickLinearLayout::insertLayoutItems()
diff --git a/src/imports/qtqml/qmldir b/src/imports/qtqml/qmldir
deleted file mode 100644
index a8adb2010d..0000000000
--- a/src/imports/qtqml/qmldir
+++ /dev/null
@@ -1,7 +0,0 @@
-module QtQml
-plugin qmlplugin
-classname QtQmlPlugin
-typeinfo plugins.qmltypes
-import QtQml.Models
-import QtQml.WorkerScript
-designersupported
diff --git a/src/imports/qtqml/qtqml.pro b/src/imports/qtqml/qtqml.pro
index 7a5169b8fc..902f0b1247 100644
--- a/src/imports/qtqml/qtqml.pro
+++ b/src/imports/qtqml/qtqml.pro
@@ -9,4 +9,15 @@ SOURCES += \
# In Qt6 we won't need qmlmodels-private here
QT = qml-private qmlmodels-private
+DYNAMIC_QMLDIR = \
+ "module QtQml" \
+ "plugin qmlplugin" \
+ "classname QtQmlPlugin" \
+ "typeinfo plugins.qmltypes" \
+ "designersupported" \
+ "import QtQml.Models"
+
+qtConfig(qml-worker-script): DYNAMIC_QMLDIR += \
+ "import QtQml.WorkerScript"
+
load(qml_plugin)
diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml
index e7669fd03d..6e075d8792 100644
--- a/src/imports/testlib/TestCase.qml
+++ b/src/imports/testlib/TestCase.qml
@@ -1631,7 +1631,7 @@ Item {
TestCase {
name: "ItemTests"
- when: area.pressed
+ when: windowShown
id: test1
function test_touch() {
diff --git a/src/imports/window/plugin.cpp b/src/imports/window/plugin.cpp
index a331708e87..2ef4bcb2f1 100644
--- a/src/imports/window/plugin.cpp
+++ b/src/imports/window/plugin.cpp
@@ -39,7 +39,7 @@
#include <QtQml/qqmlextensionplugin.h>
-#include <private/qquickwindowmodule_p.h>
+#include "plugin.h"
QT_BEGIN_NAMESPACE
@@ -69,7 +69,13 @@ public:
void registerTypes(const char *uri) override
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("QtQuick.Window"));
- QQuickWindowModule::defineModule();
+
+ qmlRegisterTypesAndRevisions<
+ QWindowForeign,
+ QQuickWindowForeign,
+ QQuickWindowQmlImplForeign,
+ QQuickScreenForeign,
+ QQuickScreenInfoForeign>(uri, 2);
qmlRegisterModule(uri, 2, 15);
}
diff --git a/src/imports/window/plugin.h b/src/imports/window/plugin.h
new file mode 100644
index 0000000000..9f58ca9ac7
--- /dev/null
+++ b/src/imports/window/plugin.h
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQuick module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PLUGIN_H
+#define PLUGIN_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qwindow_p.h>
+#include <QtQuick/private/qquickwindow_p.h>
+#include <QtQuick/private/qquickwindowattached_p.h>
+#include <QtQuick/private/qquickscreen_p.h>
+#include <QtQuick/private/qquickwindowmodule_p.h>
+#include <QtQml/qqml.h>
+
+QT_BEGIN_NAMESPACE
+
+struct QWindowForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QWindow)
+ QML_ANONYMOUS
+ QML_ADDED_IN_MINOR_VERSION(1)
+};
+
+struct QQuickWindowForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QQuickWindow)
+ QML_NAMED_ELEMENT(Window)
+ QML_ADDED_IN_MINOR_VERSION(0)
+ QML_REMOVED_IN_MINOR_VERSION(1)
+};
+
+struct QQuickWindowForeignAttached
+{
+ Q_GADGET
+ QML_FOREIGN(QQuickWindowAttached)
+ QML_ANONYMOUS
+};
+
+struct QQuickScreenInfoForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QQuickScreenInfo)
+ QML_NAMED_ELEMENT(ScreenInfo)
+ QML_ADDED_IN_MINOR_VERSION(3)
+ QML_UNCREATABLE("ScreenInfo can only be used via the attached property.")
+};
+
+struct QQuickScreenForeignAttached
+{
+ Q_GADGET
+ QML_FOREIGN(QQuickScreenAttached)
+ QML_ANONYMOUS
+};
+
+struct QQuickScreenForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QQuickScreen)
+ QML_NAMED_ELEMENT(Screen)
+ QML_UNCREATABLE("Screen can only be used via the attached property.")
+};
+
+struct QQuickWindowQmlImplForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QQuickWindowQmlImpl)
+ QML_NAMED_ELEMENT(Window)
+ QML_ADDED_IN_MINOR_VERSION(1)
+};
+
+QT_END_NAMESPACE
+
+#endif // PLUGIN_H
diff --git a/src/imports/window/window.pro b/src/imports/window/window.pro
index 77bd9518e9..a8ce79f275 100644
--- a/src/imports/window/window.pro
+++ b/src/imports/window/window.pro
@@ -6,6 +6,9 @@ IMPORT_VERSION = 2.$$QT_MINOR_VERSION
SOURCES += \
plugin.cpp
+HEADERS += \
+ plugin.h
+
QT += quick-private qml-private
load(qml_plugin)
diff --git a/src/particles/qquickimageparticle.cpp b/src/particles/qquickimageparticle.cpp
index bd3865f42f..4ce8186c7c 100644
--- a/src/particles/qquickimageparticle.cpp
+++ b/src/particles/qquickimageparticle.cpp
@@ -1104,6 +1104,7 @@ void fillUniformArrayFromImage(float* array, const QImage& img, int size)
QQuickImageParticle::QQuickImageParticle(QQuickItem* parent)
: QQuickParticlePainter(parent)
, m_color_variation(0.0)
+ , m_outgoingNode(nullptr)
, m_material(nullptr)
, m_alphaVariation(0.0)
, m_alpha(1.0)
@@ -1149,6 +1150,8 @@ void QQuickImageParticle::sceneGraphInvalidated()
{
m_nodes.clear();
m_material = nullptr;
+ delete m_outgoingNode;
+ m_outgoingNode = nullptr;
}
void QQuickImageParticle::setImage(const QUrl &image)
@@ -1931,8 +1934,11 @@ QSGNode *QQuickImageParticle::updatePaintNode(QSGNode *node, UpdatePaintNodeData
}
if (m_pleaseReset){
- if (node)
- delete node;
+ // Cannot just destroy the node and then return null (in case image
+ // loading is still in progress). Rather, keep track of the old node
+ // until we have a new one.
+ delete m_outgoingNode;
+ m_outgoingNode = node;
node = nullptr;
m_lastLevel = perfLevel;
@@ -1946,6 +1952,9 @@ QSGNode *QQuickImageParticle::updatePaintNode(QSGNode *node, UpdatePaintNodeData
m_pleaseReset = false;
m_startedImageLoading = 0;//Cancel a part-way build (may still have a pending load)
+ } else if (!m_material) {
+ delete node;
+ node = nullptr;
}
if (m_system && m_system->isRunning() && !m_system->isPaused()){
@@ -1959,6 +1968,11 @@ QSGNode *QQuickImageParticle::updatePaintNode(QSGNode *node, UpdatePaintNodeData
}
}
+ if (!node) {
+ node = m_outgoingNode;
+ m_outgoingNode = nullptr;
+ }
+
return node;
}
diff --git a/src/particles/qquickimageparticle_p.h b/src/particles/qquickimageparticle_p.h
index 83fc75e9c9..fdb404861c 100644
--- a/src/particles/qquickimageparticle_p.h
+++ b/src/particles/qquickimageparticle_p.h
@@ -390,6 +390,7 @@ private:
QColor m_color;
qreal m_color_variation;
+ QSGNode *m_outgoingNode;
QHash<int, QSGGeometryNode *> m_nodes;
QHash<int, int> m_idxStarts;//TODO: Proper resizing will lead to needing a spriteEngine per particle - do this after sprite engine gains transparent sharing?
QList<QPair<int, int> > m_startsIdx;//Same data, optimized for alternate retrieval
diff --git a/src/qml/common/qqmlapiversion_p.h b/src/qml/common/qqmlapiversion_p.h
index 576619c518..4baf37e11c 100644
--- a/src/qml/common/qqmlapiversion_p.h
+++ b/src/qml/common/qqmlapiversion_p.h
@@ -51,6 +51,6 @@
// We mean it.
//
-#define Q_QML_PRIVATE_API_VERSION 6
+#define Q_QML_PRIVATE_API_VERSION 7
#endif // QQMLAPIVERSION_P_H
diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h
index 11de506a53..7abf530996 100644
--- a/src/qml/common/qv4compileddata_p.h
+++ b/src/qml/common/qv4compileddata_p.h
@@ -65,6 +65,7 @@
#include <private/qendian_p.h>
#include <private/qv4staticvalue_p.h>
#include <functional>
+#include <limits.h>
QT_BEGIN_NAMESPACE
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp
index 940d61ba97..9623d2ed58 100644
--- a/src/qml/compiler/qqmlirbuilder.cpp
+++ b/src/qml/compiler/qqmlirbuilder.cpp
@@ -250,9 +250,11 @@ QString Object::appendAlias(Alias *alias, const QString &aliasName, bool isDefau
if (!target)
target = this;
- for (Alias *p = target->aliases->first; p; p = p->next)
- if (p->nameIndex == alias->nameIndex)
- return tr("Duplicate alias name");
+ auto aliasWithSameName = std::find_if(target->aliases->begin(), target->aliases->end(), [&alias](const Alias &targetAlias){
+ return targetAlias.nameIndex == alias->nameIndex;
+ });
+ if (aliasWithSameName != target->aliases->end())
+ return tr("Duplicate alias name");
if (aliasName.constData()->isUpper())
return tr("Alias names cannot begin with an upper case letter");
diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h
index 4279f5b768..ab0ddf6ef8 100644
--- a/src/qml/compiler/qqmlirbuilder_p.h
+++ b/src/qml/compiler/qqmlirbuilder_p.h
@@ -158,6 +158,13 @@ struct PoolList
}
struct Iterator {
+ // turn Iterator into a proper iterator
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = T;
+ using difference_type = ptrdiff_t;
+ using pointer = T *;
+ using reference = T &;
+
T *ptr;
explicit Iterator(T *p) : ptr(p) {}
@@ -178,8 +185,15 @@ struct PoolList
return *ptr;
}
- void operator++() {
+ Iterator& operator++() {
ptr = ptr->next;
+ return *this;
+ }
+
+ Iterator operator++(int) {
+ Iterator that {ptr};
+ ptr = ptr->next;
+ return that;
}
bool operator==(const Iterator &rhs) const {
@@ -193,6 +207,8 @@ struct PoolList
Iterator begin() { return Iterator(first); }
Iterator end() { return Iterator(nullptr); }
+
+ using iterator = Iterator;
};
struct Object;
diff --git a/src/qml/compiler/qv4instr_moth_p.h b/src/qml/compiler/qv4instr_moth_p.h
index c0dd696b8a..254e1c46e9 100644
--- a/src/qml/compiler/qv4instr_moth_p.h
+++ b/src/qml/compiler/qv4instr_moth_p.h
@@ -348,7 +348,7 @@ QT_BEGIN_NAMESPACE
#endif
#endif
-#define MOTH_INSTR_ALIGN_MASK (Q_ALIGNOF(QV4::Moth::Instr) - 1)
+#define MOTH_INSTR_ALIGN_MASK (alignof(QV4::Moth::Instr) - 1)
#define MOTH_INSTR_ENUM(I) I, I##_Wide,
#define MOTH_INSTR_SIZE(I) (sizeof(QV4::Moth::Instr::instr_##I))
diff --git a/src/qml/doc/images/cpp-qml-integration-flowchart.odg b/src/qml/doc/images/cpp-qml-integration-flowchart.odg
index f24021635e..026f89fd73 100644
--- a/src/qml/doc/images/cpp-qml-integration-flowchart.odg
+++ b/src/qml/doc/images/cpp-qml-integration-flowchart.odg
Binary files differ
diff --git a/src/qml/doc/images/cpp-qml-integration-flowchart.png b/src/qml/doc/images/cpp-qml-integration-flowchart.png
index 3649ff9e41..97f075f51e 100644
--- a/src/qml/doc/images/cpp-qml-integration-flowchart.png
+++ b/src/qml/doc/images/cpp-qml-integration-flowchart.png
Binary files differ
diff --git a/src/qml/doc/src/external-resources.qdoc b/src/qml/doc/src/external-resources.qdoc
index 68c5ab4664..17ac7693bc 100644
--- a/src/qml/doc/src/external-resources.qdoc
+++ b/src/qml/doc/src/external-resources.qdoc
@@ -45,7 +45,7 @@
\title Mozilla Developer Network Date Reference
*/
/*!
- \externalpage hhttps://www.froglogic.com/squish/gui-testing
+ \externalpage https://www.froglogic.com/squish/gui-testing
\title Squish
*/
/*!
diff --git a/src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc b/src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc
index c4ecaf367c..401e099ebf 100644
--- a/src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc
+++ b/src/qml/doc/src/qmllanguageref/syntax/objectattributes.qdoc
@@ -464,22 +464,24 @@ Unlike an ordinary property, an alias has the following restrictions:
must be provided when the alias is first declared.
\li It cannot refer to \l {Attached Properties and Attached Signal Handlers}
{attached properties}.
-\li It cannot refer to grouped properties; the following code will not work:
+\li It cannot refer to properties inside a hierarchy with depth 3 or greater. The
+ following code will not work:
\code
- property alias color: rectangle.border.color
+ property alias color: myItem.myRect.border.color
- Rectangle {
- id: rectangle
+ Item {
+ id: myItem
+ property Rectangle myRect
}
\endcode
- However, aliases to \l {QML Basic Types}{value type} properties do work:
+ However, aliases to properties that are up to two levels deep will work.
+
\code
- property alias rectX: object.rectProperty.x
+ property alias color: rectangle.border.color
- Item {
- id: object
- property rect rectProperty
+ Rectangle {
+ id: rectangle
}
\endcode
\endlist
diff --git a/src/qml/jit/qv4assemblercommon.cpp b/src/qml/jit/qv4assemblercommon.cpp
index 800ee22cd7..e75f35a665 100644
--- a/src/qml/jit/qv4assemblercommon.cpp
+++ b/src/qml/jit/qv4assemblercommon.cpp
@@ -96,8 +96,9 @@ private:
static void printDisassembledOutputWithCalls(QByteArray processedOutput,
const QHash<const void*, const char*>& functions)
{
- for (QHash<const void*, const char*>::ConstIterator it = functions.begin(), end = functions.end();
- it != end; ++it) {
+ const auto symbols = Runtime::symbolTable();
+ const QByteArray padding(" ; ");
+ for (auto it = functions.begin(), end = functions.end(); it != end; ++it) {
const QByteArray ptrString = "0x" + QByteArray::number(quintptr(it.key()), 16);
int idx = 0;
while (idx >= 0) {
@@ -107,7 +108,9 @@ static void printDisassembledOutputWithCalls(QByteArray processedOutput,
idx = processedOutput.indexOf('\n', idx);
if (idx < 0)
break;
- processedOutput = processedOutput.insert(idx, QByteArrayLiteral(" ; ") + it.value());
+ const char *functionName = it.value();
+ processedOutput = processedOutput.insert(
+ idx, padding + QByteArray(functionName ? functionName : symbols[it.key()]));
}
}
@@ -302,27 +305,29 @@ void JIT::PlatformAssemblerCommon::passPointerAsArg(void *ptr, int arg)
storePtr(TrustedImmPtr(ptr), argStackAddress(arg));
}
-void PlatformAssemblerCommon::callRuntime(const char *functionName, const void *funcPtr)
+void PlatformAssemblerCommon::callRuntime(const void *funcPtr, const char *functionName)
{
#ifndef QT_NO_DEBUG
Q_ASSERT(remainingArgcForCall == 0);
remainingArgcForCall = NoCall;
#endif
- callRuntimeUnchecked(functionName, funcPtr);
+ callRuntimeUnchecked(funcPtr, functionName);
if (argcOnStackForCall > 0) {
addPtr(TrustedImm32(argcOnStackForCall), StackPointerRegister);
argcOnStackForCall = 0;
}
}
-void PlatformAssemblerCommon::callRuntimeUnchecked(const char *functionName, const void *funcPtr)
+void PlatformAssemblerCommon::callRuntimeUnchecked(const void *funcPtr, const char *functionName)
{
+ Q_ASSERT(functionName || Runtime::symbolTable().contains(funcPtr));
functions.insert(funcPtr, functionName);
callAbsolute(funcPtr);
}
-void PlatformAssemblerCommon::tailCallRuntime(const char *functionName, const void *funcPtr)
+void PlatformAssemblerCommon::tailCallRuntime(const void *funcPtr, const char *functionName)
{
+ Q_ASSERT(functionName || Runtime::symbolTable().contains(funcPtr));
functions.insert(funcPtr, functionName);
setTailCallArg(EngineRegister, 1);
setTailCallArg(CppStackFrameRegister, 0);
diff --git a/src/qml/jit/qv4assemblercommon_p.h b/src/qml/jit/qv4assemblercommon_p.h
index b18d082be6..ead1e757de 100644
--- a/src/qml/jit/qv4assemblercommon_p.h
+++ b/src/qml/jit/qv4assemblercommon_p.h
@@ -706,9 +706,9 @@ public:
void passCppFrameAsArg(int arg);
void passInt32AsArg(int value, int arg);
void passPointerAsArg(void *ptr, int arg);
- void callRuntime(const char *functionName, const void *funcPtr);
- void callRuntimeUnchecked(const char *functionName, const void *funcPtr);
- void tailCallRuntime(const char *functionName, const void *funcPtr);
+ void callRuntime(const void *funcPtr, const char *functionName = nullptr);
+ void callRuntimeUnchecked(const void *funcPtr, const char *functionName = nullptr);
+ void tailCallRuntime(const void *funcPtr, const char *functionName = nullptr);
void setTailCallArg(RegisterID src, int arg);
Address jsAlloca(int slotCount);
void storeInt32AsValue(int srcInt, Address destAddr);
diff --git a/src/qml/jit/qv4baselineassembler.cpp b/src/qml/jit/qv4baselineassembler.cpp
index 59de86a85d..25652e0a63 100644
--- a/src/qml/jit/qv4baselineassembler.cpp
+++ b/src/qml/jit/qv4baselineassembler.cpp
@@ -61,7 +61,8 @@ namespace JIT {
#define ASM_GENERATE_RUNTIME_CALL(function, destination) \
pasm()->GENERATE_RUNTIME_CALL(function, destination)
-#define callHelper(x) PlatformAssemblerCommon::callRuntimeUnchecked(#x, reinterpret_cast<void *>(&x))
+#define callHelper(x) \
+ PlatformAssemblerCommon::callRuntimeUnchecked(reinterpret_cast<void *>(&x), #x)
const QV4::Value::ValueTypeInternal IntegerTag = QV4::Value::ValueTypeInternal::Integer;
@@ -83,10 +84,9 @@ public:
: PlatformAssemblerCommon(constantTable)
{}
- void callRuntime(const char *functionName, const void *funcPtr,
- CallResultDestination dest)
+ void callRuntime(const void *funcPtr, CallResultDestination dest)
{
- PlatformAssemblerCommon::callRuntime(functionName, funcPtr);
+ PlatformAssemblerCommon::callRuntime(funcPtr);
if (dest == CallResultDestination::InAccumulator)
saveReturnValueInAccumulator();
}
@@ -240,7 +240,7 @@ public:
auto isInt = branch32(Equal, TrustedImm32(Value::QT_Int), ScratchRegister2);
move(AccumulatorRegister, registerForArg(0));
- callRuntimeUnchecked("toInt32Helper", reinterpret_cast<void *>(&toInt32Helper));
+ callHelper(toInt32Helper);
saveReturnValueInAccumulator();
isInt.link(this);
@@ -383,10 +383,9 @@ public:
: PlatformAssemblerCommon(constantTable)
{}
- void callRuntime(const char *functionName, const void *funcPtr,
- CallResultDestination dest)
+ void callRuntime(const void *funcPtr, CallResultDestination dest)
{
- PlatformAssemblerCommon::callRuntime(functionName, funcPtr);
+ PlatformAssemblerCommon::callRuntime(funcPtr);
if (dest == CallResultDestination::InAccumulator)
saveReturnValueInAccumulator();
}
@@ -491,7 +490,7 @@ public:
move(AccumulatorRegisterValue, registerForArg(0));
move(AccumulatorRegisterTag, registerForArg(1));
}
- callRuntimeUnchecked("toNumberHelper", reinterpret_cast<void *>(&toNumberHelper));
+ callHelper(toNumberHelper);
saveReturnValueInAccumulator();
if (ArgInRegCount < 2)
addPtr(TrustedImm32(4 * PointerSize), StackPointerRegister);
@@ -548,7 +547,7 @@ public:
move(AccumulatorRegisterValue, registerForArg(0));
move(AccumulatorRegisterTag, registerForArg(1));
}
- callRuntimeUnchecked("toInt32Helper", reinterpret_cast<void *>(&toInt32Helper));
+ callHelper(toInt32Helper);
saveReturnValueInAccumulator();
if (ArgInRegCount < 2)
addPtr(TrustedImm32(4 * PointerSize), StackPointerRegister);
@@ -570,7 +569,7 @@ public:
move(AccumulatorRegisterValue, registerForArg(0));
move(AccumulatorRegisterTag, registerForArg(1));
}
- callRuntimeUnchecked("toInt32Helper", reinterpret_cast<void *>(&toInt32Helper));
+ callHelper(toInt32Helper);
saveReturnValueInAccumulator();
if (ArgInRegCount < 2)
addPtr(TrustedImm32(4 * PointerSize), StackPointerRegister);
@@ -1267,7 +1266,7 @@ void BaselineAssembler::cmpeqInt(int lhs)
else
pasm()->move(PlatformAssembler::StackPointerRegister, pasm()->registerForArg(1));
pasm()->pushAccumulatorAsArg(0);
- pasm()->callRuntimeUnchecked("Equal", (void*)Runtime::Equal::call);
+ pasm()->callRuntimeUnchecked((void*)Runtime::Equal::call);
pasm()->saveReturnValueInAccumulator();
if (PlatformAssembler::ArgInRegCount < 2)
pasm()->addPtr(TrustedImm32(2 * PlatformAssembler::PointerSize), PlatformAssembler::StackPointerRegister);
@@ -1291,7 +1290,7 @@ void BaselineAssembler::cmpneInt(int lhs)
else
pasm()->move(PlatformAssembler::StackPointerRegister, pasm()->registerForArg(1));
pasm()->pushAccumulatorAsArg(0);
- pasm()->callRuntimeUnchecked("NotEqual", (void*)Runtime::NotEqual::call);
+ pasm()->callRuntimeUnchecked((void*)Runtime::NotEqual::call);
pasm()->saveReturnValueInAccumulator();
if (PlatformAssembler::ArgInRegCount < 2)
pasm()->addPtr(TrustedImm32(2 * PlatformAssembler::PointerSize), PlatformAssembler::StackPointerRegister);
@@ -1305,7 +1304,7 @@ void BaselineAssembler::cmpneInt(int lhs)
done.link(pasm());
}
-void BaselineAssembler::cmp(int cond, CmpFunc function, const char *functionName, int lhs)
+void BaselineAssembler::cmp(int cond, CmpFunc function, int lhs)
{
auto c = static_cast<PlatformAssembler::RelationalCondition>(cond);
auto done = pasm()->binopBothIntPath(regAddr(lhs), [this, c](){
@@ -1321,7 +1320,7 @@ void BaselineAssembler::cmp(int cond, CmpFunc function, const char *functionName
pasm()->passAccumulatorAsArg(1);
pasm()->passJSSlotAsArg(lhs, 0);
- callRuntime(functionName, reinterpret_cast<void*>(function), CallResultDestination::InAccumulator);
+ callRuntime(reinterpret_cast<void*>(function), CallResultDestination::InAccumulator);
checkException();
// done.
@@ -1331,50 +1330,42 @@ void BaselineAssembler::cmp(int cond, CmpFunc function, const char *functionName
void BaselineAssembler::cmpeq(int lhs)
{
- cmp(PlatformAssembler::Equal, &Runtime::CompareEqual::call,
- "CompareEqual", lhs);
+ cmp(PlatformAssembler::Equal, &Runtime::CompareEqual::call, lhs);
}
void BaselineAssembler::cmpne(int lhs)
{
- cmp(PlatformAssembler::NotEqual, &Runtime::CompareNotEqual::call,
- "CompareNotEqual", lhs);
+ cmp(PlatformAssembler::NotEqual, &Runtime::CompareNotEqual::call, lhs);
}
void BaselineAssembler::cmpgt(int lhs)
{
- cmp(PlatformAssembler::GreaterThan, &Runtime::CompareGreaterThan::call,
- "CompareGreaterThan", lhs);
+ cmp(PlatformAssembler::GreaterThan, &Runtime::CompareGreaterThan::call, lhs);
}
void BaselineAssembler::cmpge(int lhs)
{
- cmp(PlatformAssembler::GreaterThanOrEqual, &Runtime::CompareGreaterEqual::call,
- "CompareGreaterEqual", lhs);
+ cmp(PlatformAssembler::GreaterThanOrEqual, &Runtime::CompareGreaterEqual::call, lhs);
}
void BaselineAssembler::cmplt(int lhs)
{
- cmp(PlatformAssembler::LessThan, &Runtime::CompareLessThan::call,
- "CompareLessThan", lhs);
+ cmp(PlatformAssembler::LessThan, &Runtime::CompareLessThan::call, lhs);
}
void BaselineAssembler::cmple(int lhs)
{
- cmp(PlatformAssembler::LessThanOrEqual, &Runtime::CompareLessEqual::call,
- "CompareLessEqual", lhs);
+ cmp(PlatformAssembler::LessThanOrEqual, &Runtime::CompareLessEqual::call, lhs);
}
void BaselineAssembler::cmpStrictEqual(int lhs)
{
- cmp(PlatformAssembler::Equal, &Runtime::CompareStrictEqual::call,
- "RuntimeHelpers::strictEqual", lhs);
+ cmp(PlatformAssembler::Equal, &Runtime::CompareStrictEqual::call, lhs);
}
void BaselineAssembler::cmpStrictNotEqual(int lhs)
{
- cmp(PlatformAssembler::NotEqual, &Runtime::CompareStrictNotEqual::call,
- "RuntimeHelpers::strictNotEqual", lhs);
+ cmp(PlatformAssembler::NotEqual, &Runtime::CompareStrictNotEqual::call, lhs);
}
int BaselineAssembler::jump(int offset)
@@ -1463,9 +1454,9 @@ void BaselineAssembler::passPointerAsArg(void *ptr, int arg)
pasm()->passPointerAsArg(ptr, arg);
}
-void BaselineAssembler::callRuntime(const char *functionName, const void *funcPtr, CallResultDestination dest)
+void BaselineAssembler::callRuntime(const void *funcPtr, CallResultDestination dest)
{
- pasm()->callRuntime(functionName, funcPtr, dest);
+ pasm()->callRuntime(funcPtr, dest);
}
void BaselineAssembler::saveAccumulatorInFrame()
@@ -1498,8 +1489,9 @@ void BaselineAssembler::jsTailCall(int func, int thisObject, int argc, int argv)
pasm()->storeInt32AsValue(argv, Address(tos.base, argvOffset));
pasm()->moveReg(regAddr(thisObject), Address(tos.base, thisOffset));
pasm()->moveReg(regAddr(func), Address(tos.base, funcOffset));
- pasm()->tailCallRuntime("TheJitIs__Tail_Calling__ToTheRuntimeSoTheJitFrameIsMissing",
- reinterpret_cast<void *>(TheJitIs__Tail_Calling__ToTheRuntimeSoTheJitFrameIsMissing));
+ pasm()->tailCallRuntime(
+ reinterpret_cast<void *>(TheJitIs__Tail_Calling__ToTheRuntimeSoTheJitFrameIsMissing),
+ "TheJitIs__Tail_Calling__ToTheRuntimeSoTheJitFrameIsMissing");
}
void BaselineAssembler::checkException()
diff --git a/src/qml/jit/qv4baselineassembler_p.h b/src/qml/jit/qv4baselineassembler_p.h
index 33fd288ac3..c2c735282b 100644
--- a/src/qml/jit/qv4baselineassembler_p.h
+++ b/src/qml/jit/qv4baselineassembler_p.h
@@ -62,16 +62,11 @@ QT_BEGIN_NAMESPACE
namespace QV4 {
namespace JIT {
-#define JIT_STRINGIFYx(s) #s
-#define JIT_STRINGIFY(s) JIT_STRINGIFYx(s)
-
#define GENERATE_RUNTIME_CALL(function, destination) \
- callRuntime(JIT_STRINGIFY(function), \
- reinterpret_cast<void *>(&Runtime::function::call), \
+ callRuntime(reinterpret_cast<void *>(&Runtime::function::call), \
destination)
#define GENERATE_TAIL_CALL(function) \
- tailCallRuntime(JIT_STRINGIFY(function), \
- reinterpret_cast<void *>(&function))
+ tailCallRuntime(reinterpret_cast<void *>(&function))
class BaselineAssembler {
public:
@@ -153,7 +148,7 @@ public:
void passCppFrameAsArg(int arg);
void passInt32AsArg(int value, int arg);
void passPointerAsArg(void *ptr, int arg);
- void callRuntime(const char *functionName, const void *funcPtr, CallResultDestination dest);
+ void callRuntime(const void *funcPtr, CallResultDestination dest);
void saveAccumulatorInFrame();
void loadAccumulatorFromFrame();
void jsTailCall(int func, int thisObject, int argc, int argv);
@@ -179,7 +174,7 @@ protected:
private:
typedef unsigned(*CmpFunc)(const Value&,const Value&);
- void cmp(int cond, CmpFunc function, const char *functionName, int lhs);
+ void cmp(int cond, CmpFunc function, int lhs);
};
} // namespace JIT
diff --git a/src/qml/jsruntime/qv4arrayobject.cpp b/src/qml/jsruntime/qv4arrayobject.cpp
index af1a2d1de0..d8d0d4739f 100644
--- a/src/qml/jsruntime/qv4arrayobject.cpp
+++ b/src/qml/jsruntime/qv4arrayobject.cpp
@@ -597,65 +597,63 @@ ReturnedValue ArrayPrototype::method_findIndex(const FunctionObject *b, const Va
return Encode(-1);
}
-ReturnedValue ArrayPrototype::method_join(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
+ReturnedValue ArrayPrototype::method_join(const FunctionObject *functionObject,
+ const Value *thisObject, const Value *argv, int argc)
{
- Scope scope(b);
+ Scope scope(functionObject);
ScopedObject instance(scope, thisObject->toObject(scope.engine));
if (!instance)
return Encode(scope.engine->newString());
- ScopedValue arg(scope, argc ? argv[0] : Value::undefinedValue());
-
- QString r4;
- if (arg->isUndefined())
- r4 = QStringLiteral(",");
- else
- r4 = arg->toQString();
+ // We cannot optimize the resolution of the argument away in case of length == 0
+ // It may have side effects.
+ ScopedValue argument(scope, argc ? argv[0] : Value::undefinedValue());
+ const QString separator = argument->isUndefined()
+ ? QStringLiteral(",")
+ : argument->toQString();
- ScopedValue length(scope, instance->get(scope.engine->id_length()));
- const quint32 r2 = length->isUndefined() ? 0 : length->toUInt32();
-
- if (!r2)
+ ScopedValue scopedLength(scope, instance->get(scope.engine->id_length()));
+ const quint32 genericLength = scopedLength->isUndefined() ? 0 : scopedLength->toUInt32();
+ if (!genericLength)
return Encode(scope.engine->newString());
- QString R;
-
- // ### FIXME
- if (ArrayObject *a = instance->as<ArrayObject>()) {
- ScopedValue e(scope);
- for (uint i = 0; i < a->getLength(); ++i) {
+ QString result;
+ if (auto *arrayObject = instance->as<ArrayObject>()) {
+ ScopedValue entry(scope);
+ const qint64 arrayLength = arrayObject->getLength();
+ Q_ASSERT(arrayLength >= 0);
+ Q_ASSERT(arrayLength <= std::numeric_limits<quint32>::max());
+ for (quint32 i = 0; i < quint32(arrayLength); ++i) {
if (i)
- R += r4;
+ result += separator;
- e = a->get(i);
+ entry = arrayObject->get(i);
CHECK_EXCEPTION();
- if (!e->isNullOrUndefined())
- R += e->toQString();
+ if (!entry->isNullOrUndefined())
+ result += entry->toQString();
}
} else {
- //
- // crazy!
- //
ScopedString name(scope, scope.engine->newString(QStringLiteral("0")));
- ScopedValue r6(scope, instance->get(name));
- if (!r6->isNullOrUndefined())
- R = r6->toQString();
+ ScopedValue value(scope, instance->get(name));
+ CHECK_EXCEPTION();
+
+ if (!value->isNullOrUndefined())
+ result = value->toQString();
- ScopedValue r12(scope);
- for (quint32 k = 1; k < r2; ++k) {
- R += r4;
+ for (quint32 i = 1; i < genericLength; ++i) {
+ result += separator;
- name = Value::fromDouble(k).toString(scope.engine);
- r12 = instance->get(name);
+ name = Value::fromDouble(i).toString(scope.engine);
+ value = instance->get(name);
CHECK_EXCEPTION();
- if (!r12->isNullOrUndefined())
- R += r12->toQString();
+ if (!value->isNullOrUndefined())
+ result += value->toQString();
}
}
- return Encode(scope.engine->newString(R));
+ return Encode(scope.engine->newString(result));
}
ReturnedValue ArrayPrototype::method_pop(const FunctionObject *b, const Value *thisObject, const Value *, int)
diff --git a/src/qml/jsruntime/qv4executablecompilationunit.cpp b/src/qml/jsruntime/qv4executablecompilationunit.cpp
index d51e986006..7c6368d60a 100644
--- a/src/qml/jsruntime/qv4executablecompilationunit.cpp
+++ b/src/qml/jsruntime/qv4executablecompilationunit.cpp
@@ -283,7 +283,7 @@ void ExecutableCompilationUnit::unlink()
Q_ASSERT(data && propertyCaches.count() > 0 && propertyCaches.at(/*root object*/0));
if (qmlEngine)
qmlEngine->unregisterInternalCompositeType(this);
- QQmlMetaType::unregisterInternalCompositeType(this);
+ QQmlMetaType::unregisterInternalCompositeType({metaTypeId, listMetaTypeId});
isRegisteredWithEngine = false;
}
@@ -383,13 +383,17 @@ IdentifierHash ExecutableCompilationUnit::createNamedObjectsPerComponent(int com
return *namedObjectsPerComponentCache.insert(componentObjectIndex, namedObjectCache);
}
-void ExecutableCompilationUnit::finalizeCompositeType(QQmlEnginePrivate *qmlEngine)
+void ExecutableCompilationUnit::finalizeCompositeType(QQmlEnginePrivate *qmlEngine, QQmlMetaType::CompositeMetaTypeIds typeIds)
{
this->qmlEngine = qmlEngine;
// Add to type registry of composites
if (propertyCaches.needsVMEMetaObject(/*root object*/0)) {
- QQmlMetaType::registerInternalCompositeType(this);
+ // typeIds is only valid for types that have references to themselves.
+ if (!typeIds.isValid())
+ typeIds = QQmlMetaType::registerInternalCompositeType(rootPropertyCache()->className());
+ metaTypeId = typeIds.id;
+ listMetaTypeId = typeIds.listId;
qmlEngine->registerInternalCompositeType(this);
} else {
const QV4::CompiledData::Object *obj = objectAt(/*root object*/0);
diff --git a/src/qml/jsruntime/qv4executablecompilationunit_p.h b/src/qml/jsruntime/qv4executablecompilationunit_p.h
index 6eef3b12c3..1272e7a2c3 100644
--- a/src/qml/jsruntime/qv4executablecompilationunit_p.h
+++ b/src/qml/jsruntime/qv4executablecompilationunit_p.h
@@ -58,6 +58,7 @@
#include <private/qqmlpropertycachevector_p.h>
#include <private/qqmltype_p.h>
#include <private/qqmlnullablevalue_p.h>
+#include <private/qqmlmetatype_p.h>
QT_BEGIN_NAMESPACE
@@ -142,7 +143,7 @@ public:
QHash<int, IdentifierHash> namedObjectsPerComponentCache;
inline IdentifierHash namedObjectsPerComponent(int componentObjectIndex);
- void finalizeCompositeType(QQmlEnginePrivate *qmlEngine);
+ void finalizeCompositeType(QQmlEnginePrivate *qmlEngine, QQmlMetaType::CompositeMetaTypeIds typeIds);
int totalBindingsCount = 0; // Number of bindings used in this type
int totalParserStatusCount = 0; // Number of instantiated types that are QQmlParserStatus subclasses
@@ -154,6 +155,8 @@ public:
bool verifyChecksum(const CompiledData::DependentTypesHasher &dependencyHasher) const;
+ QQmlMetaType::CompositeMetaTypeIds typeIds() const { return {metaTypeId, listMetaTypeId}; }
+
int metaTypeId = -1;
int listMetaTypeId = -1;
bool isRegisteredWithEngine = false;
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 2b5e8bd2b9..5a81f24e06 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -1622,7 +1622,7 @@ static QV4::ReturnedValue CallOverloaded(const QQmlObjectOrGadget &object, const
int methodMatchScore = 0;
for (int ii = 0; ii < methodArgumentCount; ++ii) {
- methodMatchScore += MatchScore((v = Value::fromStaticValue(callArgs->args[ii])),
+ methodMatchScore += MatchScore((v = QV4::Value::fromStaticValue(callArgs->args[ii])),
methodArgTypes[ii]);
}
@@ -2268,7 +2268,7 @@ ReturnedValue QMetaObjectWrapper::callOverloadedConstructor(QV4::ExecutionEngine
int methodMatchScore = 0;
for (int ii = 0; ii < methodArgumentCount; ++ii) {
- methodMatchScore += MatchScore((v = Value::fromStaticValue(callArgs->args[ii])),
+ methodMatchScore += MatchScore((v = QV4::Value::fromStaticValue(callArgs->args[ii])),
methodArgTypes[ii]);
}
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index aaa198c62a..21a0017728 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -2316,6 +2316,133 @@ Bool Runtime::CompareStrictNotEqual::call(const Value &left, const Value &right)
return ! RuntimeHelpers::strictEqual(left, right);
}
+template<typename Operation>
+static inline const void *symbol()
+{
+ return reinterpret_cast<void *>(&Operation::call);
+}
+
+QHash<const void *, const char *> Runtime::symbolTable()
+{
+ static const QHash<const void *, const char *> symbols({
+#ifndef V4_BOOTSTRAP
+ {symbol<CallGlobalLookup>(), "CallGlobalLookup" },
+ {symbol<CallQmlContextPropertyLookup>(), "CallQmlContextPropertyLookup" },
+ {symbol<CallName>(), "CallName" },
+ {symbol<CallProperty>(), "CallProperty" },
+ {symbol<CallPropertyLookup>(), "CallPropertyLookup" },
+ {symbol<CallElement>(), "CallElement" },
+ {symbol<CallValue>(), "CallValue" },
+ {symbol<CallWithReceiver>(), "CallWithReceiver" },
+ {symbol<CallPossiblyDirectEval>(), "CallPossiblyDirectEval" },
+ {symbol<CallWithSpread>(), "CallWithSpread" },
+ {symbol<TailCall>(), "TailCall" },
+
+ {symbol<Construct>(), "Construct" },
+ {symbol<ConstructWithSpread>(), "ConstructWithSpread" },
+
+ {symbol<StoreNameStrict>(), "StoreNameStrict" },
+ {symbol<StoreNameSloppy>(), "StoreNameSloppy" },
+ {symbol<StoreProperty>(), "StoreProperty" },
+ {symbol<StoreElement>(), "StoreElement" },
+ {symbol<LoadProperty>(), "LoadProperty" },
+ {symbol<LoadName>(), "LoadName" },
+ {symbol<LoadElement>(), "LoadElement" },
+ {symbol<LoadSuperProperty>(), "LoadSuperProperty" },
+ {symbol<StoreSuperProperty>(), "StoreSuperProperty" },
+ {symbol<LoadSuperConstructor>(), "LoadSuperConstructor" },
+ {symbol<LoadGlobalLookup>(), "LoadGlobalLookup" },
+ {symbol<LoadQmlContextPropertyLookup>(), "LoadQmlContextPropertyLookup" },
+ {symbol<GetLookup>(), "GetLookup" },
+ {symbol<SetLookupStrict>(), "SetLookupStrict" },
+ {symbol<SetLookupSloppy>(), "SetLookupSloppy" },
+
+ {symbol<TypeofValue>(), "TypeofValue" },
+ {symbol<TypeofName>(), "TypeofName" },
+
+ {symbol<DeleteProperty_NoThrow>(), "DeleteProperty_NoThrow" },
+ {symbol<DeleteProperty>(), "DeleteProperty" },
+ {symbol<DeleteName_NoThrow>(), "DeleteName_NoThrow" },
+ {symbol<DeleteName>(), "DeleteName" },
+
+ {symbol<ThrowException>(), "ThrowException" },
+ {symbol<PushCallContext>(), "PushCallContext" },
+ {symbol<PushWithContext>(), "PushWithContext" },
+ {symbol<PushCatchContext>(), "PushCatchContext" },
+ {symbol<PushBlockContext>(), "PushBlockContext" },
+ {symbol<CloneBlockContext>(), "CloneBlockContext" },
+ {symbol<PushScriptContext>(), "PushScriptContext" },
+ {symbol<PopScriptContext>(), "PopScriptContext" },
+ {symbol<ThrowReferenceError>(), "ThrowReferenceError" },
+ {symbol<ThrowOnNullOrUndefined>(), "ThrowOnNullOrUndefined" },
+
+ {symbol<Closure>(), "Closure" },
+
+ {symbol<ConvertThisToObject>(), "ConvertThisToObject" },
+ {symbol<DeclareVar>(), "DeclareVar" },
+ {symbol<CreateMappedArgumentsObject>(), "CreateMappedArgumentsObject" },
+ {symbol<CreateUnmappedArgumentsObject>(), "CreateUnmappedArgumentsObject" },
+ {symbol<CreateRestParameter>(), "CreateRestParameter" },
+
+ {symbol<ArrayLiteral>(), "ArrayLiteral" },
+ {symbol<ObjectLiteral>(), "ObjectLiteral" },
+ {symbol<CreateClass>(), "CreateClass" },
+
+ {symbol<GetIterator>(), "GetIterator" },
+ {symbol<IteratorNext>(), "IteratorNext" },
+ {symbol<IteratorNextForYieldStar>(), "IteratorNextForYieldStar" },
+ {symbol<IteratorClose>(), "IteratorClose" },
+ {symbol<DestructureRestElement>(), "DestructureRestElement" },
+
+ {symbol<ToObject>(), "ToObject" },
+ {symbol<ToBoolean>(), "ToBoolean" },
+ {symbol<ToNumber>(), "ToNumber" },
+
+ {symbol<UMinus>(), "UMinus" },
+
+ {symbol<Instanceof>(), "Instanceof" },
+ {symbol<In>(), "In" },
+ {symbol<Add>(), "Add" },
+ {symbol<Sub>(), "Sub" },
+ {symbol<Mul>(), "Mul" },
+ {symbol<Div>(), "Div" },
+ {symbol<Mod>(), "Mod" },
+ {symbol<Exp>(), "Exp" },
+ {symbol<BitAnd>(), "BitAnd" },
+ {symbol<BitOr>(), "BitOr" },
+ {symbol<BitXor>(), "BitXor" },
+ {symbol<Shl>(), "Shl" },
+ {symbol<Shr>(), "Shr" },
+ {symbol<UShr>(), "UShr" },
+ {symbol<GreaterThan>(), "GreaterThan" },
+ {symbol<LessThan>(), "LessThan" },
+ {symbol<GreaterEqual>(), "GreaterEqual" },
+ {symbol<LessEqual>(), "LessEqual" },
+ {symbol<Equal>(), "Equal" },
+ {symbol<NotEqual>(), "NotEqual" },
+ {symbol<StrictEqual>(), "StrictEqual" },
+ {symbol<StrictNotEqual>(), "StrictNotEqual" },
+
+ {symbol<CompareGreaterThan>(), "CompareGreaterThan" },
+ {symbol<CompareLessThan>(), "CompareLessThan" },
+ {symbol<CompareGreaterEqual>(), "CompareGreaterEqual" },
+ {symbol<CompareLessEqual>(), "CompareLessEqual" },
+ {symbol<CompareEqual>(), "CompareEqual" },
+ {symbol<CompareNotEqual>(), "CompareNotEqual" },
+ {symbol<CompareStrictEqual>(), "CompareStrictEqual" },
+ {symbol<CompareStrictNotEqual>(), "CompareStrictNotEqual" },
+
+ {symbol<CompareInstanceof>(), "CompareInstanceOf" },
+ {symbol<CompareIn>(), "CompareIn" },
+
+ {symbol<RegexpLiteral>(), "RegexpLiteral" },
+ {symbol<GetTemplateObject>(), "GetTemplateObject" }
+#endif
+ });
+
+ return symbols;
+}
+
} // namespace QV4
QT_END_NAMESPACE
diff --git a/src/qml/jsruntime/qv4runtimeapi_p.h b/src/qml/jsruntime/qv4runtimeapi_p.h
index 05ffb84d58..d155187e48 100644
--- a/src/qml/jsruntime/qv4runtimeapi_p.h
+++ b/src/qml/jsruntime/qv4runtimeapi_p.h
@@ -501,6 +501,8 @@ struct Q_QML_PRIVATE_EXPORT Runtime {
static const int tailCall_argv = -3;
static const int tailCall_argc = -4;
};
+
+ static QHash<const void *, const char *> symbolTable();
};
static_assert(std::is_standard_layout<Runtime>::value, "Runtime needs to be standard layout in order for us to be able to use offsetof");
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h
index e4aceef3ee..12a6381e6f 100644
--- a/src/qml/jsruntime/qv4scopedvalue_p.h
+++ b/src/qml/jsruntime/qv4scopedvalue_p.h
@@ -70,7 +70,7 @@ struct ScopedValue;
#define CHECK_EXCEPTION() \
do { \
- if (scope.hasException()) { \
+ if (scope.hasException() || scope.engine->isInterrupted.loadAcquire()) { \
return QV4::Encode::undefined(); \
} \
} while (false)
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp
index 77a98247ac..7caa122698 100644
--- a/src/qml/jsruntime/qv4sequenceobject.cpp
+++ b/src/qml/jsruntime/qv4sequenceobject.cpp
@@ -80,7 +80,6 @@ static void generateWarning(QV4::ExecutionEngine *v4, const QString& description
#if QT_CONFIG(qml_itemmodel)
#define FOREACH_QML_SEQUENCE_TYPE_FOR_ITEMMODEL(F) \
F(QModelIndex, QModelIndex, QModelIndexList, QModelIndex()) \
- F(QModelIndex, QModelIndexVector, QVector<QModelIndex>, QModelIndex()) \
F(QModelIndex, QModelIndexStdVector, std::vector<QModelIndex>, QModelIndex()) \
F(QItemSelectionRange, QItemSelectionRange, QItemSelection, QItemSelectionRange())
#else
@@ -88,9 +87,6 @@ static void generateWarning(QV4::ExecutionEngine *v4, const QString& description
#endif
#define FOREACH_QML_SEQUENCE_TYPE(F) \
- F(int, IntVector, QVector<int>, 0) \
- F(qreal, RealVector, QVector<qreal>, 0.0) \
- F(bool, BoolVector, QVector<bool>, false) \
F(int, IntStdVector, std::vector<int>, 0) \
F(qreal, RealStdVector, std::vector<qreal>, 0.0) \
F(bool, BoolStdVector, std::vector<bool>, false) \
@@ -99,10 +95,8 @@ static void generateWarning(QV4::ExecutionEngine *v4, const QString& description
F(bool, Bool, QList<bool>, false) \
F(QString, String, QList<QString>, QString()) \
F(QString, QString, QStringList, QString()) \
- F(QString, StringVector, QVector<QString>, QString()) \
F(QString, StringStdVector, std::vector<QString>, QString()) \
F(QUrl, Url, QList<QUrl>, QUrl()) \
- F(QUrl, UrlVector, QVector<QUrl>, QUrl()) \
F(QUrl, UrlStdVector, std::vector<QUrl>, QUrl()) \
FOREACH_QML_SEQUENCE_TYPE_FOR_ITEMMODEL(F)
@@ -654,12 +648,6 @@ void Heap::QQmlSequence<Container>::init(QObject *object, int propertyIndex, boo
namespace QV4 {
-typedef QQmlSequence<QVector<int> > QQmlIntVectorList;
-DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlIntVectorList);
-typedef QQmlSequence<QVector<qreal> > QQmlRealVectorList;
-DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlRealVectorList);
-typedef QQmlSequence<QVector<bool> > QQmlBoolVectorList;
-DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlBoolVectorList);
typedef QQmlSequence<std::vector<int> > QQmlIntStdVectorList;
DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlIntStdVectorList);
typedef QQmlSequence<std::vector<qreal> > QQmlRealStdVectorList;
@@ -670,23 +658,17 @@ typedef QQmlSequence<QStringList> QQmlQStringList;
DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlQStringList);
typedef QQmlSequence<QList<QString> > QQmlStringList;
DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlStringList);
-typedef QQmlSequence<QVector<QString> > QQmlStringVectorList;
-DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlStringVectorList);
typedef QQmlSequence<std::vector<QString> > QQmlStringStdVectorList;
-DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlStringStdVectorList);
typedef QQmlSequence<QList<int> > QQmlIntList;
DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlIntList);
+DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlStringStdVectorList);
typedef QQmlSequence<QList<QUrl> > QQmlUrlList;
DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlUrlList);
-typedef QQmlSequence<QVector<QUrl> > QQmlUrlVectorList;
-DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlUrlVectorList);
typedef QQmlSequence<std::vector<QUrl> > QQmlUrlStdVectorList;
DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlUrlStdVectorList);
#if QT_CONFIG(qml_itemmodel)
typedef QQmlSequence<QModelIndexList> QQmlQModelIndexList;
DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlQModelIndexList);
-typedef QQmlSequence<QVector<QModelIndex> > QQmlQModelIndexVectorList;
-DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlQModelIndexVectorList);
typedef QQmlSequence<std::vector<QModelIndex> > QQmlQModelIndexStdVectorList;
DEFINE_OBJECT_TEMPLATE_VTABLE(QQmlQModelIndexStdVectorList);
typedef QQmlSequence<QItemSelection> QQmlQItemSelectionRangeList;
diff --git a/src/qml/jsruntime/qv4sparsearray.cpp b/src/qml/jsruntime/qv4sparsearray.cpp
index 8930c9a94d..7457e724e2 100644
--- a/src/qml/jsruntime/qv4sparsearray.cpp
+++ b/src/qml/jsruntime/qv4sparsearray.cpp
@@ -359,7 +359,7 @@ static inline void qMapDeallocate(SparseArrayNode *node, int alignment)
SparseArrayNode *SparseArray::createNode(uint sl, SparseArrayNode *parent, bool left)
{
- SparseArrayNode *node = static_cast<SparseArrayNode *>(qMapAllocate(sizeof(SparseArrayNode), Q_ALIGNOF(SparseArrayNode)));
+ SparseArrayNode *node = static_cast<SparseArrayNode *>(qMapAllocate(sizeof(SparseArrayNode), alignof(SparseArrayNode)));
Q_CHECK_PTR(node);
node->p = (quintptr)parent;
diff --git a/src/qml/jsruntime/qv4sparsearray_p.h b/src/qml/jsruntime/qv4sparsearray_p.h
index c1e50c8dcf..248fcdb02f 100644
--- a/src/qml/jsruntime/qv4sparsearray_p.h
+++ b/src/qml/jsruntime/qv4sparsearray_p.h
@@ -147,7 +147,7 @@ struct Q_QML_EXPORT SparseArray
SparseArray();
~SparseArray() {
if (root())
- freeTree(header.left, Q_ALIGNOF(SparseArrayNode));
+ freeTree(header.left, alignof(SparseArrayNode));
}
SparseArray(const SparseArray &other);
diff --git a/src/qml/jsruntime/qv4stackframe_p.h b/src/qml/jsruntime/qv4stackframe_p.h
index bf689a74bc..616fa9a5a9 100644
--- a/src/qml/jsruntime/qv4stackframe_p.h
+++ b/src/qml/jsruntime/qv4stackframe_p.h
@@ -117,7 +117,7 @@ struct Q_QML_EXPORT CppStackFrame {
void setupJSFrame(Value *stackSpace, const Value &function, const Heap::ExecutionContext *scope,
const Value &thisObject, const Value &newTarget = Value::undefinedValue()) {
setupJSFrame(stackSpace, function, scope, thisObject, newTarget,
- v4Function->nFormals, v4Function->compiledFunction->nRegisters);
+ v4Function->compiledFunction->nFormals, v4Function->compiledFunction->nRegisters);
}
void setupJSFrame(Value *stackSpace, const Value &function, const Heap::ExecutionContext *scope,
const Value &thisObject, const Value &newTarget, uint nFormals, uint nRegisters)
diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp
index 7d33167762..893fe06e8e 100644
--- a/src/qml/jsruntime/qv4typedarray.cpp
+++ b/src/qml/jsruntime/qv4typedarray.cpp
@@ -1068,51 +1068,44 @@ ReturnedValue IntrinsicTypedArrayPrototype::method_indexOf(const FunctionObject
return Encode(-1);
}
-ReturnedValue IntrinsicTypedArrayPrototype::method_join(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc)
+ReturnedValue IntrinsicTypedArrayPrototype::method_join(
+ const FunctionObject *functionObject, const Value *thisObject, const Value *argv, int argc)
{
- Scope scope(b);
- Scoped<TypedArray> v(scope, thisObject);
- if (!v || v->d()->buffer->isDetachedBuffer())
+ Scope scope(functionObject);
+ Scoped<TypedArray> typedArray(scope, thisObject);
+ if (!typedArray || typedArray->d()->buffer->isDetachedBuffer())
return scope.engine->throwTypeError();
- uint len = v->length();
-
- ScopedValue arg(scope, argc ? argv[0] : Value::undefinedValue());
+ // We cannot optimize the resolution of the argument away if length is 0.
+ // It may have side effects.
+ ScopedValue argument(scope, argc ? argv[0] : Value::undefinedValue());
+ const QString separator = argument->isUndefined()
+ ? QStringLiteral(",")
+ : argument->toQString();
- QString r4;
- if (arg->isUndefined())
- r4 = QStringLiteral(",");
- else
- r4 = arg->toQString();
-
- const quint32 r2 = len;
-
- if (!r2)
+ const quint32 length = typedArray->length();
+ if (!length)
return Encode(scope.engine->newString());
- QString R;
+ QString result;
- //
- // crazy!
- //
ScopedString name(scope, scope.engine->newString(QStringLiteral("0")));
- ScopedValue r6(scope, v->get(name));
- if (!r6->isNullOrUndefined())
- R = r6->toQString();
+ ScopedValue value(scope, typedArray->get(name));
+ if (!value->isNullOrUndefined())
+ result = value->toQString();
- ScopedValue r12(scope);
- for (quint32 k = 1; k < r2; ++k) {
- R += r4;
+ for (quint32 i = 1; i < length; ++i) {
+ result += separator;
- name = Value::fromDouble(k).toString(scope.engine);
- r12 = v->get(name);
+ name = Value::fromDouble(i).toString(scope.engine);
+ value = typedArray->get(name);
CHECK_EXCEPTION();
- if (!r12->isNullOrUndefined())
- R += r12->toQString();
+ if (!value->isNullOrUndefined())
+ result += value->toQString();
}
- return Encode(scope.engine->newString(R));
+ return Encode(scope.engine->newString(result));
}
ReturnedValue IntrinsicTypedArrayPrototype::method_keys(const FunctionObject *b, const Value *thisObject, const Value *, int)
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index 27d518f5c6..ad5a6ebc8c 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -364,7 +364,7 @@ static inline Heap::CallContext *getScope(QV4::Value *stack, int level)
static inline const QV4::Value &constant(Function *function, int index)
{
- return function->compilationUnit->constants[index].asValue<Value>();
+ return function->compilationUnit->constants[index].asValue<QV4::Value>();
}
static bool compareEqualInt(QV4::Value &accumulator, QV4::Value lhs, int rhs)
diff --git a/src/qml/qml/ftw/qflagpointer_p.h b/src/qml/qml/ftw/qflagpointer_p.h
index 71b41cd30b..a10e57aeca 100644
--- a/src/qml/qml/ftw/qflagpointer_p.h
+++ b/src/qml/qml/ftw/qflagpointer_p.h
@@ -55,6 +55,17 @@
QT_BEGIN_NAMESPACE
+namespace QtPrivate {
+template <typename T> struct QFlagPointerAlignment
+{
+ enum : size_t { Value = Q_ALIGNOF(T) };
+};
+template <> struct QFlagPointerAlignment<void>
+{
+ enum : size_t { Value = ~size_t(0) };
+};
+}
+
template<typename T>
class QFlagPointer {
public:
@@ -133,6 +144,7 @@ template<typename T>
QFlagPointer<T>::QFlagPointer(T *v)
: ptr_value(quintptr(v))
{
+ Q_STATIC_ASSERT_X(Q_ALIGNOF(T) >= 4, "Type T does not have sufficient alignment");
Q_ASSERT((ptr_value & FlagsMask) == 0);
}
@@ -247,6 +259,8 @@ template<typename T, typename T2>
QBiPointer<T, T2>::QBiPointer(T *v)
: ptr_value(quintptr(v))
{
+ Q_STATIC_ASSERT_X(QtPrivate::QFlagPointerAlignment<T>::Value >= 4,
+ "Type T does not have sufficient alignment");
Q_ASSERT((quintptr(v) & FlagsMask) == 0);
}
@@ -254,6 +268,8 @@ template<typename T, typename T2>
QBiPointer<T, T2>::QBiPointer(T2 *v)
: ptr_value(quintptr(v) | Flag2Bit)
{
+ Q_STATIC_ASSERT_X(QtPrivate::QFlagPointerAlignment<T2>::Value >= 4,
+ "Type T2 does not have sufficient alignment");
Q_ASSERT((quintptr(v) & FlagsMask) == 0);
}
diff --git a/src/qml/qml/ftw/qqmlthread.cpp b/src/qml/qml/ftw/qqmlthread.cpp
index e961ed3d0d..7d2ad354d6 100644
--- a/src/qml/qml/ftw/qqmlthread.cpp
+++ b/src/qml/qml/ftw/qqmlthread.cpp
@@ -131,6 +131,9 @@ QQmlThreadPrivate::QQmlThreadPrivate(QQmlThread *q)
m_mainThreadWaiting(false), mainSync(nullptr), m_mainObject(this)
{
setObjectName(QStringLiteral("QQmlThread"));
+ // This size is aligned with the recursion depth limits in the parser/codegen. In case of
+ // absurd content we want to hit the recursion checks instead of running out of stack.
+ setStackSize(8 * 1024 * 1024);
}
bool QQmlThreadPrivate::event(QEvent *e)
diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri
index 2e9c6f3de6..a16f3d4167 100644
--- a/src/qml/qml/qml.pri
+++ b/src/qml/qml/qml.pri
@@ -3,6 +3,7 @@ SOURCES += \
$$PWD/qqmldatablob.cpp \
$$PWD/qqmldirdata.cpp \
$$PWD/qqmlerror.cpp \
+ $$PWD/qqmlmoduleregistration.cpp \
$$PWD/qqmlopenmetaobject.cpp \
$$PWD/qqmlscriptblob.cpp \
$$PWD/qqmlscriptdata.cpp \
@@ -71,6 +72,7 @@ HEADERS += \
$$PWD/qqmldatablob_p.h \
$$PWD/qqmldirdata_p.h \
$$PWD/qqmlglobal_p.h \
+ $$PWD/qqmlmoduleregistration.h \
$$PWD/qqmlopenmetaobject_p.h \
$$PWD/qqmlscriptblob_p.h \
$$PWD/qqmlscriptdata_p.h \
diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp
index 2f6aabf61e..112e5b558a 100644
--- a/src/qml/qml/qqmlbinding.cpp
+++ b/src/qml/qml/qqmlbinding.cpp
@@ -298,8 +298,9 @@ protected:
case QMetaType::Int:
if (result.isInteger())
return doStore<int>(result.integerValue(), pd, flags);
- else if (result.isNumber())
- return doStore<int>(result.doubleValue(), pd, flags);
+ else if (result.isNumber()) {
+ return doStore<int>(QV4::StaticValue::toInteger(result.doubleValue()), pd, flags);
+ }
break;
case QMetaType::Double:
if (result.isNumber())
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp
index f03f90e7f3..1d5f974d5c 100644
--- a/src/qml/qml/qqmlcomponent.cpp
+++ b/src/qml/qml/qqmlcomponent.cpp
@@ -969,6 +969,7 @@ void QQmlComponentPrivate::beginDeferred(QQmlEnginePrivate *enginePriv,
if (!state->creator->populateDeferredProperties(object, deferredData))
state->errors << state->creator->errors;
+ deferredData->bindings.clear();
deferredState->constructionStates += state;
}
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp
index 254b6cc3db..9157bb95c3 100644
--- a/src/qml/qml/qqmlcontext.cpp
+++ b/src/qml/qml/qqmlcontext.cpp
@@ -532,6 +532,9 @@ QObject *QQmlContextPrivate::context_at(QQmlListProperty<QObject> *prop, int ind
void QQmlContextPrivate::dropDestroyedQObject(const QString &name, QObject *destroyed)
{
+ if (!data->isValid())
+ return;
+
const int idx = data->propertyNames().value(name);
Q_ASSERT(idx >= 0);
if (qvariant_cast<QObject *>(propertyValues[idx]) != destroyed)
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 1a868bfaa1..bde4df1340 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -784,9 +784,9 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in
// marshalled back onto the QObject's thread and handled by QML from there. This is tested
// by the qqmlecmascript::threadSignal() autotest.
if (ddata->notifyList &&
- QThread::currentThreadId() != QObjectPrivate::get(object)->threadData->threadId.loadRelaxed()) {
+ QThread::currentThreadId() != QObjectPrivate::get(object)->getThreadData()->threadId.loadRelaxed()) {
- if (!QObjectPrivate::get(object)->threadData->thread.loadAcquire())
+ if (!QObjectPrivate::get(object)->getThreadData()->thread.loadAcquire())
return;
QMetaMethod m = QMetaObjectPrivate::signal(object->metaObject(), index);
@@ -818,7 +818,7 @@ void QQmlData::signalEmitted(QAbstractDeclarativeData *, QObject *object, int in
QQmlThreadNotifierProxyObject *mpo = new QQmlThreadNotifierProxyObject;
mpo->target = object;
- mpo->moveToThread(QObjectPrivate::get(object)->threadData->thread.loadAcquire());
+ mpo->moveToThread(QObjectPrivate::get(object)->getThreadData()->thread.loadAcquire());
QCoreApplication::postEvent(mpo, ev.take());
} else {
@@ -2233,7 +2233,7 @@ void QQmlEngine::setPluginPathList(const QStringList &paths)
On failure and if non-null, the \a errors list will have any errors which occurred prepended to it.
- The plugin has to be a Qt plugin which implements the QQmlExtensionPlugin interface.
+ The plugin has to be a Qt plugin which implements the QQmlEngineExtensionPlugin interface.
*/
bool QQmlEngine::importPlugin(const QString &filePath, const QString &uri, QList<QQmlError> *errors)
{
diff --git a/src/qml/qml/qqmlextensioninterface.h b/src/qml/qml/qqmlextensioninterface.h
index d2eb79c5c9..1490bc512e 100644
--- a/src/qml/qml/qqmlextensioninterface.h
+++ b/src/qml/qml/qqmlextensioninterface.h
@@ -62,8 +62,14 @@ public:
virtual void initializeEngine(QQmlEngine *engine, const char *uri) = 0;
};
-#define QQmlTypesExtensionInterface_iid "org.qt-project.Qt.QQmlTypesExtensionInterface"
+class Q_QML_EXPORT QQmlEngineExtensionInterface
+{
+public:
+ virtual ~QQmlEngineExtensionInterface() = default;
+ virtual void initializeEngine(QQmlEngine *engine, const char *uri) = 0;
+};
+#define QQmlTypesExtensionInterface_iid "org.qt-project.Qt.QQmlTypesExtensionInterface"
Q_DECLARE_INTERFACE(QQmlTypesExtensionInterface, "org.qt-project.Qt.QQmlTypesExtensionInterface/1.0")
// NOTE: When changing this to a new version and deciding to add backup code to
@@ -73,6 +79,9 @@ Q_DECLARE_INTERFACE(QQmlTypesExtensionInterface, "org.qt-project.Qt.QQmlTypesExt
Q_DECLARE_INTERFACE(QQmlExtensionInterface, QQmlExtensionInterface_iid)
+#define QQmlEngineExtensionInterface_iid "org.qt-project.Qt.QQmlEngineExtensionInterface"
+Q_DECLARE_INTERFACE(QQmlEngineExtensionInterface, QQmlEngineExtensionInterface_iid)
+
QT_END_NAMESPACE
#endif // QQMLEXTENSIONINTERFACE_H
diff --git a/src/qml/qml/qqmlextensionplugin.cpp b/src/qml/qml/qqmlextensionplugin.cpp
index c1c971f0a9..26364661a8 100644
--- a/src/qml/qml/qqmlextensionplugin.cpp
+++ b/src/qml/qml/qqmlextensionplugin.cpp
@@ -43,10 +43,11 @@
QT_BEGIN_NAMESPACE
/*!
- \since 5.0
+ \since 5.14
\inmodule QtQml
- \class QQmlExtensionPlugin
- \brief The QQmlExtensionPlugin class provides an abstract base for custom QML extension plugins.
+ \class QQmlEngineExtensionPlugin
+ \brief The QQmlEngineExtensionPlugin class provides an abstract base for custom QML extension
+ plugins.
\ingroup plugins
@@ -60,6 +61,7 @@ QT_BEGIN_NAMESPACE
/*!
\fn void QQmlExtensionPlugin::registerTypes(const char *uri)
+ \internal
Registers the QML types in the given \a uri. Subclasses should implement
this to call qmlRegisterType() for all types which are provided by the extension
@@ -70,26 +72,39 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \internal
+*/
+QQmlExtensionPlugin::QQmlExtensionPlugin(QObject *parent)
+ : QObject(*(new QQmlExtensionPluginPrivate), parent)
+{
+}
+
+/*!
Constructs a QML extension plugin with the given \a parent.
Note that this constructor is invoked automatically by the
Q_PLUGIN_METADATA() macro, so there is no need for calling it
explicitly.
-*/
-QQmlExtensionPlugin::QQmlExtensionPlugin(QObject *parent)
- : QObject(*(new QQmlExtensionPluginPrivate), parent)
+ */
+QQmlEngineExtensionPlugin::QQmlEngineExtensionPlugin(QObject *parent)
+ : QObject(parent)
{
}
+
/*!
\internal
*/
-QQmlExtensionPlugin::~QQmlExtensionPlugin()
-{
-}
+QQmlExtensionPlugin::~QQmlExtensionPlugin() = default;
+
+/*!
+ \internal
+ */
+QQmlEngineExtensionPlugin::~QQmlEngineExtensionPlugin() = default;
/*!
\since 5.1
+ \internal
\brief Returns the URL of the directory from which the extension is loaded.
This is useful when the plugin also needs to load QML files or other
@@ -102,14 +117,23 @@ QUrl QQmlExtensionPlugin::baseUrl() const
}
/*!
- \fn void QQmlExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
+ \internal
+*/
+
+void QQmlExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
+{
+ Q_UNUSED(engine);
+ Q_UNUSED(uri);
+}
+
+/*!
+ \fn void QQmlEngineExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
Initializes the extension from the \a uri using the \a engine. Here an application
plugin might, for example, expose some data or objects to QML,
as context properties on the engine's root context.
-*/
-
-void QQmlExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
+ */
+void QQmlEngineExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
Q_UNUSED(engine);
Q_UNUSED(uri);
@@ -127,6 +151,12 @@ void QQmlExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
\inmodule QtQml
*/
+/*!
+ \class QQmlEngineExtensionInterface
+ \internal
+ \inmodule QtQml
+*/
+
QT_END_NAMESPACE
#include "moc_qqmlextensionplugin.cpp"
diff --git a/src/qml/qml/qqmlextensionplugin.h b/src/qml/qml/qqmlextensionplugin.h
index 55e9b89dae..ef7ff422cd 100644
--- a/src/qml/qml/qqmlextensionplugin.h
+++ b/src/qml/qml/qqmlextensionplugin.h
@@ -70,6 +70,19 @@ private:
Q_DISABLE_COPY(QQmlExtensionPlugin)
};
+class Q_QML_EXPORT QQmlEngineExtensionPlugin
+ : public QObject
+ , public QQmlEngineExtensionInterface
+{
+ Q_OBJECT
+ Q_DISABLE_COPY_MOVE(QQmlEngineExtensionPlugin)
+ Q_INTERFACES(QQmlEngineExtensionInterface)
+public:
+ explicit QQmlEngineExtensionPlugin(QObject *parent = nullptr);
+ ~QQmlEngineExtensionPlugin() override;
+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
+};
+
QT_END_NAMESPACE
#endif // QQMLEXTENSIONPLUGIN_H
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index d69c2ac903..21ca24d38b 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -229,8 +229,7 @@ public:
bool resolveType(const QHashedStringRef &type, int *vmajor, int *vminor,
QQmlType *type_return, QList<QQmlError> *errors,
QQmlType::RegistrationType registrationType,
- QQmlImport::RecursionRestriction recursionRestriction
- = QQmlImport::PreventRecursion);
+ bool *typeRecursionDetected = nullptr);
QUrl baseUrl;
QString base;
@@ -594,7 +593,7 @@ bool QQmlImports::resolveType(const QHashedStringRef &type,
QQmlType *type_return, int *vmaj, int *vmin,
QQmlImportNamespace** ns_return, QList<QQmlError> *errors,
QQmlType::RegistrationType registrationType,
- QQmlImport::RecursionRestriction recursionRestriction) const
+ bool *typeRecursionDetected) const
{
QQmlImportNamespace* ns = d->findQualifiedNamespace(type);
if (ns) {
@@ -604,7 +603,7 @@ bool QQmlImports::resolveType(const QHashedStringRef &type,
}
if (type_return) {
if (d->resolveType(type, vmaj, vmin, type_return, errors, registrationType,
- recursionRestriction)) {
+ typeRecursionDetected)) {
if (qmlImportTrace()) {
#define RESOLVE_TYPE_DEBUG qDebug().nospace() << "QQmlImports(" << qPrintable(baseUrl().toString()) \
<< ')' << "::resolveType: " << type.toString() << " => "
@@ -744,9 +743,12 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedSt
if (resolveLocalUrl(*base, c.fileName) != componentUrl)
continue; // failed attempt to access an internal type
}
- if (recursionRestriction == QQmlImport::PreventRecursion && *base == componentUrl) {
- if (typeRecursionDetected)
- *typeRecursionDetected = true;
+
+ const bool recursion = *base == componentUrl;
+ if (typeRecursionDetected)
+ *typeRecursionDetected = recursion;
+
+ if (recursionRestriction == QQmlImport::PreventRecursion && recursion) {
continue; // no recursion
}
}
@@ -803,10 +805,10 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedSt
}
if (exists) {
- if (recursionRestriction == QQmlImport::PreventRecursion && base && (*base == qmlUrl)) { // no recursion
- if (typeRecursionDetected)
- *typeRecursionDetected = true;
- } else {
+ const bool recursion = base && *base == qmlUrl;
+ if (typeRecursionDetected)
+ *typeRecursionDetected = recursion;
+ if (recursionRestriction == QQmlImport::AllowRecursion || !recursion) {
QQmlType returnType = QQmlMetaType::typeForUrl(
qmlUrl, type, registrationType == QQmlType::CompositeSingletonType, errors);
if (type_return)
@@ -822,7 +824,7 @@ bool QQmlImportInstance::resolveType(QQmlTypeLoader *typeLoader, const QHashedSt
bool QQmlImportsPrivate::resolveType(const QHashedStringRef& type, int *vmajor, int *vminor,
QQmlType *type_return, QList<QQmlError> *errors,
QQmlType::RegistrationType registrationType,
- QQmlImport::RecursionRestriction recursionRestriction)
+ bool *typeRecursionDetected)
{
QQmlImportNamespace *s = nullptr;
int dot = type.indexOf(Dot);
@@ -852,7 +854,7 @@ bool QQmlImportsPrivate::resolveType(const QHashedStringRef& type, int *vmajor,
QHashedStringRef unqualifiedtype = dot < 0 ? type : QHashedStringRef(type.constData()+dot+1, type.length()-dot-1);
if (s) {
if (s->resolveType(typeLoader, unqualifiedtype, vmajor, vminor, type_return, &base, errors,
- registrationType, recursionRestriction))
+ registrationType, typeRecursionDetected))
return true;
if (s->imports.count() == 1 && !s->imports.at(0)->isLibrary && type_return && s != &unqualifiedset) {
// qualified, and only 1 url
@@ -880,13 +882,19 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS
int *vmajor, int *vminor, QQmlType *type_return,
QString *base, QList<QQmlError> *errors,
QQmlType::RegistrationType registrationType,
- QQmlImport::RecursionRestriction recursionRestriction)
+ bool *typeRecursionDetected)
{
- bool typeRecursionDetected = false;
+ QQmlImport::RecursionRestriction recursionRestriction =
+ typeRecursionDetected ? QQmlImport::AllowRecursion : QQmlImport::PreventRecursion;
+
+ bool localTypeRecursionDetected = false;
+ if (!typeRecursionDetected)
+ typeRecursionDetected = &localTypeRecursionDetected;
+
for (int i=0; i<imports.count(); ++i) {
const QQmlImportInstance *import = imports.at(i);
if (import->resolveType(typeLoader, type, vmajor, vminor, type_return, base,
- &typeRecursionDetected, registrationType, recursionRestriction, errors)) {
+ typeRecursionDetected, registrationType, recursionRestriction, errors)) {
if (qmlCheckTypes()) {
// check for type clashes
for (int j = i+1; j<imports.count(); ++j) {
@@ -933,7 +941,7 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS
}
if (errors) {
QQmlError error;
- if (typeRecursionDetected)
+ if (*typeRecursionDetected)
error.setDescription(QQmlImportDatabase::tr("is instantiated recursively"));
else
error.setDescription(QQmlImportDatabase::tr("is not a type"));
@@ -990,7 +998,9 @@ static QVector<QStaticPlugin> makePlugins()
const auto staticPlugins = QPluginLoader::staticPlugins();
for (const QStaticPlugin &plugin : staticPlugins) {
const QString iid = plugin.metaData().value(QLatin1String("IID")).toString();
- if (iid == QLatin1String(QQmlExtensionInterface_iid) || iid == QLatin1String(QQmlExtensionInterface_iid_old)) {
+ if (iid == QLatin1String(QQmlEngineExtensionInterface_iid)
+ || iid == QLatin1String(QQmlExtensionInterface_iid)
+ || iid == QLatin1String(QQmlExtensionInterface_iid_old)) {
plugins.append(plugin);
}
}
@@ -1008,7 +1018,9 @@ bool QQmlImportsPrivate::populatePluginPairVector(QVector<StaticPluginPair> &res
static const QVector<QStaticPlugin> plugins = makePlugins();
for (const QStaticPlugin &plugin : plugins) {
// Since a module can list more than one plugin, we keep iterating even after we found a match.
- if (QQmlExtensionPlugin *instance = qobject_cast<QQmlExtensionPlugin *>(plugin.instance())) {
+ QObject *instance = plugin.instance();
+ if (qobject_cast<QQmlEngineExtensionPlugin *>(instance)
+ || qobject_cast<QQmlExtensionPlugin *>(instance)) {
const QJsonArray metaTagsUriList = plugin.metaData().value(QLatin1String("uri")).toArray();
if (metaTagsUriList.isEmpty()) {
if (errors) {
@@ -1812,7 +1824,8 @@ QString QQmlImportDatabase::resolvePlugin(QQmlTypeLoader *typeLoader,
if (qmldirPath.size() > 25 && qmldirPath.at(0) == QLatin1Char(':') && qmldirPath.at(1) == QLatin1Char('/') &&
qmldirPath.startsWith(QStringLiteral(":/android_rcc_bundle/qml/"), Qt::CaseInsensitive)) {
QString pluginName = qmldirPath.mid(21) + Slash + baseName;
- auto bundledPath = resolvedPath + QLatin1String("lib") + pluginName.replace(QLatin1Char('/'), QLatin1Char('_'));
+ pluginName.replace(QLatin1Char('/'), QLatin1Char('_'));
+ QString bundledPath = resolvedPath + QLatin1String("lib") + pluginName;
for (const QString &suffix : suffixes) {
const QString absolutePath = typeLoader->absoluteFilePath(bundledPath + suffix);
if (!absolutePath.isEmpty())
@@ -2055,17 +2068,8 @@ bool QQmlImportDatabase::importStaticPlugin(QObject *instance, const QString &ba
// other QML loader threads and thus not process the initializeEngine call).
}
- // The plugin's per-engine initialization does not need lock protection, as this function is
- // only called from the engine specific loader thread and importDynamicPlugin as well as
- // importStaticPlugin are the only places of access.
- if (!initializedPlugins.contains(uniquePluginID)) {
- initializedPlugins.insert(uniquePluginID);
-
- if (QQmlExtensionInterface *eiface = qobject_cast<QQmlExtensionInterface *>(instance)) {
- QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
- ep->typeLoader.initializeEngine(eiface, uri.toUtf8().constData());
- }
- }
+ if (!initializedPlugins.contains(uniquePluginID))
+ finalizePlugin(instance, uniquePluginID, uri);
return true;
}
@@ -2140,22 +2144,46 @@ bool QQmlImportDatabase::importDynamicPlugin(const QString &filePath, const QStr
// other QML loader threads and thus not process the initializeEngine call).
}
+ if (!engineInitialized)
+ finalizePlugin(instance, absoluteFilePath, uri);
- if (!engineInitialized) {
- // The plugin's per-engine initialization does not need lock protection, as this function is
- // only called from the engine specific loader thread and importDynamicPlugin as well as
- // importStaticPlugin are the only places of access.
- initializedPlugins.insert(absoluteFilePath);
+ return true;
+}
- if (QQmlExtensionInterface *eiface = qobject_cast<QQmlExtensionInterface *>(instance)) {
- QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
- ep->typeLoader.initializeEngine(eiface, uri.toUtf8().constData());
- }
+bool QQmlImportDatabase::removeDynamicPlugin(const QString &filePath)
+{
+ StringRegisteredPluginMap *plugins = qmlEnginePluginsWithRegisteredTypes();
+ QMutexLocker lock(&plugins->mutex);
+
+ auto it = plugins->find(QFileInfo(filePath).absoluteFilePath());
+ if (it == plugins->end())
+ return false;
+
+ QPluginLoader *loader = it->loader;
+ if (!loader)
+ return false;
+
+ if (!loader->unload()) {
+ qWarning("Unloading %s failed: %s", qPrintable(it->uri),
+ qPrintable(loader->errorString()));
}
+ delete loader;
+ plugins->erase(it);
return true;
}
+QStringList QQmlImportDatabase::dynamicPlugins() const
+{
+ StringRegisteredPluginMap *plugins = qmlEnginePluginsWithRegisteredTypes();
+ QMutexLocker lock(&plugins->mutex);
+ QStringList results;
+ for (auto it = plugins->constBegin(), end = plugins->constEnd(); it != end; ++it) {
+ if (it->loader != nullptr)
+ results.append(it.key());
+ }
+ return results;
+}
#endif // QT_CONFIG(library)
void QQmlImportDatabase::clearDirCache()
@@ -2174,4 +2202,20 @@ void QQmlImportDatabase::clearDirCache()
qmldirCache.clear();
}
+void QQmlImportDatabase::finalizePlugin(QObject *instance, const QString &path, const QString &uri)
+{
+ // The plugin's per-engine initialization does not need lock protection, as this function is
+ // only called from the engine specific loader thread and importDynamicPlugin as well as
+ // importStaticPlugin are the only places of access.
+
+ initializedPlugins.insert(path);
+ if (auto *extensionIface = qobject_cast<QQmlExtensionInterface *>(instance)) {
+ QQmlEnginePrivate::get(engine)->typeLoader.initializeEngine(
+ extensionIface, uri.toUtf8().constData());
+ } else if (auto *engineIface = qobject_cast<QQmlEngineExtensionInterface *>(instance)) {
+ QQmlEnginePrivate::get(engine)->typeLoader.initializeEngine(
+ engineIface, uri.toUtf8().constData());
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h
index e24b3c447c..7cf1ae61b9 100644
--- a/src/qml/qml/qqmlimport_p.h
+++ b/src/qml/qml/qqmlimport_p.h
@@ -114,7 +114,7 @@ public:
int *vmajor, int *vminor, QQmlType* type_return,
QString *base = nullptr, QList<QQmlError> *errors = nullptr,
QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType,
- QQmlImport::RecursionRestriction recursionRestriction = QQmlImport::PreventRecursion);
+ bool *typeRecursionDeteced = nullptr);
// Prefix when used as a qualified import. Otherwise empty.
QHashedString prefix;
@@ -142,8 +142,7 @@ public:
QQmlImportNamespace **ns_return,
QList<QQmlError> *errors = nullptr,
QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType,
- QQmlImport::RecursionRestriction recursionRestriction
- = QQmlImport::PreventRecursion) const;
+ bool *typeRecursionDetected = nullptr) const;
bool resolveType(QQmlImportNamespace *,
const QHashedStringRef& type,
QQmlType *type_return, int *version_major, int *version_minor,
@@ -203,7 +202,7 @@ private:
QQmlImportsPrivate *d;
};
-class QQmlImportDatabase
+class Q_QML_PRIVATE_EXPORT QQmlImportDatabase
{
Q_DECLARE_TR_FUNCTIONS(QQmlImportDatabase)
public:
@@ -214,6 +213,8 @@ public:
#if QT_CONFIG(library)
bool importDynamicPlugin(const QString &filePath, const QString &uri, const QString &importNamespace, int vmaj, QList<QQmlError> *errors);
+ bool removeDynamicPlugin(const QString &filePath);
+ QStringList dynamicPlugins() const;
#endif
QStringList importPathList(PathType type = LocalOrRemote) const;
@@ -236,6 +237,7 @@ private:
bool importStaticPlugin(QObject *instance, const QString &basePath, const QString &uri,
const QString &typeNamespace, int vmaj, QList<QQmlError> *errors);
void clearDirCache();
+ void finalizePlugin(QObject *instance, const QString &path, const QString &uri);
struct QmldirCache {
int versionMajor;
diff --git a/src/qml/qml/qqmlincubator.cpp b/src/qml/qml/qqmlincubator.cpp
index f0ef5360b0..4911cd2879 100644
--- a/src/qml/qml/qqmlincubator.cpp
+++ b/src/qml/qml/qqmlincubator.cpp
@@ -403,26 +403,51 @@ void QQmlIncubationController::incubateFor(int msecs)
if (!d || !d->incubatorCount)
return;
- QQmlInstantiationInterrupt i(msecs * 1000000);
+ QQmlInstantiationInterrupt i(msecs * Q_INT64_C(1000000));
i.reset();
do {
static_cast<QQmlIncubatorPrivate*>(d->incubatorList.first())->incubate(i);
} while (d && d->incubatorCount != 0 && !i.shouldInterrupt());
}
+#if QT_DEPRECATED_SINCE(5, 15)
/*!
-Incubate objects while the bool pointed to by \a flag is true, or until there are no
-more objects to incubate, or up to \a msecs if \a msecs is not zero.
+\obsolete
+
+\warning Do not use this function.
+Use the overload taking a \c{std::atomic<bool>} instead.
+*/
+void QQmlIncubationController::incubateWhile(volatile bool *flag, int msecs)
+{
+ if (!d || !d->incubatorCount)
+ return;
+
+ QQmlInstantiationInterrupt i(flag, msecs * Q_INT64_C(1000000));
+ i.reset();
+ do {
+ static_cast<QQmlIncubatorPrivate*>(d->incubatorList.first())->incubate(i);
+ } while (d && d->incubatorCount != 0 && !i.shouldInterrupt());
+}
+#endif
+
+/*!
+\since 5.15
+
+Incubate objects while the atomic bool pointed to by \a flag is true,
+or until there are no more objects to incubate, or up to \a msecs if \a
+msecs is not zero.
Generally this method is used in conjunction with a thread or a UNIX signal that sets
the bool pointed to by \a flag to false when it wants incubation to be interrupted.
+
+\note \a flag is read using acquire memory ordering.
*/
-void QQmlIncubationController::incubateWhile(volatile bool *flag, int msecs)
+void QQmlIncubationController::incubateWhile(std::atomic<bool> *flag, int msecs)
{
if (!d || !d->incubatorCount)
return;
- QQmlInstantiationInterrupt i(flag, msecs * 1000000);
+ QQmlInstantiationInterrupt i(flag, msecs * Q_INT64_C(1000000));
i.reset();
do {
static_cast<QQmlIncubatorPrivate*>(d->incubatorList.first())->incubate(i);
diff --git a/src/qml/qml/qqmlincubator.h b/src/qml/qml/qqmlincubator.h
index f075407e73..6e47ca2173 100644
--- a/src/qml/qml/qqmlincubator.h
+++ b/src/qml/qml/qqmlincubator.h
@@ -42,6 +42,7 @@
#include <QtQml/qtqmlglobal.h>
#include <QtQml/qqmlerror.h>
+#include <atomic>
QT_BEGIN_NAMESPACE
@@ -112,7 +113,11 @@ public:
int incubatingObjectCount() const;
void incubateFor(int msecs);
+#if QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_VERSION_X(5, 15, "Use the overload that takes a std::atomic<bool>")
void incubateWhile(volatile bool *flag, int msecs=0);
+#endif
+ void incubateWhile(std::atomic<bool> *flag, int msecs = 0);
protected:
virtual void incubatingObjectCountChanged(int);
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 1a5affb0ad..b8c17c9374 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -267,6 +267,23 @@ void QQmlMetaType::clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
}
}
+void QQmlMetaType::qmlInsertModuleRegistration(const QString &uri, int majorVersion,
+ void (*registerFunction)())
+{
+ const QQmlMetaTypeData::VersionedUri versionedUri(uri, majorVersion);
+ QQmlMetaTypeDataPtr data;
+ if (data->moduleTypeRegistrationFunctions.contains(versionedUri))
+ qFatal("Canot add multiple registrations for %s %d", qPrintable(uri), majorVersion);
+ else
+ data->moduleTypeRegistrationFunctions.insert(versionedUri, registerFunction);
+}
+
+bool QQmlMetaType::qmlRegisterModuleTypes(const QString &uri, int majorVersion)
+{
+ QQmlMetaTypeDataPtr data;
+ return data->registerModuleTypes(QQmlMetaTypeData::VersionedUri(uri, majorVersion));
+}
+
void QQmlMetaType::clearTypeRegistrations()
{
//Only cleans global static, assumed no running engine
@@ -501,12 +518,10 @@ QQmlType QQmlMetaType::registerCompositeType(const QQmlPrivate::RegisterComposit
return QQmlType(priv);
}
-void QQmlMetaType::registerInternalCompositeType(QV4::ExecutableCompilationUnit *compilationUnit)
+QQmlMetaType::CompositeMetaTypeIds QQmlMetaType::registerInternalCompositeType(const QByteArray &className)
{
- QByteArray name = compilationUnit->rootPropertyCache()->className();
-
- QByteArray ptr = name + '*';
- QByteArray lst = "QQmlListProperty<" + name + '>';
+ QByteArray ptr = className + '*';
+ QByteArray lst = "QQmlListProperty<" + className + '>';
int ptr_type = QMetaType::registerNormalizedType(ptr,
QtMetaTypePrivate::QMetaTypeFunctionHelper<QObject*>::Destruct,
@@ -521,23 +536,19 @@ void QQmlMetaType::registerInternalCompositeType(QV4::ExecutableCompilationUnit
static_cast<QFlags<QMetaType::TypeFlag> >(QtPrivate::QMetaTypeTypeFlags<QQmlListProperty<QObject> >::Flags),
static_cast<QMetaObject*>(nullptr));
- compilationUnit->metaTypeId = ptr_type;
- compilationUnit->listMetaTypeId = lst_type;
-
QQmlMetaTypeDataPtr data;
data->qmlLists.insert(lst_type, ptr_type);
+
+ return {ptr_type, lst_type};
}
-void QQmlMetaType::unregisterInternalCompositeType(QV4::ExecutableCompilationUnit *compilationUnit)
+void QQmlMetaType::unregisterInternalCompositeType(const QQmlMetaType::CompositeMetaTypeIds &typeIds)
{
- int ptr_type = compilationUnit->metaTypeId;
- int lst_type = compilationUnit->listMetaTypeId;
-
QQmlMetaTypeDataPtr data;
- data->qmlLists.remove(lst_type);
+ data->qmlLists.remove(typeIds.listId);
- QMetaType::unregisterType(ptr_type);
- QMetaType::unregisterType(lst_type);
+ QMetaType::unregisterType(typeIds.id);
+ QMetaType::unregisterType(typeIds.listId);
}
int QQmlMetaType::registerUnitCacheHook(
@@ -633,17 +644,6 @@ bool QQmlMetaType::registerPluginTypes(QObject *instance, const QString &basePat
const QString &uri, const QString &typeNamespace, int vmaj,
QList<QQmlError> *errors)
{
- QQmlTypesExtensionInterface *iface = qobject_cast<QQmlTypesExtensionInterface *>(instance);
- if (!iface) {
- if (errors) {
- QQmlError error;
- error.setDescription(QStringLiteral("Module loaded for URI '%1' does not implement "
- "QQmlTypesExtensionInterface").arg(typeNamespace));
- errors->prepend(error);
- }
- return false;
- }
-
if (!typeNamespace.isEmpty() && typeNamespace != uri) {
// This is an 'identified' module
// The namespace for type registrations must match the URI for locating the module
@@ -681,26 +681,42 @@ bool QQmlMetaType::registerPluginTypes(QObject *instance, const QString &basePat
"it cannot be protected from external registrations.").arg(uri));
}
- if (auto *plugin = qobject_cast<QQmlExtensionPlugin *>(instance)) {
- // basepath should point to the directory of the module, not the plugin file itself:
- QQmlExtensionPluginPrivate::get(plugin)->baseUrl
- = QQmlImports::urlFromLocalFileOrQrcOrUrl(basePath);
+ if (!qobject_cast<QQmlEngineExtensionInterface *>(instance)) {
+ QQmlTypesExtensionInterface *iface = qobject_cast<QQmlTypesExtensionInterface *>(instance);
+ if (!iface) {
+ if (errors) {
+ QQmlError error;
+ // Also does not implement QQmlTypesExtensionInterface, but we want to discourage that.
+ error.setDescription(QStringLiteral("Module loaded for URI '%1' does not implement "
+ "QQmlEngineExtensionInterface").arg(typeNamespace));
+ errors->prepend(error);
+ }
+ return false;
+ }
+
+ if (auto *plugin = qobject_cast<QQmlExtensionPlugin *>(instance)) {
+ // basepath should point to the directory of the module, not the plugin file itself:
+ QQmlExtensionPluginPrivate::get(plugin)->baseUrl
+ = QQmlImports::urlFromLocalFileOrQrcOrUrl(basePath);
+ }
+
+ const QByteArray bytes = uri.toUtf8();
+ const char *moduleId = bytes.constData();
+ iface->registerTypes(moduleId);
}
- const QByteArray bytes = uri.toUtf8();
- const char *moduleId = bytes.constData();
- iface->registerTypes(moduleId);
- }
+ data->registerModuleTypes(QQmlMetaTypeData::VersionedUri(uri, vmaj));
- if (!failures.isEmpty()) {
- if (errors) {
- for (const QString &failure : qAsConst(failures)) {
- QQmlError error;
- error.setDescription(failure);
- errors->prepend(error);
+ if (!failures.isEmpty()) {
+ if (errors) {
+ for (const QString &failure : qAsConst(failures)) {
+ QQmlError error;
+ error.setDescription(failure);
+ errors->prepend(error);
+ }
}
+ return false;
}
- return false;
}
return true;
diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h
index 35d5386e1f..ed4675046d 100644
--- a/src/qml/qml/qqmlmetatype_p.h
+++ b/src/qml/qml/qqmlmetatype_p.h
@@ -80,8 +80,17 @@ public:
static void unregisterType(int type);
- static void registerInternalCompositeType(QV4::ExecutableCompilationUnit *compilationUnit);
- static void unregisterInternalCompositeType(QV4::ExecutableCompilationUnit *compilationUnit);
+ struct CompositeMetaTypeIds
+ {
+ int id = -1;
+ int listId = -1;
+ CompositeMetaTypeIds() = default;
+ CompositeMetaTypeIds(int id, int listId) : id(id), listId(listId) {}
+ bool isValid() const { return id != -1 && listId != -1; }
+ };
+
+ static CompositeMetaTypeIds registerInternalCompositeType(const QByteArray &className);
+ static void unregisterInternalCompositeType(const QQmlMetaType::CompositeMetaTypeIds &typeIds);
static void registerModule(const char *uri, int versionMajor, int versionMinor);
static bool protectModule(const QString &uri, int majVersion);
@@ -188,6 +197,10 @@ public:
static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
const QMetaObject *ignoreStart, const QMetaObject *ignoreEnd);
+
+ static void qmlInsertModuleRegistration(const QString &uri, int majorVersion,
+ void (*registerFunction)());
+ static bool qmlRegisterModuleTypes(const QString &uri, int majorVersion);
};
Q_DECLARE_TYPEINFO(QQmlMetaType, Q_MOVABLE_TYPE);
diff --git a/src/qml/qml/qqmlmetatypedata.cpp b/src/qml/qml/qqmlmetatypedata.cpp
index 775bc8bdb4..ed885eaa97 100644
--- a/src/qml/qml/qqmlmetatypedata.cpp
+++ b/src/qml/qml/qqmlmetatypedata.cpp
@@ -78,6 +78,16 @@ void QQmlMetaTypeData::registerType(QQmlTypePrivate *priv)
priv->release();
}
+bool QQmlMetaTypeData::registerModuleTypes(const QQmlMetaTypeData::VersionedUri &versionedUri)
+{
+ auto function = moduleTypeRegistrationFunctions.constFind(versionedUri);
+ if (function != moduleTypeRegistrationFunctions.constEnd()) {
+ (*function)();
+ return true;
+ }
+ return false;
+}
+
QQmlPropertyCache *QQmlMetaTypeData::propertyCacheForMinorVersion(int index, int minorVersion) const
{
return (index < typePropertyCaches.length())
diff --git a/src/qml/qml/qqmlmetatypedata_p.h b/src/qml/qml/qqmlmetatypedata_p.h
index ea796ee7c6..f193e51f5a 100644
--- a/src/qml/qml/qqmlmetatypedata_p.h
+++ b/src/qml/qml/qqmlmetatypedata_p.h
@@ -96,9 +96,13 @@ struct QQmlMetaTypeData
QHashedString uri;
int majorVersion;
};
+
typedef QHash<VersionedUri, QQmlTypeModule *> TypeModules;
TypeModules uriToModule;
+ QHash<VersionedUri, void (*)()> moduleTypeRegistrationFunctions;
+ bool registerModuleTypes(const VersionedUri &versionedUri);
+
QBitArray objects;
QBitArray interfaces;
QBitArray lists;
diff --git a/src/qml/qml/qqmlmoduleregistration.cpp b/src/qml/qml/qqmlmoduleregistration.cpp
new file mode 100644
index 0000000000..bb82ec1d95
--- /dev/null
+++ b/src/qml/qml/qqmlmoduleregistration.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtQml/private/qqmlmetatype_p.h>
+#include <QtQml/qqmlmoduleregistration.h>
+#include <QtCore/qglobalstatic.h>
+
+QT_BEGIN_NAMESPACE
+
+QQmlModuleRegistration::QQmlModuleRegistration(
+ const char *uri, int majorVersion,
+ void (*registerFunction)())
+{
+ QQmlMetaType::qmlInsertModuleRegistration(QString::fromUtf8(uri), majorVersion,
+ registerFunction);
+}
+
+QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlmoduleregistration.h b/src/qml/qml/qqmlmoduleregistration.h
new file mode 100644
index 0000000000..8924724b48
--- /dev/null
+++ b/src/qml/qml/qqmlmoduleregistration.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQMLMODULEREGISTRATION_H
+#define QQMLMODULEREGISTRATION_H
+
+#include <QtQml/qtqmlglobal.h>
+
+QT_BEGIN_NAMESPACE
+
+class Q_QML_EXPORT QQmlModuleRegistration
+{
+ Q_DISABLE_COPY_MOVE(QQmlModuleRegistration)
+
+public:
+ QQmlModuleRegistration(const char *uri, int majorVersion, void (*registerFunction)());
+ ~QQmlModuleRegistration() = default;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQMLMODULEREGISTRATION_H
diff --git a/src/qml/qml/qqmlnotifier.cpp b/src/qml/qml/qqmlnotifier.cpp
index 1359586b31..fe839a50dc 100644
--- a/src/qml/qml/qqmlnotifier.cpp
+++ b/src/qml/qml/qqmlnotifier.cpp
@@ -118,8 +118,8 @@ void QQmlNotifierEndpoint::connect(QObject *source, int sourceSignal, QQmlEngine
disconnect();
Q_ASSERT(engine);
- if (QObjectPrivate::get(source)->threadData->threadId.loadRelaxed() !=
- QObjectPrivate::get(engine)->threadData->threadId.loadRelaxed()) {
+ if (QObjectPrivate::get(source)->getThreadData()->threadId.loadRelaxed() !=
+ QObjectPrivate::get(engine)->getThreadData()->threadId.loadRelaxed()) {
QString sourceName;
QDebug(&sourceName) << source;
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index cf1795aafa..d68ad69260 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -59,22 +59,12 @@
#include <private/qjsvalue_p.h>
#include <private/qv4generatorobject_p.h>
+#include <QScopedValueRollback>
+
#include <qtqml_tracepoints_p.h>
QT_USE_NAMESPACE
-namespace {
-struct ActiveOCRestorer
-{
- ActiveOCRestorer(QQmlObjectCreator *creator, QQmlEnginePrivate *ep)
- : ep(ep), oldCreator(ep->activeObjectCreator) { ep->activeObjectCreator = creator; }
- ~ActiveOCRestorer() { ep->activeObjectCreator = oldCreator; }
-
- QQmlEnginePrivate *ep;
- QQmlObjectCreator *oldCreator;
-};
-}
-
QQmlObjectCreator::QQmlObjectCreator(QQmlContextData *parentContext, const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, QQmlContextData *creationContext,
QQmlIncubatorPrivate *incubator)
: phase(Startup)
@@ -234,73 +224,20 @@ QObject *QQmlObjectCreator::create(int subComponentIndex, QObject *parent, QQmlI
return instance;
}
-// ### unify or keep in sync with populateDeferredBinding()
-bool QQmlObjectCreator::populateDeferredProperties(QObject *instance, QQmlData::DeferredData *deferredData)
+void QQmlObjectCreator::beginPopulateDeferred(QQmlContextData *newContext)
{
- QQmlData *declarativeData = QQmlData::get(instance);
- context = deferredData->context;
- sharedState->rootContext = context;
-
- QObject *bindingTarget = instance;
-
- QQmlRefPointer<QQmlPropertyCache> cache = declarativeData->propertyCache;
- QQmlVMEMetaObject *vmeMetaObject = QQmlVMEMetaObject::get(instance);
-
- QObject *scopeObject = instance;
- qSwap(_scopeObject, scopeObject);
-
- QV4::Scope valueScope(v4);
+ context = newContext;
+ sharedState->rootContext = newContext;
Q_ASSERT(topLevelCreator);
Q_ASSERT(!sharedState->allJavaScriptObjects);
- sharedState->allJavaScriptObjects = valueScope.alloc(compilationUnit->totalObjectCount);
-
- QV4::QmlContext *qmlContext = static_cast<QV4::QmlContext *>(valueScope.alloc());
-
- qSwap(_qmlContext, qmlContext);
-
- qSwap(_propertyCache, cache);
- qSwap(_qobject, instance);
-
- int objectIndex = deferredData->deferredIdx;
- qSwap(_compiledObjectIndex, objectIndex);
-
- const QV4::CompiledData::Object *obj = compilationUnit->objectAt(_compiledObjectIndex);
- qSwap(_compiledObject, obj);
-
- qSwap(_ddata, declarativeData);
- qSwap(_bindingTarget, bindingTarget);
- qSwap(_vmeMetaObject, vmeMetaObject);
-
- setupBindings(/*applyDeferredBindings=*/true);
-
- qSwap(_vmeMetaObject, vmeMetaObject);
- qSwap(_bindingTarget, bindingTarget);
- qSwap(_ddata, declarativeData);
- qSwap(_compiledObject, obj);
- qSwap(_compiledObjectIndex, objectIndex);
- qSwap(_qobject, instance);
- qSwap(_propertyCache, cache);
-
- qSwap(_qmlContext, qmlContext);
- qSwap(_scopeObject, scopeObject);
-
- deferredData->bindings.clear();
- phase = ObjectsCreated;
-
- return errors.isEmpty();
}
-// ### unify or keep in sync with populateDeferredProperties()
-bool QQmlObjectCreator::populateDeferredBinding(const QQmlProperty &qmlProperty, QQmlData::DeferredData *deferredData, const QV4::CompiledData::Binding *binding)
+void QQmlObjectCreator::populateDeferred(QObject *instance, int deferredIndex,
+ const QQmlPropertyPrivate *qmlProperty,
+ const QV4::CompiledData::Binding *binding)
{
- Q_ASSERT(binding->flags & QV4::CompiledData::Binding::IsDeferredBinding);
-
- QObject *instance = qmlProperty.object();
QQmlData *declarativeData = QQmlData::get(instance);
- context = deferredData->context;
- sharedState->rootContext = context;
-
QObject *bindingTarget = instance;
QQmlRefPointer<QQmlPropertyCache> cache = declarativeData->propertyCache;
@@ -310,11 +247,10 @@ bool QQmlObjectCreator::populateDeferredBinding(const QQmlProperty &qmlProperty,
qSwap(_scopeObject, scopeObject);
QV4::Scope valueScope(v4);
+ QScopedValueRollback<QV4::Value*> jsObjectGuard(sharedState->allJavaScriptObjects,
+ valueScope.alloc(compilationUnit->totalObjectCount));
Q_ASSERT(topLevelCreator);
- if (!sharedState->allJavaScriptObjects)
- sharedState->allJavaScriptObjects = valueScope.alloc(compilationUnit->totalObjectCount);
-
QV4::QmlContext *qmlContext = static_cast<QV4::QmlContext *>(valueScope.alloc());
qSwap(_qmlContext, qmlContext);
@@ -322,7 +258,7 @@ bool QQmlObjectCreator::populateDeferredBinding(const QQmlProperty &qmlProperty,
qSwap(_propertyCache, cache);
qSwap(_qobject, instance);
- int objectIndex = deferredData->deferredIdx;
+ int objectIndex = deferredIndex;
qSwap(_compiledObjectIndex, objectIndex);
const QV4::CompiledData::Object *obj = compilationUnit->objectAt(_compiledObjectIndex);
@@ -332,21 +268,28 @@ bool QQmlObjectCreator::populateDeferredBinding(const QQmlProperty &qmlProperty,
qSwap(_bindingTarget, bindingTarget);
qSwap(_vmeMetaObject, vmeMetaObject);
- QQmlListProperty<void> savedList;
- qSwap(_currentList, savedList);
+ if (binding) {
+ Q_ASSERT(qmlProperty);
+ Q_ASSERT(binding->flags & QV4::CompiledData::Binding::IsDeferredBinding);
- const QQmlPropertyData &property = QQmlPropertyPrivate::get(qmlProperty)->core;
+ QQmlListProperty<void> savedList;
+ qSwap(_currentList, savedList);
- if (property.isQList()) {
- void *argv[1] = { (void*)&_currentList };
- QMetaObject::metacall(_qobject, QMetaObject::ReadProperty, property.coreIndex(), argv);
- } else if (_currentList.object) {
- _currentList = QQmlListProperty<void>();
- }
+ const QQmlPropertyData &property = qmlProperty->core;
- setPropertyBinding(&property, binding);
+ if (property.isQList()) {
+ void *argv[1] = { (void*)&_currentList };
+ QMetaObject::metacall(_qobject, QMetaObject::ReadProperty, property.coreIndex(), argv);
+ } else if (_currentList.object) {
+ _currentList = QQmlListProperty<void>();
+ }
- qSwap(_currentList, savedList);
+ setPropertyBinding(&property, binding);
+
+ qSwap(_currentList, savedList);
+ } else {
+ setupBindings(/*applyDeferredBindings=*/true);
+ }
qSwap(_vmeMetaObject, vmeMetaObject);
qSwap(_bindingTarget, bindingTarget);
@@ -358,12 +301,29 @@ bool QQmlObjectCreator::populateDeferredBinding(const QQmlProperty &qmlProperty,
qSwap(_qmlContext, qmlContext);
qSwap(_scopeObject, scopeObject);
+}
- phase = ObjectsCreated;
-
+bool QQmlObjectCreator::populateDeferredProperties(QObject *instance,
+ const QQmlData::DeferredData *deferredData)
+{
+ beginPopulateDeferred(deferredData->context);
+ populateDeferred(instance, deferredData->deferredIdx);
+ finalizePopulateDeferred();
return errors.isEmpty();
}
+void QQmlObjectCreator::populateDeferredBinding(const QQmlProperty &qmlProperty, int deferredIndex,
+ const QV4::CompiledData::Binding *binding)
+{
+ populateDeferred(qmlProperty.object(), deferredIndex, QQmlPropertyPrivate::get(qmlProperty),
+ binding);
+}
+
+void QQmlObjectCreator::finalizePopulateDeferred()
+{
+ phase = ObjectsCreated;
+}
+
void QQmlObjectCreator::setPropertyValue(const QQmlPropertyData *property, const QV4::CompiledData::Binding *binding)
{
QQmlPropertyData::WriteFlags propertyWriteFlags = QQmlPropertyData::BypassInterceptor | QQmlPropertyData::RemoveBindingOnAliasWrite;
@@ -1191,7 +1151,7 @@ QObject *QQmlObjectCreator::createInstance(int index, QObject *parent, bool isCo
QString typeName;
Q_TRACE_EXIT(QQmlObjectCreator_createInstance_exit, typeName);
- ActiveOCRestorer ocRestorer(this, QQmlEnginePrivate::get(engine));
+ QScopedValueRollback<QQmlObjectCreator*> ocRestore(QQmlEnginePrivate::get(engine)->activeObjectCreator, this);
bool isComponent = false;
QObject *instance = nullptr;
@@ -1392,7 +1352,7 @@ QQmlContextData *QQmlObjectCreator::finalize(QQmlInstantiationInterrupt &interru
phase = Finalizing;
QQmlObjectCreatorRecursionWatcher watcher(this);
- ActiveOCRestorer ocRestorer(this, QQmlEnginePrivate::get(engine));
+ QScopedValueRollback<QQmlObjectCreator*> ocRestore(QQmlEnginePrivate::get(engine)->activeObjectCreator, this);
while (!sharedState->allCreatedBindings.isEmpty()) {
QQmlAbstractBinding::Ptr b = sharedState->allCreatedBindings.pop();
diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h
index 59e236c855..8b6cb67341 100644
--- a/src/qml/qml/qqmlobjectcreator_p.h
+++ b/src/qml/qml/qqmlobjectcreator_p.h
@@ -112,8 +112,14 @@ public:
~QQmlObjectCreator();
QObject *create(int subComponentIndex = -1, QObject *parent = nullptr, QQmlInstantiationInterrupt *interrupt = nullptr);
- bool populateDeferredProperties(QObject *instance, QQmlData::DeferredData *deferredData);
- bool populateDeferredBinding(const QQmlProperty &qmlProperty, QQmlData::DeferredData *deferredData, const QV4::CompiledData::Binding *binding);
+
+ bool populateDeferredProperties(QObject *instance, const QQmlData::DeferredData *deferredData);
+
+ void beginPopulateDeferred(QQmlContextData *context);
+ void populateDeferredBinding(const QQmlProperty &qmlProperty, int deferredIndex,
+ const QV4::CompiledData::Binding *binding);
+ void finalizePopulateDeferred();
+
QQmlContextData *finalize(QQmlInstantiationInterrupt &interrupt);
void clear();
@@ -139,6 +145,11 @@ private:
bool populateInstance(int index, QObject *instance,
QObject *bindingTarget, const QQmlPropertyData *valueTypeProperty);
+ // If qmlProperty and binding are null, populate all properties, otherwise only the given one.
+ void populateDeferred(QObject *instance, int deferredIndex,
+ const QQmlPropertyPrivate *qmlProperty = nullptr,
+ const QV4::CompiledData::Binding *binding = nullptr);
+
void setupBindings(bool applyDeferredBindings = false);
bool setPropertyBinding(const QQmlPropertyData *property, const QV4::CompiledData::Binding *binding);
void setPropertyValue(const QQmlPropertyData *property, const QV4::CompiledData::Binding *binding);
diff --git a/src/qml/qml/qqmlprivate.h b/src/qml/qml/qqmlprivate.h
index 27dac71571..9504fc37dc 100644
--- a/src/qml/qml/qqmlprivate.h
+++ b/src/qml/qml/qqmlprivate.h
@@ -62,7 +62,7 @@
#include <QtCore/qglobal.h>
#include <QtCore/qvariant.h>
#include <QtCore/qurl.h>
-#include <QPointer>
+#include <QtCore/qpointer.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qdebug.h>
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index eff3e94fbd..27667de678 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -63,6 +63,7 @@
#include <private/qqmlvaluetypewrapper_p.h>
#include <QtCore/qdebug.h>
#include <cmath>
+#include <QtQml/QQmlPropertyMap>
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<qreal>)
@@ -331,10 +332,15 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
return;
} else {
- if (!property->isQObject())
- return; // Not an object property
+ if (!property->isQObject()) {
+ if (auto asPropertyMap = qobject_cast<QQmlPropertyMap*>(currentObject))
+ currentObject = asPropertyMap->value(path.at(ii).toString()).value<QObject*>();
+ else
+ return; // Not an object property, and not a property map
+ } else {
+ property->readProperty(currentObject, &currentObject);
+ }
- property->readProperty(currentObject, &currentObject);
if (!currentObject) return; // No value
}
@@ -1373,8 +1379,9 @@ bool QQmlPropertyPrivate::write(QObject *object,
}
}
if (!ok) {
- // the only other option is that they are assigning a single value
+ // the only other options are that they are assigning a single value
// to a sequence type property (eg, an int to a QList<int> property).
+ // or that we encountered an interface type
// Note that we've already handled single-value assignment to QList<QUrl> properties.
if (variantType == QVariant::Int && propertyType == qMetaTypeId<QList<int> >()) {
QList<int> list;
@@ -1405,6 +1412,15 @@ bool QQmlPropertyPrivate::write(QObject *object,
}
}
+ if (!ok && QQmlMetaType::isInterface(propertyType)) {
+ auto valueAsQObject = qvariant_cast<QObject *>(value);
+ if (valueAsQObject && valueAsQObject->qt_metacast(QQmlMetaType::interfaceIId(propertyType))) {
+ // this case can occur when object has an interface type
+ // and the variant contains a type implementing the interface
+ return property.writeProperty(object, const_cast<void *>(value.constData()), flags);
+ }
+ }
+
if (ok) {
return property.writeProperty(object, const_cast<void *>(v.constData()), flags);
} else {
diff --git a/src/qml/qml/qqmlpropertycachecreator.cpp b/src/qml/qml/qqmlpropertycachecreator.cpp
index 034ebfc743..36581bda4e 100644
--- a/src/qml/qml/qqmlpropertycachecreator.cpp
+++ b/src/qml/qml/qqmlpropertycachecreator.cpp
@@ -74,6 +74,22 @@ int QQmlPropertyCacheCreatorBase::metaTypeForPropertyType(QV4::CompiledData::Bui
return QMetaType::UnknownType;
}
+QByteArray QQmlPropertyCacheCreatorBase::createClassNameTypeByUrl(const QUrl &url)
+{
+ const QString path = url.path();
+ int lastSlash = path.lastIndexOf(QLatin1Char('/'));
+ // Not a reusable type if we don't have an absolute Url
+ if (lastSlash <= -1)
+ return QByteArray();
+ // ### this might not be correct for .ui.qml files
+ const QStringRef nameBase = path.midRef(lastSlash + 1, path.length() - lastSlash - 5);
+ // Not a reusable type if it doesn't start with a upper case letter.
+ if (nameBase.isEmpty() || !nameBase.at(0).isUpper())
+ return QByteArray();
+ return nameBase.toUtf8() + "_QMLTYPE_" +
+ QByteArray::number(classIndexCounter.fetchAndAddRelaxed(1));
+}
+
QQmlBindingInstantiationContext::QQmlBindingInstantiationContext(int referencingObjectIndex, const QV4::CompiledData::Binding *instantiatingBinding,
const QString &instantiatingPropertyName, QQmlPropertyCache *referencingObjectPropertyCache)
: referencingObjectIndex(referencingObjectIndex)
diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h
index 39778aa328..8571b0c9b3 100644
--- a/src/qml/qml/qqmlpropertycachecreator_p.h
+++ b/src/qml/qml/qqmlpropertycachecreator_p.h
@@ -97,6 +97,8 @@ public:
static QAtomicInt classIndexCounter;
static int metaTypeForPropertyType(QV4::CompiledData::BuiltinType type);
+
+ static QByteArray createClassNameTypeByUrl(const QUrl &url);
};
template <typename ObjectContainer>
@@ -108,7 +110,8 @@ public:
QQmlPropertyCacheCreator(QQmlPropertyCacheVector *propertyCaches,
QQmlPendingGroupPropertyBindings *pendingGroupPropertyBindings,
QQmlEnginePrivate *enginePrivate,
- const ObjectContainer *objectContainer, const QQmlImports *imports);
+ const ObjectContainer *objectContainer, const QQmlImports *imports,
+ const QByteArray &typeClassName);
QQmlJS::DiagnosticMessage buildMetaObjects();
@@ -126,18 +129,21 @@ protected:
const QQmlImports * const imports;
QQmlPropertyCacheVector *propertyCaches;
QQmlPendingGroupPropertyBindings *pendingGroupPropertyBindings;
+ const QByteArray typeClassName;
};
template <typename ObjectContainer>
inline QQmlPropertyCacheCreator<ObjectContainer>::QQmlPropertyCacheCreator(QQmlPropertyCacheVector *propertyCaches,
QQmlPendingGroupPropertyBindings *pendingGroupPropertyBindings,
QQmlEnginePrivate *enginePrivate,
- const ObjectContainer *objectContainer, const QQmlImports *imports)
+ const ObjectContainer *objectContainer, const QQmlImports *imports,
+ const QByteArray &typeClassName)
: enginePrivate(enginePrivate)
, objectContainer(objectContainer)
, imports(imports)
, propertyCaches(propertyCaches)
, pendingGroupPropertyBindings(pendingGroupPropertyBindings)
+ , typeClassName(typeClassName)
{
propertyCaches->resize(objectContainer->objectCount());
}
@@ -293,14 +299,7 @@ inline QQmlJS::DiagnosticMessage QQmlPropertyCacheCreator<ObjectContainer>::crea
QByteArray newClassName;
if (objectIndex == /*root object*/0) {
- const QString path = objectContainer->url().path();
- int lastSlash = path.lastIndexOf(QLatin1Char('/'));
- if (lastSlash > -1) {
- const QStringRef nameBase = path.midRef(lastSlash + 1, path.length() - lastSlash - 5);
- if (!nameBase.isEmpty() && nameBase.at(0).isUpper())
- newClassName = nameBase.toUtf8() + "_QMLTYPE_" +
- QByteArray::number(classIndexCounter.fetchAndAddRelaxed(1));
- }
+ newClassName = typeClassName;
}
if (newClassName.isEmpty()) {
newClassName = QQmlMetaObject(baseTypeCache.data()).className();
@@ -499,22 +498,30 @@ inline QQmlJS::DiagnosticMessage QQmlPropertyCacheCreator<ObjectContainer>::crea
Q_ASSERT(!p->isBuiltinType);
QQmlType qmltype;
- if (!imports->resolveType(stringAt(p->builtinTypeOrTypeNameIndex), &qmltype, nullptr, nullptr, nullptr)) {
+ bool selfReference = false;
+ if (!imports->resolveType(stringAt(p->builtinTypeOrTypeNameIndex), &qmltype, nullptr, nullptr, nullptr,
+ nullptr, QQmlType::AnyRegistrationType, &selfReference)) {
return qQmlCompileError(p->location, QQmlPropertyCacheCreatorBase::tr("Invalid property type"));
}
Q_ASSERT(qmltype.isValid());
if (qmltype.isComposite()) {
- QQmlRefPointer<QQmlTypeData> tdata = enginePrivate->typeLoader.getType(qmltype.sourceUrl());
- Q_ASSERT(tdata);
- Q_ASSERT(tdata->isComplete());
+ QQmlMetaType::CompositeMetaTypeIds typeIds;
+ if (selfReference) {
+ typeIds = objectContainer->typeIds();
+ } else {
+ QQmlRefPointer<QQmlTypeData> tdata = enginePrivate->typeLoader.getType(qmltype.sourceUrl());
+ Q_ASSERT(tdata);
+ Q_ASSERT(tdata->isComplete());
- auto compilationUnit = tdata->compilationUnit();
+ auto compilationUnit = tdata->compilationUnit();
+ typeIds = compilationUnit->typeIds();
+ }
if (p->isList) {
- propertyType = compilationUnit->listMetaTypeId;
+ propertyType = typeIds.listId;
} else {
- propertyType = compilationUnit->metaTypeId;
+ propertyType = typeIds.id;
}
} else {
if (p->isList) {
@@ -562,12 +569,17 @@ inline int QQmlPropertyCacheCreator<ObjectContainer>::metaTypeForParameter(const
if (customTypeName)
*customTypeName = typeName;
QQmlType qmltype;
- if (!imports->resolveType(typeName, &qmltype, nullptr, nullptr, nullptr))
+ bool selfReference = false;
+ if (!imports->resolveType(typeName, &qmltype, nullptr, nullptr, nullptr, nullptr, QQmlType::AnyRegistrationType,
+ &selfReference))
return QMetaType::UnknownType;
if (!qmltype.isComposite())
return qmltype.typeId();
+ if (selfReference)
+ return objectContainer->typeIds().id;
+
QQmlRefPointer<QQmlTypeData> tdata = enginePrivate->typeLoader.getType(qmltype.sourceUrl());
Q_ASSERT(tdata);
Q_ASSERT(tdata->isComplete());
diff --git a/src/qml/qml/qqmlpropertyvalidator.cpp b/src/qml/qml/qqmlpropertyvalidator.cpp
index d7361ea2c6..238a535b89 100644
--- a/src/qml/qml/qqmlpropertyvalidator.cpp
+++ b/src/qml/qml/qqmlpropertyvalidator.cpp
@@ -728,12 +728,12 @@ QQmlJS::DiagnosticMessage QQmlPropertyValidator::validateObjectBinding(QQmlPrope
return noError;
} else if (isPrimitiveType(propType)) {
auto typeName = QString::fromUtf8(QMetaType::typeName(propType));
- return qQmlCompileError(binding->location, tr("Can not assign value of type \"%1\" to property \"%2\", expecting \"%3\"")
+ return qQmlCompileError(binding->location, tr("Cannot assign value of type \"%1\" to property \"%2\", expecting \"%3\"")
.arg(rhsType())
.arg(propertyName)
.arg(typeName));
} else if (QQmlValueTypeFactory::isValueType(propType)) {
- return qQmlCompileError(binding->location, tr("Can not assign value of type \"%1\" to property \"%2\", expecting an object")
+ return qQmlCompileError(binding->location, tr("Cannot assign value of type \"%1\" to property \"%2\", expecting an object")
.arg(rhsType()).arg(propertyName));
} else if (propType == qMetaTypeId<QQmlScriptString>()) {
return qQmlCompileError(binding->valueLocation, tr("Invalid property assignment: script expected"));
diff --git a/src/qml/qml/qqmlscriptblob.cpp b/src/qml/qml/qqmlscriptblob.cpp
index 6ac30d3ab5..eb103dc434 100644
--- a/src/qml/qml/qqmlscriptblob.cpp
+++ b/src/qml/qml/qqmlscriptblob.cpp
@@ -68,7 +68,7 @@ QQmlRefPointer<QQmlScriptData> QQmlScriptBlob::scriptData() const
void QQmlScriptBlob::dataReceived(const SourceCodeData &data)
{
- if (!diskCacheDisabled() || diskCacheForced()) {
+ if (diskCacheEnabled()) {
QQmlRefPointer<QV4::ExecutableCompilationUnit> unit
= QV4::ExecutableCompilationUnit::create();
QString error;
@@ -132,7 +132,7 @@ void QQmlScriptBlob::dataReceived(const SourceCodeData &data)
auto executableUnit = QV4::ExecutableCompilationUnit::create(std::move(unit));
- if ((!diskCacheDisabled() || diskCacheForced()) && !isDebugging()) {
+ if (diskCacheEnabled()) {
QString errorString;
if (executableUnit->saveToDisk(url(), &errorString)) {
QString error;
diff --git a/src/qml/qml/qqmltypecompiler.cpp b/src/qml/qml/qqmltypecompiler.cpp
index 9ff0e3fb9e..7b4cf1a580 100644
--- a/src/qml/qml/qqmltypecompiler.cpp
+++ b/src/qml/qml/qqmltypecompiler.cpp
@@ -81,7 +81,7 @@ QQmlRefPointer<QV4::ExecutableCompilationUnit> QQmlTypeCompiler::compile()
{
QQmlPropertyCacheCreator<QQmlTypeCompiler> propertyCacheBuilder(&m_propertyCaches, &pendingGroupPropertyBindings,
- engine, this, imports());
+ engine, this, imports(), typeData->typeClassName());
QQmlJS::DiagnosticMessage error = propertyCacheBuilder.buildMetaObjects();
if (error.isValid()) {
recordError(error);
@@ -279,6 +279,11 @@ void QQmlTypeCompiler::addImport(const QString &module, const QString &qualifier
document->imports.append(import);
}
+QQmlMetaType::CompositeMetaTypeIds QQmlTypeCompiler::typeIds() const
+{
+ return typeData->typeIds();
+}
+
QQmlCompilePass::QQmlCompilePass(QQmlTypeCompiler *typeCompiler)
: compiler(typeCompiler)
{
diff --git a/src/qml/qml/qqmltypecompiler_p.h b/src/qml/qml/qqmltypecompiler_p.h
index 40b0337848..b43089dc06 100644
--- a/src/qml/qml/qqmltypecompiler_p.h
+++ b/src/qml/qml/qqmltypecompiler_p.h
@@ -129,6 +129,8 @@ public:
return resolvedTypes->value(id);
}
+ QQmlMetaType::CompositeMetaTypeIds typeIds() const;
+
private:
QList<QQmlError> errors;
QQmlEnginePrivate *engine;
diff --git a/src/qml/qml/qqmltypedata.cpp b/src/qml/qml/qqmltypedata.cpp
index cfdcf6aad5..22587c226a 100644
--- a/src/qml/qml/qqmltypedata.cpp
+++ b/src/qml/qml/qqmltypedata.cpp
@@ -105,12 +105,14 @@ void QQmlTypeData::unregisterCallback(TypeDataCallback *callback)
Q_ASSERT(!m_callbacks.contains(callback));
}
-bool QQmlTypeData::tryLoadFromDiskCache()
+QQmlMetaType::CompositeMetaTypeIds QQmlTypeData::typeIds() const
{
- if (diskCacheDisabled() && !diskCacheForced())
- return false;
+ return m_typeIds;
+}
- if (isDebugging())
+bool QQmlTypeData::tryLoadFromDiskCache()
+{
+ if (!diskCacheEnabled())
return false;
QV4::ExecutionEngine *v4 = typeLoader()->engine()->handle();
@@ -199,7 +201,7 @@ void QQmlTypeData::createTypeAndPropertyCaches(
{
QQmlPropertyCacheCreator<QV4::ExecutableCompilationUnit> propertyCacheCreator(
&m_compiledData->propertyCaches, &pendingGroupPropertyBindings, engine,
- m_compiledData.data(), &m_importCache);
+ m_compiledData.data(), &m_importCache, typeClassName());
QQmlJS::DiagnosticMessage error = propertyCacheCreator.buildMetaObjects();
if (error.isValid()) {
setError(error);
@@ -299,6 +301,14 @@ void QQmlTypeData::done()
}
}
+ m_typeClassName = QQmlPropertyCacheCreatorBase::createClassNameTypeByUrl(finalUrl());
+ if (!m_typeClassName.isEmpty())
+ m_typeIds = QQmlMetaType::registerInternalCompositeType(m_typeClassName);
+ auto typeCleanupGuard = qScopeGuard([&]() {
+ if (isError() && m_typeIds.isValid())
+ QQmlMetaType::unregisterInternalCompositeType(m_typeIds);
+ });
+
QQmlRefPointer<QQmlTypeNameCache> typeNameCache;
QV4::ResolvedTypeReferenceMap resolvedTypeCache;
{
@@ -351,7 +361,7 @@ void QQmlTypeData::done()
}
}
- m_compiledData->finalizeCompositeType(enginePrivate);
+ m_compiledData->finalizeCompositeType(enginePrivate, typeIds());
}
{
@@ -621,8 +631,7 @@ void QQmlTypeData::compile(const QQmlRefPointer<QQmlTypeNameCache> &typeNameCach
return;
}
- const bool trySaveToDisk = (!diskCacheDisabled() || diskCacheForced())
- && !m_document->jsModule.debugMode && !typeRecompilation;
+ const bool trySaveToDisk = diskCacheEnabled() && !typeRecompilation;
if (trySaveToDisk) {
QString errorString;
if (m_compiledData->saveToDisk(url(), &errorString)) {
@@ -704,12 +713,14 @@ void QQmlTypeData::resolveTypes()
const QString name = stringAt(unresolvedRef.key());
+ bool *selfReferenceDetection = unresolvedRef->needsCreation ? nullptr : &ref.selfReference;
+
if (!resolveType(name, majorVersion, minorVersion, ref, unresolvedRef->location.line,
unresolvedRef->location.column, reportErrors,
- QQmlType::AnyRegistrationType) && reportErrors)
+ QQmlType::AnyRegistrationType, selfReferenceDetection) && reportErrors)
return;
- if (ref.type.isComposite()) {
+ if (ref.type.isComposite() && !ref.selfReference) {
ref.typeData = typeLoader()->getType(ref.type.sourceUrl());
addDependency(ref.typeData.data());
}
@@ -755,7 +766,7 @@ QQmlJS::DiagnosticMessage QQmlTypeData::buildTypeResolutionCaches(
return qQmlCompileError(resolvedType->location, tr("Composite Singleton Type %1 is not creatable.").arg(qmlType.qmlTypeName()));
}
ref->compilationUnit = resolvedType->typeData->compilationUnit();
- } else if (qmlType.isValid()) {
+ } else if (qmlType.isValid() && !resolvedType->selfReference) {
ref->type = qmlType;
Q_ASSERT(ref->type.isValid());
@@ -782,20 +793,23 @@ QQmlJS::DiagnosticMessage QQmlTypeData::buildTypeResolutionCaches(
bool QQmlTypeData::resolveType(const QString &typeName, int &majorVersion, int &minorVersion,
TypeReference &ref, int lineNumber, int columnNumber,
- bool reportErrors, QQmlType::RegistrationType registrationType)
+ bool reportErrors, QQmlType::RegistrationType registrationType,
+ bool *typeRecursionDetected)
{
QQmlImportNamespace *typeNamespace = nullptr;
QList<QQmlError> errors;
bool typeFound = m_importCache.resolveType(typeName, &ref.type, &majorVersion, &minorVersion,
- &typeNamespace, &errors, registrationType);
+ &typeNamespace, &errors, registrationType,
+ typeRecursionDetected);
if (!typeNamespace && !typeFound && !m_implicitImportLoaded) {
// Lazy loading of implicit import
if (loadImplicitImport()) {
// Try again to find the type
errors.clear();
typeFound = m_importCache.resolveType(typeName, &ref.type, &majorVersion, &minorVersion,
- &typeNamespace, &errors, registrationType);
+ &typeNamespace, &errors, registrationType,
+ typeRecursionDetected);
} else {
return false; //loadImplicitImport() hit an error, and called setError already
}
diff --git a/src/qml/qml/qqmltypedata_p.h b/src/qml/qml/qqmltypedata_p.h
index e1d0c900ea..53e78e06d7 100644
--- a/src/qml/qml/qqmltypedata_p.h
+++ b/src/qml/qml/qqmltypedata_p.h
@@ -69,6 +69,7 @@ public:
int majorVersion;
int minorVersion;
QQmlRefPointer<QQmlTypeData> typeData;
+ bool selfReference = false;
QString prefix; // used by CompositeSingleton types
QString qualifiedName() const;
bool needsCreation;
@@ -102,6 +103,9 @@ public:
void registerCallback(TypeDataCallback *);
void unregisterCallback(TypeDataCallback *);
+ QQmlMetaType::CompositeMetaTypeIds typeIds() const;
+ QByteArray typeClassName() const { return m_typeClassName; }
+
protected:
void done() override;
void completed() override;
@@ -130,11 +134,11 @@ private:
bool resolveType(const QString &typeName, int &majorVersion, int &minorVersion,
TypeReference &ref, int lineNumber = -1, int columnNumber = -1,
bool reportErrors = true,
- QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType);
+ QQmlType::RegistrationType registrationType = QQmlType::AnyRegistrationType,
+ bool *typeRecursionDetected = nullptr);
void scriptImported(const QQmlRefPointer<QQmlScriptBlob> &blob, const QV4::CompiledData::Location &location, const QString &qualifier, const QString &nameSpace) override;
-
SourceCodeData m_backupSourceCode; // used when cache verification fails.
QScopedPointer<QmlIR::Document> m_document;
QV4::CompiledData::TypeReferenceMap m_typeReferences;
@@ -150,6 +154,10 @@ private:
QMap<int, TypeReference> m_resolvedTypes;
bool m_typesResolved:1;
+ // Used for self-referencing types, otherwise -1.
+ QQmlMetaType::CompositeMetaTypeIds m_typeIds;
+ QByteArray m_typeClassName; // used for meta-object later
+
QQmlRefPointer<QV4::ExecutableCompilationUnit> m_compiledData;
QList<TypeDataCallback *> m_callbacks;
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index c62f760ee3..b164f5873c 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -395,19 +395,29 @@ QQmlEngine *QQmlTypeLoader::engine() const
Call the initializeEngine() method on \a iface. Used by QQmlImportDatabase to ensure it
gets called in the correct thread.
*/
-void QQmlTypeLoader::initializeEngine(QQmlExtensionInterface *iface,
- const char *uri)
+template<class Interface>
+void doInitializeEngine(Interface *iface, QQmlTypeLoaderThread *thread, QQmlEngine *engine,
+ const char *uri)
{
- Q_ASSERT(m_thread->isThisThread() || engine()->thread() == QThread::currentThread());
+ Q_ASSERT(thread->isThisThread() || engine->thread() == QThread::currentThread());
- if (m_thread->isThisThread()) {
- m_thread->initializeEngine(iface, uri);
+ if (thread->isThisThread()) {
+ thread->initializeEngine(iface, uri);
} else {
- Q_ASSERT(engine()->thread() == QThread::currentThread());
- iface->initializeEngine(engine(), uri);
+ Q_ASSERT(engine->thread() == QThread::currentThread());
+ iface->initializeEngine(engine, uri);
}
}
+void QQmlTypeLoader::initializeEngine(QQmlEngineExtensionInterface *iface, const char *uri)
+{
+ doInitializeEngine(iface, m_thread, engine(), uri);
+}
+
+void QQmlTypeLoader::initializeEngine(QQmlExtensionInterface *iface, const char *uri)
+{
+ doInitializeEngine(iface, m_thread, engine(), uri);
+}
void QQmlTypeLoader::setData(QQmlDataBlob *blob, const QByteArray &data)
{
@@ -588,7 +598,8 @@ bool QQmlTypeLoader::Blob::addImport(QQmlTypeLoader::Blob::PendingImportPtr impo
}
} else {
// Is this a module?
- if (QQmlMetaType::isAnyModule(import->uri)) {
+ if (QQmlMetaType::isAnyModule(import->uri)
+ || QQmlMetaType::qmlRegisterModuleTypes(import->uri, import->majorVersion)) {
if (!m_importCache.addLibraryImport(importDatabase, import->uri, import->qualifier, import->majorVersion,
import->minorVersion, QString(), QString(), false, errors))
return false;
@@ -697,14 +708,9 @@ bool QQmlTypeLoader::Blob::isDebugging() const
return typeLoader()->engine()->handle()->debugger() != nullptr;
}
-bool QQmlTypeLoader::Blob::diskCacheDisabled()
+bool QQmlTypeLoader::Blob::diskCacheEnabled() const
{
- return disableDiskCache();
-}
-
-bool QQmlTypeLoader::Blob::diskCacheForced()
-{
- return forceDiskCache();
+ return (!disableDiskCache() || forceDiskCache()) && !isDebugging();
}
bool QQmlTypeLoader::Blob::qmldirDataAvailable(const QQmlRefPointer<QQmlQmldirData> &data, QList<QQmlError> *errors)
@@ -963,48 +969,56 @@ bool QQmlTypeLoader::fileExists(const QString &path, const QString &file)
return false;
Q_ASSERT(path.endsWith(QLatin1Char('/')));
+
+ LockHolder<QQmlTypeLoader> holder(this);
+ QCache<QString, bool> *fileSet = m_importDirCache.object(path);
+ if (fileSet) {
+ if (bool *value = fileSet->object(file))
+ return *value;
+ } else if (m_importDirCache.contains(path)) {
+ // explicit nullptr in cache
+ return false;
+ }
+
+ auto addToCache = [&](const QFileInfo &fileInfo) {
+ if (!fileSet) {
+ fileSet = fileInfo.dir().exists() ? new QCache<QString, bool> : nullptr;
+ m_importDirCache.insert(path, fileSet);
+ if (!fileSet)
+ return false;
+ }
+
+ const bool exists = fileInfo.exists();
+ fileSet->insert(file, new bool(exists));
+ return exists;
+ };
+
if (path.at(0) == QLatin1Char(':')) {
// qrc resource
- QFileInfo fileInfo(path + file);
- return fileInfo.isFile();
- } else if (path.count() > 3 && path.at(3) == QLatin1Char(':') &&
- path.startsWith(QLatin1String("qrc"), Qt::CaseInsensitive)) {
+ return addToCache(QFileInfo(path + file));
+ }
+
+ if (path.count() > 3 && path.at(3) == QLatin1Char(':')
+ && path.startsWith(QLatin1String("qrc"), Qt::CaseInsensitive)) {
// qrc resource url
- QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(path + file));
- return fileInfo.isFile();
+ return addToCache(QFileInfo(QQmlFile::urlToLocalFileOrQrc(path + file)));
}
+
#if defined(Q_OS_ANDROID)
- else if (path.count() > 7 && path.at(6) == QLatin1Char(':') && path.at(7) == QLatin1Char('/') &&
- path.startsWith(QLatin1String("assets"), Qt::CaseInsensitive)) {
+ if (path.count() > 7 && path.at(6) == QLatin1Char(':') && path.at(7) == QLatin1Char('/')
+ && path.startsWith(QLatin1String("assets"), Qt::CaseInsensitive)) {
// assets resource url
- QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(path + file));
- return fileInfo.isFile();
- } else if (path.count() > 8 && path.at(7) == QLatin1Char(':') && path.at(8) == QLatin1Char('/') &&
- path.startsWith(QLatin1String("content"), Qt::CaseInsensitive)) {
- // content url
- QFileInfo fileInfo(QQmlFile::urlToLocalFileOrQrc(path + file));
- return fileInfo.isFile();
+ return addToCache(QFileInfo(QQmlFile::urlToLocalFileOrQrc(path + file)));
}
-#endif
- LockHolder<QQmlTypeLoader> holder(this);
- if (!m_importDirCache.contains(path)) {
- bool exists = QDir(path).exists();
- QCache<QString, bool> *entry = exists ? new QCache<QString, bool> : nullptr;
- m_importDirCache.insert(path, entry);
+ if (path.count() > 8 && path.at(7) == QLatin1Char(':') && path.at(8) == QLatin1Char('/')
+ && path.startsWith(QLatin1String("content"), Qt::CaseInsensitive)) {
+ // content url
+ return addToCache(QFileInfo(QQmlFile::urlToLocalFileOrQrc(path + file)));
}
- QCache<QString, bool> *fileSet = m_importDirCache.object(path);
- if (!fileSet)
- return false;
+#endif
- bool *value = fileSet->object(file);
- if (value) {
- return *value;
- } else {
- bool exists = QFile::exists(path + file);
- fileSet->insert(file, new bool(exists));
- return exists;
- }
+ return addToCache(QFileInfo(path + file));
}
diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h
index 612d6777ed..adecf61896 100644
--- a/src/qml/qml/qqmltypeloader_p.h
+++ b/src/qml/qml/qqmltypeloader_p.h
@@ -68,6 +68,7 @@ QT_BEGIN_NAMESPACE
class QQmlScriptBlob;
class QQmlQmldirData;
class QQmlTypeData;
+class QQmlEngineExtensionInterface;
class QQmlExtensionInterface;
class QQmlProfiler;
class QQmlTypeLoaderThread;
@@ -128,9 +129,7 @@ public:
virtual QString stringAt(int) const { return QString(); }
bool isDebugging() const;
-
- static bool diskCacheDisabled();
- static bool diskCacheForced();
+ bool diskCacheEnabled() const;
QQmlImports m_importCache;
QVector<PendingImportPtr> m_unresolvedImports;
@@ -172,6 +171,7 @@ public:
void loadWithCachedUnit(QQmlDataBlob *blob, const QV4::CompiledData::Unit *unit, Mode mode = PreferSynchronous);
QQmlEngine *engine() const;
+ void initializeEngine(QQmlEngineExtensionInterface *, const char *);
void initializeEngine(QQmlExtensionInterface *, const char *);
void invalidate();
diff --git a/src/qml/qml/qqmltypeloaderthread.cpp b/src/qml/qml/qqmltypeloaderthread.cpp
index 0e1cecd1e5..618bb09039 100644
--- a/src/qml/qml/qqmltypeloaderthread.cpp
+++ b/src/qml/qml/qqmltypeloaderthread.cpp
@@ -138,7 +138,13 @@ void QQmlTypeLoaderThread::callDownloadProgressChanged(QQmlDataBlob *b, qreal p)
void QQmlTypeLoaderThread::initializeEngine(QQmlExtensionInterface *iface,
const char *uri)
{
- callMethodInMain(&This::initializeEngineMain, iface, uri);
+ callMethodInMain(&This::initializeExtensionMain, iface, uri);
+}
+
+void QQmlTypeLoaderThread::initializeEngine(QQmlEngineExtensionInterface *iface,
+ const char *uri)
+{
+ callMethodInMain(&This::initializeEngineExtensionMain, iface, uri);
}
void QQmlTypeLoaderThread::shutdownThread()
@@ -188,7 +194,14 @@ void QQmlTypeLoaderThread::callDownloadProgressChangedMain(QQmlDataBlob *b, qrea
b->release();
}
-void QQmlTypeLoaderThread::initializeEngineMain(QQmlExtensionInterface *iface,
+void QQmlTypeLoaderThread::initializeExtensionMain(QQmlExtensionInterface *iface,
+ const char *uri)
+{
+ Q_ASSERT(m_loader->engine()->thread() == QThread::currentThread());
+ iface->initializeEngine(m_loader->engine(), uri);
+}
+
+void QQmlTypeLoaderThread::initializeEngineExtensionMain(QQmlEngineExtensionInterface *iface,
const char *uri)
{
Q_ASSERT(m_loader->engine()->thread() == QThread::currentThread());
diff --git a/src/qml/qml/qqmltypeloaderthread_p.h b/src/qml/qml/qqmltypeloaderthread_p.h
index 67e47e86de..9fb441e6e2 100644
--- a/src/qml/qml/qqmltypeloaderthread_p.h
+++ b/src/qml/qml/qqmltypeloaderthread_p.h
@@ -65,6 +65,7 @@ QT_BEGIN_NAMESPACE
class QQmlDataBlob;
class QQmlTypeLoader;
+class QQmlEngineExtensionInterface;
class QQmlExtensionInterface;
class QQmlTypeLoaderThread : public QQmlThread
@@ -86,6 +87,7 @@ public:
void callCompleted(QQmlDataBlob *b);
void callDownloadProgressChanged(QQmlDataBlob *b, qreal p);
void initializeEngine(QQmlExtensionInterface *, const char *);
+ void initializeEngine(QQmlEngineExtensionInterface *, const char *);
protected:
void shutdownThread() override;
@@ -96,7 +98,8 @@ private:
void loadWithCachedUnitThread(QQmlDataBlob *b, const QV4::CompiledData::Unit *unit);
void callCompletedMain(QQmlDataBlob *b);
void callDownloadProgressChangedMain(QQmlDataBlob *b, qreal p);
- void initializeEngineMain(QQmlExtensionInterface *iface, const char *uri);
+ void initializeExtensionMain(QQmlExtensionInterface *iface, const char *uri);
+ void initializeEngineExtensionMain(QQmlEngineExtensionInterface *iface, const char *uri);
QQmlTypeLoader *m_loader;
#if QT_CONFIG(qml_network)
diff --git a/src/qml/qml/qqmltypenamecache.cpp b/src/qml/qml/qqmltypenamecache.cpp
index 8f1a61e6ad..1015403226 100644
--- a/src/qml/qml/qqmltypenamecache.cpp
+++ b/src/qml/qml/qqmltypenamecache.cpp
@@ -154,8 +154,10 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name, QQml
QQmlImportNamespace *typeNamespace = nullptr;
QList<QQmlError> errors;
QQmlType t;
+ bool typeRecursionDetected = false;
bool typeFound = m_imports.resolveType(typeName, &t, nullptr, nullptr, &typeNamespace, &errors,
- QQmlType::AnyRegistrationType, recursionRestriction);
+ QQmlType::AnyRegistrationType,
+ recursionRestriction == QQmlImport::AllowRecursion ? &typeRecursionDetected : nullptr);
if (typeFound) {
return Result(t);
}
diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp
index ef4a628a04..fa5d36503d 100644
--- a/src/qml/qml/qqmltypewrapper.cpp
+++ b/src/qml/qml/qqmltypewrapper.cpp
@@ -400,7 +400,7 @@ ReturnedValue QQmlTypeWrapper::virtualInstanceOf(const Object *typeObject, const
// can only compare a QObject* against a QML type
const QObjectWrapper *wrapper = var.as<QObjectWrapper>();
if (!wrapper)
- return engine->throwTypeError();
+ return QV4::Encode(false);
// in case the wrapper outlived the QObject*
const QObject *wrapperObject = wrapper->object();
diff --git a/src/qml/qml/qqmlvme_p.h b/src/qml/qml/qqmlvme_p.h
index 13c5524d96..05a78a17fe 100644
--- a/src/qml/qml/qqmlvme_p.h
+++ b/src/qml/qml/qqmlvme_p.h
@@ -64,6 +64,8 @@
#include <private/qqmlengine_p.h>
#include <private/qfinitestack_p.h>
+#include <atomic>
+
QT_BEGIN_NAMESPACE
class QObject;
@@ -97,17 +99,20 @@ class QTypeInfo<QQmlVMETypes::State> : public QTypeInfoMerger<QQmlVMETypes::Stat
class QQmlInstantiationInterrupt {
public:
inline QQmlInstantiationInterrupt();
- inline QQmlInstantiationInterrupt(volatile bool *runWhile, int nsecs=0);
- inline QQmlInstantiationInterrupt(int nsecs);
+ // ### Qt 6: remove
+ inline QQmlInstantiationInterrupt(volatile bool *runWhile, qint64 nsecs=0);
+ inline QQmlInstantiationInterrupt(std::atomic<bool> *runWhile, qint64 nsecs = 0);
+ inline QQmlInstantiationInterrupt(qint64 nsecs);
inline void reset();
inline bool shouldInterrupt() const;
private:
- enum Mode { None, Time, Flag };
+ enum Mode { None, Time, LegacyFlag, Flag }; // ### Qt 6: remove LegacyFlag
Mode mode;
QElapsedTimer timer;
- int nsecs;
- volatile bool *runWhile;
+ qint64 nsecs = 0;
+ volatile bool *runWhileLegacy = nullptr; // ### Qt 6: remove
+ std::atomic<bool> *runWhile = nullptr;
};
class Q_QML_PRIVATE_EXPORT QQmlVME
@@ -147,17 +152,22 @@ private:
};
QQmlInstantiationInterrupt::QQmlInstantiationInterrupt()
- : mode(None), nsecs(0), runWhile(nullptr)
+ : mode(None)
{
}
-QQmlInstantiationInterrupt::QQmlInstantiationInterrupt(volatile bool *runWhile, int nsecs)
+QQmlInstantiationInterrupt::QQmlInstantiationInterrupt(volatile bool *runWhile, qint64 nsecs)
+ : mode(LegacyFlag), nsecs(nsecs), runWhileLegacy(runWhile)
+{
+}
+
+QQmlInstantiationInterrupt::QQmlInstantiationInterrupt(std::atomic<bool> *runWhile, qint64 nsecs)
: mode(Flag), nsecs(nsecs), runWhile(runWhile)
{
}
-QQmlInstantiationInterrupt::QQmlInstantiationInterrupt(int nsecs)
- : mode(Time), nsecs(nsecs), runWhile(nullptr)
+QQmlInstantiationInterrupt::QQmlInstantiationInterrupt(qint64 nsecs)
+ : mode(Time), nsecs(nsecs)
{
}
@@ -169,15 +179,18 @@ void QQmlInstantiationInterrupt::reset()
bool QQmlInstantiationInterrupt::shouldInterrupt() const
{
- if (mode == None) {
+ switch (mode) {
+ case None:
return false;
- } else if (mode == Time) {
+ case Time:
return timer.nsecsElapsed() > nsecs;
- } else if (mode == Flag) {
- return !*runWhile || (nsecs && timer.nsecsElapsed() > nsecs);
- } else {
- return false;
+ case LegacyFlag:
+ return !*runWhileLegacy || (nsecs && timer.nsecsElapsed() > nsecs);
+ case Flag:
+ return !runWhile->load(std::memory_order_acquire) || (nsecs && timer.nsecsElapsed() > nsecs);
}
+ Q_UNREACHABLE();
+ return false;
}
QT_END_NAMESPACE
diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp
index 921d60caa1..6d762401d0 100644
--- a/src/qml/types/qqmlbind.cpp
+++ b/src/qml/types/qqmlbind.cpp
@@ -73,8 +73,7 @@ public:
, delayed(false)
, pendingEval(false)
, restoreBinding(true)
- , restoreValue(false)
- , restoreModeExplicit(false)
+ , restoreValue(true)
, writingProperty(false)
{}
~QQmlBindPrivate() { }
@@ -93,7 +92,6 @@ public:
bool pendingEval:1;
bool restoreBinding:1;
bool restoreValue:1;
- bool restoreModeExplicit:1;
bool writingProperty: 1;
void validate(QObject *binding) const;
@@ -196,13 +194,8 @@ QQmlBind::~QQmlBind()
}
\endcode
- When the binding becomes inactive again, any direct bindings that were previously
- set on the property will be restored.
-
- \note By default, a previously set literal value is not restored when the Binding becomes
- inactive. Rather, the last value set by the now inactive Binding is retained. You can customize
- the restoration behavior for literal values as well as bindings using the \l restoreMode
- property. The default will change in Qt 6.0.
+ By default, any binding or value that was set perviously is restored when the binding becomes
+ inactive. You can customize the restoration behavior using the \l restoreMode property.
\sa restoreMode
*/
@@ -371,8 +364,7 @@ void QQmlBind::setDelayed(bool delayed)
\li Binding.RestoreBindingOrValue The original value is always restored.
\endlist
- \warning The default value is Binding.RestoreBinding. This will change in
- Qt 6.0 to Binding.RestoreBindingOrValue.
+ The default value is \c Binding.RestoreBindingOrValue.
If you rely on any specific behavior regarding the restoration of plain
values when bindings get disabled you should migrate to explicitly set the
@@ -395,7 +387,6 @@ QQmlBind::RestorationMode QQmlBind::restoreMode() const
void QQmlBind::setRestoreMode(RestorationMode newMode)
{
Q_D(QQmlBind);
- d->restoreModeExplicit = true;
if (newMode != restoreMode()) {
d->restoreValue = (newMode & RestoreValue);
d->restoreBinding = (newMode & RestoreBinding);
@@ -482,23 +473,11 @@ void QQmlBind::eval()
Q_ASSERT(vmemo);
vmemo->setVMEProperty(propPriv->core.coreIndex(), *d->v4Value.valueRef());
d->clearPrev();
- } else if (!d->restoreModeExplicit) {
- qmlWarning(this)
- << "Not restoring previous value because restoreMode has not been set."
- << "This behavior is deprecated."
- << "In Qt < 6.0 the default is Binding.RestoreBinding."
- << "In Qt >= 6.0 the default is Binding.RestoreBindingOrValue.";
}
} else if (d->prevIsVariant) {
if (d->restoreValue) {
d->prop.write(d->prevValue);
d->clearPrev();
- } else if (!d->restoreModeExplicit) {
- qmlWarning(this)
- << "Not restoring previous value because restoreMode has not been set."
- << "This behavior is deprecated."
- << "In Qt < 6.0 the default is Binding.RestoreBinding."
- << "In Qt >= 6.0 the default is Binding.RestoreBindingOrValue.";
}
}
return;
diff --git a/src/qmlmodels/qmlmodels.pro b/src/qmlmodels/qmlmodels.pro
index 1d733f5bdb..78bf579903 100644
--- a/src/qmlmodels/qmlmodels.pro
+++ b/src/qmlmodels/qmlmodels.pro
@@ -28,14 +28,10 @@ qtConfig(qml-object-model) {
qtConfig(qml-table-model) {
SOURCES += \
- $$PWD/qqmltableinstancemodel.cpp \
- $$PWD/qqmltablemodel.cpp \
- $$PWD/qqmltablemodelcolumn.cpp
+ $$PWD/qqmltableinstancemodel.cpp
HEADERS += \
- $$PWD/qqmltableinstancemodel_p.h \
- $$PWD/qqmltablemodel_p.h \
- $$PWD/qqmltablemodelcolumn_p.h
+ $$PWD/qqmltableinstancemodel_p.h
}
qtConfig(qml-list-model) {
@@ -51,18 +47,18 @@ qtConfig(qml-list-model) {
qtConfig(qml-delegate-model) {
SOURCES += \
+ $$PWD/qqmlabstractdelegatecomponent.cpp \
$$PWD/qqmladaptormodel.cpp \
$$PWD/qqmldelegatemodel.cpp \
- $$PWD/qqmldelegatecomponent.cpp \
$$PWD/qqmllistaccessor.cpp \
$$PWD/qqmllistcompositor.cpp \
$$PWD/qquickpackage.cpp
HEADERS += \
+ $$PWD/qqmlabstractdelegatecomponent_p.h \
$$PWD/qqmladaptormodel_p.h \
$$PWD/qqmldelegatemodel_p.h \
$$PWD/qqmldelegatemodel_p_p.h \
- $$PWD/qqmldelegatecomponent_p.h \
$$PWD/qqmllistaccessor_p.h \
$$PWD/qqmllistcompositor_p.h \
$$PWD/qquickpackage_p.h
diff --git a/src/qmlmodels/qqmlabstractdelegatecomponent.cpp b/src/qmlmodels/qqmlabstractdelegatecomponent.cpp
new file mode 100644
index 0000000000..1058d87485
--- /dev/null
+++ b/src/qmlmodels/qqmlabstractdelegatecomponent.cpp
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtQmlModels/private/qqmlabstractdelegatecomponent_p.h>
+#include <QtQmlModels/private/qqmladaptormodel_p.h>
+
+QT_BEGIN_NAMESPACE
+
+QQmlAbstractDelegateComponent::QQmlAbstractDelegateComponent(QObject *parent)
+ : QQmlComponent(parent)
+{
+}
+
+QQmlAbstractDelegateComponent::~QQmlAbstractDelegateComponent()
+{
+}
+
+QVariant QQmlAbstractDelegateComponent::value(QQmlAdaptorModel *adaptorModel, int row, int column, const QString &role) const
+{
+ if (!adaptorModel)
+ return QVariant();
+ return adaptorModel->value(adaptorModel->indexAt(row, column), role);
+}
+
+QT_END_NAMESPACE
diff --git a/src/qmlmodels/qqmlabstractdelegatecomponent_p.h b/src/qmlmodels/qqmlabstractdelegatecomponent_p.h
new file mode 100644
index 0000000000..07cae6b092
--- /dev/null
+++ b/src/qmlmodels/qqmlabstractdelegatecomponent_p.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQMLABSTRACTDELEGATECOMPONENT_P_H
+#define QQMLABSTRACTDELEGATECOMPONENT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qtqmlmodelsglobal_p.h>
+#include <private/qqmlcomponentattached_p.h>
+#include <qqmlcomponent.h>
+
+QT_REQUIRE_CONFIG(qml_delegate_model);
+
+QT_BEGIN_NAMESPACE
+
+// TODO: consider making QQmlAbstractDelegateComponent public API
+class QQmlAdaptorModel;
+class Q_QMLMODELS_PRIVATE_EXPORT QQmlAbstractDelegateComponent : public QQmlComponent
+{
+ Q_OBJECT
+ QML_NAMED_ELEMENT(AbstractDelegateComponent)
+ QML_UNCREATABLE("Cannot create instance of abstract class AbstractDelegateComponent.")
+
+public:
+ QQmlAbstractDelegateComponent(QObject *parent = nullptr);
+ ~QQmlAbstractDelegateComponent() override;
+
+ virtual QQmlComponent *delegate(QQmlAdaptorModel *adaptorModel, int row, int column = 0) const = 0;
+
+signals:
+ void delegateChanged();
+
+protected:
+ QVariant value(QQmlAdaptorModel *adaptorModel,int row, int column, const QString &role) const;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQMLABSTRACTDELEGATECOMPONENT_P_H
diff --git a/src/qmlmodels/qqmladaptormodel.cpp b/src/qmlmodels/qqmladaptormodel.cpp
index 48ff4e7d5b..012540244f 100644
--- a/src/qmlmodels/qqmladaptormodel.cpp
+++ b/src/qmlmodels/qqmladaptormodel.cpp
@@ -459,6 +459,11 @@ public:
QVariant value(const QQmlAdaptorModel &model, int index, const QString &role) const override
{
+ if (!metaObject) {
+ VDMAbstractItemModelDataType *dataType = const_cast<VDMAbstractItemModelDataType *>(this);
+ dataType->initializeMetaType(model);
+ }
+
QHash<QByteArray, int>::const_iterator it = roleNames.find(role.toUtf8());
if (it != roleNames.end()) {
return model.aim()->index(model.rowAt(index), model.columnAt(index), model.rootIndex).data(*it);
@@ -505,7 +510,7 @@ public:
return new QQmlDMAbstractItemModelData(metaType, dataType, index, row, column);
}
- void initializeMetaType(QQmlAdaptorModel &model)
+ void initializeMetaType(const QQmlAdaptorModel &model)
{
QMetaObjectBuilder builder;
setModelDataType<QQmlDMAbstractItemModelData>(&builder, this);
diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp
index 2c3382c643..e3c01d040a 100644
--- a/src/qmlmodels/qqmldelegatemodel.cpp
+++ b/src/qmlmodels/qqmldelegatemodel.cpp
@@ -38,10 +38,10 @@
****************************************************************************/
#include "qqmldelegatemodel_p_p.h"
-#include "qqmldelegatecomponent_p.h"
#include <QtQml/qqmlinfo.h>
+#include <private/qqmlabstractdelegatecomponent_p.h>
#include <private/qquickpackage_p.h>
#include <private/qmetaobjectbuilder_p.h>
#include <private/qqmladaptormodel_p.h>
diff --git a/src/qmlmodels/qqmlmodelsmodule.cpp b/src/qmlmodels/qqmlmodelsmodule.cpp
index 7ed8561558..8bd9b179b3 100644
--- a/src/qmlmodels/qqmlmodelsmodule.cpp
+++ b/src/qmlmodels/qqmlmodelsmodule.cpp
@@ -45,8 +45,8 @@
#include <private/qqmllistmodelworkeragent_p.h>
#endif
#if QT_CONFIG(qml_delegate_model)
+#include <private/qqmlabstractdelegatecomponent_p.h>
#include <private/qqmldelegatemodel_p.h>
-#include <private/qqmldelegatecomponent_p.h>
#include <private/qquickpackage_p.h>
#include <private/qqmlcomponentattached_p.h>
#endif
@@ -54,10 +54,6 @@
#include <private/qqmlobjectmodel_p.h>
#include <private/qqmlinstantiator_p.h>
#endif
-#if QT_CONFIG(qml_table_model)
-#include <private/qqmltablemodel_p.h>
-#include <private/qqmltablemodelcolumn_p.h>
-#endif
QT_BEGIN_NAMESPACE
@@ -73,7 +69,7 @@ void QQmlModelsModule::defineModule()
qmlRegisterType<QQmlDelegateModel>(uri, 2, 0, "VisualDataModel");
qmlRegisterType<QQmlDelegateModelGroup>(uri, 2, 0, "VisualDataGroup");
- qmlRegisterTypesAndRevisions<QQmlDelegateModel, QQmlDelegateModelGroup, QQuickPackage>(uri, 2);
+ qmlRegisterTypesAndRevisions<QQmlDelegateModel, QQmlDelegateModelGroup, QQuickPackage, QQmlAbstractDelegateComponent>(uri, 2);
#endif
#if QT_CONFIG(qml_object_model)
qmlRegisterTypesAndRevisions<QQmlObjectModel, QQmlInstantiator, QQmlInstanceModel>(uri, 2);
@@ -83,17 +79,4 @@ void QQmlModelsModule::defineModule()
#endif
}
-void QQmlModelsModule::defineLabsModule()
-{
- const char uri[] = "Qt.labs.qmlmodels";
-
-#if QT_CONFIG(qml_delegate_model)
- qmlRegisterTypesAndRevisions<
- QQmlAbstractDelegateComponent, QQmlDelegateChooser, QQmlDelegateChoice>(uri, 1);
-#endif
-#if QT_CONFIG(qml_table_model)
- qmlRegisterTypesAndRevisions<QQmlTableModel, QQmlTableModelColumn>(uri, 1);
-#endif
-}
-
QT_END_NAMESPACE
diff --git a/src/qmlmodels/qqmlobjectmodel.cpp b/src/qmlmodels/qqmlobjectmodel.cpp
index 7409178616..8e7b0a9b5f 100644
--- a/src/qmlmodels/qqmlobjectmodel.cpp
+++ b/src/qmlmodels/qqmlobjectmodel.cpp
@@ -154,7 +154,8 @@ public:
void clear() {
Q_Q(QQmlObjectModel);
- for (const Item &child : qAsConst(children))
+ const auto copy = children;
+ for (const Item &child : copy)
emit q->destroyingItem(child.item);
remove(0, children.count());
}
@@ -170,6 +171,8 @@ public:
QList<Item> children;
};
+Q_DECLARE_TYPEINFO(QQmlObjectModelPrivate::Item, Q_PRIMITIVE_TYPE);
+
/*!
\qmltype ObjectModel
@@ -278,7 +281,7 @@ QVariant QQmlObjectModel::variantValue(int index, const QString &role)
Q_D(QQmlObjectModel);
if (index < 0 || index >= d->children.count())
return QString();
- return QQmlEngine::contextForObject(d->children.at(index).item)->contextProperty(role);
+ return d->children.at(index).item->property(role.toUtf8().constData());
}
QQmlIncubator::Status QQmlObjectModel::incubationStatus(int)
diff --git a/src/qmlmodels/qqmltableinstancemodel.cpp b/src/qmlmodels/qqmltableinstancemodel.cpp
index 9b79df3441..a538ae4a1f 100644
--- a/src/qmlmodels/qqmltableinstancemodel.cpp
+++ b/src/qmlmodels/qqmltableinstancemodel.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "qqmltableinstancemodel_p.h"
-#include "qqmldelegatecomponent_p.h"
+#include "qqmlabstractdelegatecomponent_p.h"
#include <QtCore/QTimer>
diff --git a/src/qmltest/quicktestevent.cpp b/src/qmltest/quicktestevent.cpp
index 1e949615c2..127efa3894 100644
--- a/src/qmltest/quicktestevent.cpp
+++ b/src/qmltest/quicktestevent.cpp
@@ -138,6 +138,8 @@ bool QuickTestEvent::keySequence(const QVariant &keySequence)
return false;
#if QT_CONFIG(shortcut)
QTest::keySequence(window, valueToKeySequence(keySequence));
+#else
+ Q_UNUSED(keySequence);
#endif
return true;
}
diff --git a/src/qmltyperegistrar/qmltyperegistrar.cpp b/src/qmltyperegistrar/qmltyperegistrar.cpp
new file mode 100644
index 0000000000..8813907697
--- /dev/null
+++ b/src/qmltyperegistrar/qmltyperegistrar.cpp
@@ -0,0 +1,410 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmltypescreator.h"
+
+#include <QCoreApplication>
+#include <QCommandLineParser>
+#include <QtDebug>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonValue>
+#include <QJsonObject>
+#include <QFile>
+#include <QScopedPointer>
+#include <QSaveFile>
+#include <QQueue>
+
+#include <cstdlib>
+
+struct ScopedPointerFileCloser
+{
+ static inline void cleanup(FILE *handle) { if (handle) fclose(handle); }
+};
+
+static bool acceptClassForQmlTypeRegistration(const QJsonObject &classDef)
+{
+ const QJsonArray classInfos = classDef[QLatin1String("classInfos")].toArray();
+ for (const QJsonValue &info: classInfos) {
+ if (info[QLatin1String("name")].toString() == QLatin1String("QML.Element"))
+ return true;
+ }
+ return false;
+}
+
+static QVector<QJsonObject> foreignRelatedTypes(const QVector<QJsonObject> &types,
+ const QVector<QJsonObject> &foreignTypes)
+{
+ const QLatin1String classInfosKey("classInfos");
+ const QLatin1String nameKey("name");
+ const QLatin1String qualifiedClassNameKey("qualifiedClassName");
+ const QLatin1String qmlNamePrefix("QML.");
+ const QLatin1String qmlForeignName("QML.Foreign");
+ const QLatin1String qmlAttachedName("QML.Attached");
+ const QLatin1String valueKey("value");
+ const QLatin1String superClassesKey("superClasses");
+ const QLatin1String accessKey("access");
+ const QLatin1String publicAccess("public");
+
+ QSet<QString> processedRelatedNames;
+ QQueue<QJsonObject> typeQueue;
+ typeQueue.append(types.toList());
+ QVector<QJsonObject> relatedTypes;
+
+ // First mark all classes registered from this module as already processed.
+ for (const QJsonObject &type : types) {
+ processedRelatedNames.insert(type.value(qualifiedClassNameKey).toString());
+ const auto classInfos = type.value(classInfosKey).toArray();
+ for (const QJsonValue &classInfo : classInfos) {
+ const QJsonObject obj = classInfo.toObject();
+ if (obj.value(nameKey).toString() == qmlForeignName) {
+ processedRelatedNames.insert(obj.value(valueKey).toString());
+ break;
+ }
+ }
+ }
+
+ // Then mark all classes registered from other modules as already processed.
+ // We don't want to generate them again for this module.
+ for (const QJsonObject &foreignType : foreignTypes) {
+ const auto classInfos = foreignType.value(classInfosKey).toArray();
+ bool seenQmlPrefix = false;
+ for (const QJsonValue &classInfo : classInfos) {
+ const QJsonObject obj = classInfo.toObject();
+ const QString name = obj.value(nameKey).toString();
+ if (!seenQmlPrefix && name.startsWith(qmlNamePrefix)) {
+ processedRelatedNames.insert(foreignType.value(qualifiedClassNameKey).toString());
+ seenQmlPrefix = true;
+ }
+ if (name == qmlForeignName) {
+ processedRelatedNames.insert(obj.value(valueKey).toString());
+ break;
+ }
+ }
+ }
+
+ auto addType = [&](const QString &typeName) {
+ if (processedRelatedNames.contains(typeName))
+ return;
+ processedRelatedNames.insert(typeName);
+ if (const QJsonObject *other = QmlTypesClassDescription::findType(foreignTypes, typeName)) {
+ relatedTypes.append(*other);
+ typeQueue.enqueue(*other);
+ }
+ };
+
+ // Then recursively iterate the super types and attached types, marking the
+ // ones we are interested in as related.
+ while (!typeQueue.isEmpty()) {
+ const QJsonObject classDef = typeQueue.dequeue();
+
+ const auto classInfos = classDef.value(classInfosKey).toArray();
+ for (const QJsonValue &classInfo : classInfos) {
+ const QJsonObject obj = classInfo.toObject();
+ if (obj.value(nameKey).toString() == qmlAttachedName) {
+ addType(obj.value(valueKey).toString());
+ } else if (obj.value(nameKey).toString() == qmlForeignName) {
+ const QString foreignClassName = obj.value(valueKey).toString();
+ if (const QJsonObject *other = QmlTypesClassDescription::findType(
+ foreignTypes, foreignClassName)) {
+ const auto otherSupers = other->value(superClassesKey).toArray();
+ if (!otherSupers.isEmpty()) {
+ const QJsonObject otherSuperObject = otherSupers.first().toObject();
+ if (otherSuperObject.value(accessKey).toString() == publicAccess)
+ addType(otherSuperObject.value(nameKey).toString());
+ }
+
+ const auto otherClassInfos = other->value(classInfosKey).toArray();
+ for (const QJsonValue &otherClassInfo : otherClassInfos) {
+ const QJsonObject obj = otherClassInfo.toObject();
+ if (obj.value(nameKey).toString() == qmlAttachedName) {
+ addType(obj.value(valueKey).toString());
+ break;
+ }
+ // No, you cannot chain QML_FOREIGN declarations. Sorry.
+ }
+ break;
+ }
+ }
+ }
+
+ const auto supers = classDef.value(superClassesKey).toArray();
+ if (!supers.isEmpty()) {
+ const QJsonObject superObject = supers.first().toObject();
+ if (superObject.value(accessKey).toString() == publicAccess)
+ addType(superObject.value(nameKey).toString());
+ }
+ }
+
+ return relatedTypes;
+}
+
+int main(int argc, char **argv)
+{
+ // Produce reliably the same output for the same input by disabling QHash's random seeding.
+ qSetGlobalQHashSeed(0);
+
+ QCoreApplication app(argc, argv);
+ QCoreApplication::setApplicationName(QStringLiteral("qmltyperegistrar"));
+ QCoreApplication::setApplicationVersion(QLatin1String(QT_VERSION_STR));
+
+ QCommandLineParser parser;
+ parser.addHelpOption();
+ parser.addVersionOption();
+
+ QCommandLineOption outputOption(QStringLiteral("o"));
+ outputOption.setDescription(QStringLiteral("Write output to specified file."));
+ outputOption.setValueName(QStringLiteral("file"));
+ outputOption.setFlags(QCommandLineOption::ShortOptionStyle);
+ parser.addOption(outputOption);
+
+ QCommandLineOption privateIncludesOption(
+ QStringLiteral("private-includes"),
+ QStringLiteral("Include headers ending in \"_p.h\" using \"#include <private/foo_p.h>\""
+ "rather than \"#include <foo_p.h>\"."));
+ parser.addOption(privateIncludesOption);
+
+ QCommandLineOption importNameOption(QStringLiteral("import-name"));
+ importNameOption.setDescription(QStringLiteral("Name of the module to use with QML type registrations."));
+ importNameOption.setValueName(QStringLiteral("QML module name"));
+ parser.addOption(importNameOption);
+
+ QCommandLineOption majorVersionOption(QStringLiteral("major-version"));
+ majorVersionOption.setDescription(QStringLiteral("Major version to use for type registrations."));
+ majorVersionOption.setValueName(QStringLiteral("major version"));
+ parser.addOption(majorVersionOption);
+
+ QCommandLineOption minorVersionOption(QStringLiteral("minor-version"));
+ minorVersionOption.setDescription(QStringLiteral("Minor version to use for module registration."));
+ minorVersionOption.setValueName(QStringLiteral("minor version"));
+ parser.addOption(minorVersionOption);
+
+ QCommandLineOption pluginTypesOption(QStringLiteral("generate-plugintypes"));
+ pluginTypesOption.setDescription(QStringLiteral("Generate plugins.qmltypes into specified directory."));
+ pluginTypesOption.setValueName(QStringLiteral("qmltypes target Directory"));
+ parser.addOption(pluginTypesOption);
+
+ QCommandLineOption foreignTypesOption(QStringLiteral("foreign-types"));
+ foreignTypesOption.setDescription(QStringLiteral("Consider foreign types when generating plugins.qmltypes."));
+ foreignTypesOption.setValueName(QStringLiteral("Comma separated list of other modules to consult for types."));
+ parser.addOption(foreignTypesOption);
+
+ QCommandLineOption dependenciesOption(QStringLiteral("dependencies"));
+ dependenciesOption.setDescription(QStringLiteral("Dependencies to be stated in plugins.qmltypes"));
+ dependenciesOption.setValueName(QStringLiteral("name of JSON file with dependencies"));
+ parser.addOption(dependenciesOption);
+
+ parser.addPositionalArgument(QStringLiteral("[MOC generated json file]"),
+ QStringLiteral("MOC generated json output"));
+
+ parser.process(app);
+
+ FILE *output = stdout;
+ QScopedPointer<FILE, ScopedPointerFileCloser> outputFile;
+
+ if (parser.isSet(outputOption)) {
+ QString outputName = parser.value(outputOption);
+#if defined(_MSC_VER)
+ if (_wfopen_s(&output, reinterpret_cast<const wchar_t *>(outputName.utf16()), L"w") != 0) {
+#else
+ output = fopen(QFile::encodeName(outputName).constData(), "w"); // create output file
+ if (!output) {
+#endif
+ fprintf(stderr, "Error: Cannot open %s for writing\n", qPrintable(outputName));
+ return EXIT_FAILURE;
+ }
+ outputFile.reset(output);
+ }
+
+ fprintf(output,
+ "/****************************************************************************\n"
+ "** Generated QML type registration code\n**\n");
+ fprintf(output,
+ "** WARNING! All changes made in this file will be lost!\n"
+ "*****************************************************************************/\n\n");
+ fprintf(output,
+ "#include <QtQml/qqmlengine.h>\n");
+
+ QStringList includes;
+ QVector<QJsonObject> types;
+ QVector<QJsonObject> foreignTypes;
+
+ const QString module = parser.value(importNameOption);
+ const QStringList files = parser.positionalArguments();
+ for (const QString &source: files) {
+ QJsonDocument metaObjects;
+ {
+ QFile f(source);
+ if (!f.open(QIODevice::ReadOnly)) {
+ fprintf(stderr, "Error opening %s for reading\n", qPrintable(source));
+ return EXIT_FAILURE;
+ }
+ QJsonParseError error = {0, QJsonParseError::NoError};
+ metaObjects = QJsonDocument::fromJson(f.readAll(), &error);
+ if (error.error != QJsonParseError::NoError) {
+ fprintf(stderr, "Error parsing %s\n", qPrintable(source));
+ return EXIT_FAILURE;
+ }
+ }
+
+ auto processMetaObject = [&](const QJsonObject &metaObject) {
+ const QJsonArray classes = metaObject[QLatin1String("classes")].toArray();
+ for (const auto &cls : classes) {
+ QJsonObject classDef = cls.toObject();
+ if (acceptClassForQmlTypeRegistration(classDef)) {
+ const QString include = metaObject[QLatin1String("inputFile")].toString();
+ const bool declaredInHeader = include.endsWith(QLatin1String(".h"));
+ if (declaredInHeader) {
+ includes.append(include);
+ classDef.insert(QLatin1String("registerable"), true);
+ } else {
+ fprintf(stderr, "Cannot generate QML type registration for class %s "
+ "because it is not declared in a header.",
+ qPrintable(classDef.value(QLatin1String("qualifiedClassName"))
+ .toString()));
+ }
+ types.append(classDef);
+ } else {
+ foreignTypes.append(classDef);
+ }
+ }
+ };
+
+ if (metaObjects.isArray()) {
+ const QJsonArray metaObjectsArray = metaObjects.array();
+ for (const auto &metaObject : metaObjectsArray) {
+ if (!metaObject.isObject()) {
+ fprintf(stderr, "Error parsing %s: JSON is not an object\n",
+ qPrintable(source));
+ return EXIT_FAILURE;
+ }
+
+ processMetaObject(metaObject.toObject());
+ }
+ } else if (metaObjects.isObject()) {
+ processMetaObject(metaObjects.object());
+ } else {
+ fprintf(stderr, "Error parsing %s: JSON is not an object or an array\n",
+ qPrintable(source));
+ return EXIT_FAILURE;
+ }
+ }
+
+ const QLatin1String qualifiedClassNameKey("qualifiedClassName");
+ auto sortTypes = [&](QVector<QJsonObject> &types) {
+ std::sort(types.begin(), types.end(), [&](const QJsonObject &a, const QJsonObject &b) {
+ return a.value(qualifiedClassNameKey).toString() <
+ b.value(qualifiedClassNameKey).toString();
+ });
+ };
+
+ sortTypes(types);
+
+ fprintf(output, "\n#include <QtQml/qqmlmoduleregistration.h>");
+ const bool privateIncludes = parser.isSet(privateIncludesOption);
+ for (const QString &include : qAsConst(includes)) {
+ if (privateIncludes && include.endsWith(QLatin1String("_p.h")))
+ fprintf(output, "\n#include <private/%s>", qPrintable(include));
+ else
+ fprintf(output, "\n#include <%s>", qPrintable(include));
+ }
+
+ fprintf(output, "\n\n");
+
+ QString moduleAsSymbol = module;
+ moduleAsSymbol.replace(QLatin1Char('.'), QLatin1Char('_'));
+
+ const QString functionName = QStringLiteral("qml_register_types_") + moduleAsSymbol;
+
+ fprintf(output, "void %s()\n{", qPrintable(functionName));
+ const auto majorVersion = parser.value(majorVersionOption);
+
+ for (const QJsonObject &classDef : qAsConst(types)) {
+ if (!classDef.value(QLatin1String("registerable")).toBool())
+ continue;
+
+ const QString className = classDef[QLatin1String("qualifiedClassName")].toString();
+ fprintf(output, "\n qmlRegisterTypesAndRevisions<%s>(\"%s\", %s);", qPrintable(className),
+ qPrintable(module), qPrintable(majorVersion));
+ }
+
+ fprintf(output, "\n qmlRegisterModule(\"%s\", %s, %s);",
+ qPrintable(module), qPrintable(majorVersion),
+ qPrintable(parser.value(minorVersionOption)));
+ fprintf(output, "\n}\n");
+ fprintf(output, "\nstatic const QQmlModuleRegistration registration(\"%s\", %s, %s);\n",
+ qPrintable(module), qPrintable(majorVersion), qPrintable(functionName));
+
+ if (!parser.isSet(pluginTypesOption))
+ return EXIT_SUCCESS;
+
+ if (parser.isSet(foreignTypesOption)) {
+ const QStringList foreignTypesFiles = parser.value(foreignTypesOption)
+ .split(QLatin1Char(','));
+ for (const QString &types : foreignTypesFiles) {
+ QFile typesFile(types);
+ if (!typesFile.open(QIODevice::ReadOnly)) {
+ fprintf(stderr, "Cannot open foreign types file %s\n", qPrintable(types));
+ continue;
+ }
+
+ QJsonParseError error = {0, QJsonParseError::NoError};
+ QJsonDocument foreignMetaObjects = QJsonDocument::fromJson(typesFile.readAll(), &error);
+ if (error.error != QJsonParseError::NoError) {
+ fprintf(stderr, "Error parsing %s\n", qPrintable(types));
+ continue;
+ }
+
+ const QJsonArray foreignObjectsArray = foreignMetaObjects.array();
+ for (const auto &metaObject : foreignObjectsArray) {
+ if (!metaObject.isObject()) {
+ fprintf(stderr, "Error parsing %s: JSON is not an object\n",
+ qPrintable(types));
+ continue;
+ }
+
+ const QJsonArray classes = metaObject[QLatin1String("classes")].toArray();
+ for (const auto &cls : classes)
+ foreignTypes.append(cls.toObject());
+ }
+ }
+ }
+
+ sortTypes(foreignTypes);
+ types += foreignRelatedTypes(types, foreignTypes);
+ sortTypes(types);
+
+ QmlTypesCreator creator;
+ creator.setOwnTypes(std::move(types));
+ creator.setForeignTypes(std::move(foreignTypes));
+ creator.setModule(module);
+ creator.setMajorVersion(parser.value(majorVersionOption).toInt());
+
+ creator.generate(parser.value(pluginTypesOption), parser.value(dependenciesOption));
+ return EXIT_SUCCESS;
+}
diff --git a/src/qmltyperegistrar/qmltyperegistrar.pro b/src/qmltyperegistrar/qmltyperegistrar.pro
new file mode 100644
index 0000000000..dff8f00ca3
--- /dev/null
+++ b/src/qmltyperegistrar/qmltyperegistrar.pro
@@ -0,0 +1,32 @@
+option(host_build)
+
+QT = core-private
+DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
+
+QMAKE_TARGET_DESCRIPTION = QML Types Registrar
+
+include(../../tools/shared/shared.pri)
+
+SOURCES += \
+ qmltyperegistrar.cpp \
+ qmltypesclassdescription.cpp \
+ qmltypescreator.cpp
+
+HEADERS += \
+ qmltypesclassdescription.h \
+ qmltypescreator.h
+
+build_integration.files = qmltypes.prf
+build_integration.path = $$[QT_HOST_DATA]/mkspecs/features
+
+prefix_build {
+ load(qt_build_paths)
+ qmltypes_to_builddir.files = qmltypes.prf
+ qmltypes_to_builddir.path = $$MODULE_BASE_OUTDIR/mkspecs/features
+ COPIES += qmltypes_to_builddir
+ INSTALLS += build_integration
+} else {
+ COPIES += build_integration
+}
+
+load(qt_tool)
diff --git a/src/qmltyperegistrar/qmltypes.prf b/src/qmltyperegistrar/qmltypes.prf
new file mode 100644
index 0000000000..ed11ef44cf
--- /dev/null
+++ b/src/qmltyperegistrar/qmltypes.prf
@@ -0,0 +1,95 @@
+CONFIG += metatypes
+
+qtPrepareTool(QML_TYPEREGISTRAR, qmltyperegistrar)
+
+isEmpty(QML_IMPORT_VERSION): \
+ QML_IMPORT_VERSION = $$IMPORT_VERSION
+
+# from moc.prf
+isEmpty(QML_IMPORT_MAJOR_VERSION):!isEmpty(QML_IMPORT_VERSION): \
+ QML_IMPORT_MAJOR_VERSION = $$section(QML_IMPORT_VERSION, ., 0, 0)
+
+isEmpty(QML_IMPORT_MINOR_VERSION):!isEmpty(QML_IMPORT_VERSION): \
+ QML_IMPORT_MINOR_VERSION = $$section(QML_IMPORT_VERSION, ., 1, 1)
+
+isEmpty(QML_IMPORT_NAME):!isEmpty(TARGETPATH) {
+ QML_IMPORT_NAME = $$replace(TARGETPATH, "/", ".")
+ QML_IMPORT_NAME = $$replace(QML_IMPORT_NAME, .$${QML_IMPORT_MAJOR_VERSION}$, '')
+}
+
+isEmpty(QML_IMPORT_NAME) {
+ error("Need TARGET_PATH or QML_IMPORT_NAME in order to generate qml types.");
+}
+
+isEmpty(QML_IMPORT_MAJOR_VERSION) {
+ error("Need IMPORT_VERSION, QML_IMPORT_VERSION, or QML_IMPORT_MAJOR_VERSION in order to generate qml types.");
+}
+
+isEmpty(QML_IMPORT_MINOR_VERSION) {
+ QML_IMPORT_MINOR_VERSION = 0
+}
+
+isEmpty(QMLTYPES_FILENAME) {
+ plugin: QMLTYPES_FILENAME = plugins.qmltypes
+ else: QMLTYPES_FILENAME = $${TEMPLATE}.qmltypes
+}
+
+qt_module_deps = $$replace(QT, -private$, '')
+qt_module_deps += $$replace(QT_PRIVATE, -private$, '')
+qt_module_deps = $$replace(qt_module_deps, _private$, '')
+all_qt_module_deps = $$resolve_depends(qt_module_deps, "QT.", ".depends" ".run_depends")
+foreign_types =
+for(dep, all_qt_module_deps) {
+ METATYPES_FILENAME = $$lower($$eval(QT.$${dep}.module))_metatypes.json
+ INSTALLED_METATYPES = $$[QT_INSTALL_LIBS]/metatypes/$$METATYPES_FILENAME
+ isEmpty(MODULE_BASE_OUTDIR) {
+ foreign_types += $$INSTALLED_METATYPES
+ } else {
+ MODULE_BASE_METATYPES = $$MODULE_BASE_OUTDIR/lib/metatypes/$$METATYPES_FILENAME
+ exists($$MODULE_BASE_METATYPES): foreign_types += $$MODULE_BASE_METATYPES
+ else: foreign_types += $$INSTALLED_METATYPES
+ }
+}
+
+QML_TYPEREGISTRAR_FLAGS = \
+ --generate-plugintypes=$$QMLTYPES_FILENAME \
+ --import-name=$$QML_IMPORT_NAME \
+ --major-version=$$QML_IMPORT_MAJOR_VERSION \
+ --minor-version=$$QML_IMPORT_MINOR_VERSION \
+ --foreign-types=$$join(foreign_types, ',')
+
+DEPENDENCIESFILE = $$_PRO_FILE_PWD_/dependencies.json
+exists($$DEPENDENCIESFILE): QML_TYPEREGISTRAR_FLAGS += --dependencies=$$DEPENDENCIESFILE
+
+!isEmpty(MODULE_PRIVATE_INCLUDES): QML_TYPEREGISTRAR_FLAGS += --private-includes
+
+METATYPES_JSON = $$lower($$basename(TARGET))_metatypes.json
+
+TYPEREGISTRATIONS = $$lower($$basename(TARGET))_qmltyperegistrations$${first(QMAKE_EXT_CPP)}
+
+qmltyperegistrar_compiler.CONFIG += combine
+qmltyperegistrar_compiler.commands = \
+ $$QML_TYPEREGISTRAR $$QML_TYPEREGISTRAR_FLAGS -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
+qmltyperegistrar_compiler.input = METATYPES_JSON
+qmltyperegistrar_compiler.output = $$TYPEREGISTRATIONS
+qmltyperegistrar_compiler.variable_out = SOURCES
+qmltyperegistrar_compiler.name = Automatic QML type registration
+qmltyperegistrar_compiler.dependency_type = TYPE_C
+
+qmltyperegistrar_qmltypes.input = METATYPES_JSON
+qmltyperegistrar_qmltypes.depends = $$TYPEREGISTRATIONS
+qmltyperegistrar_qmltypes.output = $$QMLTYPES_FILENAME
+qmltyperegistrar_qmltypes.CONFIG = no_link
+qmltyperegistrar_qmltypes.commands = $$escape_expand(\\n) # force creation of rule
+
+install_qmltypes {
+ isEmpty(QMLTYPES_INSTALL_DIR): \
+ QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/$$TARGETPATH
+ do_install_qmltypes.files = $$OUT_PWD/$$QMLTYPES_FILENAME
+ do_install_qmltypes.path = $$QMLTYPES_INSTALL_DIR
+ do_install_qmltypes.CONFIG += no_link
+ prefix_build: INSTALLS += do_install_qmltypes
+ else: COPIES += do_install_qmltypes
+}
+
+QMAKE_EXTRA_COMPILERS += qmltyperegistrar_compiler qmltyperegistrar_qmltypes
diff --git a/src/qmltyperegistrar/qmltypesclassdescription.cpp b/src/qmltyperegistrar/qmltypesclassdescription.cpp
new file mode 100644
index 0000000000..8189bcd52e
--- /dev/null
+++ b/src/qmltyperegistrar/qmltypesclassdescription.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmltypesclassdescription.h"
+
+#include <QtCore/qjsonarray.h>
+
+static void collectExtraVersions(const QJsonObject *component, const QString &key,
+ QList<int> &extraVersions)
+{
+ const QJsonArray &items = component->value(key).toArray();
+ for (const QJsonValue &item : items) {
+ const QJsonObject obj = item.toObject();
+ const auto revision = obj.find(QLatin1String("revision"));
+ if (revision != obj.end()) {
+ const int extraVersion = revision.value().toInt();
+ if (!extraVersions.contains(extraVersion))
+ extraVersions.append(extraVersion);
+ }
+ }
+}
+
+const QJsonObject *QmlTypesClassDescription::findType(const QVector<QJsonObject> &types,
+ const QString &name)
+{
+ static const QLatin1String qualifiedClassNameKey("qualifiedClassName");
+ auto it = std::lower_bound(types.begin(), types.end(), name,
+ [&](const QJsonObject &type, const QString &typeName) {
+ return type.value(qualifiedClassNameKey).toString() < typeName;
+ });
+
+ return (it != types.end() && it->value(qualifiedClassNameKey) == name) ? &(*it) : nullptr;
+}
+
+void QmlTypesClassDescription::collect(const QJsonObject *classDef,
+ const QVector<QJsonObject> &types,
+ const QVector<QJsonObject> &foreign,
+ bool topLevel)
+{
+ const auto classInfos = classDef->value(QLatin1String("classInfos")).toArray();
+ for (const QJsonValue &classInfo : classInfos) {
+ const QJsonObject obj = classInfo.toObject();
+ const QString name = obj[QLatin1String("name")].toString();
+ const QString value = obj[QLatin1String("value")].toString();
+
+ if (name == QLatin1String("DefaultProperty")) {
+ if (defaultProp.isEmpty())
+ defaultProp = value;
+ } else if (name == QLatin1String("QML.AddedInMinorVersion")) {
+ if (topLevel) {
+ addedInRevision = value.toInt();
+ revisions.append(value.toInt());
+ } else if (!elementName.isEmpty()) {
+ revisions.append(value.toInt());
+ }
+ }
+
+ if (!topLevel)
+ continue;
+
+ // These only apply to the original class
+ if (name == QLatin1String("QML.Element")) {
+ if (value == QLatin1String("auto"))
+ elementName = classDef->value(QLatin1String("className")).toString();
+ else if (value != QLatin1String("anonymous"))
+ elementName = value;
+ } else if (name == QLatin1String("QML.RemovedInMinorVersion")) {
+ removedInRevision = value.toInt();
+ } else if (name == QLatin1String("QML.Creatable")) {
+ isCreatable = (value != QLatin1String("false"));
+ } else if (name == QLatin1String("QML.Attached")) {
+ attachedType = value;
+ if (const QJsonObject *other = findType(types, attachedType))
+ collect(other, types, foreign, false);
+ else if (const QJsonObject *other = findType(foreign, attachedType))
+ collect(other, types, foreign, false);
+ } else if (name == QLatin1String("QML.Singleton")) {
+ if (value == QLatin1String("true"))
+ isSingleton = true;
+ } else if (name == QLatin1String("QML.Foreign")) {
+ if (const QJsonObject *other = findType(foreign, value)) {
+ classDef = other;
+ if (defaultProp.isEmpty()) {
+ // Foreign type can have a default property
+ const auto classInfos = classDef->value(QLatin1String("classInfos")).toArray();
+ for (const QJsonValue &classInfo : classInfos) {
+ QJsonObject obj = classInfo.toObject();
+ if (obj[QLatin1String("name")].toString() == QLatin1String("DefaultProperty")) {
+ defaultProp = obj[QLatin1String("value")].toString();
+ break;
+ }
+ }
+ }
+ }
+ } else if (name == QLatin1String("QML.Root")) {
+ isRootClass = true;
+ isBuiltin = true;
+ } else if (name == QLatin1String("QML.Builtin")) {
+ isBuiltin = true;
+ }
+ }
+
+ if (!elementName.isEmpty()) {
+ collectExtraVersions(classDef, QString::fromLatin1("properties"), revisions);
+ collectExtraVersions(classDef, QString::fromLatin1("slots"), revisions);
+ collectExtraVersions(classDef, QString::fromLatin1("methods"), revisions);
+ collectExtraVersions(classDef, QString::fromLatin1("signals"), revisions);
+ }
+
+ const auto supers = classDef->value(QLatin1String("superClasses")).toArray();
+ if (!supers.isEmpty()) {
+ const QJsonObject superObject = supers.first().toObject();
+ if (superObject[QLatin1String("access")].toString() == QLatin1String("public")) {
+ const QString superName = superObject[QLatin1String("name")].toString();
+ if (topLevel && superClass.isEmpty())
+ superClass = superName;
+
+ if (const QJsonObject *other = findType(types, superName))
+ collect(other, types, foreign, false);
+ else if (const QJsonObject *other = findType(foreign, superName))
+ collect(other, types, foreign, false);
+ }
+ }
+
+ if (addedInRevision == -1) {
+ revisions.append(0);
+ addedInRevision = 0;
+ }
+
+ std::sort(revisions.begin(), revisions.end(),
+ [](int a, int b) { return QByteArray::number(a) < QByteArray::number(b); });
+ const auto end = std::unique(revisions.begin(), revisions.end());
+ revisions.erase(end, revisions.end());
+
+ resolvedClass = classDef;
+}
diff --git a/src/qmltyperegistrar/qmltypesclassdescription.h b/src/qmltyperegistrar/qmltypesclassdescription.h
new file mode 100644
index 0000000000..8f3a6ea124
--- /dev/null
+++ b/src/qmltyperegistrar/qmltypesclassdescription.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLTYPESCLASSDESCRIPTION_H
+#define QMLTYPESCLASSDESCRIPTION_H
+
+#include <QtCore/qstring.h>
+#include <QtCore/qjsonobject.h>
+#include <QtCore/qvector.h>
+#include <QtCore/qset.h>
+
+struct QmlTypesClassDescription
+{
+ const QJsonObject *resolvedClass = nullptr;
+ QString elementName;
+ QString defaultProp;
+ QString superClass;
+ QString attachedType;
+ QList<int> revisions;
+ int addedInRevision = -1;
+ int removedInRevision = -1;
+ bool isCreatable = true;
+ bool isSingleton = false;
+ bool isRootClass = false;
+ bool isBuiltin = false;
+
+ void collect(const QJsonObject *classDef, const QVector<QJsonObject> &types,
+ const QVector<QJsonObject> &foreign, bool topLevel);
+
+ static const QJsonObject *findType(const QVector<QJsonObject> &types, const QString &name);
+};
+
+#endif // QMLTYPESCLASSDESCRIPTION_H
diff --git a/src/qmltyperegistrar/qmltypescreator.cpp b/src/qmltyperegistrar/qmltypescreator.cpp
new file mode 100644
index 0000000000..7bac6a87d8
--- /dev/null
+++ b/src/qmltyperegistrar/qmltypescreator.cpp
@@ -0,0 +1,357 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmltypescreator.h"
+#include "qmlstreamwriter.h"
+#include "qmltypesclassdescription.h"
+
+#include <QtCore/qset.h>
+#include <QtCore/qjsonarray.h>
+#include <QtCore/qsavefile.h>
+#include <QtCore/qfile.h>
+#include <QtCore/qjsondocument.h>
+
+static QString enquote(const QString &string)
+{
+ QString s = string;
+ return QString::fromLatin1("\"%1\"").arg(s.replace(QLatin1Char('\\'), QLatin1String("\\\\"))
+ .replace(QLatin1Char('"'),QLatin1String("\\\"")));
+}
+
+void QmlTypesCreator::writeClassProperties(const QmlTypesClassDescription &collector)
+{
+ m_qml.writeScriptBinding(
+ QLatin1String("name"),
+ enquote(collector.resolvedClass->value(
+ QLatin1String("qualifiedClassName")).toString()));
+
+ if (!collector.defaultProp.isEmpty())
+ m_qml.writeScriptBinding(QLatin1String("defaultProperty"), enquote(collector.defaultProp));
+
+ if (!collector.superClass.isEmpty())
+ m_qml.writeScriptBinding(QLatin1String("prototype"), enquote(collector.superClass));
+
+ if (collector.elementName.isEmpty())
+ return;
+
+ QStringList exports;
+ QStringList metaObjects;
+
+ for (auto it = collector.revisions.begin(), end = collector.revisions.end(); it != end; ++it) {
+ const int revision = *it;
+ if (revision < collector.addedInRevision)
+ continue;
+ if (collector.removedInRevision > collector.addedInRevision
+ && revision >= collector.removedInRevision) {
+ break;
+ }
+
+ if (collector.isBuiltin) {
+ exports.append(enquote(QString::fromLatin1("QML/%1 1.0").arg(collector.elementName)));
+ metaObjects.append(QLatin1String("0"));
+ }
+
+ exports.append(enquote(QString::fromLatin1("%1/%2 %3.%4")
+ .arg(m_module).arg(collector.elementName)
+ .arg(m_majorVersion).arg(revision)));
+ metaObjects.append(QString::number(revision));
+ }
+
+ m_qml.writeArrayBinding(QLatin1String("exports"), exports);
+
+ if (!collector.isCreatable || collector.isSingleton)
+ m_qml.writeScriptBinding(QLatin1String("isCreatable"), QLatin1String("false"));
+
+ if (collector.isSingleton)
+ m_qml.writeScriptBinding(QLatin1String("isSingleton"), QLatin1String("true"));
+
+ m_qml.writeArrayBinding(QLatin1String("exportMetaObjectRevisions"), metaObjects);
+
+ if (!collector.attachedType.isEmpty())
+ m_qml.writeScriptBinding(QLatin1String("attachedType"), enquote(collector.attachedType));
+}
+
+void QmlTypesCreator::writeType(const QJsonObject &property, const QString &key, bool isReadonly,
+ bool parsePointer)
+{
+ auto it = property.find(key);
+ if (it == property.end())
+ return;
+
+ QString type = (*it).toString();
+ if (type.isEmpty() || type == QLatin1String("void"))
+ return;
+
+ const QLatin1String typeKey("type");
+
+ bool isList = false;
+ bool isPointer = false;
+
+ if (type == QLatin1String("QString")) {
+ type = QLatin1String("string");
+ } else if (type == QLatin1String("qreal")) {
+ type = QLatin1String("double");
+ } else if (type == QLatin1String("qint32")) {
+ type = QLatin1String("int");
+ } else if (type == QLatin1String("quint32")) {
+ type = QLatin1String("uint");
+ } else if (type == QLatin1String("qint64")) {
+ type = QLatin1String("qlonglong");
+ } else if (type == QLatin1String("quint64")) {
+ type = QLatin1String("qulonglong");
+ } else {
+
+ const QLatin1String listProperty("QQmlListProperty<");
+ if (type.startsWith(listProperty)) {
+ isList = true;
+ const int listPropertySize = listProperty.size();
+ type = type.mid(listPropertySize, type.size() - listPropertySize - 1);
+ }
+
+ if (parsePointer && type.endsWith(QLatin1Char('*'))) {
+ isPointer = true;
+ type = type.left(type.size() - 1);
+ }
+ }
+
+ m_qml.writeScriptBinding(typeKey, enquote(type));
+ const QLatin1String trueString("true");
+ if (isList)
+ m_qml.writeScriptBinding(QLatin1String("isList"), trueString);
+ if (isReadonly)
+ m_qml.writeScriptBinding(QLatin1String("isReadonly"), trueString);
+ if (isPointer)
+ m_qml.writeScriptBinding(QLatin1String("isPointer"), trueString);
+}
+
+void QmlTypesCreator::writeProperties(const QJsonArray &properties, QSet<QString> &notifySignals)
+{
+ for (const QJsonValue &property : properties) {
+ const QJsonObject obj = property.toObject();
+ const QString name = obj[QLatin1String("name")].toString();
+ m_qml.writeStartObject(QLatin1String("Property"));
+ m_qml.writeScriptBinding(QLatin1String("name"), enquote(name));
+ const auto it = obj.find(QLatin1String("revision"));
+ if (it != obj.end())
+ m_qml.writeScriptBinding(QLatin1String("revision"), QString::number(it.value().toInt()));
+ writeType(obj, QLatin1String("type"), !obj.contains(QLatin1String("write")), true);
+ m_qml.writeEndObject();
+
+ const QString notify = obj[QLatin1String("notify")].toString();
+ if (notify == name + QLatin1String("Changed"))
+ notifySignals.insert(notify);
+ }
+}
+
+void QmlTypesCreator::writeMethods(const QJsonArray &methods, const QString &type,
+ const QSet<QString> &notifySignals)
+{
+ for (const QJsonValue &method : methods) {
+ const QJsonObject obj = method.toObject();
+ if (obj[QLatin1String("access")].toString() != QLatin1String("public"))
+ continue;
+ const QString name = obj[QLatin1String("name")].toString();
+ const QJsonArray arguments = method[QLatin1String("arguments")].toArray();
+ const auto revision = obj.find(QLatin1String("revision"));
+ if (notifySignals.contains(name) && arguments.isEmpty() && revision == obj.end())
+ continue;
+ m_qml.writeStartObject(type);
+ m_qml.writeScriptBinding(QLatin1String("name"), enquote(name));
+ if (revision != obj.end())
+ m_qml.writeScriptBinding(QLatin1String("revision"), QString::number(revision.value().toInt()));
+ writeType(obj, QLatin1String("returnType"), false, false);
+ for (const QJsonValue &argument : arguments) {
+ const QJsonObject obj = argument.toObject();
+ m_qml.writeStartObject(QLatin1String("Parameter"));
+ const QString name = obj[QLatin1String("name")].toString();
+ if (!name.isEmpty())
+ m_qml.writeScriptBinding(QLatin1String("name"), enquote(name));
+ writeType(obj, QLatin1String("type"), false, true);
+ m_qml.writeEndObject();
+ }
+ m_qml.writeEndObject();
+ }
+}
+
+void QmlTypesCreator::writeEnums(const QJsonArray &enums)
+{
+ for (const auto &item : enums) {
+ const QJsonObject obj = item.toObject();
+ const QJsonArray values = obj.value(QLatin1String("values")).toArray();
+ QStringList valueList;
+
+ for (const QJsonValue &value : values)
+ valueList.append(enquote(value.toString()));
+
+ m_qml.writeStartObject(QLatin1String("Enum"));
+ m_qml.writeScriptBinding(QLatin1String("name"),
+ enquote(obj.value(QLatin1String("name")).toString()));
+ m_qml.writeArrayBinding(QLatin1String("values"), valueList);
+ m_qml.writeEndObject();
+ }
+}
+
+void QmlTypesCreator::writeComponents()
+{
+ const QLatin1String nameKey("name");
+ const QLatin1String signalsKey("signals");
+ const QLatin1String enumsKey("enums");
+ const QLatin1String propertiesKey("properties");
+ const QLatin1String slotsKey("slots");
+ const QLatin1String methodsKey("methods");
+ const QLatin1String accessKey("access");
+ const QLatin1String typeKey("type");
+ const QLatin1String argumentsKey("arguments");
+
+ const QLatin1String destroyedName("destroyed");
+ const QLatin1String deleteLaterName("deleteLater");
+ const QLatin1String toStringName("toString");
+ const QLatin1String destroyName("destroy");
+ const QLatin1String delayName("delay");
+
+ const QLatin1String signalElement("Signal");
+ const QLatin1String componentElement("Component");
+ const QLatin1String methodElement("Method");
+
+ const QLatin1String publicAccess("public");
+ const QLatin1String intType("int");
+
+ for (const QJsonObject &component : m_ownTypes) {
+ m_qml.writeStartObject(componentElement);
+
+ QmlTypesClassDescription collector;
+ collector.collect(&component, m_ownTypes, m_foreignTypes, true);
+
+ writeClassProperties(collector);
+
+ const QJsonObject *classDef = collector.resolvedClass;
+ writeEnums(classDef->value(enumsKey).toArray());
+
+ QSet<QString> notifySignals;
+ writeProperties(classDef->value(propertiesKey).toArray(), notifySignals);
+
+ if (collector.isRootClass) {
+
+ // Hide destroyed() signals
+ QJsonArray componentSignals = classDef->value(signalsKey).toArray();
+ for (auto it = componentSignals.begin(); it != componentSignals.end();) {
+ if (it->toObject().value(nameKey).toString() == destroyedName)
+ it = componentSignals.erase(it);
+ else
+ ++it;
+ }
+ writeMethods(componentSignals, signalElement, notifySignals);
+
+ // Hide deleteLater() methods
+ QJsonArray componentMethods = classDef->value(methodsKey).toArray()
+ + classDef->value(slotsKey).toArray();
+ for (auto it = componentMethods.begin(); it != componentMethods.end();) {
+ if (it->toObject().value(nameKey).toString() == deleteLaterName)
+ it = componentMethods.erase(it);
+ else
+ ++it;
+ }
+
+ // Add toString()
+ QJsonObject toStringMethod;
+ toStringMethod.insert(nameKey, toStringName);
+ toStringMethod.insert(accessKey, publicAccess);
+ componentMethods.append(toStringMethod);
+
+ // Add destroy()
+ QJsonObject destroyMethod;
+ destroyMethod.insert(nameKey, destroyName);
+ destroyMethod.insert(accessKey, publicAccess);
+ componentMethods.append(destroyMethod);
+
+ // Add destroy(int)
+ QJsonObject destroyMethodWithArgument;
+ destroyMethodWithArgument.insert(nameKey, destroyName);
+ destroyMethodWithArgument.insert(accessKey, publicAccess);
+ QJsonObject delayArgument;
+ delayArgument.insert(nameKey, delayName);
+ delayArgument.insert(typeKey, intType);
+ QJsonArray destroyArguments;
+ destroyArguments.append(delayArgument);
+ destroyMethodWithArgument.insert(argumentsKey, destroyArguments);
+ componentMethods.append(destroyMethodWithArgument);
+
+ writeMethods(componentMethods, methodElement);
+ } else {
+ writeMethods(classDef->value(signalsKey).toArray(), signalElement, notifySignals);
+ writeMethods(classDef->value(slotsKey).toArray(), methodElement);
+ writeMethods(classDef->value(methodsKey).toArray(), methodElement);
+ }
+ m_qml.writeEndObject();
+ }
+}
+
+void QmlTypesCreator::generate(const QString &outFileName, const QString &dependenciesFileName)
+{
+ m_qml.writeStartDocument();
+ m_qml.writeLibraryImport(QLatin1String("QtQuick.tooling"), 1, 2);
+ m_qml.write(QString::fromLatin1(
+ "\n// This file describes the plugin-supplied types contained in the library."
+ "\n// It is used for QML tooling purposes only."
+ "\n//"
+ "\n// This file was auto-generated by qmltyperegistrar.\n\n"));
+ m_qml.writeStartObject(QLatin1String("Module"));
+
+ QStringList dependencies;
+ if (!dependenciesFileName.isEmpty()) {
+ QFile file(dependenciesFileName);
+ if (!file.open(QIODevice::ReadOnly)) {
+ fprintf(stderr, "Failed to open %s\n", qPrintable(dependenciesFileName));
+ } else {
+ QJsonParseError error { -1, QJsonParseError::NoError };
+ QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &error);
+ if (error.error != QJsonParseError::NoError) {
+ fprintf(stderr, "Failed to parse %s\n", qPrintable(dependenciesFileName));
+ } else {
+ const QJsonArray array = doc.array();
+ for (const QJsonValue &value : array)
+ dependencies.append(enquote(value.toString()));
+ }
+ }
+ } else {
+ // Default dependency is QtQuick 2.0
+ dependencies.append(enquote(QLatin1String("QtQuick 2.0")));
+ }
+
+ m_qml.writeArrayBinding(QLatin1String("dependencies"), dependencies);
+
+ writeComponents();
+
+ m_qml.writeEndObject();
+
+ QSaveFile file(outFileName);
+ file.open(QIODevice::WriteOnly);
+ file.write(m_output);
+ file.commit();
+}
+
diff --git a/src/qmltyperegistrar/qmltypescreator.h b/src/qmltyperegistrar/qmltypescreator.h
new file mode 100644
index 0000000000..9207a64b7e
--- /dev/null
+++ b/src/qmltyperegistrar/qmltypescreator.h
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLTYPESCREATOR_H
+#define QMLTYPESCREATOR_H
+
+#include "qmlstreamwriter.h"
+#include "qmltypesclassdescription.h"
+
+#include <QtCore/qstring.h>
+#include <QtCore/qset.h>
+
+class QmlTypesCreator
+{
+public:
+ QmlTypesCreator() : m_qml(&m_output) {}
+
+ void generate(const QString &outFileName, const QString &dependenciesFileName);
+
+ void setOwnTypes(QVector<QJsonObject> ownTypes) { m_ownTypes = std::move(ownTypes); }
+ void setForeignTypes(QVector<QJsonObject> foreignTypes) { m_foreignTypes = std::move(foreignTypes); }
+ void setModule(QString module) { m_module = std::move(module); }
+ void setMajorVersion(int majorVersion) { m_majorVersion = majorVersion; }
+
+private:
+ void writeClassProperties(const QmlTypesClassDescription &collector);
+ void writeType(const QJsonObject &property, const QString &key, bool isReadonly,
+ bool parsePointer);
+ void writeProperties(const QJsonArray &properties, QSet<QString> &notifySignals);
+ void writeMethods(const QJsonArray &methods, const QString &type,
+ const QSet<QString> &notifySignals = QSet<QString>());
+ void writeEnums(const QJsonArray &enums);
+ void writeComponents();
+
+ QByteArray m_output;
+ QmlStreamWriter m_qml;
+ QVector<QJsonObject> m_ownTypes;
+ QVector<QJsonObject> m_foreignTypes;
+ QString m_module;
+ int m_majorVersion = 0;
+};
+
+#endif // QMLTYPESCREATOR_H
diff --git a/src/quick/doc/src/examples.qdoc b/src/quick/doc/src/examples.qdoc
index 8c31e13a2d..a913af47c1 100644
--- a/src/quick/doc/src/examples.qdoc
+++ b/src/quick/doc/src/examples.qdoc
@@ -176,6 +176,7 @@ Creator.
\li \l{Scene Graph - Metal Texture Import}{Metal Texture Import}
\li \l{Scene Graph - OpenGL Under QML}{OpenGL Under QML}
\li \l{Scene Graph - Direct3D 11 Under QML}{Direct3D 11 Under QML}
+ \li \l{Scene Graph - Vulkan Under QML}{Vulkan Under QML}
\li \l{Scene Graph - Custom Rendering with QSGRenderNode}{Render Node}
\li \l{Scene Graph - Painted Item}{Painted Item}
\li \l{Scene Graph - Graph}{Graph}
diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp
index d22e77c8ad..b285fe56ed 100644
--- a/src/quick/items/qquickanimatedsprite.cpp
+++ b/src/quick/items/qquickanimatedsprite.cpp
@@ -263,6 +263,19 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \qmlproperty enumeration QtQuick::AnimatedSprite::finishBehavior
+
+ The behavior when the animation finishes on its own.
+
+ \value FinishAtInitialFrame
+ When the animation finishes it returns to the initial frame.
+ This is the default behavior.
+
+ \value FinishAtFinalFrame
+ When the animation finishes it stays on the final frame.
+*/
+
+/*!
\qmlmethod int QtQuick::AnimatedSprite::restart()
Stops, then starts the sprite animation.
@@ -381,6 +394,12 @@ int QQuickAnimatedSprite::currentFrame() const
return d->m_curFrame;
}
+QQuickAnimatedSprite::FinishBehavior QQuickAnimatedSprite::finishBehavior() const
+{
+ Q_D(const QQuickAnimatedSprite);
+ return d->m_finishBehavior;
+}
+
bool QQuickAnimatedSprite::isCurrentFrameChangedConnected()
{
IS_SIGNAL_CONNECTED(this, QQuickAnimatedSprite, currentFrameChanged, (int));
@@ -395,20 +414,34 @@ void QQuickAnimatedSprite::reloadImage()
void QQuickAnimatedSprite::componentComplete()
{
- Q_D(const QQuickAnimatedSprite);
+ Q_D(QQuickAnimatedSprite);
createEngine();
QQuickItem::componentComplete();
- if (d->m_running)
+ if (d->m_running) {
+ d->m_running = false;
start();
+ }
}
+/*!
+ \qmlmethod QtQuick::AnimatedSprite::start()
+ \since 5.15
+
+ Starts the sprite animation. If the animation is already running, calling
+ this method has no effect.
+
+ \sa stop()
+*/
void QQuickAnimatedSprite::start()
{
Q_D(QQuickAnimatedSprite);
+ if (d->m_running)
+ return;
d->m_running = true;
if (!isComponentComplete())
return;
d->m_curLoop = 0;
+ d->m_curFrame = 0;
d->m_timestamp.start();
if (d->m_spriteEngine) {
d->m_spriteEngine->stop(0);
@@ -420,9 +453,20 @@ void QQuickAnimatedSprite::start()
maybeUpdate();
}
+/*!
+ \qmlmethod QtQuick::AnimatedSprite::stop()
+ \since 5.15
+
+ Stops the sprite animation. If the animation is not running, calling this
+ method has no effect.
+
+ \sa start()
+*/
void QQuickAnimatedSprite::stop()
{
Q_D(QQuickAnimatedSprite);
+ if (!d->m_running)
+ return;
d->m_running = false;
if (!isComponentComplete())
return;
@@ -679,6 +723,16 @@ void QQuickAnimatedSprite::setCurrentFrame(int arg) //TODO-C: Probably only work
}
}
+void QQuickAnimatedSprite::setFinishBehavior(FinishBehavior arg)
+{
+ Q_D(QQuickAnimatedSprite);
+
+ if (d->m_finishBehavior != arg) {
+ d->m_finishBehavior = arg;
+ Q_EMIT finishBehaviorChanged(arg);
+ }
+}
+
void QQuickAnimatedSprite::createEngine()
{
Q_D(QQuickAnimatedSprite);
@@ -813,7 +867,11 @@ void QQuickAnimatedSprite::prepareNextFrame(QSGSpriteNode *node)
progress = 0;
}
if (d->m_loops > 0 && d->m_curLoop >= d->m_loops) {
- frameAt = 0;
+ if (d->m_finishBehavior == FinishAtInitialFrame)
+ frameAt = 0;
+ else
+ frameAt = frameCount() - 1;
+ d->m_curFrame = frameAt;
d->m_running = false;
emit runningChanged(false);
emit finished();
diff --git a/src/quick/items/qquickanimatedsprite_p.h b/src/quick/items/qquickanimatedsprite_p.h
index 30f64e9def..c28b6ce3af 100644
--- a/src/quick/items/qquickanimatedsprite_p.h
+++ b/src/quick/items/qquickanimatedsprite_p.h
@@ -92,6 +92,7 @@ class Q_AUTOTEST_EXPORT QQuickAnimatedSprite : public QQuickItem
Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
Q_PROPERTY(bool paused READ paused WRITE setPaused NOTIFY pausedChanged)
Q_PROPERTY(int currentFrame READ currentFrame WRITE setCurrentFrame NOTIFY currentFrameChanged)
+ Q_PROPERTY(FinishBehavior finishBehavior READ finishBehavior WRITE setFinishBehavior NOTIFY finishBehaviorChanged REVISION 15)
QML_NAMED_ELEMENT(AnimatedSprite)
public:
@@ -101,6 +102,12 @@ public:
};
Q_ENUM(LoopParameters)
+ enum FinishBehavior {
+ FinishAtInitialFrame,
+ FinishAtFinalFrame
+ };
+ Q_ENUM(FinishBehavior)
+
bool running() const;
bool interpolate() const;
QUrl source() const;
@@ -116,6 +123,7 @@ public:
int loops() const;
bool paused() const;
int currentFrame() const;
+ FinishBehavior finishBehavior() const;
Q_SIGNALS:
@@ -135,6 +143,7 @@ Q_SIGNALS:
void frameDurationChanged(int arg);
void loopsChanged(int arg);
void currentFrameChanged(int arg);
+ Q_REVISION(15) void finishBehaviorChanged(FinishBehavior arg);
Q_REVISION(12) void finished();
@@ -163,7 +172,7 @@ public Q_SLOTS:
void resetFrameDuration();
void setLoops(int arg);
void setCurrentFrame(int arg);
-
+ void setFinishBehavior(FinishBehavior arg);
private Q_SLOTS:
void createEngine();
diff --git a/src/quick/items/qquickanimatedsprite_p_p.h b/src/quick/items/qquickanimatedsprite_p_p.h
index 3610e58861..fb8faefbee 100644
--- a/src/quick/items/qquickanimatedsprite_p_p.h
+++ b/src/quick/items/qquickanimatedsprite_p_p.h
@@ -57,11 +57,10 @@ QT_REQUIRE_CONFIG(quick_sprite);
#include "qquickitem_p.h"
#include "qquicksprite_p.h"
+#include "qquickanimatedsprite_p.h"
QT_BEGIN_NAMESPACE
-class QQuickAnimatedSprite;
-
class QQuickAnimatedSpritePrivate : public QQuickItemPrivate
{
Q_DECLARE_PUBLIC(QQuickAnimatedSprite)
@@ -78,6 +77,7 @@ public:
, m_loops(-1)
, m_curLoop(0)
, m_pauseOffset(0)
+ , m_finishBehavior(QQuickAnimatedSprite::FinishAtInitialFrame)
{
}
@@ -93,6 +93,7 @@ public:
int m_loops;
int m_curLoop;
int m_pauseOffset;
+ QQuickAnimatedSprite::FinishBehavior m_finishBehavior;
};
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp
index ff4d9b0fd1..737b7ffe24 100644
--- a/src/quick/items/qquickdrag.cpp
+++ b/src/quick/items/qquickdrag.cpp
@@ -442,7 +442,7 @@ void QQuickDragAttached::setImageSource(const QUrl &url)
if (url.isEmpty()) {
d->pixmapLoader.clear();
} else {
- d->pixmapLoader.load(qmlEngine(this), url);
+ d->pixmapLoader.load(qmlEngine(parent()), url);
}
Q_EMIT imageSourceChanged();
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp
index 7d51a55a0c..89340dd992 100644
--- a/src/quick/items/qquickevents.cpp
+++ b/src/quick/items/qquickevents.cpp
@@ -1806,7 +1806,7 @@ const QTouchEvent::TouchPoint *QQuickPointerTouchEvent::touchPointById(int point
auto it = std::find_if(tps.constBegin(), tps.constEnd(),
[pointId](QTouchEvent::TouchPoint const& tp) { return tp.id() == pointId; } );
// return the pointer to the actual TP in QTouchEvent::_touchPoints
- return (it == tps.constEnd() ? nullptr : it.operator->());
+ return (it == tps.constEnd() ? nullptr : &*it);
}
/*!
@@ -1942,6 +1942,10 @@ Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QQuickPointerEvent *e
{
QDebugStateSaver saver(dbg);
dbg.nospace();
+ if (!event) {
+ dbg << "QQuickPointerEvent(0)";
+ return dbg;
+ }
dbg << "QQuickPointerEvent(";
dbg << event->timestamp();
dbg << " dev:";
@@ -1962,6 +1966,10 @@ Q_QUICK_PRIVATE_EXPORT QDebug operator<<(QDebug dbg, const QQuickEventPoint *eve
{
QDebugStateSaver saver(dbg);
dbg.nospace();
+ if (!event) {
+ dbg << "QQuickEventPoint(0)";
+ return dbg;
+ }
dbg << "QQuickEventPoint(accepted:" << event->isAccepted()
<< " state:";
QtDebugUtils::formatQEnum(dbg, event->state());
diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h
index 1d2ffefc9d..5acf98d471 100644
--- a/src/quick/items/qquickevents_p_p.h
+++ b/src/quick/items/qquickevents_p_p.h
@@ -58,7 +58,9 @@
#include <QtCore/qpointer.h>
#include <QtGui/qvector2d.h>
#include <QtGui/qevent.h>
-#include <QtGui/qkeysequence.h>
+#if QT_CONFIG(shortcut)
+# include <QtGui/qkeysequence.h>
+#endif
#include <QtQuick/qquickitem.h>
QT_BEGIN_NAMESPACE
diff --git a/src/quick/items/qquickframebufferobject.cpp b/src/quick/items/qquickframebufferobject.cpp
index 190bc6853c..d5550e78b6 100644
--- a/src/quick/items/qquickframebufferobject.cpp
+++ b/src/quick/items/qquickframebufferobject.cpp
@@ -83,6 +83,11 @@ public:
* Everything that relates to rendering must be located in the
* QQuickFramebufferObject::Renderer class.
*
+ * \warning This class is only functional when Qt Quick is rendering
+ * via OpenGL, either directly or through the \l{Scene Graph
+ * Adaptations}{RHI-based rendering path}. It is not compatible with
+ * other RHI backends, such as, Vulkan or Metal.
+ *
* To avoid race conditions and read/write issues from two threads
* it is important that the renderer and the item never read or
* write shared variables. Communication between the item and the renderer
@@ -109,10 +114,6 @@ public:
* and can be used directly in \l {ShaderEffect}{ShaderEffects} and other
* classes that consume texture providers.
*
- * \warning This class is only suitable when working directly with OpenGL. It
- * is not compatible with the \l{Scene Graph Adaptations}{RHI-based rendering
- * path}.
- *
* \sa {Scene Graph - Rendering FBOs}, {Scene Graph and Rendering}
*/
@@ -233,6 +234,13 @@ public Q_SLOTS:
{
if (renderPending) {
renderPending = false;
+
+ const bool needsWrap = QSGRendererInterface::isApiRhiBased(window->rendererInterface()->graphicsApi());
+ if (needsWrap) {
+ window->beginExternalCommands();
+ window->resetOpenGLState();
+ }
+
fbo->bind();
QOpenGLContext::currentContext()->functions()->glViewport(0, 0, fbo->width(), fbo->height());
renderer->render();
@@ -241,6 +249,9 @@ public Q_SLOTS:
if (msDisplayFbo)
QOpenGLFramebufferObject::blitFramebuffer(msDisplayFbo, fbo);
+ if (needsWrap)
+ window->endExternalCommands();
+
markDirty(QSGNode::DirtyMaterial);
emit textureChanged();
}
@@ -270,7 +281,8 @@ public:
static inline bool isOpenGL(QSGRenderContext *rc)
{
QSGRendererInterface *rif = rc->sceneGraphContext()->rendererInterface(rc);
- return !rif || rif->graphicsApi() == QSGRendererInterface::OpenGL;
+ return rif && (rif->graphicsApi() == QSGRendererInterface::OpenGL
+ || rif->graphicsApi() == QSGRendererInterface::OpenGLRhi);
}
/*!
@@ -335,9 +347,11 @@ QSGNode *QQuickFramebufferObject::updatePaintNode(QSGNode *node, UpdatePaintNode
displayTexture = n->msDisplayFbo->texture();
}
- n->setTexture(window()->createTextureFromId(displayTexture,
- n->fbo->size(),
- QQuickWindow::TextureHasAlphaChannel));
+ QSGTexture *wrapper = window()->createTextureFromNativeObject(QQuickWindow::NativeObjectTexture,
+ &displayTexture, 0,
+ n->fbo->size(),
+ QQuickWindow::TextureHasAlphaChannel);
+ n->setTexture(wrapper);
}
n->setTextureCoordinatesTransform(d->mirrorVertically ? QSGSimpleTextureNode::MirrorVertically : QSGSimpleTextureNode::NoTransform);
diff --git a/src/quick/items/qquickframebufferobject.h b/src/quick/items/qquickframebufferobject.h
index db143e48cf..e26c8293a6 100644
--- a/src/quick/items/qquickframebufferobject.h
+++ b/src/quick/items/qquickframebufferobject.h
@@ -48,7 +48,8 @@ class QOpenGLFramebufferObject;
class QQuickFramebufferObjectPrivate;
class QSGFramebufferObjectNode;
-// ### Qt 6: To be removed. To be seen if an alternative will need to be introduced.
+// ### Qt 6: Consider what to do here. QQuickFbo supports both direct OpenGL and
+// OpenGL via QRhi, but it cannot function when running with another rhi backend.
class Q_QUICK_EXPORT QQuickFramebufferObject : public QQuickItem
{
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 796ab6cdd7..4c20b7e2e1 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -2748,22 +2748,36 @@ void QQuickItem::setParentItem(QQuickItem *parentItem)
}
QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window : nullptr;
+ bool alreadyAddedChild = false;
if (d->window == parentWindow) {
// Avoid freeing and reallocating resources if the window stays the same.
d->parentItem = parentItem;
} else {
- if (d->window)
- d->derefWindow();
+ auto oldParentItem = d->parentItem;
d->parentItem = parentItem;
+ if (d->parentItem) {
+ QQuickItemPrivate::get(d->parentItem)->addChild(this);
+ alreadyAddedChild = true;
+ }
+ if (d->window) {
+ d->derefWindow();
+ // as we potentially changed d->parentWindow above
+ // the check in derefWindow could not work
+ // thus, we redo it here with the old parent
+ // Also, the window may have been deleted by derefWindow()
+ if (!oldParentItem && d->window) {
+ QQuickWindowPrivate::get(d->window)->parentlessItems.remove(this);
+ }
+ }
if (parentWindow)
d->refWindow(parentWindow);
}
d->dirty(QQuickItemPrivate::ParentChanged);
- if (d->parentItem)
+ if (d->parentItem && !alreadyAddedChild)
QQuickItemPrivate::get(d->parentItem)->addChild(this);
- else if (d->window)
+ else if (d->window && !alreadyAddedChild)
QQuickWindowPrivate::get(d->window)->parentlessItems.insert(this);
d->setEffectiveVisibleRecur(d->calcEffectiveVisible());
@@ -8534,7 +8548,11 @@ void QQuickItemLayer::setSourceRect(const QRectF &sourceRect)
/*!
\qmlproperty bool QtQuick::Item::layer.smooth
- Holds whether the layer is smoothly transformed.
+ Holds whether the layer is smoothly transformed. When enabled, sampling the
+ layer's texture is performed using \c linear interpolation, while
+ non-smooth results in using the \c nearest filtering mode.
+
+ By default, this property is set to \c false.
\sa {Item Layers}
*/
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp
index fccd467274..661f19509a 100644
--- a/src/quick/items/qquickitemview.cpp
+++ b/src/quick/items/qquickitemview.cpp
@@ -1581,9 +1581,7 @@ FxViewItem *QQuickItemViewPrivate::visibleItem(int modelIndex) const {
return nullptr;
}
-// should rename to firstItemInView() to avoid confusion with other "*visible*" methods
-// that don't look at the view position and size
-FxViewItem *QQuickItemViewPrivate::firstVisibleItem() const {
+FxViewItem *QQuickItemViewPrivate::firstItemInView() const {
const qreal pos = isContentFlowReversed() ? -position()-size() : position();
for (FxViewItem *item : visibleItems) {
if (item->index != -1 && item->endPosition() > pos)
@@ -1955,22 +1953,22 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
bool viewportChanged = !currentChanges.pendingChanges.removes().isEmpty()
|| !currentChanges.pendingChanges.inserts().isEmpty();
- FxViewItem *prevFirstVisible = firstVisibleItem();
- QQmlNullableValue<qreal> prevViewPos;
- int prevFirstVisibleIndex = -1;
- if (prevFirstVisible) {
- prevViewPos = prevFirstVisible->position();
- prevFirstVisibleIndex = prevFirstVisible->index;
+ FxViewItem *prevFirstItemInView = firstItemInView();
+ QQmlNullableValue<qreal> prevFirstItemInViewPos;
+ int prevFirstItemInViewIndex = -1;
+ if (prevFirstItemInView) {
+ prevFirstItemInViewPos = prevFirstItemInView->position();
+ prevFirstItemInViewIndex = prevFirstItemInView->index;
}
qreal prevVisibleItemsFirstPos = visibleItems.count() ? visibleItems.constFirst()->position() : 0.0;
- totalInsertionResult->visiblePos = prevViewPos;
- totalRemovalResult->visiblePos = prevViewPos;
+ totalInsertionResult->visiblePos = prevFirstItemInViewPos;
+ totalRemovalResult->visiblePos = prevFirstItemInViewPos;
const QVector<QQmlChangeSet::Change> &removals = currentChanges.pendingChanges.removes();
const QVector<QQmlChangeSet::Change> &insertions = currentChanges.pendingChanges.inserts();
- ChangeResult insertionResult(prevViewPos);
- ChangeResult removalResult(prevViewPos);
+ ChangeResult insertionResult(prevFirstItemInViewPos);
+ ChangeResult removalResult(prevFirstItemInViewPos);
int removedCount = 0;
for (const QQmlChangeSet::Change &r : removals) {
@@ -1979,7 +1977,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
visibleAffected = true;
if (!visibleAffected && needsRefillForAddedOrRemovedIndex(r.index))
visibleAffected = true;
- const int correctedFirstVisibleIndex = prevFirstVisibleIndex - removalResult.countChangeBeforeVisible;
+ const int correctedFirstVisibleIndex = prevFirstItemInViewIndex - removalResult.countChangeBeforeVisible;
if (correctedFirstVisibleIndex >= 0 && r.index < correctedFirstVisibleIndex) {
if (r.index + r.count < correctedFirstVisibleIndex)
removalResult.countChangeBeforeVisible += r.count;
@@ -2006,7 +2004,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
// set positions correctly for the next insertion
if (!insertions.isEmpty()) {
- repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstVisible, &insertionResult, &removalResult);
+ repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstItemInView, &insertionResult, &removalResult);
layoutVisibleItems(removals.first().index);
}
}
@@ -2026,7 +2024,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
// set positions correctly for the next insertion
if (i < insertions.count() - 1) {
- repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstVisible, &insertionResult, &removalResult);
+ repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstItemInView, &insertionResult, &removalResult);
layoutVisibleItems(insertions[i].index);
}
itemCount += insertions[i].count;
@@ -2043,7 +2041,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
for (const MovedItem &m : qAsConst(movingIntoView)) {
int fromIndex = findMoveKeyIndex(m.moveKey, removals);
if (fromIndex >= 0) {
- if (prevFirstVisibleIndex >= 0 && fromIndex < prevFirstVisibleIndex)
+ if (prevFirstItemInViewIndex >= 0 && fromIndex < prevFirstItemInViewIndex)
repositionItemAt(m.item, fromIndex, -totalInsertionResult->sizeChangesAfterVisiblePos);
else
repositionItemAt(m.item, fromIndex, totalInsertionResult->sizeChangesAfterVisiblePos);
@@ -2054,7 +2052,7 @@ bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult
// reposition visibleItems.first() correctly so that the content y doesn't jump
if (removedCount != prevVisibleItemsCount)
- repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstVisible, &insertionResult, &removalResult);
+ repositionFirstItem(prevVisibleItemsFirst, prevVisibleItemsFirstPos, prevFirstItemInView, &insertionResult, &removalResult);
// Whatever removed/moved items remain are no longer visible items.
prepareRemoveTransitions(&currentChanges.removedItems);
diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h
index 860cf5fa20..6442fee27d 100644
--- a/src/quick/items/qquickitemview_p_p.h
+++ b/src/quick/items/qquickitemview_p_p.h
@@ -158,7 +158,7 @@ public:
qreal contentStartOffset() const;
int findLastVisibleIndex(int defaultValue = -1) const;
FxViewItem *visibleItem(int modelIndex) const;
- FxViewItem *firstVisibleItem() const;
+ FxViewItem *firstItemInView() const;
int findLastIndexInView() const;
int mapFromModel(int modelIndex) const;
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp
index 725d35f325..23925871e5 100644
--- a/src/quick/items/qquicklistview.cpp
+++ b/src/quick/items/qquicklistview.cpp
@@ -455,7 +455,7 @@ qreal QQuickListViewPrivate::lastPosition() const
// All visible items are in delayRemove state
invisibleCount = model->count();
}
- pos = (*(--visibleItems.constEnd()))->endPosition();
+ pos = (*(visibleItems.constEnd() - 1))->endPosition();
if (invisibleCount > 0)
pos += invisibleCount * (averageSize + spacing);
} else if (model && model->count()) {
@@ -480,7 +480,7 @@ qreal QQuickListViewPrivate::positionAt(int modelIndex) const
return (*visibleItems.constBegin())->position() - count * (averageSize + spacing) - cs;
} else {
int count = modelIndex - findLastVisibleIndex(visibleIndex) - 1;
- return (*(--visibleItems.constEnd()))->endPosition() + spacing + count * (averageSize + spacing);
+ return (*(visibleItems.constEnd() - 1))->endPosition() + spacing + count * (averageSize + spacing);
}
}
return 0;
@@ -496,7 +496,7 @@ qreal QQuickListViewPrivate::endPositionAt(int modelIndex) const
return (*visibleItems.constBegin())->position() - (count - 1) * (averageSize + spacing) - spacing;
} else {
int count = modelIndex - findLastVisibleIndex(visibleIndex) - 1;
- return (*(--visibleItems.constEnd()))->endPosition() + count * (averageSize + spacing);
+ return (*(visibleItems.constEnd() - 1))->endPosition() + count * (averageSize + spacing);
}
}
return 0;
@@ -522,7 +522,7 @@ qreal QQuickListViewPrivate::snapPosAt(qreal pos)
return snapItem->itemPosition();
if (visibleItems.count()) {
qreal firstPos = (*visibleItems.constBegin())->position();
- qreal endPos = (*(--visibleItems.constEnd()))->position();
+ qreal endPos = (*(visibleItems.constEnd() - 1))->position();
if (pos < firstPos) {
return firstPos - qRound((firstPos - pos) / averageSize) * averageSize;
} else if (pos > endPos)
@@ -667,7 +667,7 @@ bool QQuickListViewPrivate::addVisibleItems(qreal fillFrom, qreal fillTo, qreal
qreal itemEnd = visiblePos;
if (visibleItems.count()) {
visiblePos = (*visibleItems.constBegin())->position();
- itemEnd = (*(--visibleItems.constEnd()))->endPosition() + spacing;
+ itemEnd = (*(visibleItems.constEnd() - 1))->endPosition() + spacing;
}
int modelIndex = findLastVisibleIndex();
diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp
index 819a3a73e3..8722a45373 100644
--- a/src/quick/items/qquickloader.cpp
+++ b/src/quick/items/qquickloader.cpp
@@ -591,8 +591,8 @@ void QQuickLoader::setSource(QQmlV4Function *args)
d->clear();
QUrl sourceUrl = d->resolveSourceUrl(args);
+ d->disposeInitialPropertyValues();
if (!ipv->isUndefined()) {
- d->disposeInitialPropertyValues();
d->initialPropertyValues.set(args->v4engine(), ipv);
}
d->qmlCallingContext.set(scope.engine, scope.engine->qmlContext());
@@ -602,6 +602,7 @@ void QQuickLoader::setSource(QQmlV4Function *args)
void QQuickLoaderPrivate::disposeInitialPropertyValues()
{
+ initialPropertyValues.clear();
}
void QQuickLoaderPrivate::load()
diff --git a/src/quick/items/qquickscreen_p.h b/src/quick/items/qquickscreen_p.h
index 9d9f9a1567..61cbdf7387 100644
--- a/src/quick/items/qquickscreen_p.h
+++ b/src/quick/items/qquickscreen_p.h
@@ -54,7 +54,7 @@
#include <qqml.h>
#include <QRect>
#include <QSize>
-#include <private/qqmlglobal_p.h>
+#include <private/qtquickglobal_p.h>
QT_BEGIN_NAMESPACE
@@ -64,7 +64,7 @@ class QQuickWindow;
class QScreen;
-class Q_AUTOTEST_EXPORT QQuickScreenInfo : public QObject
+class Q_QUICK_PRIVATE_EXPORT QQuickScreenInfo : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
@@ -86,10 +86,6 @@ class Q_AUTOTEST_EXPORT QQuickScreenInfo : public QObject
Q_PROPERTY(int virtualX READ virtualX NOTIFY virtualXChanged REVISION 3)
Q_PROPERTY(int virtualY READ virtualY NOTIFY virtualYChanged REVISION 3)
- QML_NAMED_ELEMENT(ScreenInfo)
- QML_ADDED_IN_MINOR_VERSION(3)
- QML_UNCREATABLE("ScreenInfo can only be used via the attached property.")
-
public:
QQuickScreenInfo(QObject *parent = nullptr, QScreen *wrappedScreen = nullptr);
@@ -132,7 +128,7 @@ protected:
QPointer<QScreen> m_screen;
};
-class Q_AUTOTEST_EXPORT QQuickScreenAttached : public QQuickScreenInfo
+class Q_QUICK_PRIVATE_EXPORT QQuickScreenAttached : public QQuickScreenInfo
{
Q_OBJECT
Q_PROPERTY(Qt::ScreenOrientations orientationUpdateMask READ orientationUpdateMask
@@ -162,11 +158,9 @@ private:
bool m_updateMaskSet;
};
-class Q_AUTOTEST_EXPORT QQuickScreen : public QObject
+class Q_QUICK_PRIVATE_EXPORT QQuickScreen : public QObject
{
Q_OBJECT
- QML_NAMED_ELEMENT(Screen)
- QML_UNCREATABLE("Screen can only be used via the attached property.")
QML_ATTACHED(QQuickScreenAttached)
public:
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index ae849aeb4b..31df4fdff3 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -517,6 +517,11 @@ void QQuickTextLine::setLineOffset(int offset)
m_lineOffset = offset;
}
+void QQuickTextLine::setFullLayoutTextLength(int length)
+{
+ m_fullLayoutTextLength = length;
+}
+
int QQuickTextLine::number() const
{
if (m_line)
@@ -524,6 +529,24 @@ int QQuickTextLine::number() const
return 0;
}
+qreal QQuickTextLine::implicitWidth() const
+{
+ if (m_line)
+ return m_line->naturalTextWidth();
+ return 0;
+}
+
+bool QQuickTextLine::isLast() const
+{
+ if (m_line && (m_line->textStart() + m_line->textLength()) == m_fullLayoutTextLength) {
+ // Ensure that isLast will change if the user reduced the width of the line
+ // so that the text no longer fits.
+ return m_line->width() >= m_line->naturalTextWidth();
+ }
+
+ return false;
+}
+
qreal QQuickTextLine::width() const
{
if (m_line)
@@ -585,12 +608,13 @@ bool QQuickTextPrivate::isLineLaidOutConnected()
IS_SIGNAL_CONNECTED(q, QQuickText, lineLaidOut, (QQuickTextLine *));
}
-void QQuickTextPrivate::setupCustomLineGeometry(QTextLine &line, qreal &height, int lineOffset)
+void QQuickTextPrivate::setupCustomLineGeometry(QTextLine &line, qreal &height, int fullLayoutTextLength, int lineOffset)
{
Q_Q(QQuickText);
if (!textLine)
textLine = new QQuickTextLine;
+ textLine->setFullLayoutTextLength(fullLayoutTextLength);
textLine->setLine(&line);
textLine->setY(height);
textLine->setHeight(0);
@@ -790,7 +814,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline)
if (noBreakLastLine && visibleCount == maxLineCount)
layout.engine()->option.setWrapMode(QTextOption::WrapAnywhere);
if (customLayout) {
- setupCustomLineGeometry(line, naturalHeight);
+ setupCustomLineGeometry(line, naturalHeight, layoutText.length());
} else {
setLineGeometry(line, lineWidth, naturalHeight);
}
@@ -1128,7 +1152,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const baseline)
QTextLine elidedLine = elideLayout->createLine();
elidedLine.setPosition(QPointF(0, height));
if (customLayout) {
- setupCustomLineGeometry(elidedLine, height, visibleCount - 1);
+ setupCustomLineGeometry(elidedLine, height, elideText.length(), visibleCount - 1);
} else {
setLineGeometry(elidedLine, lineWidth, height);
}
@@ -1335,20 +1359,43 @@ QQuickText::~QQuickText()
\qmlsignal QtQuick::Text::lineLaidOut(object line)
This signal is emitted for each line of text that is laid out during the layout
- process. The specified \a line object provides more details about the line that
+ process in plain text or styled text mode. It is not emitted in rich text mode.
+ The specified \a line object provides more details about the line that
is currently being laid out.
This gives the opportunity to position and resize a line as it is being laid out.
It can for example be used to create columns or lay out text around objects.
The properties of the specified \a line object are:
- \list
- \li number (read-only)
- \li x
- \li y
- \li width
- \li height
- \endlist
+
+ \table
+ \header
+ \li Property name
+ \li Description
+ \row
+ \li number (read-only)
+ \li Line number, starts with zero.
+ \row
+ \li x
+ \li Specifies the line's x position inside the \c Text element.
+ \row
+ \li y
+ \li Specifies the line's y position inside the \c Text element.
+ \row
+ \li width
+ \li Specifies the width of the line.
+ \row
+ \li height
+ \li Specifies the height of the line.
+ \row
+ \li implicitWidth (read-only)
+ \li The width that the line would naturally occupy based on its contents,
+ not taking into account any modifications made to \a width.
+ \row
+ \li isLast (read-only)
+ \li Whether the line is the last. This property can change if you
+ set the \a width property to a different value.
+ \endtable
For example, this will move the first 5 lines of a Text item by 100 pixels to the right:
\code
@@ -1360,6 +1407,16 @@ QQuickText::~QQuickText()
}
\endcode
+ The following example will allow you to position an item at the end of the last line:
+ \code
+ onLineLaidOut: {
+ if (line.isLast) {
+ lastLineMarker.x = line.x + line.implicitWidth
+ lastLineMarker.y = line.y + (line.height - lastLineMarker.height) / 2
+ }
+ }
+ \endcode
+
The corresponding handler is \c onLineLaidOut.
*/
diff --git a/src/quick/items/qquicktext_p.h b/src/quick/items/qquicktext_p.h
index 394ea25b83..d310db508e 100644
--- a/src/quick/items/qquicktext_p.h
+++ b/src/quick/items/qquicktext_p.h
@@ -330,6 +330,8 @@ class QQuickTextLine : public QObject
Q_PROPERTY(qreal height READ height WRITE setHeight)
Q_PROPERTY(qreal x READ x WRITE setX)
Q_PROPERTY(qreal y READ y WRITE setY)
+ Q_PROPERTY(qreal implicitWidth READ implicitWidth)
+ Q_PROPERTY(bool isLast READ isLast)
QML_ANONYMOUS
public:
@@ -337,7 +339,10 @@ public:
void setLine(QTextLine* line);
void setLineOffset(int offset);
+ void setFullLayoutTextLength(int length);
int number() const;
+ qreal implicitWidth() const;
+ bool isLast() const;
qreal width() const;
void setWidth(qreal width);
@@ -355,6 +360,7 @@ private:
QTextLine *m_line;
qreal m_height;
int m_lineOffset;
+ int m_fullLayoutTextLength;
};
QT_END_NAMESPACE
diff --git a/src/quick/items/qquicktext_p_p.h b/src/quick/items/qquicktext_p_p.h
index c01998b100..1fbf942130 100644
--- a/src/quick/items/qquicktext_p_p.h
+++ b/src/quick/items/qquicktext_p_p.h
@@ -195,7 +195,7 @@ public:
void ensureDoc();
QRectF setupTextLayout(qreal * const baseline);
- void setupCustomLineGeometry(QTextLine &line, qreal &height, int lineOffset = 0);
+ void setupCustomLineGeometry(QTextLine &line, qreal &height, int fullLayoutTextLength, int lineOffset = 0);
bool isLinkActivatedConnected();
bool isLinkHoveredConnected();
static QString anchorAt(const QTextLayout *layout, const QPointF &mousePos);
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index c4e9c0d316..7d34cc3f56 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -2060,20 +2060,19 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
firstDirtyPos = nodeIterator->startPos();
// ### this could be optimized if the first and last dirty nodes are not connected
// as the intermediate text nodes would usually only need to be transformed differently.
- int lastDirtyPos = firstDirtyPos;
+ QQuickTextNode *firstCleanNode = nullptr;
auto it = d->textNodeMap.constEnd();
while (it != nodeIterator) {
--it;
- if (it->dirty()) {
- lastDirtyPos = it->startPos();
+ if (it->dirty())
break;
- }
+ firstCleanNode = it->textNode();
}
do {
rootNode->removeChildNode(nodeIterator->textNode());
delete nodeIterator->textNode();
nodeIterator = d->textNodeMap.erase(nodeIterator);
- } while (nodeIterator != d->textNodeMap.constEnd() && nodeIterator->startPos() <= lastDirtyPos);
+ } while (nodeIterator != d->textNodeMap.constEnd() && nodeIterator->textNode() != firstCleanNode);
}
// FIXME: the text decorations could probably be handled separately (only updated for affected textFrames)
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index 34105d8c81..a83b9beaa5 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -2259,8 +2259,8 @@ void QQuickTextInput::remove(int start, int end)
d->m_cursor -= qMin(d->m_cursor, end) - start;
if (d->m_selstart > start)
d->m_selstart -= qMin(d->m_selstart, end) - start;
- if (d->m_selend > end)
- d->m_selend -= qMin(d->m_selend, end) - start;
+ if (d->m_selend >= end)
+ d->m_selend -= end - start;
}
d->addCommand(QQuickTextInputPrivate::Command(
QQuickTextInputPrivate::SetSelection, d->m_cursor, 0, d->m_selstart, d->m_selend));
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index ea1a74ef26..9b45750a3b 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -39,7 +39,6 @@
#include "qquickwindow.h"
#include "qquickwindow_p.h"
-#include "qquickwindowattached_p.h"
#include "qquickitem.h"
#include "qquickitem_p.h"
@@ -4221,16 +4220,18 @@ QQmlIncubationController *QQuickWindow::incubationController() const
The OpenGL context used for rendering the scene graph will be bound
at this point.
- When using the RHI and a graphics API other than OpenGL, the signal is
- emitted after the preparations for the frame have been done, meaning there
- is a command buffer in recording mode, where applicable. If desired, the
- slot function connected to this signal can query native resources like the
- command before via QSGRendererInterface. Note however that the recording of
- the main render pass is not yet started at this point and it is not
- possible to add commands within that pass. Instead, use
- beforeRenderPassRecording() for that. However, connecting to this signal is
- still important if the recording of copy type of commands is desired since
- those cannot be enqueued within a render pass.
+ When using the RHI, the signal is emitted after the preparations for the
+ frame have been done, meaning there is a command buffer in recording mode,
+ where applicable. If desired, the slot function connected to this signal
+ can query native resources like the command before via
+ QSGRendererInterface. Note however that the recording of the main render
+ pass is not yet started at this point and it is not possible to add
+ commands within that pass. Starting a pass means clearing the color, depth,
+ and stencil buffers so it is not possible to achieve an underlay type of
+ rendering by just connecting to this signal. Rather, connect to
+ beforeRenderPassRecording(). However, connecting to this signal is still
+ important if the recording of copy type of commands is desired since those
+ cannot be enqueued within a render pass.
\warning This signal is emitted from the scene graph rendering thread. If your
slot function needs to finish before execution continues, you must make sure that
@@ -4253,18 +4254,17 @@ QQmlIncubationController *QQuickWindow::incubationController() const
The OpenGL context used for rendering the scene graph will be bound at this point.
- When using the RHI and a graphics API other than OpenGL, the signal is
- emitted after scene graph has added its commands to the command buffer,
- which is not yet submitted to the graphics queue. If desired, the slot
- function connected to this signal can query native resources, like the
- command buffer, before via QSGRendererInterface. Note however that the
- render pass (or passes) are already recorded at this point and it is not
- possible to add more commands within the scenegraph's pass. Instead, use
- afterRenderPassRecording() for that. This signal has therefore limited use
- and is rarely needed in an RHI-based setup. Rather, it is the combination
- of beforeRendering() + beforeRenderPassRecording() or beforeRendering() +
- afterRenderPassRecording() that is typically used to achieve under- or
- overlaying of the custom rendering.
+ When using the RHI, the signal is emitted after scene graph has added its
+ commands to the command buffer, which is not yet submitted to the graphics
+ queue. If desired, the slot function connected to this signal can query
+ native resources, like the command buffer, before via QSGRendererInterface.
+ Note however that the render pass (or passes) are already recorded at this
+ point and it is not possible to add more commands within the scenegraph's
+ pass. Instead, use afterRenderPassRecording() for that. This signal has
+ therefore limited use and is rarely needed in an RHI-based setup. Rather,
+ it is the combination of beforeRendering() + beforeRenderPassRecording() or
+ beforeRendering() + afterRenderPassRecording() that is typically used to
+ achieve under- or overlaying of the custom rendering.
\warning This signal is emitted from the scene graph rendering thread. If your
slot function needs to finish before execution continues, you must make sure that
@@ -4735,8 +4735,7 @@ void QQuickWindow::setDefaultAlphaBuffer(bool useAlpha)
adaptation.
\note This function has no effect when running on the RHI graphics
- abstraction. With the RHI, the functions to call when enqueuing native
- graphics commands are beginExternalCommands() and endExternalCommands().
+ abstraction and the underlying RHI backend is not OpenGL.
\sa QQuickWindow::beforeRendering(), beginExternalCommands(), endExternalCommands()
*/
@@ -4744,7 +4743,7 @@ void QQuickWindow::resetOpenGLState()
{
Q_D(QQuickWindow);
- if (d->rhi || !openglContext())
+ if (!openglContext())
return;
QOpenGLContext *ctx = openglContext();
@@ -4859,7 +4858,13 @@ const QQuickWindow::GraphicsStateInfo &QQuickWindow::graphicsStateInfo()
directly and the RHI graphics abstraction layer is not in use. Refer to
resetOpenGLState() in that case.
- \sa endExternalCommands()
+ \note When the scenegraph is using the RHI graphics abstraction layer with
+ the OpenGL backend underneath, pay attention to the fact that the OpenGL
+ state in the context can have arbitrary settings, and this function does not
+ perform any resetting of the state back to defaults. Call
+ resetOpenGLState() if that is seen necessary.
+
+ \sa endExternalCommands(), resetOpenGLState()
\since 5.14
*/
diff --git a/src/quick/items/qquickwindow.h b/src/quick/items/qquickwindow.h
index bec1ace2a6..56d50cec2a 100644
--- a/src/quick/items/qquickwindow.h
+++ b/src/quick/items/qquickwindow.h
@@ -76,9 +76,6 @@ class Q_QUICK_EXPORT QQuickWindow : public QWindow
Q_PROPERTY(QQuickItem* contentItem READ contentItem CONSTANT)
Q_PROPERTY(QQuickItem* activeFocusItem READ activeFocusItem NOTIFY activeFocusItemChanged REVISION 1)
Q_CLASSINFO("DefaultProperty", "data")
- QML_NAMED_ELEMENT(Window)
- QML_ADDED_IN_MINOR_VERSION(0)
- QML_REMOVED_IN_MINOR_VERSION(1)
Q_DECLARE_PRIVATE(QQuickWindow)
public:
enum CreateTextureOption {
diff --git a/src/quick/items/qquickwindowmodule.cpp b/src/quick/items/qquickwindowmodule.cpp
index 0f952d194c..ee90af4341 100644
--- a/src/quick/items/qquickwindowmodule.cpp
+++ b/src/quick/items/qquickwindowmodule.cpp
@@ -48,6 +48,7 @@
#include <private/qguiapplication_p.h>
#include <private/qqmlengine_p.h>
#include <private/qv4qobjectwrapper_p.h>
+#include <private/qqmlglobal_p.h>
#include <qpa/qplatformintegration.h>
QT_BEGIN_NAMESPACE
@@ -195,19 +196,6 @@ void QQuickWindowQmlImpl::setScreen(QObject *screen)
QWindow::setScreen(screenWrapper ? screenWrapper->wrappedScreen() : nullptr);
}
-void QQuickWindowModule::defineModule()
-{
- const char uri[] = "QtQuick.Window";
-
- // Cannot automatically register these. They are from QtGui.
- qmlRegisterRevision<QWindow,1>(uri, 2, 1);
- qmlRegisterRevision<QWindow,2>(uri, 2, 2);
- qmlRegisterRevision<QWindow,13>(uri, 2, 13);
-
- qmlRegisterTypesAndRevisions<QQuickWindow, QQuickWindowQmlImpl,
- QQuickScreen, QQuickScreenInfo>(uri, 2);
-}
-
QT_END_NAMESPACE
#include "moc_qquickwindowmodule_p.cpp"
diff --git a/src/quick/items/qquickwindowmodule_p.h b/src/quick/items/qquickwindowmodule_p.h
index 1769e5aeb4..d0bf5c29b3 100644
--- a/src/quick/items/qquickwindowmodule_p.h
+++ b/src/quick/items/qquickwindowmodule_p.h
@@ -68,8 +68,6 @@ class Q_QUICK_PRIVATE_EXPORT QQuickWindowQmlImpl : public QQuickWindow, public Q
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
Q_PROPERTY(Visibility visibility READ visibility WRITE setVisibility NOTIFY visibilityChanged)
Q_PROPERTY(QObject *screen READ screen WRITE setScreen NOTIFY screenChanged REVISION 3)
- QML_NAMED_ELEMENT(Window)
- QML_ADDED_IN_MINOR_VERSION(1)
QML_ATTACHED(QQuickWindowAttached)
public:
@@ -100,12 +98,6 @@ private:
Q_DECLARE_PRIVATE(QQuickWindowQmlImpl)
};
-class Q_QUICK_PRIVATE_EXPORT QQuickWindowModule
-{
-public:
- static void defineModule();
-};
-
QT_END_NAMESPACE
QML_DECLARE_TYPE(QQuickWindowQmlImpl)
diff --git a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
index d3dc4978f2..46b2c6386c 100644
--- a/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
+++ b/src/quick/scenegraph/compressedtexture/qsgcompressedatlastexture.cpp
@@ -88,10 +88,20 @@ Texture *Atlas::create(const QByteArray &data, int dataLength, int dataOffset, c
void Atlas::generateTexture()
{
+ int bytesPerBlock = 8;
+ switch (m_format) {
+ case QOpenGLTexture::RGBA8_ETC2_EAC:
+ case QOpenGLTexture::RGBA_DXT3:
+ case QOpenGLTexture::RGBA_DXT5:
+ bytesPerBlock = 16;
+ default:
+ break;
+ }
+
QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
funcs->glCompressedTexImage2D(GL_TEXTURE_2D, 0, m_format,
m_size.width(), m_size.height(), 0,
- (m_size.width() * m_size.height()) / 2,
+ (m_size.width() / 4 * m_size.height() / 4) * bytesPerBlock,
nullptr);
}
diff --git a/src/quick/scenegraph/qsgrhitextureglyphcache_p.h b/src/quick/scenegraph/qsgrhitextureglyphcache_p.h
index a7374d91a4..49854a596e 100644
--- a/src/quick/scenegraph/qsgrhitextureglyphcache_p.h
+++ b/src/quick/scenegraph/qsgrhitextureglyphcache_p.h
@@ -75,8 +75,10 @@ public:
QRhiTexture *texture() const { return m_texture; }
void commitResourceUpdates(QRhiResourceUpdateBatch *mergeInto);
- int width() const { return m_size.width(); }
- int height() const { return m_size.height(); }
+ // Clamp the default -1 width and height to 0 for compatibility with
+ // QOpenGLTextureGlyphCache.
+ int width() const { return qMax(0, m_size.width()); }
+ int height() const { return qMax(0, m_size.height()); }
bool eightBitFormatIsAlphaSwizzled() const;
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
index 86d9590863..dc1f97de54 100644
--- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp
+++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp
@@ -807,9 +807,7 @@ void QSGRenderThread::syncAndRender(QImage *grabImage)
}
}
if (current) {
- const QSize outputSize = rhi ? cd->swapchain->currentPixelSize() : windowSize;
-
- d->renderSceneGraph(outputSize);
+ d->renderSceneGraph(windowSize, rhi ? cd->swapchain->currentPixelSize() : QSize());
if (profileFrames)
renderTime = threadTimer.nsecsElapsed();
diff --git a/src/quick/scenegraph/util/qsgopenglatlastexture.cpp b/src/quick/scenegraph/util/qsgopenglatlastexture.cpp
index ae7d9cf8cc..75a874424a 100644
--- a/src/quick/scenegraph/util/qsgopenglatlastexture.cpp
+++ b/src/quick/scenegraph/util/qsgopenglatlastexture.cpp
@@ -150,6 +150,10 @@ QSGTexture *Manager::create(const QSGCompressedTextureFactory *factory)
case QOpenGLTexture::RGB8_ETC2:
case QOpenGLTexture::RGBA8_ETC2_EAC:
case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2:
+ case QOpenGLTexture::RGB_DXT1:
+ case QOpenGLTexture::RGBA_DXT1:
+ case QOpenGLTexture::RGBA_DXT3:
+ case QOpenGLTexture::RGBA_DXT5:
break;
default:
return t;
@@ -158,8 +162,12 @@ QSGTexture *Manager::create(const QSGCompressedTextureFactory *factory)
QSize size = factory->m_textureData.size();
if (size.width() < m_atlas_size_limit && size.height() < m_atlas_size_limit) {
QHash<unsigned int, QSGCompressedAtlasTexture::Atlas*>::iterator i = m_atlases.find(format);
- if (i == m_atlases.end())
- i = m_atlases.insert(format, new QSGCompressedAtlasTexture::Atlas(m_atlas_size, format));
+ if (i == m_atlases.end()) {
+ // must be multiple of 4
+ QSize paddedSize(((m_atlas_size.width() + 3) / 4) * 4, ((m_atlas_size.height() + 3) / 4) * 4);
+ i = m_atlases.insert(format, new QSGCompressedAtlasTexture::Atlas(paddedSize, format));
+ }
+
// must be multiple of 4
QSize paddedSize(((size.width() + 3) / 4) * 4, ((size.height() + 3) / 4) * 4);
QByteArray data = factory->m_textureData.data();
diff --git a/src/quick/util/qquickimageprovider.cpp b/src/quick/util/qquickimageprovider.cpp
index ebcca77f17..c081d45268 100644
--- a/src/quick/util/qquickimageprovider.cpp
+++ b/src/quick/util/qquickimageprovider.cpp
@@ -291,7 +291,7 @@ void QQuickImageResponse::cancel()
\image imageprovider.png
See the \l {imageprovider}{Image Provider Example} for the complete implementation.
- Note that the example registers the provider via a \l{QQmlExtensionPlugin}{plugin}
+ Note that the example registers the provider via a \l{QQmlEngineExtensionPlugin}{plugin}
instead of registering it in the application \c main() function as shown above.
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index 4d2914ff6c..3854a8bd0b 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -885,7 +885,9 @@ void QQuickWidgetPrivate::createContext()
context = new QOpenGLContext;
context->setFormat(offscreenWindow->requestedFormat());
-
+ const QWindow *win = q->window()->windowHandle();
+ if (win && win->screen())
+ context->setScreen(win->screen());
QOpenGLContext *shareContext = qt_gl_global_share_context();
if (!shareContext)
shareContext = QWidgetPrivate::get(q->window())->shareContext();
diff --git a/src/src.pro b/src/src.pro
index 98e1779dc5..2855102eff 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -3,7 +3,13 @@ CONFIG += ordered
include($$OUT_PWD/qml/qtqml-config.pri)
include($$OUT_PWD/quick/qtquick-config.pri)
QT_FOR_CONFIG += qml qml-private quick-private
+
+# Otherwise we cannot compile qmltyperegistrar
+requires(qtConfig(commandlineparser))
+
+# We need qmltyperegistrar for all type registrations, even in qml
SUBDIRS += \
+ qmltyperegistrar \
qml \
qmlmodels
diff --git a/tests/auto/qml/debugger/qqmldebugjs/data/quit.js b/tests/auto/qml/debugger/qqmldebugjs/data/quit.js
new file mode 100644
index 0000000000..1a45fd5538
--- /dev/null
+++ b/tests/auto/qml/debugger/qqmldebugjs/data/quit.js
@@ -0,0 +1,4 @@
+function quit() {
+ console.log("hit");
+ Qt.quit();
+}
diff --git a/tests/auto/qml/debugger/qqmldebugjs/data/quitInJS.qml b/tests/auto/qml/debugger/qqmldebugjs/data/quitInJS.qml
new file mode 100644
index 0000000000..6e4183100b
--- /dev/null
+++ b/tests/auto/qml/debugger/qqmldebugjs/data/quitInJS.qml
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import "quit.js" as Quit;
+
+//DO NOT CHANGE
+
+Item {
+ Timer {
+ running: true
+ triggeredOnStart: true
+ onTriggered: Quit.quit();
+ }
+}
+
diff --git a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp
index 255d679b1b..5b6c43bc0c 100644
--- a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp
+++ b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp
@@ -58,6 +58,8 @@ const char *ONCOMPLETED_QMLFILE = "oncompleted.qml";
const char *CREATECOMPONENT_QMLFILE = "createComponent.qml";
const char *CONDITION_QMLFILE = "condition.qml";
const char *QUIT_QMLFILE = "quit.qml";
+const char *QUITINJS_QMLFILE = "quitInJS.qml";
+const char *QUIT_JSFILE = "quit.js";
const char *CHANGEBREAKPOINT_QMLFILE = "changeBreakpoint.qml";
const char *STEPACTION_QMLFILE = "stepAction.qml";
const char *BREAKPOINTRELOCATION_QMLFILE = "breakpointRelocation.qml";
@@ -109,8 +111,10 @@ private slots:
void setBreakpointInScriptOnOptimizedBinding();
void setBreakpointInScriptWithCondition_data() { targetData(); }
void setBreakpointInScriptWithCondition();
- void setBreakpointInScriptThatQuits_data() { targetData(); }
+ void setBreakpointInScriptThatQuits_data() { targetData(); };
void setBreakpointInScriptThatQuits();
+ void setBreakpointInJavaScript_data();
+ void setBreakpointInJavaScript();
void setBreakpointWhenAttaching();
void clearBreakpoint_data() { targetData(); }
@@ -450,6 +454,48 @@ void tst_QQmlDebugJS::setBreakpointInScriptThatQuits()
QCOMPARE(m_process->exitStatus(), QProcess::NormalExit);
}
+void tst_QQmlDebugJS::setBreakpointInJavaScript_data()
+{
+ QTest::addColumn<bool>("qmlscene");
+ QTest::addColumn<bool>("seedCache");
+ QTest::newRow("custom / immediate") << false << false;
+ QTest::newRow("qmlscene / immediate") << true << false;
+ QTest::newRow("custom / seeded") << false << true;
+ QTest::newRow("qmlscene / seeded") << true << true;
+}
+
+void tst_QQmlDebugJS::setBreakpointInJavaScript()
+{
+ QFETCH(bool, qmlscene);
+ QFETCH(bool, seedCache);
+
+ if (seedCache) { // Make sure there is a qmlc file that the engine should _not_ laod.
+ QProcess process;
+ process.start(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene",
+ { testFile(QUITINJS_QMLFILE) });
+ QTRY_COMPARE(process.state(), QProcess::NotRunning);
+ }
+
+ QCOMPARE(init(qmlscene, QUITINJS_QMLFILE), ConnectSuccess);
+
+ const int sourceLine = 2;
+
+ m_client->setBreakpoint(QLatin1String(QUIT_JSFILE), sourceLine, -1, true);
+ m_client->connect();
+ QVERIFY(waitForClientSignal(SIGNAL(stopped())));
+
+ const QJsonObject body = m_client->response().body.toObject();
+
+ QCOMPARE(body.value("sourceLine").toInt(), sourceLine);
+ QCOMPARE(QFileInfo(body.value("script").toObject().value("name").toString()).fileName(),
+ QLatin1String(QUIT_JSFILE));
+
+ m_client->continueDebugging(QV4DebugClient::Continue);
+
+ QVERIFY(m_process->waitForFinished());
+ QCOMPARE(m_process->exitStatus(), QProcess::NormalExit);
+}
+
void tst_QQmlDebugJS::setBreakpointWhenAttaching()
{
int sourceLine = 35;
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
index 1c895eb793..f1ff396d4f 100644
--- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp
+++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp
@@ -4888,6 +4888,7 @@ void tst_QJSEngine::interrupt_data()
QTest::addRow("labeled continue / %s", mode) << i << "a: while (true) { for (;;) { continue a; } }";
QTest::addRow("labeled break / %s", mode) << i << "while (true) { a: for (;;) { break a; } }";
QTest::addRow("tail call / %s", mode) << i << "'use strict';\nfunction x() { return x(); }; x();";
+ QTest::addRow("huge array join / %s", mode) << i << "Array(1E9)|1";
}
}
diff --git a/tests/auto/qml/qmlcachegen/data/parameterAdjustment.qml b/tests/auto/qml/qmlcachegen/data/parameterAdjustment.qml
new file mode 100644
index 0000000000..2128a54d81
--- /dev/null
+++ b/tests/auto/qml/qmlcachegen/data/parameterAdjustment.qml
@@ -0,0 +1,7 @@
+import QtQml 2.12
+
+QtObject {
+ signal testSignal(string a, int b, string c, bool d, bool e, real f, real g, bool h, int i, int j, string k, int l, string m, string n)
+ onTestSignal: {}
+ Component.onCompleted: testSignal("a", 1, "b", true, true, 0.1, 0.1, true, 1, 1, "a", 1, "a", "a")
+}
diff --git a/tests/auto/qml/qmlcachegen/qmlcachegen.pro b/tests/auto/qml/qmlcachegen/qmlcachegen.pro
index 1a334b68ce..452bd7d04a 100644
--- a/tests/auto/qml/qmlcachegen/qmlcachegen.pro
+++ b/tests/auto/qml/qmlcachegen/qmlcachegen.pro
@@ -17,7 +17,8 @@ RESOURCES += \
data/jsmoduleimport.qml \
data/script.mjs \
data/module.mjs \
- data/utils.mjs
+ data/utils.mjs \
+ data/parameterAdjustment.qml
workerscripts_test.files = \
data/worker.js \
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
index 5d87c319f3..f940f9c476 100644
--- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
+++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
@@ -73,6 +73,8 @@ private slots:
void reproducibleCache_data();
void reproducibleCache();
+
+ void parameterAdjustment();
};
// A wrapper around QQmlComponent to ensure the temporary reference counts
@@ -664,6 +666,14 @@ void tst_qmlcachegen::reproducibleCache()
QCOMPARE(contents1, contents2);
}
+void tst_qmlcachegen::parameterAdjustment()
+{
+ QQmlEngine engine;
+ CleanlyLoadingComponent component(&engine, QUrl("qrc:///data/parameterAdjustment.qml"));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull()); // Doesn't crash
+}
+
QTEST_GUILESS_MAIN(tst_qmlcachegen)
#include "tst_qmlcachegen.moc"
diff --git a/tests/auto/qml/qmllint/data/esmodule.mjs b/tests/auto/qml/qmllint/data/esmodule.mjs
new file mode 100644
index 0000000000..50a53be2b1
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/esmodule.mjs
@@ -0,0 +1,2 @@
+
+export function test() { console.log("hello world"); }
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 04f554ac48..e3c297fa0f 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -158,6 +158,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("catchIdentifier") << QStringLiteral("catchIdentifierNoWarning.qml");
QTest::newRow("qmldirAndQmltypes") << QStringLiteral("qmldirAndQmltypes.qml");
QTest::newRow("forLoop") << QStringLiteral("forLoop.qml");
+ QTest::newRow("esmodule") << QStringLiteral("esmodule.mjs");
}
void TestQmllint::cleanQmlCode()
diff --git a/tests/auto/qml/qmlmin/tst_qmlmin.cpp b/tests/auto/qml/qmlmin/tst_qmlmin.cpp
index 79a73299a4..e7498a8583 100644
--- a/tests/auto/qml/qmlmin/tst_qmlmin.cpp
+++ b/tests/auto/qml/qmlmin/tst_qmlmin.cpp
@@ -130,6 +130,7 @@ void tst_qmlmin::initTestCase()
invalidFiles << "tests/auto/qml/qjsengine/script/com/trolltech/syntaxerror/__init__.js";
invalidFiles << "tests/auto/qml/debugger/qqmlpreview/data/broken.qml";
invalidFiles << "tests/auto/qml/qqmllanguage/data/fuzzed.2.qml";
+ invalidFiles << "tests/auto/qml/qqmllanguage/data/fuzzed.3.qml";
invalidFiles << "tests/auto/qml/qqmllanguage/data/requiredProperties.2.qml";
invalidFiles << "tests/auto/qml/qqmllanguage/data/requiredProperties.3.qml";
// generatorFunction.qml is not invalid per se, but the minifier cannot handle yield statements
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/Imports/Derived.qml b/tests/auto/qml/qmlplugindump/data/dumper/Imports/Derived.qml
new file mode 100644
index 0000000000..2f0ac401d7
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/data/dumper/Imports/Derived.qml
@@ -0,0 +1,6 @@
+pragma Singleton
+import dumper.Imports 1.0
+
+Imports {
+ property int something: 2
+}
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro b/tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro
index d20ea967ea..b4bd9baf5b 100644
--- a/tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro
+++ b/tests/auto/qml/qmlplugindump/data/dumper/Imports/imports.pro
@@ -17,7 +17,7 @@ HEADERS += \
imports.h
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
- cp.files = qmldir plugins.qmltypes CompositeImports.qml
+ cp.files = qmldir plugins.qmltypes CompositeImports.qml Derived.qml
cp.path = $$OUT_PWD
COPIES += cp
}
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes b/tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes
index 937dd60a9e..fb13928ba0 100644
--- a/tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes
+++ b/tests/auto/qml/qmlplugindump/data/dumper/Imports/plugins.qmltypes
@@ -14,4 +14,14 @@ Module {
exports: ["dumper.Imports/Imports 1.0"]
exportMetaObjectRevisions: [0]
}
+ Component {
+ prototype: "Imports"
+ name: "dumper.Imports/Derived 1.0"
+ exports: ["dumper.Imports/Derived 1.0"]
+ exportMetaObjectRevisions: [0]
+ isComposite: true
+ isCreatable: false
+ isSingleton: true
+ Property { name: "something"; type: "int" }
+ }
}
diff --git a/tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir b/tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir
index c9058a7f95..f84fca1d75 100644
--- a/tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir
+++ b/tests/auto/qml/qmlplugindump/data/dumper/Imports/qmldir
@@ -1,3 +1,4 @@
module dumper.Imports
plugin Imports
CompositeImports 1.0 CompositeImports.qml
+singleton Derived 1.0 Derived.qml
diff --git a/tests/auto/qml/qqmlbinding/data/nanPropertyToInt.qml b/tests/auto/qml/qqmlbinding/data/nanPropertyToInt.qml
new file mode 100644
index 0000000000..366dbf0464
--- /dev/null
+++ b/tests/auto/qml/qqmlbinding/data/nanPropertyToInt.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.11
+
+Item {
+ visible: true
+ width: 320
+ height: 200
+ property int val: other.val
+
+ Rectangle {
+ id: other
+ anchors.fill: parent;
+ property int val: undefined / 2
+ }
+}
diff --git a/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp b/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp
index 2c2d311ff7..2610402455 100644
--- a/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp
+++ b/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp
@@ -56,6 +56,7 @@ private slots:
void bindingOverwriting();
void bindToQmlComponent();
void bindingDoesNoWeirdConversion();
+ void bindNaNToInt();
private:
QQmlEngine engine;
@@ -398,6 +399,16 @@ void tst_qqmlbinding::bindingDoesNoWeirdConversion()
QVERIFY(colorLabel);
}
+//QTBUG-72442
+void tst_qqmlbinding::bindNaNToInt()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("nanPropertyToInt.qml"));
+ QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem*>(c.create()));
+
+ QVERIFY(item != nullptr);
+ QCOMPARE(item->property("val").toInt(), 0);
+}
QTEST_MAIN(tst_qqmlbinding)
#include "tst_qqmlbinding.moc"
diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
index d9cb6673df..6754f22049 100644
--- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
+++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp
@@ -895,16 +895,27 @@ void tst_qqmlcontext::contextObjectHierarchy()
void tst_qqmlcontext::destroyContextProperty()
{
- QQmlEngine engine;
- QQmlContext context(&engine);
-
+ QScopedPointer<QQmlContext> context;
+ QScopedPointer<QObject> objectThatOutlivesEngine(new QObject);
{
- QObject object;
- context.setContextProperty(QLatin1String("a"), &object);
- QCOMPARE(qvariant_cast<QObject *>(context.contextProperty(QLatin1String("a"))), &object);
+ QQmlEngine engine;
+ context.reset(new QQmlContext(&engine));
+
+ {
+ QObject object;
+ context->setContextProperty(QLatin1String("a"), &object);
+ QCOMPARE(qvariant_cast<QObject *>(context->contextProperty(QLatin1String("a"))), &object);
+ }
+
+ QCOMPARE(qvariant_cast<QObject *>(context->contextProperty(QLatin1String("a"))), nullptr);
+ context->setContextProperty(QLatin1String("b"), objectThatOutlivesEngine.data());
}
- QCOMPARE(qvariant_cast<QObject *>(context.contextProperty(QLatin1String("a"))), nullptr);
+ // dropDestroyedObject() should not crash, even if the engine is gone.
+ objectThatOutlivesEngine.reset();
+
+ // We're not allowed to call context->contextProperty("b") anymore.
+ // TODO: Or are we?
}
QTEST_MAIN(tst_qqmlcontext)
diff --git a/tests/auto/qml/qqmldelegatemodel/data/abstractItemModel.qml b/tests/auto/qml/qqmldelegatemodel/data/abstractItemModel.qml
new file mode 100644
index 0000000000..01ebfd8e1e
--- /dev/null
+++ b/tests/auto/qml/qqmldelegatemodel/data/abstractItemModel.qml
@@ -0,0 +1,37 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml.Models 2.15
+import QtQuick 2.15
+
+import Test 1.0
+
+DelegateModel {
+ model: AbstractItemModel {}
+ delegate: Item {}
+}
diff --git a/tests/auto/qml/qqmldelegatemodel/data/integerModel.qml b/tests/auto/qml/qqmldelegatemodel/data/integerModel.qml
new file mode 100644
index 0000000000..f6cd886e09
--- /dev/null
+++ b/tests/auto/qml/qqmldelegatemodel/data/integerModel.qml
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml.Models 2.15
+import QtQuick 2.15
+
+DelegateModel {
+ model: 100
+ delegate: Item {}
+}
diff --git a/tests/auto/qml/qqmldelegatemodel/data/listModel.qml b/tests/auto/qml/qqmldelegatemodel/data/listModel.qml
new file mode 100644
index 0000000000..1ee8bcac72
--- /dev/null
+++ b/tests/auto/qml/qqmldelegatemodel/data/listModel.qml
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQml.Models 2.15
+import QtQuick 2.15
+
+DelegateModel {
+ model: ListModel {
+ ListElement {
+ name: "Item 0"
+ }
+ ListElement {
+ name: "Item 1"
+ }
+ ListElement {
+ name: "Item 2"
+ }
+ }
+ delegate: Item {}
+}
diff --git a/tests/auto/qml/qqmldelegatemodel/qqmldelegatemodel.pro b/tests/auto/qml/qqmldelegatemodel/qqmldelegatemodel.pro
new file mode 100644
index 0000000000..7fdd3ab5f1
--- /dev/null
+++ b/tests/auto/qml/qqmldelegatemodel/qqmldelegatemodel.pro
@@ -0,0 +1,13 @@
+CONFIG += testcase
+TARGET = tst_qqmldelegatemodel
+macos:CONFIG -= app_bundle
+
+QT += qml testlib core-private qml-private qmlmodels-private
+
+SOURCES += tst_qqmldelegatemodel.cpp
+
+include (../../shared/util.pri)
+
+TESTDATA = data/*
+
+OTHER_FILES += data/*
diff --git a/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp b/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp
new file mode 100644
index 0000000000..87f42c0c8a
--- /dev/null
+++ b/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/qtest.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQmlModels/private/qqmldelegatemodel_p.h>
+
+#include "../../shared/util.h"
+
+class tst_QQmlDelegateModel : public QQmlDataTest
+{
+ Q_OBJECT
+
+public:
+ tst_QQmlDelegateModel();
+
+private slots:
+ void valueWithoutCallingObjectFirst_data();
+ void valueWithoutCallingObjectFirst();
+};
+
+class AbstractItemModel : public QAbstractItemModel
+{
+ Q_OBJECT
+public:
+ AbstractItemModel()
+ {
+ for (int i = 0; i < 3; ++i)
+ mValues.append(QString::fromLatin1("Item %1").arg(i));
+ }
+
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
+ {
+ if (parent.isValid())
+ return QModelIndex();
+
+ return createIndex(row, column);
+ }
+
+ QModelIndex parent(const QModelIndex &) const override
+ {
+ return QModelIndex();
+ }
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const override
+ {
+ if (parent.isValid())
+ return 0;
+
+ return mValues.count();
+ }
+
+ int columnCount(const QModelIndex &parent) const override
+ {
+ if (parent.isValid())
+ return 0;
+
+ return 1;
+ }
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
+ {
+ if (role != Qt::DisplayRole)
+ return QVariant();
+
+ return mValues.at(index.row());
+ }
+
+private:
+ QVector<QString> mValues;
+};
+
+tst_QQmlDelegateModel::tst_QQmlDelegateModel()
+{
+ qmlRegisterType<AbstractItemModel>("Test", 1, 0, "AbstractItemModel");
+}
+
+void tst_QQmlDelegateModel::valueWithoutCallingObjectFirst_data()
+{
+ QTest::addColumn<QUrl>("qmlFileUrl");
+ QTest::addColumn<int>("index");
+ QTest::addColumn<QString>("role");
+ QTest::addColumn<QVariant>("expectedValue");
+
+ QTest::addRow("integer") << testFileUrl("integerModel.qml")
+ << 50 << QString::fromLatin1("modelData") << QVariant(50);
+ QTest::addRow("ListModel") << testFileUrl("listModel.qml")
+ << 1 << QString::fromLatin1("name") << QVariant(QLatin1String("Item 1"));
+ QTest::addRow("QAbstractItemModel") << testFileUrl("abstractItemModel.qml")
+ << 1 << QString::fromLatin1("display") << QVariant(QLatin1String("Item 1"));
+}
+
+// Tests that it's possible to call variantValue() without creating
+// costly delegate items first via object().
+void tst_QQmlDelegateModel::valueWithoutCallingObjectFirst()
+{
+ QFETCH(const QUrl, qmlFileUrl);
+ QFETCH(const int, index);
+ QFETCH(const QString, role);
+ QFETCH(const QVariant, expectedValue);
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(qmlFileUrl);
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY2(root, qPrintable(component.errorString()));
+ QQmlDelegateModel *model = qobject_cast<QQmlDelegateModel*>(root.data());
+ QVERIFY(model);
+ QCOMPARE(model->variantValue(index, role), expectedValue);
+}
+
+QTEST_MAIN(tst_QQmlDelegateModel)
+
+#include "tst_qqmldelegatemodel.moc"
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index f4de83eb87..a002658fee 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -5737,7 +5737,7 @@ void tst_qqmlecmascript::sequenceConversionRead()
QVERIFY(seq != nullptr);
// we haven't registered QList<NonRegisteredType> as a sequence type.
- QString warningOne = QLatin1String("QMetaProperty::read: Unable to handle unregistered datatype 'QList<NonRegisteredType>' for property 'MySequenceConversionObject::typeListProperty'");
+ QString warningOne = QLatin1String("QMetaProperty::read: Unable to handle unregistered datatype 'QVector<NonRegisteredType>' for property 'MySequenceConversionObject::typeListProperty'");
QString warningTwo = qmlFile.toString() + QLatin1String(":18: TypeError: Cannot read property 'length' of undefined");
QTest::ignoreMessage(QtWarningMsg, warningOne.toLatin1().constData());
QTest::ignoreMessage(QtWarningMsg, warningTwo.toLatin1().constData());
@@ -5747,7 +5747,7 @@ void tst_qqmlecmascript::sequenceConversionRead()
// QList<NonRegisteredType> has not been registered as a sequence type.
QCOMPARE(object->property("pointListLength").toInt(), 0);
QVERIFY(!object->property("pointList").isValid());
- QTest::ignoreMessage(QtWarningMsg, "QMetaProperty::read: Unable to handle unregistered datatype 'QList<NonRegisteredType>' for property 'MySequenceConversionObject::typeListProperty'");
+ QTest::ignoreMessage(QtWarningMsg, "QMetaProperty::read: Unable to handle unregistered datatype 'QVector<NonRegisteredType>' for property 'MySequenceConversionObject::typeListProperty'");
QQmlProperty seqProp(seq, "typeListProperty", &engine);
QVERIFY(!seqProp.read().isValid()); // not a valid/known sequence type
@@ -5790,7 +5790,7 @@ void tst_qqmlecmascript::sequenceConversionWrite()
QVERIFY(seq != nullptr);
// we haven't registered QList<QPoint> as a sequence type, so writing shouldn't work.
- QString warningOne = qmlFile.toString() + QLatin1String(":16: Error: Cannot assign QJSValue to QList<QPoint>");
+ QString warningOne = qmlFile.toString() + QLatin1String(":16: Error: Cannot assign QJSValue to QVector<QPoint>");
QTest::ignoreMessage(QtWarningMsg, warningOne.toLatin1().constData());
QMetaObject::invokeMethod(object, "performTest");
@@ -5904,7 +5904,7 @@ void tst_qqmlecmascript::sequenceConversionBindings()
{
QUrl qmlFile = testFileUrl("sequenceConversion.bindings.error.qml");
- QString warning = QString(QLatin1String("%1:17:9: Unable to assign QList<int> to QList<bool>")).arg(qmlFile.toString());
+ QString warning = QString(QLatin1String("%1:17:9: Unable to assign QVector<int> to QVector<bool>")).arg(qmlFile.toString());
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
QQmlComponent component(&engine, qmlFile);
QObject *object = component.create();
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
index ca1e52ad2c..9c865b3f73 100644
--- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
+++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
@@ -32,6 +32,7 @@
#include <QtQuick/qquickview.h>
#include <QtQuick/qquickitem.h>
#include <private/qqmlimport_p.h>
+#include <private/qqmlengine_p.h>
#include "../../shared/util.h"
class tst_QQmlImport : public QQmlDataTest
@@ -46,6 +47,7 @@ private slots:
void completeQmldirPaths();
void interceptQmldir();
void singletonVersionResolution();
+ void removeDynamicPlugin();
void cleanup();
};
@@ -260,6 +262,25 @@ void tst_QQmlImport::singletonVersionResolution()
}
}
+void tst_QQmlImport::removeDynamicPlugin()
+{
+ qmlClearTypeRegistrations();
+ QQmlEngine engine;
+ {
+ // Load something that adds a dynamic plugin
+ QQmlComponent component(&engine);
+ component.setData(QByteArray("import QtTest 1.0; TestResult{}"), QUrl());
+ QVERIFY(component.isReady());
+ }
+ QQmlImportDatabase *imports = &QQmlEnginePrivate::get(&engine)->importDatabase;
+ const QStringList &plugins = imports->dynamicPlugins();
+ QVERIFY(!plugins.isEmpty());
+ for (const QString &plugin : plugins)
+ QVERIFY(imports->removeDynamicPlugin(plugin));
+ QVERIFY(imports->dynamicPlugins().isEmpty());
+ qmlClearTypeRegistrations();
+}
+
QTEST_MAIN(tst_QQmlImport)
diff --git a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp
index 756b3b1d7c..549aae8c2b 100644
--- a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp
+++ b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp
@@ -149,7 +149,7 @@ void tst_qqmlincubator::objectDeleted()
QVERIFY(!SelfRegisteringType::me());
while (SelfRegisteringOuterType::me() == nullptr && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -157,14 +157,14 @@ void tst_qqmlincubator::objectDeleted()
QVERIFY(incubator.isLoading());
while (SelfRegisteringType::me() == nullptr && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
delete SelfRegisteringType::me();
{
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
}
@@ -205,7 +205,7 @@ void tst_qqmlincubator::clear()
component.create(incubator);
while (SelfRegisteringType::me() == nullptr && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -224,7 +224,7 @@ void tst_qqmlincubator::clear()
component.create(incubator);
{
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
}
@@ -318,7 +318,7 @@ void tst_qqmlincubator::forceCompletion()
QVERIFY(incubator.isLoading());
while (SelfRegisteringType::me() == nullptr && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -377,7 +377,7 @@ void tst_qqmlincubator::setInitialState()
MyIncubator incubator(QQmlIncubator::Asynchronous);
component.create(incubator);
QVERIFY(incubator.isLoading());
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
QVERIFY(incubator.isReady());
QVERIFY(incubator.object());
@@ -414,7 +414,7 @@ void tst_qqmlincubator::clearDuringCompletion()
QVERIFY(!CompletionRegisteringType::me());
while (CompletionRegisteringType::me() == nullptr && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -453,7 +453,7 @@ void tst_qqmlincubator::objectDeletionAfterInit()
component.create(incubator);
while (!incubator.obj && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -552,7 +552,7 @@ void tst_qqmlincubator::statusChanged()
QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading));
{
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
}
@@ -574,7 +574,7 @@ void tst_qqmlincubator::statusChanged()
QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading));
{
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
}
@@ -622,7 +622,7 @@ void tst_qqmlincubator::asynchronousIfNested()
QVERIFY(incubator.isLoading());
QVERIFY(!SelfRegisteringType::me());
while (SelfRegisteringType::me() == nullptr && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -635,7 +635,7 @@ void tst_qqmlincubator::asynchronousIfNested()
while (nested.isLoading()) {
QVERIFY(incubator.isLoading());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -643,7 +643,7 @@ void tst_qqmlincubator::asynchronousIfNested()
QVERIFY(incubator.isLoading());
{
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
}
@@ -742,7 +742,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNested()
QVERIFY(!SelfRegisteringType::me());
while (SelfRegisteringType::me() == nullptr && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -779,7 +779,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNested()
QVERIFY(incubator1.isLoading());
QVERIFY(incubator2.isNull());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -792,14 +792,14 @@ void tst_qqmlincubator::chainedAsynchronousIfNested()
QVERIFY(incubator1.isReady());
QVERIFY(incubator2.isLoading());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
QVERIFY(incubator1.isReady());
QVERIFY(incubator2.isReady());
if (incubator.isLoading()) {
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
}
@@ -856,7 +856,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNestedOnCompleted()
QVERIFY(!SelfRegisteringType::me());
while (SelfRegisteringType::me() == nullptr && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -876,7 +876,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNestedOnCompleted()
QVERIFY(incubator2.isNull());
QVERIFY(incubator3.isNull());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -891,7 +891,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNestedOnCompleted()
QVERIFY(incubator2.isNull());
QVERIFY(incubator3.isNull());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -906,7 +906,7 @@ void tst_qqmlincubator::chainedAsynchronousIfNestedOnCompleted()
QVERIFY(incubator2.isLoading());
QVERIFY(incubator3.isNull());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -921,12 +921,12 @@ void tst_qqmlincubator::chainedAsynchronousIfNestedOnCompleted()
QVERIFY(incubator2.isReady());
QVERIFY(incubator3.isLoading());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
{
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
}
@@ -984,7 +984,7 @@ void tst_qqmlincubator::chainedAsynchronousClear()
QVERIFY(!SelfRegisteringType::me());
while (SelfRegisteringType::me() == nullptr && incubator.isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -1004,7 +1004,7 @@ void tst_qqmlincubator::chainedAsynchronousClear()
QVERIFY(incubator2.isNull());
QVERIFY(incubator3.isNull());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -1019,7 +1019,7 @@ void tst_qqmlincubator::chainedAsynchronousClear()
QVERIFY(incubator2.isNull());
QVERIFY(incubator3.isNull());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -1034,7 +1034,7 @@ void tst_qqmlincubator::chainedAsynchronousClear()
QVERIFY(incubator2.isLoading());
QVERIFY(incubator3.isNull());
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -1078,7 +1078,7 @@ void tst_qqmlincubator::selfDelete()
#define DELETE_TEST(status, mode) { \
bool done = false; \
component.create(*(new MyIncubator(&done, status, mode))); \
- bool True = true; \
+ std::atomic<bool> True{true}; \
controller.incubateWhile(&True); \
QVERIFY(done == true); \
}
@@ -1107,7 +1107,7 @@ void tst_qqmlincubator::selfDelete()
QVERIFY(!SelfRegisteringType::me());
while (SelfRegisteringType::me() == nullptr && incubator->isLoading()) {
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
@@ -1121,7 +1121,7 @@ void tst_qqmlincubator::selfDelete()
delete SelfRegisteringType::me();
{
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
}
@@ -1142,7 +1142,7 @@ void tst_qqmlincubator::contextDelete()
delete context;
{
- bool b = false;
+ std::atomic<bool> b{false};
controller.incubateWhile(&b);
}
}
@@ -1155,7 +1155,7 @@ void tst_qqmlincubator::garbageCollection()
engine.collectGarbage();
- bool b = true;
+ std::atomic<bool> b{true};
controller.incubateWhile(&b);
// verify incubation completed (the incubator was not prematurely collected)
diff --git a/tests/auto/qml/qqmlitemmodels/qtestmodel.h b/tests/auto/qml/qqmlitemmodels/qtestmodel.h
index 6a022b3135..de42253708 100644
--- a/tests/auto/qml/qqmlitemmodels/qtestmodel.h
+++ b/tests/auto/qml/qqmlitemmodels/qtestmodel.h
@@ -31,6 +31,8 @@
#include <QtCore/qabstractitemmodel.h>
+#include <limits.h>
+
class TestModel: public QAbstractItemModel
{
Q_OBJECT
diff --git a/tests/auto/qml/qqmllanguage/data/SelfInstantiation.errors.txt b/tests/auto/qml/qqmllanguage/data/SelfInstantiation.errors.txt
new file mode 100644
index 0000000000..dfd077941e
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/SelfInstantiation.errors.txt
@@ -0,0 +1 @@
+3:29:SelfInstantiation is instantiated recursively
diff --git a/tests/auto/qml/qqmllanguage/data/SelfInstantiation.qml b/tests/auto/qml/qqmllanguage/data/SelfInstantiation.qml
new file mode 100644
index 0000000000..b2e4e453a0
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/SelfInstantiation.qml
@@ -0,0 +1,5 @@
+import QtQml 2.0
+QtObject {
+ property QtObject self: SelfInstantiation {
+ }
+}
diff --git a/tests/auto/qml/qqmllanguage/data/SelfReference.qml b/tests/auto/qml/qqmllanguage/data/SelfReference.qml
new file mode 100644
index 0000000000..129a171d77
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/SelfReference.qml
@@ -0,0 +1,8 @@
+import QtQml 2.0
+QtObject {
+ property SelfReference self
+ signal blah(selfParam: SelfReference)
+ function returnSelf() : SelfReference {
+ return this;
+ }
+}
diff --git a/tests/auto/qml/qqmllanguage/data/alias.14.errors.txt b/tests/auto/qml/qqmllanguage/data/alias.14.errors.txt
deleted file mode 100644
index 90a3ea4317..0000000000
--- a/tests/auto/qml/qqmllanguage/data/alias.14.errors.txt
+++ /dev/null
@@ -1 +0,0 @@
-10:34:References to other aliases within the same object are not supported at the moment
diff --git a/tests/auto/qml/qqmllanguage/data/alias.18.errors.txt b/tests/auto/qml/qqmllanguage/data/alias.18.errors.txt
new file mode 100644
index 0000000000..dda3e7a174
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/alias.18.errors.txt
@@ -0,0 +1 @@
+7:24:Duplicate alias name
diff --git a/tests/auto/qml/qqmllanguage/data/alias.18.qml b/tests/auto/qml/qqmllanguage/data/alias.18.qml
new file mode 100644
index 0000000000..a9be937975
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/alias.18.qml
@@ -0,0 +1,9 @@
+import QtQml 2.14
+
+QtObject {
+ id: root
+ property QtObject o1: QtObject {
+ property alias a: root
+ property alias a: root
+ }
+}
diff --git a/tests/auto/qml/qqmllanguage/data/fuzzed.2.qml b/tests/auto/qml/qqmllanguage/data/fuzzed.2.qml
index e726f6783c..f164ec98ea 100644
--- a/tests/auto/qml/qqmllanguage/data/fuzzed.2.qml
+++ b/tests/auto/qml/qqmllanguage/data/fuzzed.2.qml
Binary files differ
diff --git a/tests/auto/qml/qqmllanguage/data/fuzzed.3.errors.txt b/tests/auto/qml/qqmllanguage/data/fuzzed.3.errors.txt
new file mode 100644
index 0000000000..da17dc5599
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/fuzzed.3.errors.txt
@@ -0,0 +1,2 @@
+3:2:Unexpected token `version number'
+1:1:Expected a qualified name id or a string literal
diff --git a/tests/auto/qml/qqmllanguage/data/fuzzed.3.qml b/tests/auto/qml/qqmllanguage/data/fuzzed.3.qml
new file mode 100644
index 0000000000..6861ebf8a9
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/fuzzed.3.qml
Binary files differ
diff --git a/tests/auto/qml/qqmllanguage/data/objectValueTypeProperty.errors.txt b/tests/auto/qml/qqmllanguage/data/objectValueTypeProperty.errors.txt
index 043f714636..887d87b9fb 100644
--- a/tests/auto/qml/qqmllanguage/data/objectValueTypeProperty.errors.txt
+++ b/tests/auto/qml/qqmllanguage/data/objectValueTypeProperty.errors.txt
@@ -1 +1 @@
-4:18:Can not assign value of type "MyTypeObject" to property "x", expecting "int"
+4:18:Cannot assign value of type "MyTypeObject" to property "x", expecting "int"
diff --git a/tests/auto/qml/qqmllanguage/data/selfreferencingsingletonmodule/TestSingleton.qml b/tests/auto/qml/qqmllanguage/data/selfreferencingsingletonmodule/TestSingleton.qml
new file mode 100644
index 0000000000..f70a3b1fea
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/selfreferencingsingletonmodule/TestSingleton.qml
@@ -0,0 +1,7 @@
+import QtQml 2.0
+import selfreferencingsingletonmodule 1.0
+pragma Singleton
+QtObject {
+ property SelfReferencingSingleton self
+ property int dummy: 42
+}
diff --git a/tests/auto/qml/qqmllanguage/data/selfreferencingsingletonmodule/qmldir b/tests/auto/qml/qqmllanguage/data/selfreferencingsingletonmodule/qmldir
new file mode 100644
index 0000000000..617861b00b
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/selfreferencingsingletonmodule/qmldir
@@ -0,0 +1 @@
+singleton SelfReferencingSingleton 1.0 TestSingleton.qml
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index e2032c3b86..7fff982cde 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -306,6 +306,9 @@ private slots:
void extendedForeignTypes();
+ void selfReference();
+ void selfReferencingSingleton();
+
private:
QQmlEngine engine;
QStringList defaultImportPathList;
@@ -624,12 +627,15 @@ void tst_qqmllanguage::errors_data()
QTest::newRow("fuzzed.1") << "fuzzed.1.qml" << "fuzzed.1.errors.txt" << false;
QTest::newRow("fuzzed.2") << "fuzzed.2.qml" << "fuzzed.2.errors.txt" << false;
+ QTest::newRow("fuzzed.3") << "fuzzed.3.qml" << "fuzzed.3.errors.txt" << false;
QTest::newRow("bareQmlImport") << "bareQmlImport.qml" << "bareQmlImport.errors.txt" << false;
QTest::newRow("typeAnnotations.2") << "typeAnnotations.2.qml" << "typeAnnotations.2.errors.txt" << false;
QTest::newRow("propertyUnknownType") << "propertyUnknownType.qml" << "propertyUnknownType.errors.txt" << false;
+
+ QTest::newRow("selfInstantiation") << "SelfInstantiation.qml" << "SelfInstantiation.errors.txt" << false;
}
void tst_qqmllanguage::errors()
@@ -1955,7 +1961,6 @@ void tst_qqmllanguage::aliasProperties()
// "Nested" aliases within an object that require iterative resolution
{
- // This is known to fail at the moment.
QQmlComponent component(&engine, testFileUrl("alias.14.qml"));
VERIFY_ERRORS(0);
@@ -2054,6 +2059,11 @@ void tst_qqmllanguage::aliasProperties()
auto text = myText->property("text").toString();
QCOMPARE(text, "alias:\n20");
}
+
+ {
+ QQmlComponent component(&engine, testFileUrl("alias.18.qml"));
+ VERIFY_ERRORS("alias.18.errors.txt");
+ }
}
// QTBUG-13374 Test that alias properties and signals can coexist
@@ -4728,11 +4738,13 @@ static void beginDeferredOnce(QQmlEnginePrivate *enginePriv,
typedef QMultiHash<int, const QV4::CompiledData::Binding *> QV4PropertyBindingHash;
auto it = std::reverse_iterator<QV4PropertyBindingHash::iterator>(range.second);
auto last = std::reverse_iterator<QV4PropertyBindingHash::iterator>(range.first);
+ state->creator->beginPopulateDeferred(deferData->context);
while (it != last) {
- if (!state->creator->populateDeferredBinding(property, deferData, *it))
- state->errors << state->creator->errors;
+ state->creator->populateDeferredBinding(property, deferData->deferredIdx, *it);
++it;
}
+ state->creator->finalizePopulateDeferred();
+ state->errors << state->creator->errors;
deferredState->constructionStates += state;
@@ -4957,24 +4969,24 @@ void tst_qqmllanguage::instanceof_data()
// assert that basic types don't convert to QObject
QTest::newRow("1 instanceof QtObject")
<< testFileUrl("instanceof_qtqml.qml")
- << QVariant("TypeError: Type error");
+ << QVariant(false);
QTest::newRow("true instanceof QtObject")
<< testFileUrl("instanceof_qtqml.qml")
- << QVariant("TypeError: Type error");
+ << QVariant(false);
QTest::newRow("\"foobar\" instanceof QtObject")
<< testFileUrl("instanceof_qtqml.qml")
- << QVariant("TypeError: Type error");
+ << QVariant(false);
// assert that Managed don't either
QTest::newRow("new String(\"foobar\") instanceof QtObject")
<< testFileUrl("instanceof_qtqml.qml")
- << QVariant("TypeError: Type error");
+ << QVariant(false);
QTest::newRow("new Object() instanceof QtObject")
<< testFileUrl("instanceof_qtqml.qml")
- << QVariant("TypeError: Type error");
+ << QVariant(false);
QTest::newRow("new Date() instanceof QtObject")
<< testFileUrl("instanceof_qtqml.qml")
- << QVariant("TypeError: Type error");
+ << QVariant(false);
// test that simple QtQml comparisons work
QTest::newRow("qtobjectInstance instanceof QtObject")
@@ -5274,6 +5286,69 @@ void tst_qqmllanguage::extendedForeignTypes()
QCOMPARE(o->property("foreignExtendedObjectName").toString(), QLatin1String("foreignExtended"));
}
+void tst_qqmllanguage::selfReference()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("SelfReference.qml"));
+ VERIFY_ERRORS(0);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(!o.isNull());
+
+ QQmlComponentPrivate *componentPrivate = QQmlComponentPrivate::get(&component);
+ auto compilationUnit = componentPrivate->compilationUnit;
+ QVERIFY(compilationUnit);
+
+ const QMetaObject *metaObject = o->metaObject();
+ QMetaProperty selfProperty = metaObject->property(metaObject->indexOfProperty("self"));
+ QCOMPARE(selfProperty.userType(), compilationUnit->metaTypeId);
+
+ QByteArray typeName = selfProperty.typeName();
+ QVERIFY(typeName.endsWith('*'));
+ typeName = typeName.chopped(1);
+ QCOMPARE(typeName, metaObject->className());
+
+ QMetaMethod selfFunction = metaObject->method(metaObject->indexOfMethod("returnSelf()"));
+ QVERIFY(selfFunction.isValid());
+ QCOMPARE(selfFunction.returnType(), compilationUnit->metaTypeId);
+
+ QMetaMethod selfSignal;
+
+ for (int i = metaObject->methodOffset(); i < metaObject->methodCount(); ++i) {
+ QMetaMethod method = metaObject->method(i);
+ if (method.isValid() && method.name().startsWith("blah")) {
+ selfSignal = method;
+ break;
+ }
+ }
+
+ QVERIFY(selfSignal.isValid());
+ QCOMPARE(selfSignal.parameterCount(), 1);
+ QCOMPARE(selfSignal.parameterType(0), compilationUnit->metaTypeId);
+}
+
+void tst_qqmllanguage::selfReferencingSingleton()
+{
+ QQmlEngine engine;
+ engine.addImportPath(dataDirectory());
+
+ QPointer<QObject> singletonPointer;
+ {
+ QQmlComponent component(&engine);
+ component.setData(QByteArray(R"(import QtQml 2.0
+ import selfreferencingsingletonmodule 1.0
+ QtObject {
+ property SelfReferencingSingleton singletonPointer: SelfReferencingSingleton
+ })"), QUrl());
+ VERIFY_ERRORS(0);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(!o.isNull());
+ singletonPointer = o->property("singletonPointer").value<QObject*>();
+ }
+
+ QVERIFY(!singletonPointer.isNull());
+ QCOMPARE(singletonPointer->property("dummy").toInt(), 42);
+}
+
QTEST_MAIN(tst_qqmllanguage)
#include "tst_qqmllanguage.moc"
diff --git a/tests/auto/qml/qqmlproperty/data/interfaceBinding.qml b/tests/auto/qml/qqmlproperty/data/interfaceBinding.qml
new file mode 100644
index 0000000000..4e72a75f42
--- /dev/null
+++ b/tests/auto/qml/qqmlproperty/data/interfaceBinding.qml
@@ -0,0 +1,27 @@
+import QtQuick 2.12
+import io.qt.bugreports 1.0
+Item {
+ InterfaceConsumer {
+ objectName: "a1"
+ i: A {
+ property int i: 42
+ }
+ }
+
+ InterfaceConsumer {
+ objectName: "a2"
+ property A a: A {
+ property int i: 43
+ }
+ i: a
+ }
+
+ InterfaceConsumer {
+ objectName: "a3"
+ property A a: A {
+ id : aa
+ property int i: 44
+ }
+ i: aa
+ }
+}
diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
index 1a5927fa74..f039ccc110 100644
--- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
+++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
@@ -40,6 +40,8 @@
#endif
#include <QtCore/private/qobject_p.h>
#include "../../shared/util.h"
+#include "qobject.h"
+#include <QtQml/QQmlPropertyMap>
#include <QDebug>
class MyQmlObject : public QObject
@@ -148,6 +150,7 @@ private slots:
void readOnlyDynamicProperties();
void aliasToIdWithMatchingQmlFileNameOnCaseInsensitiveFileSystem();
void nullPropertyBinding();
+ void interfaceBinding();
void floatToStringPrecision_data();
void floatToStringPrecision();
@@ -155,6 +158,8 @@ private slots:
void copy();
void bindingToAlias();
+
+ void nestedQQmlPropertyMap();
private:
QQmlEngine engine;
};
@@ -2083,6 +2088,83 @@ void tst_qqmlproperty::nullPropertyBinding()
QMetaObject::invokeMethod(root.get(), "tog");
}
+struct Interface {
+};
+
+QT_BEGIN_NAMESPACE
+#define MyInterface_iid "io.qt.bugreports.Interface"
+Q_DECLARE_INTERFACE(Interface, MyInterface_iid);
+QT_END_NAMESPACE
+
+class A : public QObject, Interface {
+ Q_OBJECT
+ Q_INTERFACES(Interface)
+};
+
+class B : public QObject, Interface {
+ Q_OBJECT
+ Q_INTERFACES(Interface)
+};
+
+class C : public QObject {
+ Q_OBJECT
+};
+
+class InterfaceConsumer : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(Interface* i READ interface WRITE setInterface NOTIFY interfaceChanged)
+ Q_PROPERTY(int testValue READ testValue NOTIFY testValueChanged)
+
+
+public:
+
+ Interface* interface() const
+ {
+ return m_interface;
+ }
+ void setInterface(Interface* interface)
+ {
+ QObject* object = reinterpret_cast<QObject*>(interface);
+ m_testValue = object->property("i").toInt();
+ emit testValueChanged();
+ if (m_interface == interface)
+ return;
+
+ m_interface = interface;
+ emit interfaceChanged();
+ }
+
+ int testValue() {
+ return m_testValue;
+ }
+
+signals:
+ void interfaceChanged();
+ void testValueChanged();
+
+private:
+ Interface* m_interface = nullptr;
+ int m_testValue = 0;
+};
+void tst_qqmlproperty::interfaceBinding()
+{
+
+ qmlRegisterInterface<Interface>("Interface");
+ qmlRegisterType<A>("io.qt.bugreports", 1, 0, "A");
+ qmlRegisterType<B>("io.qt.bugreports", 1, 0, "B");
+ qmlRegisterType<C>("io.qt.bugreports", 1, 0, "C");
+ qmlRegisterType<InterfaceConsumer>("io.qt.bugreports", 1, 0, "InterfaceConsumer");
+
+ const QUrl url = testFileUrl("interfaceBinding.qml");
+ QQmlEngine engine;
+ QQmlComponent component(&engine, url);
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY(root);
+ QCOMPARE(root->findChild<QObject*>("a1")->property("testValue").toInt(), 42);
+ QCOMPARE(root->findChild<QObject*>("a2")->property("testValue").toInt(), 43);
+ QCOMPARE(root->findChild<QObject*>("a3")->property("testValue").toInt(), 44);
+}
+
void tst_qqmlproperty::floatToStringPrecision_data()
{
QTest::addColumn<QString>("propertyName");
@@ -2139,6 +2221,24 @@ void tst_qqmlproperty::bindingToAlias()
QVERIFY(!o.isNull());
}
+void tst_qqmlproperty::nestedQQmlPropertyMap()
+{
+ QQmlPropertyMap mainPropertyMap;
+ QQmlPropertyMap nestedPropertyMap;
+ QQmlPropertyMap deeplyNestedPropertyMap;
+
+ mainPropertyMap.insert("nesting1", QVariant::fromValue(&nestedPropertyMap));
+ nestedPropertyMap.insert("value", 42);
+ nestedPropertyMap.insert("nesting2", QVariant::fromValue(&deeplyNestedPropertyMap));
+ deeplyNestedPropertyMap.insert("value", "success");
+
+ QQmlProperty value{&mainPropertyMap, "nesting1.value"};
+ QCOMPARE(value.read().toInt(), 42);
+
+ QQmlProperty success{&mainPropertyMap, "nesting1.nesting2.value"};
+ QCOMPARE(success.read().toString(), QLatin1String("success"));
+}
+
QTEST_MAIN(tst_qqmlproperty)
#include "tst_qqmlproperty.moc"
diff --git a/tests/auto/qml/qqmltablemodel/qqmltablemodel.pro b/tests/auto/qml/qqmltablemodel/qqmltablemodel.pro
index 9d298dfdf2..11b11132aa 100644
--- a/tests/auto/qml/qqmltablemodel/qqmltablemodel.pro
+++ b/tests/auto/qml/qqmltablemodel/qqmltablemodel.pro
@@ -7,4 +7,4 @@ include (../../shared/util.pri)
TESTDATA = data/*
-QT += core gui qml-private qml quick-private quick testlib qmlmodels-private
+QT += core gui qml-private qml quick-private quick testlib
diff --git a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp
index d913bcdf9a..5457597df3 100644
--- a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp
+++ b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp
@@ -29,8 +29,8 @@
#include <QtTest/qtest.h>
#include <QtTest/qsignalspy.h>
#include <QtCore/qregularexpression.h>
+#include <QtCore/qabstractitemmodel.h>
#include <QtQml/private/qqmlengine_p.h>
-#include <QtQmlModels/private/qqmltablemodel_p.h>
#include <QtQml/qqmlcomponent.h>
#include <QtQuick/qquickitem.h>
#include <QtQuick/qquickview.h>
@@ -68,7 +68,7 @@ void tst_QQmlTableModel::appendRemoveRow()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel") .value<QAbstractTableModel *>();
QVERIFY(model);
QCOMPARE(model->rowCount(), 2);
QCOMPARE(model->columnCount(), 2);
@@ -213,7 +213,7 @@ void tst_QQmlTableModel::appendRowToEmptyModel()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->rowCount(), 0);
QCOMPARE(model->columnCount(), 2);
@@ -248,7 +248,7 @@ void tst_QQmlTableModel::clear()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->rowCount(), 2);
QCOMPARE(model->columnCount(), 2);
@@ -287,7 +287,7 @@ void tst_QQmlTableModel::getRow()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->rowCount(), 2);
QCOMPARE(model->columnCount(), 2);
@@ -318,7 +318,7 @@ void tst_QQmlTableModel::insertRow()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->rowCount(), 2);
QCOMPARE(model->columnCount(), 2);
@@ -474,7 +474,7 @@ void tst_QQmlTableModel::moveRow()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->columnCount(), 2);
QCOMPARE(model->rowCount(), 2);
@@ -602,7 +602,7 @@ void tst_QQmlTableModel::setRow()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->columnCount(), 2);
QCOMPARE(model->rowCount(), 2);
@@ -762,7 +762,7 @@ void tst_QQmlTableModel::setDataThroughDelegate()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->rowCount(), 2);
QCOMPARE(model->columnCount(), 2);
@@ -825,7 +825,7 @@ void tst_QQmlTableModel::setRowsImperatively()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->rowCount(), 0);
QCOMPARE(model->columnCount(), 2);
@@ -862,7 +862,7 @@ void tst_QQmlTableModel::setRowsMultipleTimes()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("testModel").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("testModel").value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->rowCount(), 2);
QCOMPARE(model->columnCount(), 2);
@@ -919,7 +919,7 @@ void tst_QQmlTableModel::dataAndEditing()
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
- QQmlTableModel *model = view.rootObject()->property("model").value<QQmlTableModel*>();
+ auto *model = view.rootObject()->property("model").value<QAbstractTableModel*>();
QVERIFY(model);
const QHash<int, QByteArray> roleNames = model->roleNames();
@@ -939,7 +939,7 @@ void tst_QQmlTableModel::omitTableModelColumnIndex()
QQmlComponent component(&engine, testFileUrl("omitTableModelColumnIndex.qml"));
QCOMPARE(component.status(), QQmlComponent::Ready);
- QScopedPointer<QQmlTableModel> model(qobject_cast<QQmlTableModel*>(component.create()));
+ QScopedPointer<QAbstractTableModel> model(qobject_cast<QAbstractTableModel*>(component.create()));
QVERIFY(model);
QCOMPARE(model->rowCount(), 2);
QCOMPARE(model->columnCount(), 2);
@@ -963,7 +963,7 @@ void tst_QQmlTableModel::complexRow()
QCOMPARE(tableView->rows(), 2);
QCOMPARE(tableView->columns(), 2);
- QQmlTableModel *model = tableView->model().value<QQmlTableModel*>();
+ auto *model = tableView->model().value<QAbstractTableModel*>();
QVERIFY(model);
QCOMPARE(model->rowCount(), 2);
QCOMPARE(model->columnCount(), 2);
diff --git a/tests/auto/qml/qqmltypeloader/data/declarativeCppType.qml b/tests/auto/qml/qqmltypeloader/data/declarativeCppType.qml
new file mode 100644
index 0000000000..9061f3beb5
--- /dev/null
+++ b/tests/auto/qml/qqmltypeloader/data/declarativeCppType.qml
@@ -0,0 +1,6 @@
+import QtQml 2.0
+import declarative.import.for.typeloader.test 3.2
+
+DeclarativeTestType {
+ objectName: "ddddd"
+}
diff --git a/tests/auto/qml/qqmltypeloader/declarativetesttype.h b/tests/auto/qml/qqmltypeloader/declarativetesttype.h
new file mode 100644
index 0000000000..a21cdcfd1d
--- /dev/null
+++ b/tests/auto/qml/qqmltypeloader/declarativetesttype.h
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DECLARATIVETESTTYPE_H
+#define DECLARATIVETESTTYPE_H
+
+#include <QObject>
+#include <qqml.h>
+
+class DeclarativeTestType : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+
+public:
+ explicit DeclarativeTestType(QObject *parent = nullptr) : QObject(parent) {}
+};
+
+#endif // DECLARATIVETESTTYPE_H
diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
index 07f67c7843..d529600723 100644
--- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
+++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
@@ -61,7 +61,7 @@ private slots:
void qrcRootPathUrl();
void implicitImport();
void compositeSingletonCycle();
-
+ void declarativeCppType();
private:
void checkSingleton(const QString & dataDirectory);
};
@@ -100,6 +100,8 @@ void tst_QQMLTypeLoader::trimCache()
{
QQmlEngine engine;
QQmlTypeLoader &loader = QQmlEnginePrivate::get(&engine)->typeLoader;
+ QVector<QQmlTypeData *> releaseLater;
+ QVector<QV4::ExecutableCompilationUnit *> releaseCompilationUnitLater;
for (int i = 0; i < 256; ++i) {
QUrl url = testFileUrl("trim_cache.qml");
url.setQuery(QString::number(i));
@@ -112,8 +114,10 @@ void tst_QQMLTypeLoader::trimCache()
// QQmlTypeData or its compiledData() should prevent the trimming.
if (i % 10 == 0) {
// keep ref on data, don't add ref on data->compiledData()
+ releaseLater.append(data);
} else if (i % 5 == 0) {
data->compilationUnit()->addref();
+ releaseCompilationUnitLater.append(data->compilationUnit());
data->release();
} else {
data->release();
@@ -129,6 +133,12 @@ void tst_QQMLTypeLoader::trimCache()
QVERIFY(!loader.isTypeLoaded(url));
// The cache is free to keep the others.
}
+
+ for (auto *data : qAsConst(releaseCompilationUnitLater))
+ data->release();
+
+ for (auto *data : qAsConst(releaseLater))
+ data->release();
}
void tst_QQMLTypeLoader::trimCache2()
@@ -557,6 +567,15 @@ void tst_QQMLTypeLoader::compositeSingletonCycle()
QCOMPARE(qvariant_cast<QColor>(object->property("color")), QColorConstants::Black);
}
+void tst_QQMLTypeLoader::declarativeCppType()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("declarativeCppType.qml"));
+ QCOMPARE(component.status(), QQmlComponent::Ready);
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+}
+
QTEST_MAIN(tst_QQMLTypeLoader)
#include "tst_qqmltypeloader.moc"
diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro
index 743f7cf3ac..c868474b5b 100644
--- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro
+++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro
@@ -1,4 +1,4 @@
-CONFIG += testcase
+CONFIG += testcase qmltypes
TARGET = tst_qqmltypeloader
QT += qml testlib qml-private quick
macx:CONFIG -= app_bundle
@@ -8,7 +8,11 @@ SOURCES += \
../../shared/testhttpserver.cpp
HEADERS += \
- ../../shared/testhttpserver.h
+ ../../shared/testhttpserver.h \
+ declarativetesttype.h
+
+QML_IMPORT_VERSION = 3.2
+QML_IMPORT_NAME = "declarative.import.for.typeloader.test"
include (../../shared/util.pri)
diff --git a/tests/auto/quick/qquickanimatedsprite/data/finishBehavior.qml b/tests/auto/quick/qquickanimatedsprite/data/finishBehavior.qml
new file mode 100644
index 0000000000..13a0ef4622
--- /dev/null
+++ b/tests/auto/quick/qquickanimatedsprite/data/finishBehavior.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.15
+
+Rectangle {
+ color: "black"
+ width: 320
+ height: 320
+
+ AnimatedSprite {
+ objectName: "sprite"
+ loops: 1
+ source: "squarefacesprite.png"
+ frameCount: 6
+ frameDuration: 64
+ width: 160
+ height: 160
+ finishBehavior: AnimatedSprite.FinishAtFinalFrame
+ }
+}
diff --git a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp
index d2bbf9e6b1..9f616c56e2 100644
--- a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp
+++ b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp
@@ -49,6 +49,7 @@ private slots:
void initTestCase();
void test_properties();
void test_runningChangedSignal();
+ void test_startStop();
void test_frameChangedSignal();
void test_largeAnimation_data();
void test_largeAnimation();
@@ -56,6 +57,7 @@ private slots:
void test_changeSourceToSmallerImgKeepingBigFrameSize();
void test_infiniteLoops();
void test_implicitSize();
+ void test_finishBehavior();
};
void tst_qquickanimatedsprite::initTestCase()
@@ -118,6 +120,42 @@ void tst_qquickanimatedsprite::test_runningChangedSignal()
QCOMPARE(finishedSpy.count(), 1);
}
+void tst_qquickanimatedsprite::test_startStop()
+{
+ QScopedPointer<QQuickView> window(new QQuickView);
+
+ window->setSource(testFileUrl("runningChange.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QVERIFY(window->rootObject());
+ QQuickAnimatedSprite* sprite = window->rootObject()->findChild<QQuickAnimatedSprite*>("sprite");
+ QVERIFY(sprite);
+
+ QVERIFY(!sprite->running());
+
+ QSignalSpy runningChangedSpy(sprite, SIGNAL(runningChanged(bool)));
+ QSignalSpy finishedSpy(sprite, SIGNAL(finished()));
+ QVERIFY(finishedSpy.isValid());
+
+ sprite->start();
+ QVERIFY(sprite->running());
+ QTRY_COMPARE(runningChangedSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+ sprite->stop();
+ QVERIFY(!sprite->running());
+ QTRY_COMPARE(runningChangedSpy.count(), 2);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ sprite->setCurrentFrame(2);
+ sprite->start();
+ QVERIFY(sprite->running());
+ QCOMPARE(sprite->currentFrame(), 0);
+ QTRY_VERIFY(sprite->currentFrame() > 0);
+ sprite->stop();
+ QVERIFY(!sprite->running());
+}
+
template <typename T>
static bool isWithinRange(T min, T value, T max)
{
@@ -391,6 +429,31 @@ void tst_qquickanimatedsprite::test_infiniteLoops()
QCOMPARE(finishedSpy.count(), 0);
}
+void tst_qquickanimatedsprite::test_finishBehavior()
+{
+ QQuickView window;
+ window.setSource(testFileUrl("finishBehavior.qml"));
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QVERIFY(window.rootObject());
+
+ QQuickAnimatedSprite* sprite = window.rootObject()->findChild<QQuickAnimatedSprite*>("sprite");
+ QVERIFY(sprite);
+
+ QTRY_VERIFY(sprite->running());
+
+ // correctly stops at last frame
+ QSignalSpy finishedSpy(sprite, SIGNAL(finished()));
+ QVERIFY(finishedSpy.wait(2000));
+ QCOMPARE(sprite->running(), false);
+ QCOMPARE(sprite->currentFrame(), 5);
+
+ // correctly starts a second time
+ sprite->start();
+ QTRY_VERIFY(sprite->running());
+ QTRY_COMPARE(sprite->currentFrame(), 5);
+}
+
QTEST_MAIN(tst_qquickanimatedsprite)
#include "tst_qquickanimatedsprite.moc"
diff --git a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp
index ee43e5e06a..f1288c2dbe 100644
--- a/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp
+++ b/tests/auto/quick/qquickdrag/tst_qquickdrag.cpp
@@ -143,6 +143,7 @@ private slots:
void source();
void recursion_data();
void recursion();
+ void noCrashWithImageProvider();
private:
QQmlEngine engine;
@@ -1279,6 +1280,30 @@ void tst_QQuickDrag::recursion()
}
}
+void tst_QQuickDrag::noCrashWithImageProvider()
+{
+ // QTBUG-72045
+ QQmlComponent component(&engine);
+ component.setData(
+ R"(
+ import QtQuick 2.9
+ Item {
+ Rectangle {
+ id: item
+ width: 50
+ height: 50
+ anchors.centerIn: parent
+ color: "orange"
+ Component.onCompleted: {
+ item.Drag.imageSource = "image://kill/me"
+ }
+ }
+ })", QUrl());
+ QScopedPointer<QObject> object(component.create());
+ QQuickItem *item = qobject_cast<QQuickItem *>(object.data());
+ QVERIFY(item);
+}
+
QTEST_MAIN(tst_QQuickDrag)
diff --git a/tests/auto/quick/qquickitem/data/setParentInWindowChange.qml b/tests/auto/quick/qquickitem/data/setParentInWindowChange.qml
new file mode 100644
index 0000000000..d68b7adb72
--- /dev/null
+++ b/tests/auto/quick/qquickitem/data/setParentInWindowChange.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.12
+
+Rectangle {
+ width: 800
+ height: 600
+ Item {
+ id: it
+ onWindowChanged: () => it.parent = newParent
+ }
+
+ Item { id: newParent }
+}
diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
index b6e40d5117..8aab13e095 100644
--- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
@@ -197,6 +197,8 @@ private slots:
void qtBug60123();
#endif
+ void setParentCalledInOnWindowChanged();
+
private:
enum PaintOrderOp {
@@ -2146,6 +2148,12 @@ void tst_qquickitem::qtBug60123()
activateWindowAndTestPress(&window);
}
#endif
+void tst_qquickitem::setParentCalledInOnWindowChanged()
+{
+ QQuickView view;
+ view.setSource(testFileUrl("setParentInWindowChange.qml"));
+ QVERIFY(ensureFocus(&view)); // should not crash
+}
QTEST_MAIN(tst_qquickitem)
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
index 399535cfa6..607cf91bfe 100644
--- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp
@@ -76,8 +76,10 @@ private slots:
void qtbug_50516_2();
void keys();
+#if QT_CONFIG(shortcut)
void standardKeys_data();
void standardKeys();
+#endif
void keysProcessingOrder();
void keysim();
void keysForward();
@@ -1429,6 +1431,8 @@ void tst_QQuickItem::keys()
delete testObject;
}
+#if QT_CONFIG(shortcut)
+
Q_DECLARE_METATYPE(QEvent::Type);
Q_DECLARE_METATYPE(QKeySequence::StandardKey);
@@ -1487,6 +1491,8 @@ void tst_QQuickItem::standardKeys()
QCOMPARE(item->property("released").toBool(), released);
}
+#endif // QT_CONFIG(shortcut)
+
void tst_QQuickItem::keysProcessingOrder()
{
QQuickView *window = new QQuickView(nullptr);
diff --git a/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml b/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml
index 49838c4fd5..e8b3960486 100644
--- a/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml
+++ b/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml
@@ -1019,5 +1019,59 @@ Item {
waitForRendering(layout);
verify(layout.children[1].visible == false);
}
+
+
+
+ Component {
+ id: gridlayout_propertyChanges_Component
+ GridLayout {
+ columns: 1
+ property alias spy : signalSpy
+ SignalSpy {
+ id: signalSpy
+ target: parent
+ }
+ }
+ }
+
+ Component {
+ id: rowlayout_propertyChanges_Component
+ RowLayout {
+ property alias spy : signalSpy
+ SignalSpy {
+ id: signalSpy
+ target: parent
+ }
+ }
+ }
+
+ function test_propertyChanges_data()
+ {
+ let data = [
+ { tag: "columnSpacing", value: 9 },
+ { tag: "rowSpacing", value: 9 },
+ { tag: "columns", value: 2 },
+ { tag: "rows", value: 2 },
+ { tag: "flow", value: GridLayout.TopToBottom},
+ { tag: "layoutDirection", value: Qt.RightToLeft },
+ { tag: "spacing", value: 9 }
+ ]
+ return data
+ }
+
+ function test_propertyChanges(data)
+ {
+ var propName = data.tag
+ var layout = createTemporaryObject(propName === "spacing"
+ ? rowlayout_propertyChanges_Component
+ : gridlayout_propertyChanges_Component
+ , container)
+
+ layout.spy.signalName = propName + "Changed"
+ verify(layout.spy.valid)
+
+ layout[propName] = data.value
+ compare(layout.spy.count, 1)
+ }
}
}
diff --git a/tests/auto/quick/qquickloader/data/CacheClearTest.qml b/tests/auto/quick/qquickloader/data/CacheClearTest.qml
new file mode 100644
index 0000000000..acab79f96e
--- /dev/null
+++ b/tests/auto/quick/qquickloader/data/CacheClearTest.qml
@@ -0,0 +1,4 @@
+import QtQml 2.12
+QtObject {
+ property int i: 42
+}
diff --git a/tests/auto/quick/qquickloader/data/initialPropertyValues.11.qml b/tests/auto/quick/qquickloader/data/initialPropertyValues.11.qml
new file mode 100644
index 0000000000..ddc874d14c
--- /dev/null
+++ b/tests/auto/quick/qquickloader/data/initialPropertyValues.11.qml
@@ -0,0 +1,20 @@
+import QtQuick 2.0
+
+Item {
+ id: root
+ property int oldi: 0
+ property int i: 0
+
+ Loader {
+ id: loader
+ objectName: "loader"
+ active: true
+ }
+
+ Component.onCompleted: {
+ loader.setSource("CacheClearTest.qml", {i: 12})
+ root.oldi = loader.item.i
+ loader.setSource("CacheClearTest.qml")
+ root.i = loader.item.i // should be 42
+ }
+}
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
index da923d4d41..e05b7ae9ce 100644
--- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp
+++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
@@ -691,6 +691,11 @@ void tst_QQuickLoader::initialPropertyValues_data()
<< (QStringList() << QString(testFileUrl("RequiredPropertyValuesComponent.qml").toString() + QLatin1String(":6:5: Required property s was not initialized")))
<< (QStringList() << "i" << "s")
<< (QVariantList() << 0 << QLatin1String(""));
+
+ QTest::newRow("source url changed, previously initial properties are discared") << testFileUrl("initialPropertyValues.11.qml")
+ << QStringList()
+ << (QStringList() << "oldi" << "i")
+ << (QVariantList() << 12 << 42);
}
void tst_QQuickLoader::initialPropertyValues()
diff --git a/tests/auto/quick/qquicktext/data/lineLayout.qml b/tests/auto/quick/qquicktext/data/lineLayout.qml
index cb2474791e..5a980de7da 100644
--- a/tests/auto/quick/qquicktext/data/lineLayout.qml
+++ b/tests/auto/quick/qquicktext/data/lineLayout.qml
@@ -14,6 +14,9 @@ Rectangle {
textFormat: Text.StyledText
focus: true
+ property int lastLineNumber: -1
+ property bool receivedMultipleLastLines
+
text: "<b>Lorem ipsum</b> dolor sit amet, consectetur adipiscing elit. Integer at ante dui. Sed eu egestas est.
<br/><p><i>Maecenas nec libero leo. Sed ac leo eget ipsum ultricies viverra sit amet eu orci. Praesent et tortor risus, viverra accumsan sapien. Sed faucibus eleifend lectus, sed euismod urna porta eu. Aenean ultricies lectus ut orci dictum quis convallis nisi ultrices. Nunc elit mi, iaculis a porttitor rutrum, venenatis malesuada nisi. Suspendisse turpis quam, euismod non imperdiet et, rutrum nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper tristique metus eu sodales. Integer eget risus ipsum. Quisque ut risus ut nulla tristique volutpat at sit amet nisl. Aliquam pulvinar auctor diam nec bibendum.</i><br/><p>Quisque luctus sapien id arcu volutpat pharetra. Praesent pretium imperdiet euismod. Integer fringilla rhoncus condimentum. Quisque sit amet ornare nulla. Cras sapien augue, sagittis a dictum id, suscipit et nunc. Cras vitae augue in enim elementum venenatis sed nec risus. Sed nisi quam, mollis quis auctor ac, vestibulum in neque. Vivamus eu justo risus. Suspendisse vel mollis est. Vestibulum gravida interdum mi, in molestie neque gravida in. Donec nibh odio, mattis facilisis vulputate et, scelerisque ut felis. Sed ornare eros nec odio aliquam eu varius augue adipiscing. Vivamus sit amet massa dapibus sapien pulvinar consectetur a sit amet felis. Cras non mi id libero dictum iaculis id dignissim eros. Praesent eget enim dui, sed bibendum neque. Ut interdum nisl id leo malesuada ornare. Pellentesque id nisl eu odio volutpat posuere et at massa. Pellentesque nec lorem justo. Integer sem urna, pharetra sed sagittis vitae, condimentum ac felis. Ut vitae sapien ac tortor adipiscing pharetra. Cras tristique urna tempus ante volutpat eleifend non eu ligula. Mauris sodales nisl et lorem tristique sodales. Mauris arcu orci, vehicula semper cursus ac, dapibus ut mi."
@@ -30,6 +33,12 @@ Rectangle {
line.x = line.width * 2 + 60
line.height = 20
}
+
+ // Save last line number, it is important to do this after setting the width
+ if (line.isLast) {
+ receivedMultipleLastLines = (lastLineNumber !== -1) && (lastLineNumber !== line.number)
+ lastLineNumber = line.number
+ }
}
}
}
diff --git a/tests/auto/quick/qquicktext/data/lineLayoutImplicitWidth.qml b/tests/auto/quick/qquicktext/data/lineLayoutImplicitWidth.qml
new file mode 100644
index 0000000000..de5ca616b8
--- /dev/null
+++ b/tests/auto/quick/qquicktext/data/lineLayoutImplicitWidth.qml
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Jolla Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+ id: main
+ width: 800; height: 600
+
+ property real off: 0
+
+ Text {
+ id: myText
+ objectName: "myText"
+ wrapMode: Text.WordWrap
+ font.pixelSize: 14
+ textFormat: Text.PlainText
+ focus: true
+ anchors.fill: parent
+
+ // The autotest will retrieve these so that it can verify them
+ property var lineImplicitWidths: []
+
+ text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam quis ante tristique, fermentum magna at, varius lacus. Donec elementum orci sit amet ligula efficitur, eget sodales orci porttitor. Etiam laoreet tellus quis nisi mollis lacinia. Cras vitae nisl sed nunc semper blandit. Duis egestas commodo lacus non congue. Fusce quis rhoncus urna. And magna arcu, sodales vitae nunc vel, rutrum hendrerit magna. Nullam imperdiet porttitor sem at euismod. Morbi faucibus libero sit amet vestibulum aliquam. Duis consectetur lacinia malesuada. Sed quis ante dui. Name dignissim faucibus felis. Quisque dapibus aliquam ante, eu cursus elit dictum in. Mauris placerat efficitur rutrum."
+
+ onLineLaidOut: {
+ var n = line.number
+
+ // Save information about the line so the autotest can retrieve it
+ lineImplicitWidths[n] = line.implicitWidth
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
index e62db81d27..06ce730091 100644
--- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
@@ -30,6 +30,7 @@
#include <QTextDocument>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qjsvalue.h>
#include <QtQuick/private/qquicktext_p.h>
#include <QtQuick/private/qquickmousearea_p.h>
#include <QtQuickTest/QtQuickTest>
@@ -119,6 +120,7 @@ private slots:
void lineLaidOut();
void lineLaidOutRelayout();
void lineLaidOutHAlign();
+ void lineLaidOutImplicitWidth();
void imgTagsBaseUrl_data();
void imgTagsBaseUrl();
@@ -2871,6 +2873,13 @@ void tst_qquicktext::lineLaidOut()
QCOMPARE(r.height(), qreal(20));
}
}
+
+ // Ensure that isLast was correctly emitted
+ int lastLineNumber = myText->property("lastLineNumber").toInt();
+ QCOMPARE(lastLineNumber, myText->lineCount() - 1);
+ // Ensure that only one line was considered last (after changing its width)
+ bool receivedMultipleLastLines = myText->property("receivedMultipleLastLines").toBool();
+ QVERIFY(!receivedMultipleLastLines);
}
void tst_qquicktext::lineLaidOutRelayout()
@@ -2975,6 +2984,53 @@ void tst_qquicktext::imgTagsBaseUrl_data()
<< 181.;
}
+void tst_qquicktext::lineLaidOutImplicitWidth()
+{
+ QScopedPointer<QQuickView> window(createView(testFile("lineLayoutImplicitWidth.qml")));
+
+ QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText");
+ QVERIFY(myText != nullptr);
+
+ QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(myText);
+ QVERIFY(textPrivate != nullptr);
+
+ // Retrieve the saved implicitWidth values of each rendered line
+ QVariant widthsProperty = myText->property("lineImplicitWidths");
+ QVERIFY(!widthsProperty.isNull());
+ QVERIFY(widthsProperty.isValid());
+ QVERIFY(widthsProperty.canConvert<QJSValue>());
+ QJSValue widthsValue = widthsProperty.value<QJSValue>();
+ QVERIFY(widthsValue.isArray());
+ int lineCount = widthsValue.property("length").toInt();
+ QVERIFY(lineCount > 0);
+
+ // Create the same text layout by hand
+ // Note that this approach needs additional processing for styled text,
+ // so we only use it for plain text here.
+ QTextLayout layout;
+ layout.setCacheEnabled(true);
+ layout.setText(myText->text());
+ layout.setTextOption(textPrivate->layout.textOption());
+ layout.setFont(myText->font());
+ layout.beginLayout();
+ for (QTextLine line = layout.createLine(); line.isValid(); line = layout.createLine()) {
+ line.setLineWidth(myText->width());
+ }
+ layout.endLayout();
+
+ // Line count of the just created layout should match the rendered text
+ QCOMPARE(lineCount, layout.lineCount());
+
+ // Go through each line and verify that the values emitted by lineLaidOut are correct
+ for (int i = 0; i < layout.lineCount(); ++i) {
+ qreal implicitWidth = widthsValue.property(i).toNumber();
+ QVERIFY(implicitWidth > 0);
+
+ QTextLine line = layout.lineAt(i);
+ QCOMPARE(implicitWidth, line.naturalTextWidth());
+ }
+}
+
static QUrl substituteTestServerUrl(const QUrl &serverUrl, const QUrl &testUrl)
{
QUrl result = testUrl;
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index facd63027e..d03441e052 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -131,8 +131,10 @@ private slots:
void mouseSelectionMode_accessors();
void selectByMouse();
void selectByKeyboard();
+#if QT_CONFIG(shortcut)
void keyboardSelection_data();
void keyboardSelection();
+#endif
void renderType();
void inputMethodHints();
@@ -190,16 +192,19 @@ private slots:
void insert();
void remove_data();
void remove();
-
+#if QT_CONFIG(shortcut)
void keySequence_data();
void keySequence();
+#endif
void undo_data();
void undo();
void redo_data();
void redo();
+#if QT_CONFIG(shortcut)
void undo_keypressevents_data();
void undo_keypressevents();
+#endif
void clear();
void baseUrl();
@@ -217,7 +222,9 @@ private slots:
private:
void simulateKeys(QWindow *window, const QList<Key> &keys);
+#if QT_CONFIG(shortcut)
void simulateKeys(QWindow *window, const QKeySequence &sequence);
+#endif
void simulateKey(QWindow *, int key, Qt::KeyboardModifiers modifiers = nullptr);
@@ -260,6 +267,8 @@ void tst_qquicktextedit::simulateKeys(QWindow *window, const QList<Key> &keys)
}
}
+#if QT_CONFIG(shortcut)
+
void tst_qquicktextedit::simulateKeys(QWindow *window, const QKeySequence &sequence)
{
for (int i = 0; i < sequence.count(); ++i) {
@@ -277,6 +286,8 @@ QList<Key> &operator <<(QList<Key> &keys, const QKeySequence &sequence)
return keys;
}
+#endif // QT_CONFIG(shortcut)
+
template <int N> QList<Key> &operator <<(QList<Key> &keys, const char (&characters)[N])
{
for (int i = 0; i < N - 1; ++i) {
@@ -2307,6 +2318,8 @@ void tst_qquicktextedit::selectByKeyboard()
QCOMPARE(spy.at(2).at(0).toBool(), false);
}
+#if QT_CONFIG(shortcut)
+
Q_DECLARE_METATYPE(QKeySequence::StandardKey)
void tst_qquicktextedit::keyboardSelection_data()
@@ -2391,6 +2404,8 @@ void tst_qquicktextedit::keyboardSelection()
QCOMPARE(edit->selectedText(), selectedText);
}
+#endif // QT_CONFIG(shortcut)
+
void tst_qquicktextedit::renderType()
{
QQmlComponent component(&engine);
@@ -4820,6 +4835,7 @@ void tst_qquicktextedit::remove()
QVERIFY(cursorPositionSpy.count() > 0);
}
+#if QT_CONFIG(shortcut)
void tst_qquicktextedit::keySequence_data()
{
@@ -4984,6 +5000,8 @@ void tst_qquicktextedit::keySequence()
QCOMPARE(textEdit->selectedText(), selectedText);
}
+#endif // QT_CONFIG(shortcut)
+
#define NORMAL 0
#define REPLACE_UNTIL_END 1
@@ -5257,6 +5275,8 @@ void tst_qquicktextedit::redo()
QCOMPARE(spy.count(), 2);
}
+#if QT_CONFIG(shortcut)
+
void tst_qquicktextedit::undo_keypressevents_data()
{
QTest::addColumn<KeyList>("keys");
@@ -5450,6 +5470,8 @@ void tst_qquicktextedit::undo_keypressevents()
QVERIFY(textEdit->text().isEmpty());
}
+#endif // QT_CONFIG(shortcut)
+
void tst_qquicktextedit::clear()
{
QString componentStr = "import QtQuick 2.0\nTextEdit { focus: true }";
diff --git a/tests/auto/quick/qquicktextinput/data/qtbug77841.qml b/tests/auto/quick/qquicktextinput/data/qtbug77841.qml
new file mode 100644
index 0000000000..ebb43a8f82
--- /dev/null
+++ b/tests/auto/quick/qquicktextinput/data/qtbug77841.qml
@@ -0,0 +1,22 @@
+import QtQuick 2.12
+
+Item {
+ id: root
+ width: 600
+ height: 300
+
+ TextInput {
+ id: qwe
+ objectName: "qwe"
+ width: 500
+ height: 100
+ font.pixelSize: 50
+ text: "123456"
+ focus: true
+ }
+
+ Component.onCompleted: {
+ qwe.insert(0, "***")
+ qwe.remove(0, 3)
+ }
+}
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
index ed2d535fda..1d12121a6f 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -146,7 +146,7 @@ private slots:
void cursorRectangle();
void navigation();
void navigation_RTL();
-#if QT_CONFIG(clipboard)
+#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void copyAndPaste();
void copyAndPasteKeySequence();
void canPasteEmpty();
@@ -181,15 +181,19 @@ private slots:
void remove_data();
void remove();
+#if QT_CONFIG(shortcut)
void keySequence_data();
void keySequence();
+#endif
void undo_data();
void undo();
void redo_data();
void redo();
+#if QT_CONFIG(shortcut)
void undo_keypressevents_data();
void undo_keypressevents();
+#endif
void clear();
void backspaceSurrogatePairs();
@@ -230,12 +234,15 @@ private slots:
void padding();
void QTBUG_51115_readOnlyResetsSelection();
+ void QTBUG_77814_InsertRemoveNoSelection();
private:
void simulateKey(QWindow *, int key);
void simulateKeys(QWindow *window, const QList<Key> &keys);
+#if QT_CONFIG(shortcut)
void simulateKeys(QWindow *window, const QKeySequence &sequence);
+#endif
QQmlEngine engine;
QStringList standard;
@@ -263,6 +270,8 @@ void tst_qquicktextinput::simulateKeys(QWindow *window, const QList<Key> &keys)
}
}
+#if QT_CONFIG(shortcut)
+
void tst_qquicktextinput::simulateKeys(QWindow *window, const QKeySequence &sequence)
{
for (int i = 0; i < sequence.count(); ++i) {
@@ -280,6 +289,8 @@ QList<Key> &operator <<(QList<Key> &keys, const QKeySequence &sequence)
return keys;
}
+#endif // QT_CONFIG(shortcut)
+
template <int N> QList<Key> &operator <<(QList<Key> &keys, const char (&characters)[N])
{
for (int i = 0; i < N - 1; ++i) {
@@ -2585,7 +2596,7 @@ void tst_qquicktextinput::navigation_RTL()
QVERIFY(input->hasActiveFocus());
}
-#if QT_CONFIG(clipboard)
+#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void tst_qquicktextinput::copyAndPaste()
{
if (!PlatformQuirks::isClipboardAvailable())
@@ -2683,7 +2694,7 @@ void tst_qquicktextinput::copyAndPaste()
}
#endif
-#if QT_CONFIG(clipboard)
+#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void tst_qquicktextinput::copyAndPasteKeySequence()
{
if (!PlatformQuirks::isClipboardAvailable())
@@ -2751,7 +2762,7 @@ void tst_qquicktextinput::copyAndPasteKeySequence()
}
#endif
-#if QT_CONFIG(clipboard)
+#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void tst_qquicktextinput::canPasteEmpty()
{
QGuiApplication::clipboard()->clear();
@@ -2767,7 +2778,7 @@ void tst_qquicktextinput::canPasteEmpty()
}
#endif
-#if QT_CONFIG(clipboard)
+#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void tst_qquicktextinput::canPaste()
{
QGuiApplication::clipboard()->setText("Some text");
@@ -2783,7 +2794,7 @@ void tst_qquicktextinput::canPaste()
}
#endif
-#if QT_CONFIG(clipboard)
+#if QT_CONFIG(clipboard) && QT_CONFIG(shortcut)
void tst_qquicktextinput::middleClickPaste()
{
if (!PlatformQuirks::isClipboardAvailable())
@@ -5097,6 +5108,7 @@ void tst_qquicktextinput::remove()
QVERIFY(cursorPositionSpy.count() > 0);
}
+#if QT_CONFIG(shortcut)
void tst_qquicktextinput::keySequence_data()
{
QTest::addColumn<QString>("text");
@@ -5282,6 +5294,8 @@ void tst_qquicktextinput::keySequence()
QCOMPARE(textInput->selectedText(), selectedText);
}
+#endif // QT_CONFIG(shortcut)
+
#define NORMAL 0
#define REPLACE_UNTIL_END 1
@@ -5555,6 +5569,8 @@ void tst_qquicktextinput::redo()
QCOMPARE(spy.count(), 2);
}
+#if QT_CONFIG(shortcut)
+
void tst_qquicktextinput::undo_keypressevents_data()
{
QTest::addColumn<KeyList>("keys");
@@ -5859,6 +5875,8 @@ void tst_qquicktextinput::undo_keypressevents()
QVERIFY(textInput->text().isEmpty());
}
+#endif // QT_CONFIG(shortcut)
+
void tst_qquicktextinput::clear()
{
QString componentStr = "import QtQuick 2.0\nTextInput { focus: true }";
@@ -7003,6 +7021,18 @@ void tst_qquicktextinput::QTBUG_51115_readOnlyResetsSelection()
QCOMPARE(obj->selectedText(), QString());
}
+void tst_qquicktextinput::QTBUG_77814_InsertRemoveNoSelection()
+{
+ QQuickView view;
+ view.setSource(testFileUrl("qtbug77841.qml"));
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QQuickTextInput *textInput = view.rootObject()->findChild<QQuickTextInput*>("qwe");
+ QVERIFY(textInput);
+
+ QCOMPARE(textInput->selectedText(), QString());
+}
+
QTEST_MAIN(tst_qquicktextinput)
#include "tst_qquicktextinput.moc"
diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro
index b6ffdc0f7e..9ab7119903 100644
--- a/tests/auto/quick/quick.pro
+++ b/tests/auto/quick/quick.pro
@@ -96,6 +96,8 @@ boot2qt: QUICKTESTS -= qquickgridview qquicklistview qquicktableview qquickposit
!qtConfig(accessibility):QUICKTESTS -= qquickaccessible
+!qtConfig(shortcut):QUICKTESTS -= qquickshortcut
+
qtConfig(private_tests) {
SUBDIRS += $$PRIVATETESTS
SUBDIRS += $$QUICKTESTS
diff --git a/tools/qmlcachegen/qmlcachegen.pro b/tools/qmlcachegen/qmlcachegen.pro
index bee0b9a37e..ec65cdb5e6 100644
--- a/tools/qmlcachegen/qmlcachegen.pro
+++ b/tools/qmlcachegen/qmlcachegen.pro
@@ -5,8 +5,10 @@ DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
SOURCES = qmlcachegen.cpp \
resourcefilter.cpp \
- generateloader.cpp \
- resourcefilemapper.cpp
+ generateloader.cpp
+
+include(../shared/shared.pri)
+
TARGET = qmlcachegen
build_integration.files = qmlcache.prf qtquickcompiler.prf
@@ -38,5 +40,3 @@ QMAKE_TARGET_DESCRIPTION = QML Cache Generator
load(qt_tool)
-HEADERS += \
- resourcefilemapper.h
diff --git a/tools/qmlimportscanner/main.cpp b/tools/qmlimportscanner/main.cpp
index 6d48f6203d..c37910bdaf 100644
--- a/tools/qmlimportscanner/main.cpp
+++ b/tools/qmlimportscanner/main.cpp
@@ -49,6 +49,8 @@
#include <QtCore/QJsonDocument>
#include <QtCore/QLibraryInfo>
+#include <resourcefilemapper.h>
+
#include <iostream>
#include <algorithm>
@@ -80,7 +82,8 @@ void printUsage(const QString &appNameIn)
#endif
std::wcerr
<< "Usage: " << appName << " -rootPath path/to/app/qml/directory -importPath path/to/qt/qml/directory\n"
- " " << appName << " -qmlFiles file1 file2 -importPath path/to/qt/qml/directory\n\n"
+ " " << appName << " -qmlFiles file1 file2 -importPath path/to/qt/qml/directory\n"
+ " " << appName << " -qrcFiles file1.qrc file2.qrc -importPath path/to/qt/qml/directory\n\n"
"Example: " << appName << " -rootPath . -importPath "
<< QDir::toNativeSeparators(qmlPath).toStdWString()
<< '\n';
@@ -542,6 +545,7 @@ int main(int argc, char *argv[])
QStringList qmlRootPaths;
QStringList scanFiles;
QStringList qmlImportPaths;
+ QStringList qrcFiles;
bool generateCmakeContent = false;
int i = 1;
@@ -569,6 +573,8 @@ int main(int argc, char *argv[])
argReceiver = &qmlImportPaths;
} else if (arg == QLatin1String("-cmake-output")) {
generateCmakeContent = true;
+ } else if (arg == QLatin1String("-qrcFiles")) {
+ argReceiver = &qrcFiles;
} else {
std::cerr << qPrintable(appName) << ": Invalid argument: \""
<< qPrintable(arg) << "\"\n";
@@ -590,6 +596,9 @@ int main(int argc, char *argv[])
}
}
+ if (!qrcFiles.isEmpty())
+ scanFiles << ResourceFileMapper(qrcFiles).qmlCompilerFiles(ResourceFileMapper::FileOutput::AbsoluteFilePath);
+
g_qmlImportPaths = qmlImportPaths;
// Find the imports!
diff --git a/tools/qmlimportscanner/qmlimportscanner.pro b/tools/qmlimportscanner/qmlimportscanner.pro
index a29b582274..d69f1a3b0b 100644
--- a/tools/qmlimportscanner/qmlimportscanner.pro
+++ b/tools/qmlimportscanner/qmlimportscanner.pro
@@ -4,6 +4,7 @@ QT = core qmldevtools-private
DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII
SOURCES += main.cpp
+include(../shared/shared.pri)
load(cmake_functions)
diff --git a/tools/qmllint/findunqualified.cpp b/tools/qmllint/findunqualified.cpp
index ee2a0c38c1..d72f02b94a 100644
--- a/tools/qmllint/findunqualified.cpp
+++ b/tools/qmllint/findunqualified.cpp
@@ -530,7 +530,7 @@ void FindUnqualifiedIDVisitor::endVisit(QQmlJS::AST::Catch *)
bool FindUnqualifiedIDVisitor::visit(QQmlJS::AST::WithStatement *withStatement)
{
m_colorOut.write(QString::asprintf("Warning: "), Warning);
- m_colorOut.write(QString::asprintf("%d:%d: with statements are strongly discouraged in QML and might cause false positives when analying unqalified identifiers\n", withStatement->firstSourceLocation().startLine, withStatement->firstSourceLocation().startColumn), Normal);
+ m_colorOut.write(QString::asprintf("%d:%d: with statements are strongly discouraged in QML and might cause false positives when analysing unqalified identifiers\n", withStatement->firstSourceLocation().startLine, withStatement->firstSourceLocation().startColumn), Normal);
enterEnvironment(ScopeType::JSLexicalScope, "with");
return true;
}
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp
index 56f72dd020..232b31934e 100644
--- a/tools/qmllint/main.cpp
+++ b/tools/qmllint/main.cpp
@@ -62,11 +62,13 @@ static bool lint_file(const QString &filename, const bool silent, const bool war
QQmlJS::Lexer lexer(&engine);
QFileInfo info(filename);
- bool isJavaScript = info.suffix().toLower() == QLatin1String("js");
+ const QString lowerSuffix = info.suffix().toLower();
+ const bool isJavaScript = (lowerSuffix == QLatin1String("js") || lowerSuffix == QLatin1String("mjs"));
+ const bool isESModule = lowerSuffix == QLatin1String("mjs");
lexer.setCode(code, /*line = */ 1, /*qmlMode=*/ !isJavaScript);
QQmlJS::Parser parser(&engine);
- bool success = isJavaScript ? parser.parseProgram() : parser.parse();
+ bool success = isJavaScript ? (isESModule ? parser.parseModule() : parser.parseProgram()) : parser.parse();
if (!success && !silent) {
const auto diagnosticMessages = parser.diagnosticMessages();
diff --git a/tools/qmlmin/main.cpp b/tools/qmlmin/main.cpp
index 26833d2a08..3c9b3c7251 100644
--- a/tools/qmlmin/main.cpp
+++ b/tools/qmlmin/main.cpp
@@ -638,6 +638,8 @@ int runQmlmin(int argc, char *argv[])
return 0;
}
+ std::cerr << "qmlmin: This tool is deprecated and will be removed in Qt 6. It is not needed anymore due to QtQml's built-in caching." << std::endl;
+
QFile file(fileName);
if (! file.open(QFile::ReadOnly)) {
std::cerr << "qmlmin: '" << qPrintable(fileName) << "' no such file or directory" << std::endl;
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp
index 5e999c557a..1556718471 100644
--- a/tools/qmlplugindump/main.cpp
+++ b/tools/qmlplugindump/main.cpp
@@ -380,23 +380,21 @@ public:
relocatableModuleUri = uri;
}
- const QString getExportString(QString qmlTyName, int majorVersion, int minorVersion)
+ QString getExportString(const QQmlType &type, const QmlVersionInfo &versionInfo)
{
- if (qmlTyName.startsWith(relocatableModuleUri + QLatin1Char('/'))) {
- qmlTyName.remove(0, relocatableModuleUri.size() + 1);
- }
- if (qmlTyName.startsWith("./")) {
- qmlTyName.remove(0, 2);
- }
- if (qmlTyName.startsWith(QLatin1Char('/'))) {
- qmlTyName.remove(0, 1);
- }
- const QString exportString = enquote(
- QString("%1 %2.%3").arg(
- qmlTyName,
- QString::number(majorVersion),
- QString::number(minorVersion)));
- return exportString;
+ const QString module = type.module().isEmpty() ? versionInfo.pluginImportUri
+ : type.module();
+ const int majorVersion = type.majorVersion() >= 0 ? type.majorVersion()
+ : versionInfo.majorVersion;
+ const int minorVersion = type.minorVersion() >= 0 ? type.minorVersion()
+ : versionInfo.minorVersion;
+
+ const QString versionedElement = type.elementName()
+ + QString::fromLatin1(" %1.%2").arg(majorVersion).arg(minorVersion);
+
+ return enquote((module == relocatableModuleUri)
+ ? versionedElement
+ : module + QLatin1Char('/') + versionedElement);
}
void writeMetaContent(const QMetaObject *meta, KnownAttributes *knownAttributes = nullptr)
@@ -441,8 +439,9 @@ public:
}
}
- QString getPrototypeNameForCompositeType(const QMetaObject *metaObject, QSet<QByteArray> &defaultReachableNames,
- QList<const QMetaObject *> *objectsToMerge, const QmlVersionInfo &versionInfo)
+ QString getPrototypeNameForCompositeType(
+ const QMetaObject *metaObject, QList<const QMetaObject *> *objectsToMerge,
+ const QmlVersionInfo &versionInfo)
{
auto ty = QQmlMetaType::qmlType(metaObject);
QString prototypeName;
@@ -454,24 +453,28 @@ public:
&& !objectsToMerge->contains(metaObject))
objectsToMerge->append(metaObject);
const QMetaObject *superMetaObject = metaObject->superClass();
- if (!superMetaObject)
+ if (!superMetaObject) {
prototypeName = "QObject";
- else
+ } else {
+ QQmlType superType = QQmlMetaType::qmlType(superMetaObject);
+ if (superType.isValid() && !superType.isComposite())
+ return convertToId(superMetaObject->className());
prototypeName = getPrototypeNameForCompositeType(
- superMetaObject, defaultReachableNames, objectsToMerge, versionInfo);
+ superMetaObject, objectsToMerge, versionInfo);
+ }
} else {
prototypeName = convertToId(metaObject->className());
}
return prototypeName;
}
- void dumpComposite(QQmlEngine *engine, const QList<QQmlType> &compositeType, QSet<QByteArray> &defaultReachableNames, const QmlVersionInfo &versionInfo)
+ void dumpComposite(QQmlEngine *engine, const QList<QQmlType> &compositeType, const QmlVersionInfo &versionInfo)
{
for (const QQmlType &type : compositeType)
- dumpCompositeItem(engine, type, defaultReachableNames, versionInfo);
+ dumpCompositeItem(engine, type, versionInfo);
}
- void dumpCompositeItem(QQmlEngine *engine, const QQmlType &compositeType, QSet<QByteArray> &defaultReachableNames, const QmlVersionInfo &versionInfo)
+ void dumpCompositeItem(QQmlEngine *engine, const QQmlType &compositeType, const QmlVersionInfo &versionInfo)
{
QQmlComponent e(engine, compositeType.sourceUrl());
if (!e.isReady()) {
@@ -492,13 +495,17 @@ public:
QList<const QMetaObject *> objectsToMerge;
KnownAttributes knownAttributes;
// Get C++ base class name for the composite type
- QString prototypeName = getPrototypeNameForCompositeType(mainMeta, defaultReachableNames,
- &objectsToMerge, versionInfo);
+ QString prototypeName = getPrototypeNameForCompositeType(mainMeta, &objectsToMerge,
+ versionInfo);
qml->writeScriptBinding(QLatin1String("prototype"), enquote(prototypeName));
QString qmlTyName = compositeType.qmlTypeName();
- const QString exportString = getExportString(qmlTyName, compositeType.majorVersion(), compositeType.minorVersion());
+ const QString exportString = getExportString(compositeType, versionInfo);
+
+ // TODO: why don't we simply output the compositeType.elementName() here?
+ // That would make more sense, but it would change the format quite a bit.
qml->writeScriptBinding(QLatin1String("name"), exportString);
+
qml->writeArrayBinding(QLatin1String("exports"), QStringList() << exportString);
qml->writeArrayBinding(QLatin1String("exportMetaObjectRevisions"), QStringList() << QString::number(compositeType.minorVersion()));
qml->writeBooleanBinding(QLatin1String("isComposite"), true);
@@ -565,7 +572,7 @@ public:
if (attachedType != meta)
attachedTypeId = convertToId(attachedType);
}
- const QString exportString = getExportString(type.qmlTypeName(), type.majorVersion(), type.minorVersion());
+ const QString exportString = getExportString(type, { QString(), -1, -1, false });
int metaObjectRevision = type.metaObjectRevision();
if (extendedObject) {
// emulate custom metaobjectrevision out of import
@@ -1239,9 +1246,6 @@ int main(int argc, char *argv[])
QSet<const QMetaObject *> uncreatableMetas;
QSet<const QMetaObject *> singletonMetas;
- // QQuickKeyEvent, QQuickPinchEvent, QQuickDropEvent are not exported
- QSet<QByteArray> defaultReachableNames;
-
// this will hold the meta objects we want to dump information of
QSet<const QMetaObject *> metas;
@@ -1370,7 +1374,7 @@ int main(int argc, char *argv[])
QMap<QString, QList<QQmlType>>::const_iterator iter = compositeTypes.constBegin();
for (; iter != compositeTypes.constEnd(); ++iter)
- dumper.dumpComposite(&engine, iter.value(), defaultReachableNames, info);
+ dumper.dumpComposite(&engine, iter.value(), info);
// define QEasingCurve as an extension of QQmlEasingValueType, this way
// properties using the QEasingCurve type get useful type information.
diff --git a/tools/qmlplugindump/qmlplugindump.pro b/tools/qmlplugindump/qmlplugindump.pro
index 62b08e9334..e374ae45f4 100644
--- a/tools/qmlplugindump/qmlplugindump.pro
+++ b/tools/qmlplugindump/qmlplugindump.pro
@@ -5,14 +5,16 @@ CONFIG += no_import_scan
QTPLUGIN.platforms = qminimal
+INCLUDEPATH += ../shared
+
SOURCES += \
main.cpp \
- qmlstreamwriter.cpp \
- qmltypereader.cpp
+ qmltypereader.cpp \
+ ../shared/qmlstreamwriter.cpp
HEADERS += \
- qmlstreamwriter.h \
- qmltypereader.h
+ qmltypereader.h \
+ ../shared/qmlstreamwriter.h
macx {
# Prevent qmlplugindump from popping up in the dock when launched.
diff --git a/tools/qmlplugindump/qmlstreamwriter.cpp b/tools/shared/qmlstreamwriter.cpp
index b0fbc4e443..b0fbc4e443 100644
--- a/tools/qmlplugindump/qmlstreamwriter.cpp
+++ b/tools/shared/qmlstreamwriter.cpp
diff --git a/tools/qmlplugindump/qmlstreamwriter.h b/tools/shared/qmlstreamwriter.h
index cb642159ea..cb642159ea 100644
--- a/tools/qmlplugindump/qmlstreamwriter.h
+++ b/tools/shared/qmlstreamwriter.h
diff --git a/tools/qmlcachegen/resourcefilemapper.cpp b/tools/shared/resourcefilemapper.cpp
index 244874717f..b9cf463575 100644
--- a/tools/qmlcachegen/resourcefilemapper.cpp
+++ b/tools/shared/resourcefilemapper.cpp
@@ -58,7 +58,7 @@ QStringList ResourceFileMapper::resourcePaths(const QString &fileName)
return resourcePaths;
}
-QStringList ResourceFileMapper::qmlCompilerFiles() const
+QStringList ResourceFileMapper::qmlCompilerFiles(FileOutput fo) const
{
QStringList files;
for (auto it = qrcPathToFileSystemPath.constBegin(), end = qrcPathToFileSystemPath.constEnd();
@@ -67,7 +67,10 @@ QStringList ResourceFileMapper::qmlCompilerFiles() const
const QString suffix = QFileInfo(qrcPath).suffix();
if (suffix != QStringLiteral("qml") && suffix != QStringLiteral("js") && suffix != QStringLiteral("mjs"))
continue;
- files << qrcPath;
+ if (fo == FileOutput::AbsoluteFilePath)
+ files << it.value();
+ else
+ files << qrcPath;
}
return files;
}
diff --git a/tools/qmlcachegen/resourcefilemapper.h b/tools/shared/resourcefilemapper.h
index 2e0ab45171..ed3e486149 100644
--- a/tools/qmlcachegen/resourcefilemapper.h
+++ b/tools/shared/resourcefilemapper.h
@@ -34,12 +34,16 @@
struct ResourceFileMapper
{
+ enum class FileOutput {
+ RelativeFilePath,
+ AbsoluteFilePath
+ };
ResourceFileMapper(const QStringList &resourceFiles);
bool isEmpty() const;
QStringList resourcePaths(const QString &fileName);
- QStringList qmlCompilerFiles() const;
+ QStringList qmlCompilerFiles(FileOutput fo = FileOutput::RelativeFilePath) const;
private:
void populateFromQrcFile(QFile &file);
diff --git a/tools/shared/shared.pri b/tools/shared/shared.pri
new file mode 100644
index 0000000000..1438c3b3da
--- /dev/null
+++ b/tools/shared/shared.pri
@@ -0,0 +1,9 @@
+INCLUDEPATH += $$PWD
+
+SOURCES += \
+ $$PWD/resourcefilemapper.cpp \
+ $$PWD/qmlstreamwriter.cpp
+
+HEADERS += \
+ $$PWD/resourcefilemapper.h \
+ $$PWD/qmlstreamwriter.h