aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/rename-qtdeclarative-symbols.sh4
-rw-r--r--doc/src/qml/basictypes.qdoc17
-rw-r--r--doc/src/qml/javascriptblocks.qdoc13
-rw-r--r--doc/src/qml/propertybinding.qdoc19
-rw-r--r--doc/src/snippets/qml/DynamicText.qml52
-rw-r--r--doc/src/snippets/qml/qtBinding.1.qml55
-rw-r--r--doc/src/snippets/qml/qtBinding.2.qml58
-rw-r--r--doc/src/snippets/qml/qtBinding.3.qml63
-rw-r--r--doc/src/snippets/qml/qtBinding.4.qml54
-rw-r--r--src/qml/debugger/qqmlenginedebugservice.cpp6
-rw-r--r--src/qml/qml/ftw/qfastmetabuilder.cpp149
-rw-r--r--src/qml/qml/ftw/qfastmetabuilder_p.h74
-rw-r--r--src/qml/qml/ftw/qqmlpool_p.h1
-rw-r--r--src/qml/qml/qml.pri2
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp8
-rw-r--r--src/qml/qml/qqmlcompiler.cpp202
-rw-r--r--src/qml/qml/qqmlengine.cpp73
-rw-r--r--src/qml/qml/qqmlengine.h11
-rw-r--r--src/qml/qml/qqmlengine_p.h7
-rw-r--r--src/qml/qml/qqmlerror.h2
-rw-r--r--src/qml/qml/qqmlmetatype.cpp9
-rw-r--r--src/qml/qml/qqmlproperty.cpp31
-rw-r--r--src/qml/qml/qqmlproperty.h2
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp79
-rw-r--r--src/qml/qml/qqmlscript.cpp61
-rw-r--r--src/qml/qml/qqmlscript_p.h20
-rw-r--r--src/qml/qml/qqmlvme.cpp9
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp2
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions.cpp59
-rw-r--r--src/qml/qml/v8/qqmlbuiltinfunctions_p.h1
-rw-r--r--src/qml/qml/v8/qv8engine.cpp7
-rw-r--r--src/qml/qml/v8/qv8engine_p.h10
-rw-r--r--src/qml/qml/v8/qv8qobjectwrapper.cpp101
-rw-r--r--src/qml/qml/v8/qv8valuetypewrapper.cpp7
-rw-r--r--src/quick/items/qquickcanvas.cpp4
-rw-r--r--src/quick/items/qquickitem.cpp11
-rw-r--r--src/quick/items/qquickitem.h1
-rw-r--r--src/quick/items/qquickrectangle.cpp5
-rw-r--r--src/quick/items/qquickrectangle_p.h1
-rw-r--r--src/quick/items/qquickshadereffect.cpp4
-rw-r--r--src/quick/particles/qquickcustomparticle.cpp4
-rw-r--r--src/quick/scenegraph/qsgcontext.cpp1
-rw-r--r--src/quick/scenegraph/qsgcontextplugin_p.h3
-rw-r--r--src/quick/util/qquickimageprovider.cpp (renamed from src/qml/qml/qqmlimageprovider.cpp)32
-rw-r--r--src/quick/util/qquickimageprovider.h (renamed from src/qml/qml/qqmlimageprovider.h)21
-rw-r--r--src/quick/util/qquickpixmapcache.cpp59
-rw-r--r--src/quick/util/qquickpixmapcache_p.h2
-rw-r--r--src/quick/util/util.pri2
-rw-r--r--sync.profile2
-rw-r--r--tests/auto/qml/qml.pro1
-rw-r--r--tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml4
-rw-r--r--tests/auto/qml/qqmlecmascript/data/functionAssignment.1.qml2
-rw-r--r--tests/auto/qml/qqmlecmascript/data/functionAssignment.2.qml14
-rw-r--r--tests/auto/qml/qqmlecmascript/data/functionAssignment.3.qml18
-rw-r--r--tests/auto/qml/qqmlecmascript/data/functionAssignment.js4
-rw-r--r--tests/auto/qml/qqmlecmascript/data/propertyVar.11.qml21
-rw-r--r--tests/auto/qml/qqmlecmascript/data/propertyVar.12.qml19
-rw-r--r--tests/auto/qml/qqmlecmascript/data/propertyVar.13.qml19
-rw-r--r--tests/auto/qml/qqmlecmascript/data/propertyVar.14.qml21
-rw-r--r--tests/auto/qml/qqmlecmascript/data/propertyVar.15.qml20
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp36
-rw-r--r--tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp52
-rw-r--r--tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp26
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.2.qml12
-rw-r--r--tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml5
-rw-r--r--tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp20
-rw-r--r--tests/auto/quick/qquickimageprovider/qquickimageprovider.pro (renamed from tests/auto/qml/qqmlimageprovider/qqmlimageprovider.pro)4
-rw-r--r--tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp (renamed from tests/auto/qml/qqmlimageprovider/tst_qqmlimageprovider.cpp)62
-rw-r--r--tests/auto/quick/qquickloader/data/initialPropertyValues.binding.qml2
-rw-r--r--tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp6
-rw-r--r--tests/auto/quick/qquickstates/tst_qquickstates.cpp2
-rw-r--r--tests/auto/quick/quick.pro1
-rw-r--r--tools/qmlplugindump/main.cpp15
73 files changed, 1220 insertions, 586 deletions
diff --git a/bin/rename-qtdeclarative-symbols.sh b/bin/rename-qtdeclarative-symbols.sh
index 96633af2d8..78df8554cc 100755
--- a/bin/rename-qtdeclarative-symbols.sh
+++ b/bin/rename-qtdeclarative-symbols.sh
@@ -154,8 +154,6 @@ QML_SYMBOLS="\
QDeclarativeGuardedContextData
QDeclarativeGuardImpl
QDeclarativeHandlingSignalProfiler
- QDeclarativeImageProvider
- QDeclarativeImageProviderPrivate
QDeclarativeImportDatabase
QDeclarativeImportedNamespace
QDeclarativeImports
@@ -319,6 +317,8 @@ QUICK_SYMBOLS="\
QDeclarativeGestureAreaParser
QDeclarativeGestureAreaPrivate
QDeclarativeGraphics
+ QDeclarativeImageProvider
+ QDeclarativeImageProviderPrivate
QDeclarativeItem
QDeclarativeItemAccessor
QDeclarativeItemChangeListener
diff --git a/doc/src/qml/basictypes.qdoc b/doc/src/qml/basictypes.qdoc
index 517bc953ea..c9998fe6e2 100644
--- a/doc/src/qml/basictypes.qdoc
+++ b/doc/src/qml/basictypes.qdoc
@@ -436,10 +436,9 @@
\brief A var type is a generic property type.
A var is a generic property type capable of storing any data type.
- It is equivalent to a regular JavaScript variable, except that you
- cannot assign a JavaScript function to such a property.
- For example, var properties can store numbers, strings, objects and
- arrays:
+ It is equivalent to a regular JavaScript variable.
+ For example, var properties can store numbers, strings, objects,
+ arrays and functions:
\qml
Item {
@@ -454,13 +453,10 @@
property var aVector3d: Qt.vector3d(100, 100, 100)
property var anArray: [1, 2, 3, "four", "five", (function() { return "six"; })]
property var anObject: { "foo": 10, "bar": 20 }
+ property var aFunction: (function() { return "one"; })
}
\endqml
- Attempting to assign a JavaScript function to a var property will result in
- a binding assignment as per other property types. You can assign a JavaScript
- array containing a single function element instead.
-
It is important to note that changes in regular properties of JavaScript
objects assigned to a var property will \b{not} trigger updates of bindings
that access them. The example below will display "The car has 4 wheels" as
@@ -481,6 +477,11 @@
}
\endqml
+ If the onCompleted handler instead had \tt{"car = new Object({wheels: 6})"}
+ then the text would be updated to say "The car has 6 wheels"., since the
+ car property itself would be changed, which causes a change notification
+ to be emitted.
+
A \c var type property can also hold an image or pixmap.
A \c var which contains a QPixmap or QImage is known as a
"scarce resource" and the declarative engine will attempt to
diff --git a/doc/src/qml/javascriptblocks.qdoc b/doc/src/qml/javascriptblocks.qdoc
index b9f1e6f0b8..a898f20049 100644
--- a/doc/src/qml/javascriptblocks.qdoc
+++ b/doc/src/qml/javascriptblocks.qdoc
@@ -72,7 +72,7 @@ Rectangle {
id: button
width: 200; height: 80; color: "lightsteelblue"
- MouseArea {
+ MouseArea {
id: mousearea
anchors.fill: parent
@@ -103,7 +103,7 @@ Rectangle {
color: mousearea.pressed ? "steelblue" : "lightsteelblue"
- MouseArea {
+ MouseArea {
id: mousearea
anchors.fill: parent
}
@@ -366,6 +366,15 @@ Likewise, the \l {Component::onDestruction} attached property is triggered on
component destruction.
+\section1 JavaScript and Property Binding
+
+Property bindings can be created in JavaScript by assigning the property the value returned
+by calling Qt.binding() where the parameter to Qt.binding() is a \c function
+that returns the required value.
+
+See \l {qml-javascript-assignment}{Property Assignment versus Property Binding} for details.
+
+
\section1 QML JavaScript Restrictions
QML executes standard JavaScript code, with the following restrictions:
diff --git a/doc/src/qml/propertybinding.qdoc b/doc/src/qml/propertybinding.qdoc
index 81ca4bbfd3..6922f54003 100644
--- a/doc/src/qml/propertybinding.qdoc
+++ b/doc/src/qml/propertybinding.qdoc
@@ -87,7 +87,7 @@ The property binding causes the width of the \c Rectangle to update whenever the
\c {parent}'s width changes.
Assigning a property value (using the equals sign "\c {=}") does not create a
-property binding.
+property binding (unless explicitly assigned, see below).
\snippet doc/src/snippets/qml/properties.qml property assignment
Instead of creating a property binding, the assignment simply sets the \c Rectangle
@@ -100,9 +100,9 @@ and if any code explicitly re-sets this value, the property binding is removed.
\section1 Binding to JavaScript Functions
The \c{property : value} syntax for property binding is QML-specific and cannot
-be used in JavaScript. Instead, to bind a property from JavaScript, assign a \c
-function to the property that returns the required value. The following code
-correctly creates
+be used in JavaScript. Instead, to bind a property from JavaScript, assign the
+result returned by the \c{Qt.binding()} function to the property. This will cause
+a binding assignment on the specified property. The following code correctly creates
the binding in JavaScript rather than QML:
\qml
@@ -110,7 +110,7 @@ Item {
width: 100
Component.onCompleted: {
- height = (function() { return width * 2 })
+ height = Qt.binding(function() { return width * 2 })
}
}
\endqml
@@ -124,10 +124,8 @@ binding.
For example, the \c Component.onCompleted handler below is defined within the
scope of the \l Item, and references to \c width within this scope would refer
to the \l Item's width, rather than that of the \l Rectangle. To bind the \l
-Rectangle's \c height to its own \c width, the function needs to explicitly
-refer to \c this.width rather than just \c width. Otherwise, the height of the
-\l Rectangle would be bound to the width of the \l Item and not the \l
-Rectangle.
+Rectangle's \c height to its own \c width, the function passed to Qt.binding()
+needs to explicitly refer to \c this.width rather than just \c width.
\qml
Item {
@@ -141,7 +139,8 @@ Item {
}
Component.onCompleted: {
- rect.height = (function() { return this.width * 2 })
+ rect.height = Qt.binding(function() { return this.width * 2 })
+ console.log("rect.height = " + rect.height) // prints 200
}
}
\endqml
diff --git a/doc/src/snippets/qml/DynamicText.qml b/doc/src/snippets/qml/DynamicText.qml
new file mode 100644
index 0000000000..9711702037
--- /dev/null
+++ b/doc/src/snippets/qml/DynamicText.qml
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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$
+**
+****************************************************************************/
+
+//![0]
+import QtQuick 2.0
+
+Text {
+ id: textElement
+ width: 200
+ height: 200
+ text: "Default text"
+ property string dynamicText: "Dynamic text"
+ onTextChanged: console.log(text)
+}
+//![0]
diff --git a/doc/src/snippets/qml/qtBinding.1.qml b/doc/src/snippets/qml/qtBinding.1.qml
new file mode 100644
index 0000000000..acec88a47f
--- /dev/null
+++ b/doc/src/snippets/qml/qtBinding.1.qml
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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
+
+//![0]
+Item {
+ property bool someCondition: true
+ property int edgePosition
+
+ Component.onCompleted: {
+ if (someCondition == true) {
+ // bind to the result of the binding expression passed to Qt.binding()
+ edgePosition = Qt.binding(function() { return x + width })
+ }
+ }
+}
+//![0]
diff --git a/doc/src/snippets/qml/qtBinding.2.qml b/doc/src/snippets/qml/qtBinding.2.qml
new file mode 100644
index 0000000000..9b78bc395a
--- /dev/null
+++ b/doc/src/snippets/qml/qtBinding.2.qml
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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
+
+//![0]
+Item {
+ id: root
+ property string dynamicText: "Root text"
+
+ Component.onCompleted: {
+ var c = Qt.createComponent("DynamicText.qml")
+
+ var obj1 = c.createObject(root, { 'text': Qt.binding(function() { return dynamicText + ' extra text' }) })
+ root.dynamicText = "Modified root text"
+
+ var obj2 = c.createObject(root, { 'text': Qt.binding(function() { return this.dynamicText + ' extra text' }) })
+ obj2.dynamicText = "Modified text element text"
+ }
+}
+//![0]
diff --git a/doc/src/snippets/qml/qtBinding.3.qml b/doc/src/snippets/qml/qtBinding.3.qml
new file mode 100644
index 0000000000..a27914cc15
--- /dev/null
+++ b/doc/src/snippets/qml/qtBinding.3.qml
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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
+
+//![0]
+Item {
+ id: root
+ property string dynamicText: "Root text"
+
+ Loader {
+ id: loaderOne
+ onLoaded: root.dynamicText = "Modified root text"
+ }
+
+ Loader {
+ id: loaderTwo
+ onLoaded: item.dynamicText = "Modified dynamic text"
+ }
+
+ Component.onCompleted: {
+ loaderOne.setSource("DynamicText.qml", { 'text': Qt.binding(function() { return dynamicText + ' extra text' }) })
+ loaderTwo.setSource("DynamicText.qml", { 'text': Qt.binding(function() { return this.dynamicText + ' extra text' }) })
+ }
+}
+//![0]
diff --git a/doc/src/snippets/qml/qtBinding.4.qml b/doc/src/snippets/qml/qtBinding.4.qml
new file mode 100644
index 0000000000..0155957a59
--- /dev/null
+++ b/doc/src/snippets/qml/qtBinding.4.qml
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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 Nokia Corporation and its Subsidiary(-ies) 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
+
+//![0]
+Item {
+ width: 50
+ property var storedBindings: [ Qt.binding(function() { return x + width }) ] // stored
+ property int a: Qt.binding(function() { return x + width }) // error!
+ property int b
+
+ Component.onCompleted: {
+ b = storedBindings[0] // causes binding assignment
+ }
+}
+//![0]
diff --git a/src/qml/debugger/qqmlenginedebugservice.cpp b/src/qml/debugger/qqmlenginedebugservice.cpp
index a89e94c1b8..67bec3577b 100644
--- a/src/qml/debugger/qqmlenginedebugservice.cpp
+++ b/src/qml/debugger/qqmlenginedebugservice.cpp
@@ -247,10 +247,8 @@ void QQmlEngineDebugService::buildObjectDump(QDataStream &message,
prop.value = expr->expression();
QObject *scope = expr->scopeObject();
if (scope) {
- QString sig = QString::fromLatin1(scope->metaObject()->method(signal->index()).signature());
- int lparen = sig.indexOf(QLatin1Char('('));
- if (lparen >= 0) {
- QString methodName = sig.mid(0, lparen);
+ QString methodName = QString::fromLatin1(scope->metaObject()->method(signal->index()).name());
+ if (!methodName.isEmpty()) {
prop.name = QLatin1String("on") + methodName[0].toUpper()
+ methodName.mid(1);
}
diff --git a/src/qml/qml/ftw/qfastmetabuilder.cpp b/src/qml/qml/ftw/qfastmetabuilder.cpp
index 08ea76b37e..9d956054d9 100644
--- a/src/qml/qml/ftw/qfastmetabuilder.cpp
+++ b/src/qml/qml/ftw/qfastmetabuilder.cpp
@@ -79,7 +79,8 @@ static inline const QFastMetaBuilderHeader *header(const QByteArray &data)
{ return reinterpret_cast<const QFastMetaBuilderHeader*>(data.constData()); }
QFastMetaBuilder::QFastMetaBuilder()
-: m_zeroPtr(0), m_stringData(0), m_stringDataLength(0), m_stringDataAllocated(0)
+ : m_stringData(0), m_stringCount(0), m_stringDataLength(0),
+ m_stringCountAllocated(0), m_stringCountLoaded(0)
{
}
@@ -89,7 +90,8 @@ QFastMetaBuilder::~QFastMetaBuilder()
QFastMetaBuilder::StringRef QFastMetaBuilder::init(int classNameLength,
int propertyCount, int methodCount,
- int signalCount, int classInfoCount)
+ int signalCount, int classInfoCount,
+ int paramDataSize, int *paramIndex)
{
Q_ASSERT(m_data.isEmpty());
Q_ASSERT(classNameLength > 0);
@@ -97,20 +99,29 @@ QFastMetaBuilder::StringRef QFastMetaBuilder::init(int classNameLength,
Q_ASSERT(methodCount >= 0);
Q_ASSERT(signalCount >= 0);
Q_ASSERT(classInfoCount >= 0);
+ Q_ASSERT(paramDataSize >= 0);
+ Q_ASSERT((paramIndex != 0) || (methodCount + signalCount == 0));
int fieldCount = FMBHEADER_FIELD_COUNT +
HEADER_FIELD_COUNT +
propertyCount * (PROPERTY_FIELD_COUNT + PROPERTY_NOTIFY_FIELD_COUNT) +
methodCount * (METHOD_FIELD_COUNT) +
signalCount * (METHOD_FIELD_COUNT) +
+ paramDataSize +
classInfoCount * CLASSINFO_FIELD_COUNT;
+ // Ensure stringdata alignment (void*)
+ fieldCount += fieldCount % (sizeof(void*) / sizeof(uint));
- m_data.resize(fieldCount * sizeof(uint) + classNameLength + 1);
- m_stringData = m_data.data() + m_data.size() - classNameLength - 1;
+ m_stringCount = 2; // class name and zero string
m_stringDataLength = classNameLength + 1;
- m_stringDataAllocated = classNameLength + 1;
- m_stringData[classNameLength] = 0;
- m_zeroPtr = classNameLength;
+ m_data.resize(fieldCount * sizeof(uint) + m_stringCount * sizeof(QByteArrayData) + m_stringDataLength);
+ m_stringCountAllocated = m_stringCount;
+ m_stringData = reinterpret_cast<QByteArrayData *>(m_data.data() + fieldCount * sizeof(uint));
+
+ m_zeroString._b = this;
+ m_zeroString._i = 1;
+ m_zeroString._o = classNameLength;
+ m_zeroString._l = 0;
header(m_data)->fieldCount = fieldCount;
@@ -118,7 +129,7 @@ QFastMetaBuilder::StringRef QFastMetaBuilder::init(int classNameLength,
int dataIndex = HEADER_FIELD_COUNT;
- p->revision = 6;
+ p->revision = 7;
p->className = 0;
// Class infos
@@ -135,6 +146,8 @@ QFastMetaBuilder::StringRef QFastMetaBuilder::init(int classNameLength,
if (p->methodCount) {
p->methodData = dataIndex;
dataIndex += p->methodCount * METHOD_FIELD_COUNT;
+ *paramIndex = dataIndex;
+ dataIndex += paramDataSize;
} else {
p->methodData = 0;
}
@@ -160,6 +173,7 @@ QFastMetaBuilder::StringRef QFastMetaBuilder::init(int classNameLength,
StringRef className;
className._b = this;
+ className._i = 0;
className._o = 0;
className._l = classNameLength;
return className;
@@ -169,12 +183,16 @@ QFastMetaBuilder::StringRef QFastMetaBuilder::init(int classNameLength,
QFastMetaBuilder::StringRef QFastMetaBuilder::newString(int length)
{
Q_ASSERT(length > 0);
+ Q_ASSERT_X(m_stringCountLoaded == 0, Q_FUNC_INFO,
+ "All strings must be created before string loading begins");
StringRef sr;
sr._b = this;
+ sr._i = m_stringCount;
sr._o = m_stringDataLength;
sr._l = length;
+ ++m_stringCount;
m_stringDataLength += length + 1 /* for null terminator */;
return sr;
@@ -190,47 +208,24 @@ void QFastMetaBuilder::setClassInfo(int index, const StringRef &key, const Strin
uint *ptr = fieldPointer(m_data) + p->classInfoData + index * CLASSINFO_FIELD_COUNT;
// classinfo: key, value
- ptr[0] = key.offset(); ptr[1] = value.offset();
+ ptr[0] = key.index(); ptr[1] = value.index();
}
-void QFastMetaBuilder::setProperty(int index, const StringRef &name, const StringRef &type,
- QMetaType::Type mtype, PropertyFlag flags, int notifySignal)
+void QFastMetaBuilder::setProperty(int index, const StringRef &name, int type,
+ PropertyFlag flags, int notifySignal)
{
Q_ASSERT(!m_data.isEmpty());
Q_ASSERT(!name.isEmpty());
- Q_ASSERT(!type.isEmpty());
-
- QMetaObjectPrivate *p = priv(m_data);
- Q_ASSERT(index < p->propertyCount);
-
- uint *ptr = fieldPointer(m_data) + p->propertyData + index * PROPERTY_FIELD_COUNT;
- // properties: name, type, flags
- ptr[0] = name.offset();
- ptr[1] = type.offset();
- if (notifySignal == -1) {
- ptr[2] = mtype << 24;
- ptr[2] |= flags | Scriptable | Readable;
- *(fieldPointer(m_data) + p->propertyData + p->propertyCount * PROPERTY_FIELD_COUNT + index) = 0;
- } else {
- ptr[2] = mtype << 24;
- ptr[2] |= flags | Scriptable | Readable | Notify;
- *(fieldPointer(m_data) + p->propertyData + p->propertyCount * PROPERTY_FIELD_COUNT + index) = notifySignal;
- }
-}
-
-void QFastMetaBuilder::setProperty(int index, const StringRef &name, const StringRef &type,
- QFastMetaBuilder::PropertyFlag flags, int notifySignal)
-{
- Q_ASSERT(!m_data.isEmpty());
- Q_ASSERT(!name.isEmpty() && !type.isEmpty());
+ Q_ASSERT(type != 0);
+ Q_ASSERT(QMetaType::isRegistered(type));
QMetaObjectPrivate *p = priv(m_data);
Q_ASSERT(index < p->propertyCount);
uint *ptr = fieldPointer(m_data) + p->propertyData + index * PROPERTY_FIELD_COUNT;
// properties: name, type, flags
- ptr[0] = name.offset();
- ptr[1] = type.offset();
+ ptr[0] = name.index();
+ ptr[1] = type;
if (notifySignal == -1) {
ptr[2] = flags | Scriptable | Readable;
*(fieldPointer(m_data) + p->propertyData + p->propertyCount * PROPERTY_FIELD_COUNT + index) = 0;
@@ -240,42 +235,72 @@ void QFastMetaBuilder::setProperty(int index, const StringRef &name, const Strin
}
}
-void QFastMetaBuilder::setSignal(int index, const StringRef &signature,
- const StringRef &parameterNames,
- const StringRef &type)
+void QFastMetaBuilder::setSignal(int index, const StringRef &name,
+ int paramIndex, int argc, const int *types,
+ const StringRef *parameterNames,
+ QMetaType::Type type)
{
Q_ASSERT(!m_data.isEmpty());
- Q_ASSERT(!signature.isEmpty());
+ Q_ASSERT(!name.isEmpty());
+ Q_ASSERT(QMetaType::isRegistered(type));
QMetaObjectPrivate *p = priv(m_data);
int mindex = metaObjectIndexForSignal(index);
uint *ptr = fieldPointer(m_data) + p->methodData + mindex * METHOD_FIELD_COUNT;
- // methods: signature, parameters, type, tag, flags
- ptr[0] = signature.offset();
- ptr[1] = parameterNames.isEmpty()?m_zeroPtr:parameterNames.offset();
- ptr[2] = type.isEmpty()?m_zeroPtr:type.offset();
- ptr[3] = m_zeroPtr;
+ // methods: name, arc, parameters, tag, flags
+ ptr[0] = name.index();
+ ptr[1] = argc;
+ ptr[2] = paramIndex;
+ ptr[3] = m_zeroString.index();
ptr[4] = AccessProtected | MethodSignal;
+
+ uint *paramPtr = fieldPointer(m_data) + paramIndex;
+ paramPtr[0] = type;
+ if (argc) {
+ Q_ASSERT(types != 0);
+ Q_ASSERT(parameterNames != 0);
+ for (int i = 0; i < argc; ++i) {
+ Q_ASSERT(types[i] != 0);
+ Q_ASSERT(QMetaType::isRegistered(types[i]));
+ paramPtr[1+i] = types[i];
+ paramPtr[1+argc+i] = parameterNames[i].index();
+ }
+ }
}
-void QFastMetaBuilder::setMethod(int index, const StringRef &signature,
- const StringRef &parameterNames,
- const StringRef &type)
+void QFastMetaBuilder::setMethod(int index, const StringRef &name,
+ int paramIndex, int argc, const int *types,
+ const StringRef *parameterNames,
+ QMetaType::Type type)
{
Q_ASSERT(!m_data.isEmpty());
- Q_ASSERT(!signature.isEmpty());
+ Q_ASSERT(!name.isEmpty());
+ Q_ASSERT(QMetaType::isRegistered(type));
QMetaObjectPrivate *p = priv(m_data);
int mindex = metaObjectIndexForMethod(index);
uint *ptr = fieldPointer(m_data) + p->methodData + mindex * METHOD_FIELD_COUNT;
- // methods: signature, parameters, type, tag, flags
- ptr[0] = signature.offset();
- ptr[1] = parameterNames.isEmpty()?m_zeroPtr:parameterNames.offset();
- ptr[2] = type.isEmpty()?m_zeroPtr:type.offset();
- ptr[3] = m_zeroPtr;
+ // methods: name, arc, parameters, tag, flags
+ ptr[0] = name.index();
+ ptr[1] = argc;
+ ptr[2] = paramIndex;
+ ptr[3] = m_zeroString.index();
ptr[4] = AccessProtected | MethodSlot;
+
+ uint *paramPtr = fieldPointer(m_data) + paramIndex;
+ paramPtr[0] = type;
+ if (argc) {
+ Q_ASSERT(types != 0);
+ Q_ASSERT(parameterNames != 0);
+ for (int i = 0; i < argc; ++i) {
+ Q_ASSERT(types[i] != 0);
+ Q_ASSERT(QMetaType::isRegistered(types[i]));
+ paramPtr[1+i] = types[i];
+ paramPtr[1+argc+i] = parameterNames[i].index();
+ }
+ }
}
int QFastMetaBuilder::metaObjectIndexForSignal(int index) const
@@ -296,17 +321,19 @@ int QFastMetaBuilder::metaObjectIndexForMethod(int index) const
void QFastMetaBuilder::allocateStringData()
{
- if (m_stringDataAllocated < m_stringDataLength) {
- m_data.resize(m_data.size() + m_stringDataLength - m_stringDataAllocated);
- m_stringDataAllocated = m_stringDataLength;
- m_stringData = m_data.data() + header(m_data)->fieldCount * sizeof(uint);
+ if (m_stringCountAllocated < m_stringCount) {
+ m_data.resize(header(m_data)->fieldCount * sizeof(uint)
+ + m_stringCount * sizeof(QByteArrayData) + m_stringDataLength);
+ m_stringCountAllocated = m_stringCount;
+ char *rawStringData = m_data.data() + header(m_data)->fieldCount * sizeof(uint);
+ m_stringData = reinterpret_cast<QByteArrayData *>(rawStringData);
}
}
void QFastMetaBuilder::fromData(QMetaObject *output, const QMetaObject *parent, const QByteArray &data)
{
output->d.superdata = parent;
- output->d.stringdata = data.constData() + header(data)->fieldCount * sizeof(uint);
+ output->d.stringdata = reinterpret_cast<const QByteArrayData *>(data.constData() + header(data)->fieldCount * sizeof(uint));
output->d.data = fieldPointer(data);
output->d.extradata = 0;
}
diff --git a/src/qml/qml/ftw/qfastmetabuilder_p.h b/src/qml/qml/ftw/qfastmetabuilder_p.h
index c1f6a3de5c..16f7b6e749 100644
--- a/src/qml/qml/ftw/qfastmetabuilder_p.h
+++ b/src/qml/qml/ftw/qfastmetabuilder_p.h
@@ -80,13 +80,15 @@ public:
inline bool isEmpty() const;
inline QFastMetaBuilder *builder() const;
- inline int offset() const;
+ inline int index() const;
inline char *data();
inline int length() const;
+ inline void loadByteArrayData();
private:
friend class QFastMetaBuilder;
QFastMetaBuilder *_b;
+ int _i;
int _o;
int _l;
};
@@ -95,7 +97,8 @@ public:
// Returns class name
StringRef init(int classNameLength,
int propertyCount, int methodCount,
- int signalCount, int classInfoCount);
+ int signalCount, int classInfoCount,
+ int paramDataSize, int *paramIndex);
void setClassInfo(int index, const StringRef &key, const StringRef &value);
@@ -106,48 +109,55 @@ public:
Constant = 0x00000400,
Final = 0x00000800
};
- // void setProperty(int index, const StringRef &name, QMetaType::Type type, int notifySignal = -1);
- void setProperty(int index, const StringRef &name, const StringRef &type,
- QMetaType::Type mtype, PropertyFlag flags, int notifySignal = -1);
- void setProperty(int index, const StringRef &name, const StringRef &type,
+ void setProperty(int index, const StringRef &name, int type,
PropertyFlag flags, int notifySignal = -1);
- void setMethod(int index, const StringRef &signature,
- const StringRef &parameterNames = StringRef(),
- const StringRef &type = StringRef());
- void setSignal(int index, const StringRef &signature,
- const StringRef &parameterNames = StringRef(),
- const StringRef &type = StringRef());
+ void setMethod(int index, const StringRef &name, int paramIndex, int argc = 0,
+ const int *types = 0, const StringRef *parameterNames = 0,
+ QMetaType::Type type = QMetaType::Void);
+ void setSignal(int index, const StringRef &name, int paramIndex, int argc = 0,
+ const int *types = 0, const StringRef *parameterNames = 0,
+ QMetaType::Type type = QMetaType::Void);
int metaObjectIndexForSignal(int) const;
int metaObjectIndexForMethod(int) const;
- QByteArray toData() const { return m_data; }
+ QByteArray toData() const {
+ if (m_stringCountLoaded == m_stringCount - 1) {
+ // zero-string is lazily loaded last
+ const_cast<StringRef &>(m_zeroString).loadByteArrayData();
+ }
+ Q_ASSERT(m_stringCountLoaded == m_stringCount);
+ return m_data;
+ }
static void fromData(QMetaObject *, const QMetaObject *parent, const QByteArray &);
private:
friend struct StringRef;
QByteArray m_data;
- int m_zeroPtr;
+ StringRef m_zeroString;
void allocateStringData();
- char *m_stringData;
+ QByteArrayData *m_stringData;
+ int m_stringCount;
int m_stringDataLength;
- int m_stringDataAllocated;
+ int m_stringCountAllocated;
+ int m_stringCountLoaded;
};
QFastMetaBuilder::StringRef::StringRef()
-: _b(0), _o(0), _l(0)
+: _b(0), _i(0), _o(0), _l(0)
{
}
QFastMetaBuilder::StringRef::StringRef(const StringRef &o)
-: _b(o._b), _o(o._o), _l(o._l)
+: _b(o._b), _i(o._i), _o(o._o), _l(o._l)
{
}
QFastMetaBuilder::StringRef &QFastMetaBuilder::StringRef::operator=(const StringRef &o)
{
_b = o._b;
+ _i = o._i;
_o = o._o;
_l = o._l;
return *this;
@@ -163,17 +173,17 @@ QFastMetaBuilder *QFastMetaBuilder::StringRef::builder() const
return _b;
}
-int QFastMetaBuilder::StringRef::offset() const
+int QFastMetaBuilder::StringRef::index() const
{
- return _o;
+ return _i;
}
char *QFastMetaBuilder::StringRef::data()
{
Q_ASSERT(_b);
- if (_b->m_stringDataLength != _b->m_stringDataAllocated)
- _b->allocateStringData();
- return _b->m_stringData + _o;
+ if (_b->m_stringCountAllocated < _b->m_stringCount)
+ _b->allocateStringData();
+ return reinterpret_cast<char *>(&_b->m_stringData[_b->m_stringCount]) + _o;
}
int QFastMetaBuilder::StringRef::length() const
@@ -186,18 +196,36 @@ void QFastMetaBuilder::StringRef::load(const QHashedStringRef &str)
Q_ASSERT(str.utf8length() == _l);
str.writeUtf8(data());
*(data() + _l) = 0;
+ loadByteArrayData();
}
void QFastMetaBuilder::StringRef::load(const QByteArray &str)
{
Q_ASSERT(str.length() == _l);
strcpy(data(), str.constData());
+ loadByteArrayData();
}
void QFastMetaBuilder::StringRef::load(const char *str)
{
Q_ASSERT(strlen(str) == (uint)_l);
strcpy(data(), str);
+ loadByteArrayData();
+}
+
+void QFastMetaBuilder::StringRef::loadByteArrayData()
+{
+ if (_b->m_stringCountAllocated < _b->m_stringCount)
+ _b->allocateStringData();
+ Q_ASSERT(_b->m_stringCountLoaded < _b->m_stringCount);
+
+ int offsetofCstrings = _b->m_stringCount * sizeof(QByteArrayData);
+ qptrdiff offset = offsetofCstrings + _o - _i * sizeof(QByteArrayData);
+
+ const QByteArrayData bad = { Q_REFCOUNT_INITIALIZE_STATIC, _l, 0, 0, offset };
+ memcpy(&_b->m_stringData[_i], &bad, sizeof(QByteArrayData));
+
+ ++_b->m_stringCountLoaded;
}
QT_END_NAMESPACE
diff --git a/src/qml/qml/ftw/qqmlpool_p.h b/src/qml/qml/ftw/qqmlpool_p.h
index e4fa03ce34..8e8f367890 100644
--- a/src/qml/qml/ftw/qqmlpool_p.h
+++ b/src/qml/qml/ftw/qqmlpool_p.h
@@ -132,6 +132,7 @@ public:
Q_ASSERT(index < m_length);
return m_data[index];
};
+ const T *data() const { return m_data; }
private:
friend class QQmlPool;
List(T *d, int l) : m_length(l), m_data(d) {}
diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri
index c75e4c9681..5d26197b1c 100644
--- a/src/qml/qml/qml.pri
+++ b/src/qml/qml/qml.pri
@@ -40,7 +40,6 @@ SOURCES += \
$$PWD/qqmltypenamecache.cpp \
$$PWD/qqmlscriptstring.cpp \
$$PWD/qquickworkerscript.cpp \
- $$PWD/qqmlimageprovider.cpp \
$$PWD/qqmlnetworkaccessmanagerfactory.cpp \
$$PWD/qqmldirparser.cpp \
$$PWD/qqmlextensionplugin.cpp \
@@ -109,7 +108,6 @@ HEADERS += \
$$PWD/qqmlscriptstring.h \
$$PWD/qquickworkerscript_p.h \
$$PWD/qqmlguard_p.h \
- $$PWD/qqmlimageprovider.h \
$$PWD/qqmlnetworkaccessmanagerfactory.h \
$$PWD/qqmldirparser_p.h \
$$PWD/qqmlextensioninterface.h \
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index ca6b13e7f8..aa130d9493 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -172,11 +172,11 @@ int QQmlBoundSignal::qt_metacall(QMetaObject::Call c, int id, void **a)
return -1;
if (QQmlDebugService::isDebuggingEnabled())
- QV8DebugService::instance()->signalEmitted(QString::fromAscii(m_signal.signature()));
+ QV8DebugService::instance()->signalEmitted(QString::fromAscii(m_signal.methodSignature().constData()));
QQmlHandlingSignalProfiler prof;
if (prof.enabled) {
- prof.setSignalInfo(QString::fromLatin1(m_signal.signature()),
+ prof.setSignalInfo(QString::fromLatin1(m_signal.methodSignature().constData()),
m_expression->expression());
prof.setLocation(m_expression->sourceFile(), m_expression->lineNumber(),
m_expression->columnNumber());
@@ -226,14 +226,14 @@ QQmlBoundSignalParameters::QQmlBoundSignalParameters(const QMetaMethod &method,
continue;
}
- QVariant::Type t = (QVariant::Type)QMetaType::type(type.constData());
+ int t = QMetaType::type(type.constData());
if (QQmlMetaType::isQObject(t)) {
types[ii] = QMetaType::QObjectStar;
QMetaPropertyBuilder prop = mob.addProperty(name, "QObject*");
prop.setWritable(false);
} else {
QByteArray propType = type;
- if (t >= QVariant::UserType || t == QVariant::Invalid) {
+ if (t >= int(QVariant::UserType) || t == QMetaType::UnknownType || t == QMetaType::Void) {
QByteArray scope;
QByteArray name;
int scopeIdx = propType.lastIndexOf("::");
diff --git a/src/qml/qml/qqmlcompiler.cpp b/src/qml/qml/qqmlcompiler.cpp
index 9304a75fbf..51343b64d5 100644
--- a/src/qml/qml/qqmlcompiler.cpp
+++ b/src/qml/qml/qqmlcompiler.cpp
@@ -71,6 +71,7 @@
#include <QAtomicInt>
#include <QtCore/qdebug.h>
#include <QtCore/qdatetime.h>
+#include <QtCore/qvarlengtharray.h>
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<qreal>)
@@ -2830,32 +2831,37 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
}
}
+ // Size of the array that describes parameter types & names
+ int paramDataSize = (obj->aggregateDynamicSignalParameterCount() + obj->aggregateDynamicSlotParameterCount()) * 2
+ + obj->dynamicProperties.count() // for Changed() signals return types
+ // Return "parameters" don't have names
+ - (obj->dynamicSignals.count() + obj->dynamicSlots.count());
+
QFastMetaBuilder builder;
+ int paramIndex;
QFastMetaBuilder::StringRef classNameRef = builder.init(newClassName.length(),
obj->dynamicProperties.count() - (resolveAlias?0:aliasCount),
obj->dynamicSlots.count(),
obj->dynamicSignals.count() + obj->dynamicProperties.count(),
- defaultProperty?1:0);
+ defaultProperty?1:0, paramDataSize, &paramIndex);
struct TypeData {
Object::DynamicProperty::Type dtype;
int metaType;
- const char *cppType;
} builtinTypes[] = {
- { Object::DynamicProperty::Var, QMetaType::QVariant, "QVariant" },
- { Object::DynamicProperty::Variant, QMetaType::QVariant, "QVariant" },
- { Object::DynamicProperty::Int, QMetaType::Int, "int" },
- { Object::DynamicProperty::Bool, QMetaType::Bool, "bool" },
- { Object::DynamicProperty::Real, QMetaType::Double, "double" },
- { Object::DynamicProperty::String, QMetaType::QString, "QString" },
- { Object::DynamicProperty::Url, QMetaType::QUrl, "QUrl" },
- { Object::DynamicProperty::Color, QMetaType::QColor, "QColor" },
- { Object::DynamicProperty::Time, QMetaType::QTime, "QTime" },
- { Object::DynamicProperty::Date, QMetaType::QDate, "QDate" },
- { Object::DynamicProperty::DateTime, QMetaType::QDateTime, "QDateTime" },
+ { Object::DynamicProperty::Var, QMetaType::QVariant },
+ { Object::DynamicProperty::Variant, QMetaType::QVariant },
+ { Object::DynamicProperty::Int, QMetaType::Int },
+ { Object::DynamicProperty::Bool, QMetaType::Bool },
+ { Object::DynamicProperty::Real, QMetaType::Double },
+ { Object::DynamicProperty::String, QMetaType::QString },
+ { Object::DynamicProperty::Url, QMetaType::QUrl },
+ { Object::DynamicProperty::Color, QMetaType::QColor },
+ { Object::DynamicProperty::Time, QMetaType::QTime },
+ { Object::DynamicProperty::Date, QMetaType::QDate },
+ { Object::DynamicProperty::DateTime, QMetaType::QDateTime },
};
static const int builtinTypeCount = sizeof(builtinTypes) / sizeof(TypeData);
- QFastMetaBuilder::StringRef typeRefs[builtinTypeCount];
// Reserve dynamic properties
if (obj->dynamicProperties.count()) {
@@ -2868,18 +2874,16 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
if (p->type != Object::DynamicProperty::Alias || resolveAlias)
p->nameRef = builder.newString(p->name.utf8length());
- int propertyType = 0;
+ int metaType = 0;
+ int propertyType = 0; // for VMD
bool readonly = false;
- QFastMetaBuilder::StringRef typeRef;
if (p->type == Object::DynamicProperty::Alias) {
continue;
} else if (p->type < builtinTypeCount) {
Q_ASSERT(builtinTypes[p->type].dtype == p->type);
- propertyType = builtinTypes[p->type].metaType;
- if (typeRefs[p->type].isEmpty())
- typeRefs[p->type] = builder.newString(strlen(builtinTypes[p->type].cppType));
- typeRef = typeRefs[p->type];
+ metaType = builtinTypes[p->type].metaType;
+ propertyType = metaType;
} else {
Q_ASSERT(p->type == Object::DynamicProperty::CustomList ||
@@ -2915,9 +2919,9 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
propertyType = qMetaTypeId<QQmlListProperty<QObject> >();
}
- p->resolvedCustomTypeName = pool->NewByteArray(customTypeName);
- p->typeRef = builder.newString(customTypeName.length());
- typeRef = p->typeRef;
+ metaType = QMetaType::type(customTypeName);
+ Q_ASSERT(metaType != QMetaType::UnknownType);
+ Q_ASSERT(metaType != QMetaType::Void);
}
if (p->type == Object::DynamicProperty::Var)
@@ -2932,17 +2936,13 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
(vmd->propertyData() + effectivePropertyIndex)->propertyType = propertyType;
}
- if (p->type < builtinTypeCount)
- builder.setProperty(effectivePropertyIndex, p->nameRef, typeRef, (QMetaType::Type)propertyType,
- readonly?QFastMetaBuilder::None:QFastMetaBuilder::Writable,
- effectivePropertyIndex);
- else
- builder.setProperty(effectivePropertyIndex, p->nameRef, typeRef,
- readonly?QFastMetaBuilder::None:QFastMetaBuilder::Writable,
- effectivePropertyIndex);
+ builder.setProperty(effectivePropertyIndex, p->nameRef, metaType,
+ readonly?QFastMetaBuilder::None:QFastMetaBuilder::Writable,
+ effectivePropertyIndex);
- p->changedSignatureRef = builder.newString(p->name.utf8length() + strlen("Changed()"));
- builder.setSignal(effectivePropertyIndex, p->changedSignatureRef);
+ p->changedNameRef = builder.newString(p->name.utf8length() + strlen("Changed"));
+ builder.setSignal(effectivePropertyIndex, p->changedNameRef, paramIndex);
+ paramIndex++;
effectivePropertyIndex++;
}
@@ -2955,19 +2955,19 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
totalPropCount = varPropCount + effectivePropertyIndex;
for (Object::DynamicProperty *p = obj->dynamicProperties.first(); p; p = obj->dynamicProperties.next(p)) {
if (p->type == Object::DynamicProperty::Var) {
- QFastMetaBuilder::StringRef typeRef = typeRefs[p->type];
if (buildData) {
vmd->propertyCount++;
(vmd->propertyData() + effectivePropertyIndex)->propertyType = QMetaType::QVariant;
}
- builder.setProperty(effectivePropertyIndex, p->nameRef, typeRef,
+ builder.setProperty(effectivePropertyIndex, p->nameRef,
QMetaType::QVariant,
p->isReadOnly?QFastMetaBuilder::None:QFastMetaBuilder::Writable,
effectivePropertyIndex);
- p->changedSignatureRef = builder.newString(p->name.utf8length() + strlen("Changed()"));
- builder.setSignal(effectivePropertyIndex, p->changedSignatureRef);
+ p->changedNameRef = builder.newString(p->name.utf8length() + strlen("Changed"));
+ builder.setSignal(effectivePropertyIndex, p->changedNameRef, paramIndex);
+ paramIndex++;
effectivePropertyIndex++;
}
@@ -2986,8 +2986,9 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
}
// Even if we aren't resolving the alias, we need a fake signal so that the
// metaobject remains consistent across the resolve and non-resolve alias runs
- p->changedSignatureRef = builder.newString(p->name.utf8length() + strlen("Changed()"));
- builder.setSignal(effectivePropertyIndex, p->changedSignatureRef);
+ p->changedNameRef = builder.newString(p->name.utf8length() + strlen("Changed"));
+ builder.setSignal(effectivePropertyIndex, p->changedNameRef, paramIndex);
+ paramIndex++;
effectivePropertyIndex++;
aliasIndex++;
}
@@ -3006,49 +3007,56 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
int signalIndex = 0;
for (Object::DynamicSignal *s = obj->dynamicSignals.first(); s; s = obj->dynamicSignals.next(s)) {
- int paramCount = s->parameterNames.count();
-
- int signatureSize = s->name.utf8length() + 2 /* paren */;
- int namesSize = 0;
- if (paramCount) signatureSize += s->parameterTypesLength() + (paramCount - 1) /* commas */;
- if (paramCount) namesSize += s->parameterNamesLength() + (paramCount - 1) /* commas */;
+ s->nameRef = builder.newString(s->name.utf8length());
- s->signatureRef = builder.newString(signatureSize);
- if (namesSize) s->parameterNamesRef = builder.newString(namesSize);
+ int paramCount = s->parameterNames.count();
+ QVarLengthArray<int, 10> paramTypes(paramCount);
+ if (paramCount) {
+ s->parameterNamesRef = pool->NewRawList<QFastMetaBuilder::StringRef>(paramCount);
+ for (int i = 0; i < paramCount; ++i) {
+ s->parameterNamesRef[i] = builder.newString(s->parameterNames.at(i).utf8length());
+ Q_ASSERT(s->parameterTypes.at(i) < builtinTypeCount);
+ paramTypes[i] = builtinTypes[s->parameterTypes.at(i)].metaType;
+ }
+ }
if (buildData)
((QQmlVMEMetaData *)dynamicData.data())->signalCount++;
- builder.setSignal(signalIndex + obj->dynamicProperties.count(), s->signatureRef, s->parameterNamesRef);
+ builder.setSignal(signalIndex + obj->dynamicProperties.count(), s->nameRef,
+ paramIndex, paramCount, paramTypes.constData(), s->parameterNamesRef.data());
+ paramIndex += paramCount*2 + 1;
++signalIndex;
}
// Reserve dynamic slots
if (obj->dynamicSlots.count()) {
- // Allocate QVariant string
- if (typeRefs[0].isEmpty())
- typeRefs[0] = builder.newString(strlen(builtinTypes[0].cppType));
-
typedef QQmlVMEMetaData VMD;
int methodIndex = 0;
for (Object::DynamicSlot *s = obj->dynamicSlots.first(); s; s = obj->dynamicSlots.next(s)) {
+ s->nameRef = builder.newString(s->name.utf8length());
int paramCount = s->parameterNames.count();
- int signatureSize = s->name.utf8length() + 2 /* paren */;
- int namesSize = 0;
- if (paramCount) signatureSize += (paramCount * strlen("QVariant") + (paramCount - 1));
- if (paramCount) namesSize += s->parameterNamesLength() + (paramCount - 1 /* commas */);
-
- s->signatureRef = builder.newString(signatureSize);
- if (namesSize) s->parameterNamesRef = builder.newString(namesSize);
+ QVarLengthArray<int, 10> paramTypes(paramCount);
+ if (paramCount) {
+ s->parameterNamesRef = pool->NewRawList<QFastMetaBuilder::StringRef>(paramCount);
+ for (int i = 0; i < paramCount; ++i) {
+ s->parameterNamesRef[i] = builder.newString(s->parameterNames.at(i).size());
+ paramTypes[i] = QMetaType::QVariant;
+ }
+ }
- builder.setMethod(methodIndex, s->signatureRef, s->parameterNamesRef, typeRefs[0]);
+ builder.setMethod(methodIndex, s->nameRef, paramIndex, paramCount,
+ paramTypes.constData(), s->parameterNamesRef.data(), QMetaType::QVariant);
+ paramIndex += paramCount*2 + 1;
if (buildData) {
QString funcScript;
- funcScript.reserve(strlen("(function ") + s->name.length() + 1 /* lparen */ +
+ int namesSize = 0;
+ if (paramCount) namesSize += s->parameterNamesLength() + (paramCount - 1 /* commas */);
+ funcScript.reserve(strlen("(function ") + s->name.length() + 1 /* lparen */ +
namesSize + 1 /* rparen */ + s->body.length() + 1 /* rparen */);
funcScript = QLatin1String("(function ") + s->name.toString() + QLatin1Char('(');
for (int jj = 0; jj < paramCount; ++jj) {
@@ -3077,28 +3085,18 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
}
}
- // Now allocate used builtin types
- for (int ii = 0; ii < builtinTypeCount; ++ii) {
- if (!typeRefs[ii].isEmpty())
- typeRefs[ii].load(builtinTypes[ii].cppType);
- }
-
// Now allocate properties
for (Object::DynamicProperty *p = obj->dynamicProperties.first(); p; p = obj->dynamicProperties.next(p)) {
- char *d = p->changedSignatureRef.data();
+ char *d = p->changedNameRef.data();
p->name.writeUtf8(d);
- strcpy(d + p->name.utf8length(), "Changed()");
+ strcpy(d + p->name.utf8length(), "Changed");
+ p->changedNameRef.loadByteArrayData();
if (p->type == Object::DynamicProperty::Alias && !resolveAlias)
continue;
p->nameRef.load(p->name);
-
- if (p->type >= builtinTypeCount) {
- Q_ASSERT(p->resolvedCustomTypeName);
- p->typeRef.load(*p->resolvedCustomTypeName);
- }
}
// Allocate default property if necessary
@@ -3108,39 +3106,18 @@ bool QQmlCompiler::buildDynamicMeta(QQmlScript::Object *obj, DynamicMetaMode mod
// Now allocate signals
for (Object::DynamicSignal *s = obj->dynamicSignals.first(); s; s = obj->dynamicSignals.next(s)) {
- char *d = s->signatureRef.data();
- char *d2 = s->parameterNamesRef.isEmpty()?0:s->parameterNamesRef.data();
- s->name.writeUtf8(d); d += s->name.utf8length();
- *d++ = '(';
+ s->nameRef.load(s->name);
- for (int jj = 0; jj < s->parameterNames.count(); ++jj) {
- if (jj != 0) { *d++ = ','; *d2++ = ','; }
- strcpy(d, s->parameterTypes.at(jj).constData());
- d += s->parameterTypes.at(jj).length();
- s->parameterNames.at(jj).writeUtf8(d2);
- d2 += s->parameterNames.at(jj).utf8length();
- }
- *d++ = ')';
- *d = 0;
- if (d2) *d2 = 0;
+ for (int jj = 0; jj < s->parameterNames.count(); ++jj)
+ s->parameterNamesRef[jj].load(s->parameterNames.at(jj));
}
// Now allocate methods
for (Object::DynamicSlot *s = obj->dynamicSlots.first(); s; s = obj->dynamicSlots.next(s)) {
- char *d = s->signatureRef.data();
- char *d2 = s->parameterNamesRef.isEmpty()?0:s->parameterNamesRef.data();
- s->name.writeUtf8(d); d += s->name.utf8length();
- *d++ = '(';
- for (int jj = 0; jj < s->parameterNames.count(); ++jj) {
- if (jj != 0) { *d++ = ','; *d2++ = ','; }
- strcpy(d, "QVariant");
- d += strlen("QVariant");
- strcpy(d2, s->parameterNames.at(jj).constData());
- d2 += s->parameterNames.at(jj).length();
- }
- *d++ = ')';
- *d = 0;
- if (d2) *d2 = 0;
+ s->nameRef.load(s->name);
+
+ for (int jj = 0; jj < s->parameterNames.count(); ++jj)
+ s->parameterNamesRef[jj].load(s->parameterNames.at(jj).constData());
}
// Now allocate class name
@@ -3233,7 +3210,6 @@ bool QQmlCompiler::compileAlias(QFastMetaBuilder &builder,
Object::DynamicProperty &prop)
{
Q_ASSERT(!prop.nameRef.isEmpty());
- Q_ASSERT(prop.typeRef.isEmpty());
if (!prop.defaultValue)
COMPILE_EXCEPTION(obj, tr("No property alias location"));
@@ -3278,9 +3254,7 @@ bool QQmlCompiler::compileAlias(QFastMetaBuilder &builder,
writable = aliasProperty.isWritable() && !prop.isReadOnly;
resettable = aliasProperty.isResettable() && !prop.isReadOnly;
- if (aliasProperty.type() < QVariant::UserType
- || uint(aliasProperty.type()) == QMetaType::QVariant)
- type = aliasProperty.type();
+ type = aliasProperty.userType();
if (alias.count() == 3) {
QQmlValueType *valueType = enginePrivate->valueTypes[aliasProperty.type()];
@@ -3298,9 +3272,7 @@ bool QQmlCompiler::compileAlias(QFastMetaBuilder &builder,
propIdx |= (valueTypeIndex << 16);
// update the property type
- type = aliasProperty.type();
- if (type >= (int)QVariant::UserType)
- type = 0;
+ type = aliasProperty.userType();
}
if (aliasProperty.isEnumType())
@@ -3322,22 +3294,26 @@ bool QQmlCompiler::compileAlias(QFastMetaBuilder &builder,
if (typeName.endsWith('*'))
flags |= QML_ALIAS_FLAG_PTR;
+ if (type == QMetaType::UnknownType) {
+ Q_ASSERT(!typeName.isEmpty());
+ type = QMetaType::type(typeName);
+ Q_ASSERT(type != QMetaType::UnknownType);
+ Q_ASSERT(type != QMetaType::Void);
+ }
+
QQmlVMEMetaData::AliasData aliasData = { idObject->idIndex, propIdx, flags };
typedef QQmlVMEMetaData VMD;
VMD *vmd = (QQmlVMEMetaData *)data.data();
*(vmd->aliasData() + aliasIndex) = aliasData;
- prop.resolvedCustomTypeName = pool->NewByteArray(typeName);
- prop.typeRef = builder.newString(typeName.length());
-
int propertyFlags = 0;
if (writable)
propertyFlags |= QFastMetaBuilder::Writable;
if (resettable)
propertyFlags |= QFastMetaBuilder::Resettable;
- builder.setProperty(propIndex, prop.nameRef, prop.typeRef, (QMetaType::Type)type,
+ builder.setProperty(propIndex, prop.nameRef, type,
(QFastMetaBuilder::PropertyFlag)propertyFlags,
propIndex);
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 489b4f895a..16cd1ecde6 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -59,7 +59,6 @@
#include "qquickworkerscript_p.h"
#include "qqmlcomponent_p.h"
#include "qqmlnetworkaccessmanagerfactory.h"
-#include "qqmlimageprovider.h"
#include "qqmldirparser_p.h"
#include "qqmlextensioninterface.h"
#include "qqmllist_p.h"
@@ -179,6 +178,12 @@ void QQmlEnginePrivate::defineModule()
qmlRegisterUncreatableType<QQmlLocale>("QtQuick",2,0,"Locale",QQmlEngine::tr("Locale cannot be instantiated. Use Qt.locale()"));
}
+
+QQmlImageProviderBase::~QQmlImageProviderBase()
+{
+}
+
+
/*!
\qmlclass Qt QQmlEnginePrivate
\ingroup qml-utility-elements
@@ -670,27 +675,29 @@ QNetworkAccessManager *QQmlEngine::networkAccessManager() const
takes ownership of \a provider.
Image providers enable support for pixmap and threaded image
- requests. See the QQmlImageProvider documentation for details on
+ requests. See the QQuickImageProvider documentation for details on
implementing and using image providers.
All required image providers should be added to the engine before any
QML sources files are loaded.
- \sa removeImageProvider()
+ \sa removeImageProvider(), QQuickImageProvider
*/
-void QQmlEngine::addImageProvider(const QString &providerId, QQmlImageProvider *provider)
+void QQmlEngine::addImageProvider(const QString &providerId, QQmlImageProviderBase *provider)
{
Q_D(QQmlEngine);
QMutexLocker locker(&d->mutex);
- d->imageProviders.insert(providerId.toLower(), QSharedPointer<QQmlImageProvider>(provider));
+ d->imageProviders.insert(providerId.toLower(), QSharedPointer<QQmlImageProviderBase>(provider));
}
/*!
- Returns the QQmlImageProvider set for \a providerId.
+ Returns the image provider set for \a providerId.
Returns the provider if it was found; otherwise returns 0.
+
+ \sa QQuickImageProvider
*/
-QQmlImageProvider *QQmlEngine::imageProvider(const QString &providerId) const
+QQmlImageProviderBase *QQmlEngine::imageProvider(const QString &providerId) const
{
Q_D(const QQmlEngine);
QMutexLocker locker(&d->mutex);
@@ -698,9 +705,9 @@ QQmlImageProvider *QQmlEngine::imageProvider(const QString &providerId) const
}
/*!
- Removes the QQmlImageProvider for \a providerId.
+ Removes the image provider for \a providerId.
- \sa addImageProvider()
+ \sa addImageProvider(), QQuickImageProvider
*/
void QQmlEngine::removeImageProvider(const QString &providerId)
{
@@ -709,54 +716,6 @@ void QQmlEngine::removeImageProvider(const QString &providerId)
d->imageProviders.take(providerId);
}
-QQmlImageProvider::ImageType QQmlEnginePrivate::getImageProviderType(const QUrl &url)
-{
- QMutexLocker locker(&mutex);
- QSharedPointer<QQmlImageProvider> provider = imageProviders.value(url.host());
- locker.unlock();
- if (provider)
- return provider->imageType();
- return QQmlImageProvider::Invalid;
-}
-
-QQuickTextureFactory *QQmlEnginePrivate::getTextureFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
-{
- QMutexLocker locker(&mutex);
- QSharedPointer<QQmlImageProvider> provider = imageProviders.value(url.host());
- locker.unlock();
- if (provider) {
- QString imageId = url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1);
- return provider->requestTexture(imageId, size, req_size);
- }
- return 0;
-}
-
-QImage QQmlEnginePrivate::getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
-{
- QMutexLocker locker(&mutex);
- QImage image;
- QSharedPointer<QQmlImageProvider> provider = imageProviders.value(url.host());
- locker.unlock();
- if (provider) {
- QString imageId = url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1);
- image = provider->requestImage(imageId, size, req_size);
- }
- return image;
-}
-
-QPixmap QQmlEnginePrivate::getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size)
-{
- QMutexLocker locker(&mutex);
- QPixmap pixmap;
- QSharedPointer<QQmlImageProvider> provider = imageProviders.value(url.host());
- locker.unlock();
- if (provider) {
- QString imageId = url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1);
- pixmap = provider->requestPixmap(imageId, size, req_size);
- }
- return pixmap;
-}
-
/*!
Return the base URL for this engine. The base URL is only used to
resolve components when a relative URL is passed to the
diff --git a/src/qml/qml/qqmlengine.h b/src/qml/qml/qqmlengine.h
index 04ac61c05b..41696923c5 100644
--- a/src/qml/qml/qqmlengine.h
+++ b/src/qml/qml/qqmlengine.h
@@ -54,6 +54,12 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
+class Q_QML_EXPORT QQmlImageProviderBase
+{
+public:
+ virtual ~QQmlImageProviderBase();
+};
+
class QQmlComponent;
class QQmlEnginePrivate;
class QQmlImportsPrivate;
@@ -62,7 +68,6 @@ class QQmlContext;
class QQmlType;
class QUrl;
class QScriptContext;
-class QQmlImageProvider;
class QNetworkAccessManager;
class QQmlNetworkAccessManagerFactory;
class QQmlIncubationController;
@@ -94,8 +99,8 @@ public:
QNetworkAccessManager *networkAccessManager() const;
- void addImageProvider(const QString &id, QQmlImageProvider *);
- QQmlImageProvider *imageProvider(const QString &id) const;
+ void addImageProvider(const QString &id, QQmlImageProviderBase *);
+ QQmlImageProviderBase *imageProvider(const QString &id) const;
void removeImageProvider(const QString &id);
void setIncubationController(QQmlIncubationController *);
diff --git a/src/qml/qml/qqmlengine_p.h b/src/qml/qml/qqmlengine_p.h
index db834489ba..73a0b5a217 100644
--- a/src/qml/qml/qqmlengine_p.h
+++ b/src/qml/qml/qqmlengine_p.h
@@ -63,7 +63,6 @@
#include "qqmlcontext.h"
#include "qqmlcontext_p.h"
#include "qqmlexpression.h"
-#include "qqmlimageprovider.h"
#include "qqmlproperty_p.h"
#include "qqmlpropertycache_p.h"
#include "qqmlmetatype_p.h"
@@ -173,11 +172,7 @@ public:
mutable QNetworkAccessManager *networkAccessManager;
mutable QQmlNetworkAccessManagerFactory *networkAccessManagerFactory;
- QHash<QString,QSharedPointer<QQmlImageProvider> > imageProviders;
- QQmlImageProvider::ImageType getImageProviderType(const QUrl &url);
- QQuickTextureFactory *getTextureFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
- QImage getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
- QPixmap getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
+ QHash<QString,QSharedPointer<QQmlImageProviderBase> > imageProviders;
// Scarce resources are "exceptionally high cost" QVariant types where allowing the
// normal JavaScript GC to clean them up is likely to lead to out-of-memory or other
diff --git a/src/qml/qml/qqmlerror.h b/src/qml/qml/qqmlerror.h
index 3c148549d0..73581e29aa 100644
--- a/src/qml/qml/qqmlerror.h
+++ b/src/qml/qml/qqmlerror.h
@@ -80,6 +80,8 @@ private:
QDebug Q_QML_EXPORT operator<<(QDebug debug, const QQmlError &error);
+Q_DECLARE_TYPEINFO(QQmlError, Q_MOVABLE_TYPE);
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index 2061530dc5..5b80f57d01 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -340,9 +340,7 @@ static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
QMetaMethod method = mo->method(ii);
// More complex - need to search name
- QByteArray name = method.signature();
- int parenIdx = name.indexOf('(');
- if (parenIdx != -1) name = name.left(parenIdx);
+ QByteArray name = method.name();
bool found = false;
@@ -352,11 +350,8 @@ static void clone(QMetaObjectBuilder &builder, const QMetaObject *mo,
++ii) {
QMetaMethod other = ignoreEnd->method(ii);
- QByteArray othername = other.signature();
- int parenIdx = othername.indexOf('(');
- if (parenIdx != -1) othername = othername.left(parenIdx);
- found = name == othername;
+ found = name == other.name();
}
QMetaMethodBuilder m = builder.addMethod(method);
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 14778ce6c8..d3778fa5c5 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -334,7 +334,7 @@ void QQmlPropertyPrivate::initProperty(QObject *obj, const QString &name)
signalName[0] = signalName.at(0).toLower();
QMetaMethod method = findSignalByName(currentObject->metaObject(), signalName.toLatin1().constData());
- if (method.signature()) {
+ if (method.isValid()) {
object = currentObject;
core.load(method);
return;
@@ -1148,7 +1148,7 @@ bool QQmlPropertyPrivate::writeEnumProperty(const QMetaProperty &prop, int idx,
return false;
} else if (v.userType() != QVariant::Int && v.userType() != QVariant::UInt) {
int enumMetaTypeId = QMetaType::type(QByteArray(menum.scope() + QByteArray("::") + menum.name()));
- if ((enumMetaTypeId == 0) || (v.userType() != enumMetaTypeId) || !v.constData())
+ if ((enumMetaTypeId == QMetaType::UnknownType) || (v.userType() != enumMetaTypeId) || !v.constData())
return false;
v = QVariant(*reinterpret_cast<const int *>(v.constData()));
}
@@ -1487,6 +1487,17 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
if (expression->hasError()) {
return false;
+ } else if (isVmeProperty) {
+ typedef QQmlVMEMetaObject VMEMO;
+ if (!result.IsEmpty() && result->IsFunction()
+ && !result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty()) {
+ // we explicitly disallow this case to avoid confusion. Users can still store one
+ // in an array in a var property if they need to, but the common case is user error.
+ expression->delayedError()->error.setDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
+ return false;
+ }
+ VMEMO *vmemo = static_cast<VMEMO *>(const_cast<QMetaObject *>(object->metaObject()));
+ vmemo->setVMEProperty(core.coreIndex, result);
} else if (isUndefined && core.isResettable()) {
void *args[] = { 0 };
QMetaObject::metacall(object, QMetaObject::ResetProperty, core.coreIndex, args);
@@ -1496,12 +1507,11 @@ bool QQmlPropertyPrivate::writeBinding(QObject *object,
expression->delayedError()->error.setDescription(QLatin1String("Unable to assign [undefined] to ") + QLatin1String(QMetaType::typeName(type)));
return false;
} else if (result->IsFunction()) {
- expression->delayedError()->error.setDescription(QLatin1String("Unable to assign a function to a property."));
+ if (!result->ToObject()->GetHiddenValue(v8engine->bindingFlagKey()).IsEmpty())
+ expression->delayedError()->error.setDescription(QLatin1String("Invalid use of Qt.binding() in a binding declaration."));
+ else
+ expression->delayedError()->error.setDescription(QLatin1String("Unable to assign a function to a property of any type other than var."));
return false;
- } else if (isVmeProperty) {
- typedef QQmlVMEMetaObject VMEMO;
- VMEMO *vmemo = static_cast<VMEMO *>(const_cast<QMetaObject *>(object->metaObject()));
- vmemo->setVMEProperty(core.coreIndex, result);
} else if (!writeValueProperty(object, engine, core, value, context, flags)) {
if (watcher.wasDeleted())
@@ -1680,7 +1690,7 @@ bool QQmlProperty::connectNotifySignal(QObject *dest, const char *slot) const
QMetaProperty prop = d->object->metaObject()->property(d->core.coreIndex);
if (prop.hasNotifySignal()) {
- QByteArray signal(QByteArray("2") + prop.notifySignal().signature());
+ QByteArray signal(QByteArray("2") + prop.notifySignal().methodSignature());
return QObject::connect(d->object, signal.constData(), dest, slot);
} else {
return false;
@@ -1786,11 +1796,8 @@ QMetaMethod QQmlPropertyPrivate::findSignalByName(const QMetaObject *mo, const Q
int methods = mo->methodCount();
for (int ii = methods - 1; ii >= 2; --ii) { // >= 2 to block the destroyed signal
QMetaMethod method = mo->method(ii);
- QByteArray methodName = method.signature();
- int idx = methodName.indexOf('(');
- methodName = methodName.left(idx);
- if (methodName == name)
+ if (method.name() == name)
return method;
}
diff --git a/src/qml/qml/qqmlproperty.h b/src/qml/qml/qqmlproperty.h
index 2c4b2544c1..bd2b1d35ba 100644
--- a/src/qml/qml/qqmlproperty.h
+++ b/src/qml/qml/qqmlproperty.h
@@ -136,6 +136,8 @@ inline uint qHash (const QQmlProperty &key)
return qHash(key.object()) + qHash(key.name());
}
+Q_DECLARE_TYPEINFO(QQmlProperty, Q_MOVABLE_TYPE);
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index 93c6aa1f00..af6cd9285b 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -176,19 +176,11 @@ void QQmlPropertyData::load(const QMetaMethod &m)
flags |= IsFunction;
if (m.methodType() == QMetaMethod::Signal)
flags |= IsSignal;
- propType = QVariant::Invalid;
-
- const char *returnType = m.typeName();
- if (returnType)
- propType = QMetaType::type(returnType);
+ propType = m.returnType();
- const char *signature = m.signature();
- while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
-
- ++signature;
- if (*signature != ')') {
+ if (m.parameterCount()) {
flags |= HasArguments;
- if (0 == ::strcmp(signature, "QQmlV8Function*)")) {
+ if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) {
flags |= IsV8Function;
}
}
@@ -212,13 +204,9 @@ void QQmlPropertyData::lazyLoad(const QMetaMethod &m)
flags |= NotFullyResolved;
}
- const char *signature = m.signature();
- while (*signature != '(') { Q_ASSERT(*signature != 0); ++signature; }
-
- ++signature;
- if (*signature != ')') {
+ if (m.parameterCount()) {
flags |= HasArguments;
- if (0 == ::strcmp(signature, "QQmlV8Function*)")) {
+ if ((m.parameterCount() == 1) && (m.parameterTypes().first() == "QQmlV8Function*")) {
flags |= IsV8Function;
}
}
@@ -414,10 +402,17 @@ void QQmlPropertyCache::append(QQmlEngine *engine, const QMetaObject *metaObject
continue;
// Extract method name
- const char *signature = m.signature();
+ const char *signature;
+ if (QMetaObjectPrivate::get(metaObject)->revision >= 7) {
+ // Safe to use the raw name pointer
+ signature = m.name().constData();
+ } else {
+ // Safe to use the raw signature pointer
+ signature = m.methodSignature().constData();
+ }
const char *cptr = signature;
char utf8 = 0;
- while (*cptr != '(') {
+ while (*cptr && *cptr != '(') {
Q_ASSERT(*cptr != 0);
utf8 |= *cptr & 0x80;
++cptr;
@@ -663,11 +658,7 @@ QString QQmlPropertyData::name(const QMetaObject *metaObject)
if (flags & IsFunction) {
QMetaMethod m = metaObject->method(coreIndex);
- QString name = QString::fromUtf8(m.signature());
- int parenIdx = name.indexOf(QLatin1Char('('));
- if (parenIdx != -1)
- name = name.left(parenIdx);
- return name;
+ return QString::fromUtf8(m.name().constData());
} else {
QMetaProperty p = metaObject->property(coreIndex);
return QString::fromUtf8(p.name());
@@ -727,15 +718,19 @@ int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
const QMetaObject *metaObject = object->metaObject();
QMetaMethod m = metaObject->method(index);
- QList<QByteArray> argTypeNames = m.parameterTypes();
- A *args = static_cast<A *>(malloc(sizeof(A) + (argTypeNames.count() + 1) * sizeof(int)));
- args->arguments[0] = argTypeNames.count();
+ int argc = m.parameterCount();
+ A *args = static_cast<A *>(malloc(sizeof(A) + (argc + 1) * sizeof(int)));
+ args->arguments[0] = argc;
+ QList<QByteArray> argTypeNames; // Only loaded if needed
- for (int ii = 0; ii < argTypeNames.count(); ++ii) {
- int type = QMetaType::type(argTypeNames.at(ii));
- if (type == QVariant::Invalid)
+ for (int ii = 0; ii < argc; ++ii) {
+ int type = m.parameterType(ii);
+ if (type == QVariant::Invalid) {
+ if (argTypeNames.isEmpty())
+ argTypeNames = m.parameterTypes();
type = EnumType(object->metaObject(), argTypeNames.at(ii));
+ }
if (type == QVariant::Invalid) {
if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
free(args);
@@ -751,14 +746,18 @@ int *QQmlPropertyCache::methodParameterTypes(QObject *object, int index,
} else {
QMetaMethod m = object->metaObject()->method(index);
- QList<QByteArray> argTypeNames = m.parameterTypes();
- dummy.resize(argTypeNames.count() + 1);
- dummy[0] = argTypeNames.count();
+ int argc = m.parameterCount();
+ dummy.resize(argc + 1);
+ dummy[0] = argc;
+ QList<QByteArray> argTypeNames; // Only loaded if needed
- for (int ii = 0; ii < argTypeNames.count(); ++ii) {
- int type = QMetaType::type(argTypeNames.at(ii));
- if (type == QVariant::Invalid)
+ for (int ii = 0; ii < argc; ++ii) {
+ int type = m.parameterType(ii);
+ if (type == QVariant::Invalid) {
+ if (argTypeNames.isEmpty())
+ argTypeNames = m.parameterTypes();
type = EnumType(object->metaObject(), argTypeNames.at(ii));
+ }
if (type == QVariant::Invalid) {
if (unknownTypeError) *unknownTypeError = argTypeNames.at(ii);
return 0;
@@ -804,13 +803,9 @@ QQmlPropertyData qQmlPropertyCacheCreate(const QMetaObject *metaObject,
QMetaMethod m = metaObject->method(ii);
if (m.access() == QMetaMethod::Private)
continue;
- QString methodName = QString::fromUtf8(m.signature());
-
- int parenIdx = methodName.indexOf(QLatin1Char('('));
- Q_ASSERT(parenIdx != -1);
- QStringRef methodNameRef = methodName.leftRef(parenIdx);
+ QString methodName = QString::fromUtf8(m.name().constData());
- if (methodNameRef == property) {
+ if (methodName == property) {
rv.load(m);
return rv;
}
diff --git a/src/qml/qml/qqmlscript.cpp b/src/qml/qml/qqmlscript.cpp
index 8e22e488ed..e1925eb238 100644
--- a/src/qml/qml/qqmlscript.cpp
+++ b/src/qml/qml/qqmlscript.cpp
@@ -182,33 +182,30 @@ Property *QQmlScript::Object::getProperty(const QString &name, bool create)
}
}
-QQmlScript::Object::DynamicProperty::DynamicProperty()
-: isDefaultProperty(false), isReadOnly(false), type(Variant), defaultValue(0), nextProperty(0),
- resolvedCustomTypeName(0)
+int QQmlScript::Object::aggregateDynamicSignalParameterCount() const
{
+ int sum = 0;
+ for (DynamicSignal *s = dynamicSignals.first(); s; s = dynamicSignals.next(s))
+ sum += s->parameterTypes.count() + 1; // +1 for return type
+ return sum;
}
-QQmlScript::Object::DynamicSignal::DynamicSignal()
-: nextSignal(0)
+int QQmlScript::Object::aggregateDynamicSlotParameterCount() const
{
+ int sum = 0;
+ for (DynamicSlot *s = dynamicSlots.first(); s; s = dynamicSlots.next(s))
+ sum += s->parameterNames.count() + 1; // +1 for return type
+ return sum;
}
-// Returns length in utf8 bytes
-int QQmlScript::Object::DynamicSignal::parameterTypesLength() const
+QQmlScript::Object::DynamicProperty::DynamicProperty()
+: isDefaultProperty(false), isReadOnly(false), type(Variant), defaultValue(0), nextProperty(0)
{
- int rv = 0;
- for (int ii = 0; ii < parameterTypes.count(); ++ii)
- rv += parameterTypes.at(ii).length();
- return rv;
}
-// Returns length in utf8 bytes
-int QQmlScript::Object::DynamicSignal::parameterNamesLength() const
+QQmlScript::Object::DynamicSignal::DynamicSignal()
+: nextSignal(0)
{
- int rv = 0;
- for (int ii = 0; ii < parameterNames.count(); ++ii)
- rv += parameterNames.at(ii).utf8length();
- return rv;
}
QQmlScript::Object::DynamicSlot::DynamicSlot()
@@ -919,25 +916,23 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
const char *name;
int nameLength;
Object::DynamicProperty::Type type;
- const char *qtName;
- int qtNameLength;
} propTypeNameToTypes[] = {
- { "int", strlen("int"), Object::DynamicProperty::Int, "int", strlen("int") },
- { "bool", strlen("bool"), Object::DynamicProperty::Bool, "bool", strlen("bool") },
- { "double", strlen("double"), Object::DynamicProperty::Real, "double", strlen("double") },
- { "real", strlen("real"), Object::DynamicProperty::Real, "double", strlen("double") },
- { "string", strlen("string"), Object::DynamicProperty::String, "QString", strlen("QString") },
- { "url", strlen("url"), Object::DynamicProperty::Url, "QUrl", strlen("QUrl") },
- { "color", strlen("color"), Object::DynamicProperty::Color, "QColor", strlen("QColor") },
+ { "int", strlen("int"), Object::DynamicProperty::Int },
+ { "bool", strlen("bool"), Object::DynamicProperty::Bool },
+ { "double", strlen("double"), Object::DynamicProperty::Real },
+ { "real", strlen("real"), Object::DynamicProperty::Real },
+ { "string", strlen("string"), Object::DynamicProperty::String },
+ { "url", strlen("url"), Object::DynamicProperty::Url },
+ { "color", strlen("color"), Object::DynamicProperty::Color },
// Internally QTime, QDate and QDateTime are all supported.
// To be more consistent with JavaScript we expose only
// QDateTime as it matches closely with the Date JS type.
// We also call it "date" to match.
- // { "time", strlen("time"), Object::DynamicProperty::Time, "QTime", strlen("QTime") },
- // { "date", strlen("date"), Object::DynamicProperty::Date, "QDate", strlen("QDate") },
- { "date", strlen("date"), Object::DynamicProperty::DateTime, "QDateTime", strlen("QDateTime") },
- { "variant", strlen("variant"), Object::DynamicProperty::Variant, "QVariant", strlen("QVariant") },
- { "var", strlen("var"), Object::DynamicProperty::Var, "QVariant", strlen("QVariant") }
+ // { "time", strlen("time"), Object::DynamicProperty::Time },
+ // { "date", strlen("date"), Object::DynamicProperty::Date },
+ { "date", strlen("date"), Object::DynamicProperty::DateTime },
+ { "variant", strlen("variant"), Object::DynamicProperty::Variant },
+ { "var", strlen("var"), Object::DynamicProperty::Var }
};
static const int propTypeNameToTypesCount = sizeof(propTypeNameToTypes) /
sizeof(propTypeNameToTypes[0]);
@@ -952,7 +947,7 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
p = node->parameters;
if (paramLength) {
- signal->parameterTypes = _parser->_pool.NewRawList<QHashedCStringRef>(paramLength);
+ signal->parameterTypes = _parser->_pool.NewRawList<Object::DynamicProperty::Type>(paramLength);
signal->parameterNames = _parser->_pool.NewRawList<QHashedStringRef>(paramLength);
}
@@ -979,7 +974,7 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
return false;
}
- signal->parameterTypes[index] = QHashedCStringRef(type->qtName, type->qtNameLength);
+ signal->parameterTypes[index] = type->type;
signal->parameterNames[index] = QHashedStringRef(p->name);
p = p->next;
index++;
diff --git a/src/qml/qml/qqmlscript_p.h b/src/qml/qml/qqmlscript_p.h
index ddf4c9a392..8705f2aef9 100644
--- a/src/qml/qml/qqmlscript_p.h
+++ b/src/qml/qml/qqmlscript_p.h
@@ -406,10 +406,8 @@ public:
DynamicProperty *nextProperty;
// Used by the compiler
- QByteArray *resolvedCustomTypeName;
- QFastMetaBuilder::StringRef typeRef;
QFastMetaBuilder::StringRef nameRef;
- QFastMetaBuilder::StringRef changedSignatureRef;
+ QFastMetaBuilder::StringRef changedNameRef;
};
struct DynamicSignal : public QQmlPool::POD
@@ -417,18 +415,15 @@ public:
DynamicSignal();
QHashedStringRef name;
- QQmlPool::List<QHashedCStringRef> parameterTypes;
+ QQmlPool::List<DynamicProperty::Type> parameterTypes;
QQmlPool::List<QHashedStringRef> parameterNames;
- int parameterTypesLength() const;
- int parameterNamesLength() const;
-
// Used by Object::DynamicSignalList
DynamicSignal *nextSignal;
// Used by the compiler
- QFastMetaBuilder::StringRef signatureRef;
- QFastMetaBuilder::StringRef parameterNamesRef;
+ QFastMetaBuilder::StringRef nameRef;
+ QQmlPool::List<QFastMetaBuilder::StringRef> parameterNamesRef;
LocationSpan location;
};
@@ -447,8 +442,8 @@ public:
DynamicSlot *nextSlot;
// Used by the compiler
- QFastMetaBuilder::StringRef signatureRef;
- QFastMetaBuilder::StringRef parameterNamesRef;
+ QFastMetaBuilder::StringRef nameRef;
+ QQmlPool::List<QFastMetaBuilder::StringRef> parameterNamesRef;
};
// The list of dynamic properties
@@ -461,6 +456,9 @@ public:
typedef QFieldList<DynamicSlot, &DynamicSlot::nextSlot> DynamicSlotList;
DynamicSlotList dynamicSlots;
+ int aggregateDynamicSignalParameterCount() const;
+ int aggregateDynamicSlotParameterCount() const;
+
// Used by compiler
QQmlCompilerTypes::ComponentCompileState *componentCompileState;
diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp
index 2a7ea45053..86e9f0963a 100644
--- a/src/qml/qml/qqmlvme.cpp
+++ b/src/qml/qml/qqmlvme.cpp
@@ -690,11 +690,14 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
if (prop.type() & QQmlProperty::SignalProperty) {
QMetaMethod method = QQmlMetaType::defaultMethod(assign);
- if (method.signature() == 0)
+ if (!method.isValid())
VME_EXCEPTION(tr("Cannot assign object type %1 with no default method").arg(QString::fromLatin1(assign->metaObject()->className())), instr.line);
- if (!QMetaObject::checkConnectArgs(prop.method().signature(), method.signature()))
- VME_EXCEPTION(tr("Cannot connect mismatched signal/slot %1 %vs. %2").arg(QString::fromLatin1(method.signature())).arg(QString::fromLatin1(prop.method().signature())), instr.line);
+ if (!QMetaObject::checkConnectArgs(prop.method(), method)) {
+ VME_EXCEPTION(tr("Cannot connect mismatched signal/slot %1 %vs. %2")
+ .arg(QString::fromLatin1(method.methodSignature().constData()))
+ .arg(QString::fromLatin1(prop.method().methodSignature().constData())), instr.line);
+ }
QQmlPropertyPrivate::connect(target, prop.index(), assign, method.methodIndex());
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index cc4ba091ce..c4e801f2db 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -760,7 +760,7 @@ int QQmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a)
// performance reasons; see QTBUG-24064) and thus compilation will have failed.
QQmlError e;
e.setDescription(QString(QLatin1String("Exception occurred during compilation of function: %1")).
- arg(QLatin1String(QMetaObject::method(_id).signature())));
+ arg(QLatin1String(QMetaObject::method(_id).methodSignature().constData())));
ep->warning(e);
return -1; // The dynamic method with that id is not available.
}
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
index b9f2b627da..68c62ef240 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp
@@ -1333,6 +1333,65 @@ v8::Handle<v8::Value> locale(const v8::Arguments &args)
return QQmlLocale::locale(v8engine, code);
}
+/*!
+ \qmlmethod Qt::binding(function)
+
+ Returns a JS object representing a binding expression which may be
+ assigned to any property in imperative code to cause a binding
+ assignment.
+
+ There are two main use-cases for the function: firstly, in imperative
+ JavaScript code to cause a binding assignment:
+
+ \snippet doc/src/snippets/declarative/qtBinding.1.qml 0
+
+ and secondly, when defining initial property values of dynamically
+ constructed objects (via Component.createObject() or
+ Loader.setSource()) as being bound to the result of an expression.
+
+ For example, assuming the existence of a DynamicText component:
+ \snippet doc/src/snippets/declarative/DynamicText.qml 0
+
+ the output from:
+ \snippet doc/src/snippets/declarative/qtBinding.2.qml 0
+
+ and from:
+ \snippet doc/src/snippets/declarative/qtBinding.3.qml 0
+
+ should both be:
+ \code
+ Root text extra text
+ Modified root text extra text
+ Dynamic text extra text
+ Modified dynamic text extra text
+ \endcode
+
+ This function cannot be used in property binding declarations
+ (see the documentation on \l{qml-javascript-assignment}{binding
+ declarations and binding assignments}) except when the result is
+ stored in an array bound to a var property.
+
+ \snippet doc/src/snippets/declarative/qtBinding.4.qml 0
+
+ Note: in QtQuick 1.x, all function assignment was treated as
+ binding assignment, so the Qt.binding() function is new in
+ QtQuick 2.0.
+
+ \since QtQuick 2.0
+*/
+v8::Handle<v8::Value> binding(const v8::Arguments &args)
+{
+ QString code;
+ if (args.Length() != 1)
+ V8THROW_ERROR("binding() requires 1 argument");
+ if (!args[0]->IsFunction())
+ V8THROW_TYPE("binding(): argument (binding expression) must be a function");
+
+ v8::Handle<v8::Object> rv = args[0]->ToObject()->Clone();
+ rv->SetHiddenValue(V8ENGINE()->bindingFlagKey(), v8::Boolean::New(true));
+ return rv;
+}
+
} // namespace QQmlBuiltinFunctions
QT_END_NAMESPACE
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
index ddb1c64243..bbfe88a292 100644
--- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
+++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h
@@ -103,6 +103,7 @@ v8::Handle<v8::Value> qsTrId(const v8::Arguments &args);
v8::Handle<v8::Value> qsTrIdNoOp(const v8::Arguments &args);
v8::Handle<v8::Value> stringArg(const v8::Arguments &args);
v8::Handle<v8::Value> locale(const v8::Arguments &args);
+v8::Handle<v8::Value> binding(const v8::Arguments &args);
}
QT_END_NAMESPACE
diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp
index 8e8223fea1..ab3283f727 100644
--- a/src/qml/qml/v8/qv8engine.cpp
+++ b/src/qml/qml/v8/qv8engine.cpp
@@ -147,6 +147,8 @@ QV8Engine::QV8Engine(QJSEngine* qq, QJSEngine::ContextOwnership ownership)
QV8GCCallback::registerGcPrologueCallback();
m_strongReferencer = qPersistentNew(v8::Object::New());
+ m_bindingFlagKey = qPersistentNew(v8::String::New("qml::binding"));
+
m_stringWrapper.init();
m_contextWrapper.init(this);
m_qobjectWrapper.init(this);
@@ -191,6 +193,8 @@ QV8Engine::~QV8Engine()
m_contextWrapper.destroy();
m_stringWrapper.destroy();
+ qPersistentDispose(m_bindingFlagKey);
+
m_originalGlobalObject.destroy();
if (m_ownsV8Context)
@@ -314,6 +318,7 @@ v8::Handle<v8::Value> QV8Engine::fromVariant(const QVariant &variant)
if (type < QMetaType::User) {
switch (QMetaType::Type(type)) {
+ case QMetaType::UnknownType:
case QMetaType::Void:
return v8::Undefined();
case QMetaType::Bool:
@@ -598,6 +603,7 @@ void QV8Engine::initializeGlobal(v8::Handle<v8::Object> global)
qt->Set(v8::String::New("atob"), V8FUNCTION(atob, this));
qt->Set(v8::String::New("resolvedUrl"), V8FUNCTION(resolvedUrl, this));
qt->Set(v8::String::New("locale"), V8FUNCTION(locale, this));
+ qt->Set(v8::String::New("binding"), V8FUNCTION(binding, this));
if (m_engine) {
qt->Set(v8::String::New("application"), newQObject(new QQuickApplication(m_engine)));
@@ -1112,6 +1118,7 @@ v8::Handle<v8::Value> QV8Engine::metaTypeToJS(int type, const void *data)
// check if it's one of the types we know
switch (QMetaType::Type(type)) {
+ case QMetaType::UnknownType:
case QMetaType::Void:
return v8::Undefined();
case QMetaType::Bool:
diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h
index bc57b27085..825d7a3583 100644
--- a/src/qml/qml/v8/qv8engine_p.h
+++ b/src/qml/qml/v8/qv8engine_p.h
@@ -357,6 +357,9 @@ public:
// a QVariant wrapper
inline v8::Handle<v8::Value> newQVariant(const QVariant &);
+ // Return the JS string key for the "function is a binding" flag
+ inline v8::Handle<v8::String> bindingFlagKey() const;
+
// Return the network access manager for this engine. By default this returns the network
// access manager of the QQmlEngine. It is overridden in the case of a threaded v8
// instance (like in WorkerScript).
@@ -461,6 +464,8 @@ protected:
v8::Persistent<v8::Context> m_context;
QScriptOriginalGlobalObject m_originalGlobalObject;
+ v8::Persistent<v8::String> m_bindingFlagKey;
+
QV8StringWrapper m_stringWrapper;
QV8ContextWrapper m_contextWrapper;
QV8QObjectWrapper m_qobjectWrapper;
@@ -609,6 +614,11 @@ v8::Handle<v8::Value> QV8Engine::newSequence(int sequenceType, QObject *object,
return m_sequenceWrapper.newSequence(sequenceType, object, property, succeeded);
}
+v8::Handle<v8::String> QV8Engine::bindingFlagKey() const
+{
+ return m_bindingFlagKey;
+}
+
// XXX Can this be made more optimal? It is called prior to resolving each and every
// unqualified name in QV8ContextWrapper.
bool QV8Engine::startsWithUpper(v8::Handle<v8::String> string)
diff --git a/src/qml/qml/v8/qv8qobjectwrapper.cpp b/src/qml/qml/v8/qv8qobjectwrapper.cpp
index 3faea2c97b..2350b9dc2c 100644
--- a/src/qml/qml/v8/qv8qobjectwrapper.cpp
+++ b/src/qml/qml/v8/qv8qobjectwrapper.cpp
@@ -449,7 +449,7 @@ static v8::Handle<v8::Value> LoadProperty(QV8Engine *engine, QObject *object,
return retn;
}
- if (property.propType == QVariant::Invalid) {
+ if (property.propType == QMetaType::UnknownType) {
QMetaProperty p = object->metaObject()->property(property.coreIndex);
qWarning("QMetaProperty::read: Unable to handle unregistered datatype '%s' for property "
"'%s::%s'", p.typeName(), object->metaObject()->className(), p.name());
@@ -519,7 +519,7 @@ v8::Handle<v8::Value> QV8QObjectWrapper::GetProperty(QV8Engine *engine, QObject
return v8::Handle<v8::Value>();
}
- if (result->isFunction()) {
+ if (result->isFunction() && !result->isVMEProperty()) {
if (result->isVMEFunction()) {
return ((QQmlVMEMetaObject *)(object->metaObject()))->vmeMethod(result->coreIndex);
} else if (result->isV8Function()) {
@@ -579,23 +579,53 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QQmlPropert
v8::Handle<v8::Value> value)
{
QQmlBinding *newBinding = 0;
-
if (value->IsFunction()) {
- QQmlContextData *context = engine->callingContext();
- v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(value);
-
- v8::Local<v8::StackTrace> trace =
- v8::StackTrace::CurrentStackTrace(1, (v8::StackTrace::StackTraceOptions)(v8::StackTrace::kLineNumber |
- v8::StackTrace::kScriptName));
- v8::Local<v8::StackFrame> frame = trace->GetFrame(0);
- int lineNumber = frame->GetLineNumber();
- int columnNumber = frame->GetColumn();
- QString url = engine->toString(frame->GetScriptName());
-
- newBinding = new QQmlBinding(&function, object, context, url, lineNumber, columnNumber);
- newBinding->setTarget(object, *property, context);
- newBinding->setEvaluateFlags(newBinding->evaluateFlags() |
- QQmlBinding::RequiresThisObject);
+ if (value->ToObject()->GetHiddenValue(engine->bindingFlagKey()).IsEmpty()) {
+ if (!property->isVMEProperty()) {
+ // XXX TODO: uncomment the following lines
+ // assigning a JS function to a non-var-property is not allowed.
+ //QString error = QLatin1String("Cannot assign JavaScript function to ") +
+ // QLatin1String(QMetaType::typeName(property->propType));
+ //v8::ThrowException(v8::Exception::Error(engine->toString(error)));
+ //return;
+ // XXX TODO: remove the following transition behaviour
+ // Temporarily allow assignment of functions to non-var properties
+ // to mean binding assignment (as per old behaviour).
+ QQmlContextData *context = engine->callingContext();
+ v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(value);
+
+ v8::Local<v8::StackTrace> trace =
+ v8::StackTrace::CurrentStackTrace(1, (v8::StackTrace::StackTraceOptions)(v8::StackTrace::kLineNumber |
+ v8::StackTrace::kScriptName));
+ v8::Local<v8::StackFrame> frame = trace->GetFrame(0);
+ int lineNumber = frame->GetLineNumber();
+ int columnNumber = frame->GetColumn();
+ QString url = engine->toString(frame->GetScriptName());
+
+ newBinding = new QQmlBinding(&function, object, context, url, lineNumber, columnNumber);
+ newBinding->setTarget(object, *property, context);
+ newBinding->setEvaluateFlags(newBinding->evaluateFlags() |
+ QQmlBinding::RequiresThisObject);
+ qWarning("WARNING: function assignment is DEPRECATED and will be removed! Wrap RHS in Qt.binding(): %s:%d", qPrintable(engine->toString(frame->GetScriptName())), frame->GetLineNumber());
+ }
+ } else {
+ // binding assignment.
+ QQmlContextData *context = engine->callingContext();
+ v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(value);
+
+ v8::Local<v8::StackTrace> trace =
+ v8::StackTrace::CurrentStackTrace(1, (v8::StackTrace::StackTraceOptions)(v8::StackTrace::kLineNumber |
+ v8::StackTrace::kScriptName));
+ v8::Local<v8::StackFrame> frame = trace->GetFrame(0);
+ int lineNumber = frame->GetLineNumber();
+ int columnNumber = frame->GetColumn();
+ QString url = engine->toString(frame->GetScriptName());
+
+ newBinding = new QQmlBinding(&function, object, context, url, lineNumber, columnNumber);
+ newBinding->setTarget(object, *property, context);
+ newBinding->setEvaluateFlags(newBinding->evaluateFlags() |
+ QQmlBinding::RequiresThisObject);
+ }
}
QQmlAbstractBinding *oldBinding =
@@ -603,6 +633,12 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QQmlPropert
if (oldBinding)
oldBinding->destroy();
+ if (!newBinding && property->isVMEProperty()) {
+ // allow assignment of "special" values (null, undefined, function) to var properties
+ static_cast<QQmlVMEMetaObject *>(const_cast<QMetaObject *>(object->metaObject()))->setVMEProperty(property->coreIndex, value);
+ return;
+ }
+
#define PROPERTY_STORE(cpptype, value) \
cpptype o = value; \
int status = -1; \
@@ -649,10 +685,14 @@ static inline void StoreProperty(QV8Engine *engine, QObject *object, QQmlPropert
if (v.userType() == QVariant::Invalid) valueType = "null";
else valueType = QMetaType::typeName(v.userType());
+ const char *targetTypeName = QMetaType::typeName(property->propType);
+ if (!targetTypeName)
+ targetTypeName = "an unregistered type";
+
QString error = QLatin1String("Cannot assign ") +
QLatin1String(valueType) +
QLatin1String(" to ") +
- QLatin1String(QMetaType::typeName(property->propType));
+ QLatin1String(targetTypeName);
v8::ThrowException(v8::Exception::Error(engine->toString(error)));
}
}
@@ -1640,16 +1680,6 @@ static inline int QMetaObject_methods(const QMetaObject *metaObject)
return reinterpret_cast<const Private *>(metaObject->d.data)->methodCount;
}
-static QByteArray QMetaMethod_name(const QMetaMethod &m)
-{
- QByteArray sig = m.signature();
- int paren = sig.indexOf('(');
- if (paren == -1)
- return sig;
- else
- return sig.left(paren);
-}
-
/*!
Returns the next related method, if one, or 0.
*/
@@ -1678,9 +1708,9 @@ static const QQmlPropertyData * RelatedMethod(QObject *object,
dummy.load(method);
// Look for overloaded methods
- QByteArray methodName = QMetaMethod_name(method);
+ QByteArray methodName = method.name();
for (int ii = current->overrideIndex - 1; ii >= methodOffset; --ii) {
- if (methodName == QMetaMethod_name(mo->method(ii))) {
+ if (methodName == mo->method(ii).name()) {
dummy.setFlags(dummy.getFlags() | QQmlPropertyData::IsOverload);
dummy.overrideIndexIsProperty = 0;
dummy.overrideIndex = ii;
@@ -1794,7 +1824,7 @@ static v8::Handle<v8::Value> CallOverloaded(QObject *object, const QQmlPropertyD
const QQmlPropertyData *candidate = &data;
while (candidate) {
error += QLatin1String("\n ") +
- QString::fromUtf8(object->metaObject()->method(candidate->coreIndex).signature());
+ QString::fromUtf8(object->metaObject()->method(candidate->coreIndex).methodSignature().constData());
candidate = RelatedMethod(object, candidate, dummy);
}
@@ -1963,7 +1993,7 @@ void *CallArgument::dataPtr()
void CallArgument::initAsType(int callType)
{
if (type != 0) { cleanup(); type = 0; }
- if (callType == 0) return;
+ if (callType == QMetaType::UnknownType) return;
if (callType == qMetaTypeId<QJSValue>()) {
qjsValuePtr = new (&allocData) QJSValue();
@@ -1989,6 +2019,9 @@ void CallArgument::initAsType(int callType)
} else if (callType == qMetaTypeId<QQmlV8Handle>()) {
type = callType;
handlePtr = new (&allocData) QQmlV8Handle;
+ } else if (callType == QMetaType::Void) {
+ type = -1;
+ qvariantPtr = new (&allocData) QVariant();
} else {
type = -1;
qvariantPtr = new (&allocData) QVariant(callType, (void *)0);
@@ -2043,6 +2076,8 @@ void CallArgument::fromValue(int callType, QV8Engine *engine, v8::Handle<v8::Val
} else if (callType == qMetaTypeId<QQmlV8Handle>()) {
handlePtr = new (&allocData) QQmlV8Handle(QQmlV8Handle::fromHandle(value));
type = callType;
+ } else if (callType == QMetaType::Void) {
+ *qvariantPtr = QVariant();
} else {
qvariantPtr = new (&allocData) QVariant();
type = -1;
diff --git a/src/qml/qml/v8/qv8valuetypewrapper.cpp b/src/qml/qml/v8/qv8valuetypewrapper.cpp
index 7a3c675d49..cf2c13fce9 100644
--- a/src/qml/qml/v8/qv8valuetypewrapper.cpp
+++ b/src/qml/qml/v8/qv8valuetypewrapper.cpp
@@ -324,6 +324,13 @@ v8::Handle<v8::Value> QV8ValueTypeWrapper::Setter(v8::Local<v8::String> property
QQmlBinding *newBinding = 0;
if (value->IsFunction()) {
+ if (value->ToObject()->GetHiddenValue(r->engine->bindingFlagKey()).IsEmpty()) {
+ // assigning a JS function to a non-var-property is not allowed.
+ QString error = QLatin1String("Cannot assign JavaScript function to value-type property");
+ v8::ThrowException(v8::Exception::Error(r->engine->toString(error)));
+ return value;
+ }
+
QQmlContextData *context = r->engine->callingContext();
v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(value);
diff --git a/src/quick/items/qquickcanvas.cpp b/src/quick/items/qquickcanvas.cpp
index a6c2a90407..cd3bbbfa2a 100644
--- a/src/quick/items/qquickcanvas.cpp
+++ b/src/quick/items/qquickcanvas.cpp
@@ -1711,7 +1711,7 @@ void QQuickCanvasPrivate::updateDirtyNode(QQuickItem *item)
if (item->clip()) {
Q_ASSERT(itemPriv->clipNode() == 0);
- itemPriv->extra.value().clipNode = new QQuickDefaultClipNode(item->boundingRect());
+ itemPriv->extra.value().clipNode = new QQuickDefaultClipNode(item->clipRect());
itemPriv->clipNode()->update();
if (child)
@@ -1803,7 +1803,7 @@ void QQuickCanvasPrivate::updateDirtyNode(QQuickItem *item)
}
if ((dirty & QQuickItemPrivate::Size) && itemPriv->clipNode()) {
- itemPriv->clipNode()->setRect(item->boundingRect());
+ itemPriv->clipNode()->setRect(item->clipRect());
itemPriv->clipNode()->update();
}
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 2d84b43008..423fb0f40c 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -3647,13 +3647,20 @@ void QQuickItem::updateInputMethod(Qt::InputMethodQueries queries)
/*! \internal */
// XXX todo - do we want/need this anymore?
-// Note that it's now used for varying clip rect
QRectF QQuickItem::boundingRect() const
{
Q_D(const QQuickItem);
return QRectF(0, 0, d->width, d->height);
}
+/*! \internal */
+QRectF QQuickItem::clipRect() const
+{
+ Q_D(const QQuickItem);
+ return QRectF(0, 0, d->width, d->height);
+}
+
+
QQuickItem::TransformOrigin QQuickItem::transformOrigin() const
{
Q_D(const QQuickItem);
@@ -5831,7 +5838,7 @@ void QQuickItemLayer::updateGeometry()
{
QQuickItem *l = m_effect ? (QQuickItem *) m_effect : (QQuickItem *) m_effectSource;
Q_ASSERT(l);
- QRectF bounds = m_item->boundingRect();
+ QRectF bounds = m_item->clipRect();
l->setWidth(bounds.width());
l->setHeight(bounds.height());
l->setX(bounds.x() + m_item->x());
diff --git a/src/quick/items/qquickitem.h b/src/quick/items/qquickitem.h
index c44192bd3a..f14d60b028 100644
--- a/src/quick/items/qquickitem.h
+++ b/src/quick/items/qquickitem.h
@@ -266,6 +266,7 @@ public:
void setFlags(Flags flags);
virtual QRectF boundingRect() const;
+ virtual QRectF clipRect() const;
bool hasActiveFocus() const;
bool hasFocus() const;
diff --git a/src/quick/items/qquickrectangle.cpp b/src/quick/items/qquickrectangle.cpp
index 062df127b3..13c101d8a2 100644
--- a/src/quick/items/qquickrectangle.cpp
+++ b/src/quick/items/qquickrectangle.cpp
@@ -553,4 +553,9 @@ QRectF QQuickRectangle::boundingRect() const
d->width + 2 * d->penMargin, d->height + 2 * d->penMargin);
}
+QRectF QQuickRectangle::clipRect() const
+{
+ return QQuickRectangle::boundingRect();
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/items/qquickrectangle_p.h b/src/quick/items/qquickrectangle_p.h
index eec2b56fd3..52aa9e81f9 100644
--- a/src/quick/items/qquickrectangle_p.h
+++ b/src/quick/items/qquickrectangle_p.h
@@ -159,6 +159,7 @@ public:
void setRadius(qreal radius);
virtual QRectF boundingRect() const;
+ virtual QRectF clipRect() const;
Q_SIGNALS:
void colorChanged();
diff --git a/src/quick/items/qquickshadereffect.cpp b/src/quick/items/qquickshadereffect.cpp
index 77047257c3..d7eedd42b6 100644
--- a/src/quick/items/qquickshadereffect.cpp
+++ b/src/quick/items/qquickshadereffect.cpp
@@ -458,7 +458,7 @@ void QQuickShaderEffect::connectPropertySignals()
if (!mp.hasNotifySignal())
qWarning("QQuickShaderEffect: property '%s' does not have notification method!", it->constData());
QByteArray signalName("2");
- signalName.append(mp.notifySignal().signature());
+ signalName.append(mp.notifySignal().methodSignature());
connect(this, signalName, this, SLOT(updateData()));
} else {
// If the source is set via a dynamic property, like the layer is, then we need this check
@@ -474,7 +474,7 @@ void QQuickShaderEffect::connectPropertySignals()
if (pi >= 0) {
QMetaProperty mp = metaObject()->property(pi);
QByteArray signalName("2");
- signalName.append(mp.notifySignal().signature());
+ signalName.append(mp.notifySignal().methodSignature());
connect(this, signalName, source.mapper, SLOT(map()));
source.mapper->setMapping(this, i);
connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
diff --git a/src/quick/particles/qquickcustomparticle.cpp b/src/quick/particles/qquickcustomparticle.cpp
index 3647e5bfc5..a8f146ad05 100644
--- a/src/quick/particles/qquickcustomparticle.cpp
+++ b/src/quick/particles/qquickcustomparticle.cpp
@@ -314,7 +314,7 @@ void QQuickCustomParticle::connectPropertySignals()
if (!mp.hasNotifySignal())
qWarning("QQuickCustomParticle: property '%s' does not have notification method!", it->constData());
QByteArray signalName("2");
- signalName.append(mp.notifySignal().signature());
+ signalName.append(mp.notifySignal().methodSignature());
connect(this, signalName, this, SLOT(updateData()));
} else {
qWarning("QQuickCustomParticle: '%s' does not have a matching property!", it->constData());
@@ -326,7 +326,7 @@ void QQuickCustomParticle::connectPropertySignals()
if (pi >= 0) {
QMetaProperty mp = metaObject()->property(pi);
QByteArray signalName("2");
- signalName.append(mp.notifySignal().signature());
+ signalName.append(mp.notifySignal().methodSignature());
connect(this, signalName, source.mapper, SLOT(map()));
source.mapper->setMapping(this, i);
connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp
index 6eae5c3abd..02fbaa1a7f 100644
--- a/src/quick/scenegraph/qsgcontext.cpp
+++ b/src/quick/scenegraph/qsgcontext.cpp
@@ -55,7 +55,6 @@
#include <QGuiApplication>
#include <QOpenGLContext>
-#include <QQmlImageProvider>
#include <private/qqmlglobal_p.h>
#include <QtQuick/private/qsgtexture_p.h>
diff --git a/src/quick/scenegraph/qsgcontextplugin_p.h b/src/quick/scenegraph/qsgcontextplugin_p.h
index cc7761a095..2c4531c239 100644
--- a/src/quick/scenegraph/qsgcontextplugin_p.h
+++ b/src/quick/scenegraph/qsgcontextplugin_p.h
@@ -43,11 +43,10 @@
#define QSGCONTEXTPLUGIN_H
#include <QtQuick/qtquickglobal.h>
+#include <QtQuick/qquickimageprovider.h>
#include <QtCore/qplugin.h>
#include <QtCore/qfactoryinterface.h>
-#include <QQmlImageProvider>
-
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
diff --git a/src/qml/qml/qqmlimageprovider.cpp b/src/quick/util/qquickimageprovider.cpp
index d1afa54498..a5d2720cea 100644
--- a/src/qml/qml/qqmlimageprovider.cpp
+++ b/src/quick/util/qquickimageprovider.cpp
@@ -39,14 +39,14 @@
**
****************************************************************************/
-#include "qqmlimageprovider.h"
+#include "qquickimageprovider.h"
QT_BEGIN_NAMESPACE
-class QQmlImageProviderPrivate
+class QQuickImageProviderPrivate
{
public:
- QQmlImageProvider::ImageType type;
+ QQuickImageProvider::ImageType type;
};
/*!
@@ -109,11 +109,11 @@ QImage QQuickTextureFactory::image() const
/*!
- \class QQmlImageProvider
+ \class QQuickImageProvider
\since 4.7
- \brief The QQmlImageProvider class provides an interface for supporting pixmaps and threaded image requests in QML.
+ \brief The QQuickImageProvider class provides an interface for supporting pixmaps and threaded image requests in QML.
- QQmlImageProvider is used to provide advanced image loading features
+ QQuickImageProvider is used to provide advanced image loading features
in QML applications. It allows images in QML to be:
\list
@@ -210,7 +210,7 @@ QImage QQuickTextureFactory::image() const
\section2 Image caching
- Images returned by a QQmlImageProvider are automatically cached,
+ Images returned by a QQuickImageProvider are automatically cached,
similar to any image loaded by the QML engine. When an image with a
"image://" prefix is loaded from cache, requestImage() and requestPixmap()
will not be called for the relevant image provider. If an image should always
@@ -222,7 +222,7 @@ QImage QQuickTextureFactory::image() const
*/
/*!
- \enum QQmlImageProvider::ImageType
+ \enum QQuickImageProvider::ImageType
Defines the type of image supported by this image provider.
@@ -237,18 +237,18 @@ QImage QQuickTextureFactory::image() const
/*!
Creates an image provider that will provide images of the given \a type.
*/
-QQmlImageProvider::QQmlImageProvider(ImageType type)
- : d(new QQmlImageProviderPrivate)
+QQuickImageProvider::QQuickImageProvider(ImageType type)
+ : d(new QQuickImageProviderPrivate)
{
d->type = type;
}
/*!
- Destroys the QQmlImageProvider
+ Destroys the QQuickImageProvider
\note The destructor of your derived class need to be thread safe.
*/
-QQmlImageProvider::~QQmlImageProvider()
+QQuickImageProvider::~QQuickImageProvider()
{
delete d;
}
@@ -256,7 +256,7 @@ QQmlImageProvider::~QQmlImageProvider()
/*!
Returns the image type supported by this provider.
*/
-QQmlImageProvider::ImageType QQmlImageProvider::imageType() const
+QQuickImageProvider::ImageType QQuickImageProvider::imageType() const
{
return d->type;
}
@@ -280,7 +280,7 @@ QQmlImageProvider::ImageType QQmlImageProvider::imageType() const
\note this method may be called by multiple threads, so ensure the
implementation of this method is reentrant.
*/
-QImage QQmlImageProvider::requestImage(const QString &id, QSize *size, const QSize& requestedSize)
+QImage QQuickImageProvider::requestImage(const QString &id, QSize *size, const QSize& requestedSize)
{
Q_UNUSED(id);
Q_UNUSED(size);
@@ -306,7 +306,7 @@ QImage QQmlImageProvider::requestImage(const QString &id, QSize *size, const QSi
is used to set the \l {Item::}{width} and \l {Item::}{height} of the
relevant \l Image if these values have not been set explicitly.
*/
-QPixmap QQmlImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
+QPixmap QQuickImageProvider::requestPixmap(const QString &id, QSize *size, const QSize& requestedSize)
{
Q_UNUSED(id);
Q_UNUSED(size);
@@ -337,7 +337,7 @@ QPixmap QQmlImageProvider::requestPixmap(const QString &id, QSize *size, const Q
implementation of this method is reentrant.
*/
-QQuickTextureFactory *QQmlImageProvider::requestTexture(const QString &id, QSize *size, const QSize &requestedSize)
+QQuickTextureFactory *QQuickImageProvider::requestTexture(const QString &id, QSize *size, const QSize &requestedSize)
{
Q_UNUSED(id);
Q_UNUSED(size);
diff --git a/src/qml/qml/qqmlimageprovider.h b/src/quick/util/qquickimageprovider.h
index da4d8c8248..2a5d146124 100644
--- a/src/qml/qml/qqmlimageprovider.h
+++ b/src/quick/util/qquickimageprovider.h
@@ -39,23 +39,24 @@
**
****************************************************************************/
-#ifndef QQMLIMAGEPROVIDER_H
-#define QQMLIMAGEPROVIDER_H
+#ifndef QQUICKIMAGEPROVIDER_H
+#define QQUICKIMAGEPROVIDER_H
-#include <QtQml/qtqmlglobal.h>
+#include <QtQuick/qtquickglobal.h>
#include <QtGui/qimage.h>
#include <QtGui/qpixmap.h>
+#include <QtQml/qqmlengine.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-class QQmlImageProviderPrivate;
+class QQuickImageProviderPrivate;
class QSGTexture;
class QQuickCanvas;
-class Q_QML_EXPORT QQuickTextureFactory : public QObject
+class Q_QUICK_EXPORT QQuickTextureFactory : public QObject
{
public:
QQuickTextureFactory();
@@ -67,7 +68,7 @@ public:
virtual QImage image() const;
};
-class Q_QML_EXPORT QQmlImageProvider
+class Q_QUICK_EXPORT QQuickImageProvider : public QQmlImageProviderBase
{
public:
enum ImageType {
@@ -77,8 +78,8 @@ public:
Invalid
};
- QQmlImageProvider(ImageType type);
- virtual ~QQmlImageProvider();
+ QQuickImageProvider(ImageType type);
+ virtual ~QQuickImageProvider();
ImageType imageType() const;
@@ -87,11 +88,11 @@ public:
virtual QQuickTextureFactory *requestTexture(const QString &id, QSize *size, const QSize &requestedSize);
private:
- QQmlImageProviderPrivate *d;
+ QQuickImageProviderPrivate *d;
};
QT_END_NAMESPACE
QT_END_HEADER
-#endif // QQMLIMAGEPROVIDER
+#endif // QQUICKIMAGEPROVIDER_H
diff --git a/src/quick/util/qquickpixmapcache.cpp b/src/quick/util/qquickpixmapcache.cpp
index 9185fba343..801b007cdd 100644
--- a/src/quick/util/qquickpixmapcache.cpp
+++ b/src/quick/util/qquickpixmapcache.cpp
@@ -41,7 +41,7 @@
#include "qquickpixmapcache_p.h"
#include <qqmlnetworkaccessmanagerfactory.h>
-#include <qqmlimageprovider.h>
+#include <qquickimageprovider.h>
#include <qqmlengine.h>
#include <private/qqmlglobal_p.h>
@@ -76,6 +76,16 @@ QT_BEGIN_NAMESPACE
// The cache limit describes the maximum "junk" in the cache.
static int cache_limit = 2048 * 1024; // 2048 KB cache limit for embedded in qpixmapcache.cpp
+static inline QString imageProviderId(const QUrl &url)
+{
+ return url.host();
+}
+
+static inline QString imageId(const QUrl &url)
+{
+ return url.toString(QUrl::RemoveScheme | QUrl::RemoveAuthority).mid(1);
+}
+
QSGTexture *QQuickDefaultTextureFactory::createTexture(QQuickCanvas *) const
{
QSGPlainTexture *t = new QSGPlainTexture();
@@ -502,11 +512,15 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
{
// fetch
if (url.scheme() == QLatin1String("image")) {
- // Use QmlImageProvider
+ // Use QQuickImageProvider
QSize readSize;
- QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
- QQmlImageProvider::ImageType imageType = ep->getImageProviderType(url);
- if (imageType == QQmlImageProvider::Invalid) {
+
+ QQuickImageProvider::ImageType imageType = QQuickImageProvider::Invalid;
+ QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)));
+ if (provider)
+ imageType = provider->imageType();
+
+ if (imageType == QQuickImageProvider::Invalid) {
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::Loading;
QString errorStr = QQuickPixmap::tr("Invalid image provider: %1").arg(url.toString());
QImage image;
@@ -514,8 +528,8 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
if (!cancelled.contains(runningJob))
runningJob->postReply(errorCode, errorStr, readSize, textureFactoryForImage(image));
mutex.unlock();
- } else if (imageType == QQmlImageProvider::Image) {
- QImage image = ep->getImageFromProvider(url, &readSize, requestSize);
+ } else if (imageType == QQuickImageProvider::Image) {
+ QImage image = provider->requestImage(imageId(url), &readSize, requestSize);
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::NoError;
QString errorStr;
if (image.isNull()) {
@@ -527,7 +541,7 @@ void QQuickPixmapReader::processJob(QQuickPixmapReply *runningJob, const QUrl &u
runningJob->postReply(errorCode, errorStr, readSize, textureFactoryForImage(image));
mutex.unlock();
} else {
- QQuickTextureFactory *t = ep->getTextureFromProvider(url, &readSize, requestSize);
+ QQuickTextureFactory *t = provider->requestTexture(imageId(url), &readSize, requestSize);
QQuickPixmapReply::ReadError errorCode = QQuickPixmapReply::NoError;
QString errorStr;
if (!t) {
@@ -919,33 +933,36 @@ static QQuickPixmapData* createPixmapDataSync(QQuickPixmap *declarativePixmap, Q
{
if (url.scheme() == QLatin1String("image")) {
QSize readSize;
- QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine);
- QQmlImageProvider::ImageType imageType = ep->getImageProviderType(url);
+
+ QQuickImageProvider::ImageType imageType = QQuickImageProvider::Invalid;
+ QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)));
+ if (provider)
+ imageType = provider->imageType();
switch (imageType) {
- case QQmlImageProvider::Invalid:
+ case QQuickImageProvider::Invalid:
return new QQuickPixmapData(declarativePixmap, url, requestSize,
QQuickPixmap::tr("Invalid image provider: %1").arg(url.toString()));
- case QQmlImageProvider::Texture:
+ case QQuickImageProvider::Texture:
{
- QQuickTextureFactory *texture = ep->getTextureFromProvider(url, &readSize, requestSize);
+ QQuickTextureFactory *texture = provider->requestTexture(imageId(url), &readSize, requestSize);
if (texture) {
*ok = true;
return new QQuickPixmapData(declarativePixmap, url, texture, readSize, requestSize);
}
}
- case QQmlImageProvider::Image:
+ case QQuickImageProvider::Image:
{
- QImage image = ep->getImageFromProvider(url, &readSize, requestSize);
+ QImage image = provider->requestImage(imageId(url), &readSize, requestSize);
if (!image.isNull()) {
*ok = true;
return new QQuickPixmapData(declarativePixmap, url, textureFactoryForImage(image), readSize, requestSize);
}
}
- case QQmlImageProvider::Pixmap:
+ case QQuickImageProvider::Pixmap:
{
- QPixmap pixmap = ep->getPixmapFromProvider(url, &readSize, requestSize);
+ QPixmap pixmap = provider->requestPixmap(imageId(url), &readSize, requestSize);
if (!pixmap.isNull()) {
*ok = true;
return new QQuickPixmapData(declarativePixmap, url, textureFactoryForImage(pixmap.toImage()), readSize, requestSize);
@@ -1152,9 +1169,11 @@ void QQuickPixmap::load(QQmlEngine *engine, const QUrl &url, const QSize &reques
if (iter == store->m_cache.end()) {
if (options & QQuickPixmap::Asynchronous) {
// pixmaps can only be loaded synchronously
- if (url.scheme() == QLatin1String("image")
- && QQmlEnginePrivate::get(engine)->getImageProviderType(url) == QQmlImageProvider::Pixmap) {
- options &= ~QQuickPixmap::Asynchronous;
+ if (url.scheme() == QLatin1String("image")) {
+ QQuickImageProvider *provider = static_cast<QQuickImageProvider *>(engine->imageProvider(imageProviderId(url)));
+ if (provider && provider->imageType() == QQuickImageProvider::Pixmap) {
+ options &= ~QQuickPixmap::Asynchronous;
+ }
}
}
diff --git a/src/quick/util/qquickpixmapcache_p.h b/src/quick/util/qquickpixmapcache_p.h
index b339e6f1a0..03f2e65cc2 100644
--- a/src/quick/util/qquickpixmapcache_p.h
+++ b/src/quick/util/qquickpixmapcache_p.h
@@ -47,9 +47,9 @@
#include <QtGui/qpixmap.h>
#include <QtCore/qurl.h>
#include <QtQuick/qtquickglobal.h>
+#include <QtQuick/qquickimageprovider.h>
#include <private/qintrusivelist_p.h>
-#include <qqmlimageprovider.h>
QT_BEGIN_HEADER
diff --git a/src/quick/util/util.pri b/src/quick/util/util.pri
index c3cec91404..d720ef02c9 100644
--- a/src/quick/util/util.pri
+++ b/src/quick/util/util.pri
@@ -25,6 +25,7 @@ SOURCES += \
$$PWD/qquickchangeset.cpp \
$$PWD/qquicklistcompositor.cpp \
$$PWD/qquickpathinterpolator.cpp \
+ $$PWD/qquickimageprovider.cpp \
$$PWD/qquicksvgparser.cpp
HEADERS += \
@@ -58,4 +59,5 @@ HEADERS += \
$$PWD/qquickchangeset_p.h \
$$PWD/qquicklistcompositor_p.h \
$$PWD/qquickpathinterpolator_p.h \
+ $$PWD/qquickimageprovider.h \
$$PWD/qquicksvgparser_p.h
diff --git a/sync.profile b/sync.profile
index 36b45b35d0..7c7e1a5507 100644
--- a/sync.profile
+++ b/sync.profile
@@ -216,7 +216,7 @@
# - any git symbolic ref resolvable from the module's repository (e.g. "refs/heads/master" to track master branch)
#
%dependencies = (
- "qtbase" => "refs/heads/master",
+ "qtbase" => "refs/heads/api_changes",
"qtxmlpatterns" => "refs/heads/master",
"qtjsbackend" => "refs/heads/master",
);
diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro
index 6892680d79..4d1644f6b3 100644
--- a/tests/auto/qml/qml.pro
+++ b/tests/auto/qml/qml.pro
@@ -32,7 +32,6 @@ PRIVATETESTS += \
qqmlecmascript \
qqmlcontext \
qqmlexpression \
- qqmlimageprovider \
qqmlinstruction \
qqmllanguage \
qqmlproperty \
diff --git a/tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml b/tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml
index 122c6a87c8..989b295cb5 100644
--- a/tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml
+++ b/tests/auto/qml/qqmlcomponent/data/createObjectWithScript.qml
@@ -37,7 +37,7 @@ Item{
root.declarativerectangle = a.createObject(root, {"x":17,"y":17, "color":"white", "border.width":3, "innerRect.border.width": 20});
root.declarativeitem = b.createObject(root, {"x":17,"y":17,"testBool":true,"testInt":17,"testObject":root});
- root.bindingTestObject = c.createObject(root, {'testValue': (function(){return width * 3}) }) // use root.width
- root.bindingThisTestObject = c.createObject(root, {'testValue': (function(){return this.width * 3}) }) // use width of Item within 'c'
+ root.bindingTestObject = c.createObject(root, {'testValue': Qt.binding(function(){return width * 3}) }) // use root.width
+ root.bindingThisTestObject = c.createObject(root, {'testValue': Qt.binding(function(){return this.width * 3}) }) // use width of Item within 'c'
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/functionAssignment.1.qml b/tests/auto/qml/qqmlecmascript/data/functionAssignment.1.qml
index 09540f1f6e..0b1b45b41b 100644
--- a/tests/auto/qml/qqmlecmascript/data/functionAssignment.1.qml
+++ b/tests/auto/qml/qqmlecmascript/data/functionAssignment.1.qml
@@ -2,4 +2,6 @@ import Qt.test 1.0
MyQmlObject {
property variant a: function myFunction() { return 2; }
+ property variant b: Qt.binding(function() { return 2; })
+ property var c: Qt.binding(function() { return 2; })
}
diff --git a/tests/auto/qml/qqmlecmascript/data/functionAssignment.2.qml b/tests/auto/qml/qqmlecmascript/data/functionAssignment.2.qml
index 0f78eaf1dc..3d8fd85a88 100644
--- a/tests/auto/qml/qqmlecmascript/data/functionAssignment.2.qml
+++ b/tests/auto/qml/qqmlecmascript/data/functionAssignment.2.qml
@@ -24,7 +24,7 @@ MyQmlObject {
function myFunction() {
return aNumber * 10;
}
- a = myFunction;
+ a = Qt.binding(myFunction);
}
property QtObject obj: QtObject {
@@ -34,7 +34,7 @@ MyQmlObject {
}
}
onAssignWithThisChanged: {
- a = obj.myFunction;
+ a = Qt.binding(obj.myFunction);
}
onAssignToPropertyFromJsFileChanged: {
@@ -47,8 +47,8 @@ MyQmlObject {
property Text text: Text { }
onAssignToValueTypeChanged: {
- text.font.pixelSize = (function() { return aNumber * 10; })
- a = (function() { return text.font.pixelSize; })
+ text.font.pixelSize = Qt.binding(function() { return aNumber * 10; })
+ a = Qt.binding(function() { return text.font.pixelSize; })
}
@@ -57,17 +57,17 @@ MyQmlObject {
onAssignFuncWithoutReturnChanged: {
function myFunction() {
}
- a = myFunction;
+ a = Qt.binding(myFunction);
}
onAssignWrongTypeChanged: {
function myFunction() {
return 'a string';
}
- aNumber = myFunction;
+ aNumber = Qt.binding(myFunction);
}
onAssignWrongTypeToValueTypeChanged: {
- text.font.pixelSize = (function() { return 'a string'; })
+ text.font.pixelSize = Qt.binding(function() { return 'a string'; })
}
}
diff --git a/tests/auto/qml/qqmlecmascript/data/functionAssignment.3.qml b/tests/auto/qml/qqmlecmascript/data/functionAssignment.3.qml
new file mode 100644
index 0000000000..c34a868949
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/functionAssignment.3.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+
+Item {
+ property int t1: 1
+ property int t2: 2
+
+ function randomNumber() {
+ return 4;
+ }
+
+ Component.onCompleted: {
+ // shouldn't "convert" the randomNumber function into a binding permanently
+ t1 = Qt.binding(randomNumber)
+
+ // therefore, the following assignment should fail.
+ t2 = randomNumber
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/functionAssignment.js b/tests/auto/qml/qqmlecmascript/data/functionAssignment.js
index 14daa7629f..3ba4e193e6 100644
--- a/tests/auto/qml/qqmlecmascript/data/functionAssignment.js
+++ b/tests/auto/qml/qqmlecmascript/data/functionAssignment.js
@@ -1,6 +1,6 @@
function bindProperty()
{
- a = (function(){ return aNumber * 10 })
+ a = Qt.binding(function(){ return aNumber * 10 })
}
@@ -13,5 +13,5 @@ var testObj = new TestObject()
function bindPropertyWithThis()
{
- a = testObj.bindFunction
+ a = Qt.binding(testObj.bindFunction)
}
diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.11.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.11.qml
new file mode 100644
index 0000000000..63be26717e
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.11.qml
@@ -0,0 +1,21 @@
+import QtQuick 2.0
+
+Item {
+ property bool test: false
+ property var fnResult: testFunction(5)
+ property var f1: testFunction
+ property var f2
+
+ function testFunction(x) {
+ return x;
+ }
+
+ Component.onCompleted: {
+ f2 = testFunction;
+ if (fnResult != 5) return;
+ if (f1(6) != 6) return;
+ if (f2(7) != 7) return;
+ if (f1 != f2) return;
+ test = true;
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.12.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.12.qml
new file mode 100644
index 0000000000..3510bd2350
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.12.qml
@@ -0,0 +1,19 @@
+import QtQuick 2.0
+
+Item {
+ property bool test: false
+ property var nullOne: null
+ property var nullTwo
+ property var undefOne: undefined
+ property var undefTwo
+
+ Component.onCompleted: {
+ nullTwo = null;
+ undefTwo = undefined;
+ if (nullOne != null) return;
+ if (nullOne != nullTwo) return;
+ if (undefOne != undefined) return;
+ if (undefOne != undefTwo) return;
+ test = true;
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.13.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.13.qml
new file mode 100644
index 0000000000..14c7c677ae
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.13.qml
@@ -0,0 +1,19 @@
+import QtQuick 2.0
+
+Item {
+ property bool test: false
+ property var f: b + 12
+ property int a: 100
+ property int b: testFunction()
+
+ function testFunction() {
+ return a * 3;
+ }
+
+ Component.onCompleted: {
+ if (f != 312) return;
+ a = 120;
+ if (f != 372) return;
+ test = true;
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.14.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.14.qml
new file mode 100644
index 0000000000..a1e26661bb
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.14.qml
@@ -0,0 +1,21 @@
+import QtQuick 2.0
+
+Item {
+ property bool test: false
+ property var f
+ property int a: 100
+ property int b
+
+ function testFunction() {
+ return a * 3;
+ }
+
+ Component.onCompleted: {
+ b = Qt.binding(testFunction);
+ f = Qt.binding(function() { return b + 12; });
+ if (f != 312) return;
+ a = 120;
+ if (f != 372) return;
+ test = true;
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/data/propertyVar.15.qml b/tests/auto/qml/qqmlecmascript/data/propertyVar.15.qml
new file mode 100644
index 0000000000..5e5071fc2d
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/propertyVar.15.qml
@@ -0,0 +1,20 @@
+import QtQuick 2.0
+
+Item {
+ property bool test: false
+ property var storedBinding: [ Qt.binding(function() { return testFunction() + 12; }) ]
+ property int a: 100
+ property int b
+
+ function testFunction() {
+ return a * 3;
+ }
+
+ Component.onCompleted: {
+ b = storedBinding[0];
+ if (b != 312) return;
+ a = 120;
+ if (b != 372) return;
+ test = true;
+ }
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 79eaa3316f..861ff2e641 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -195,6 +195,7 @@ private slots:
void functionAssignment_fromJS();
void functionAssignment_fromJS_data();
void functionAssignmentfromJS_invalid();
+ void functionAssignment_afterBinding();
void eval();
void function();
void functionException();
@@ -3792,6 +3793,11 @@ void tst_qqmlecmascript::propertyVar_data()
QTest::newRow("literal property assignment") << testFileUrl("propertyVar.8.qml");
QTest::newRow("qobject property assignment") << testFileUrl("propertyVar.9.qml");
QTest::newRow("base class var property assignment") << testFileUrl("propertyVar.10.qml");
+ QTest::newRow("javascript function assignment") << testFileUrl("propertyVar.11.qml");
+ QTest::newRow("javascript special assignment") << testFileUrl("propertyVar.12.qml");
+ QTest::newRow("declarative binding assignment") << testFileUrl("propertyVar.13.qml");
+ QTest::newRow("imperative binding assignment") << testFileUrl("propertyVar.14.qml");
+ QTest::newRow("stored binding assignment") << testFileUrl("propertyVar.15.qml");
}
void tst_qqmlecmascript::propertyVar()
@@ -4639,7 +4645,7 @@ void tst_qqmlecmascript::sequenceConversionWrite()
QVERIFY(seq != 0);
// we haven't registered QList<QPoint> as a sequence type, so writing shouldn't work.
- QString warningOne = qmlFile.toString() + QLatin1String(":16: Error: Cannot assign QVariantList to void");
+ QString warningOne = qmlFile.toString() + QLatin1String(":16: Error: Cannot assign QVariantList to an unregistered type");
QTest::ignoreMessage(QtWarningMsg, warningOne.toAscii().constData());
QMetaObject::invokeMethod(object, "performTest");
@@ -5054,9 +5060,13 @@ void tst_qqmlecmascript::functionAssignment_fromBinding()
QQmlComponent component(&engine, testFileUrl("functionAssignment.1.qml"));
QString url = component.url().toString();
- QString warning = url + ":4:25: Unable to assign a function to a property.";
- QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
-
+ QString w1 = url + ":4:25: Unable to assign a function to a property of any type other than var.";
+ QString w2 = url + ":5:25: Invalid use of Qt.binding() in a binding declaration.";
+ QString w3 = url + ":6:21: Invalid use of Qt.binding() in a binding declaration.";
+ QTest::ignoreMessage(QtWarningMsg, w1.toLatin1().constData());
+ QTest::ignoreMessage(QtWarningMsg, w2.toLatin1().constData());
+ QTest::ignoreMessage(QtWarningMsg, w3.toLatin1().constData());
+
MyQmlObject *o = qobject_cast<MyQmlObject *>(component.create());
QVERIFY(o != 0);
@@ -5123,6 +5133,24 @@ void tst_qqmlecmascript::functionAssignmentfromJS_invalid()
delete o;
}
+void tst_qqmlecmascript::functionAssignment_afterBinding()
+{
+ QQmlComponent component(&engine, testFileUrl("functionAssignment.3.qml"));
+
+ QString url = component.url().toString();
+ //QString w1 = url + ":16: Error: Cannot assign JavaScript function to int"; // for now, function assignment = binding assignment
+ QString w1 = QLatin1String("WARNING: function assignment is DEPRECATED and will be removed! Wrap RHS in Qt.binding(): ") + url + QLatin1String(":16");
+ QTest::ignoreMessage(QtWarningMsg, w1.toLatin1().constData());
+
+ QObject *o = component.create();
+ QVERIFY(o != 0);
+ QCOMPARE(o->property("t1"), QVariant::fromValue<int>(4)); // should have bound
+ //QCOMPARE(o->property("t2"), QVariant::fromValue<int>(2)); // should not have changed
+ QCOMPARE(o->property("t2"), QVariant::fromValue<int>(4)); // for now, function assignment = binding assignment
+
+ delete o;
+}
+
void tst_qqmlecmascript::eval()
{
QQmlComponent component(&engine, testFileUrl("eval.qml"));
diff --git a/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp b/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp
index f2c50ddbef..ca48f027e0 100644
--- a/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp
+++ b/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp
@@ -211,10 +211,10 @@ void tst_QQmlMetaObject::property()
QCOMPARE(prop.name(), "test");
QCOMPARE(QByteArray(prop.typeName()), cppTypeName);
- QEXPECT_FAIL("QtObject", "prop.type() returns UserType for QtObject properties", Continue);
- QEXPECT_FAIL("alias-2", "prop.type() returns UserType for QtObject properties", Continue);
if (prop.userType() < QMetaType::User)
QCOMPARE(prop.type(), QVariant::Type(cppType));
+ else
+ QCOMPARE(prop.type(), QVariant::UserType);
QCOMPARE(prop.userType(), cppType);
QVERIFY(!prop.isConstant());
@@ -244,12 +244,15 @@ void tst_QQmlMetaObject::property()
QVERIFY(prop.notifySignalIndex() != -1);
QMetaMethod signal = prop.notifySignal();
QCOMPARE(signal.methodType(), QMetaMethod::Signal);
- QCOMPARE(signal.signature(), "testChanged()");
+ QCOMPARE(signal.name(), QByteArray("testChanged"));
+ QCOMPARE(signal.methodSignature(), QByteArray("testChanged()"));
QCOMPARE(signal.access(), QMetaMethod::Protected);
+ QCOMPARE(signal.parameterCount(), 0);
QCOMPARE(signal.parameterTypes(), QList<QByteArray>());
QCOMPARE(signal.parameterNames(), QList<QByteArray>());
QCOMPARE(signal.tag(), "");
QCOMPARE(signal.typeName(), "");
+ QCOMPARE(signal.returnType(), int(QMetaType::Void));
QSignalSpy changedSpy(object, SIGNAL(testChanged()));
QObject::connect(object, SIGNAL(testChanged()), object, SLOT(deleteLater()));
@@ -277,62 +280,73 @@ void tst_QQmlMetaObject::method_data()
QTest::addColumn<QString>("testFile");
QTest::addColumn<QString>("signature");
QTest::addColumn<QMetaMethod::MethodType>("methodType");
+ QTest::addColumn<int>("returnType");
QTest::addColumn<QString>("returnTypeName");
+ QTest::addColumn<QList<int> >("parameterTypes");
QTest::addColumn<QList<QByteArray> >("parameterTypeNames");
QTest::addColumn<QList<QByteArray> >("parameterNames");
QTest::newRow("testFunction()") << "method.1.qml"
<< "testFunction()"
<< QMetaMethod::Slot
- << "QVariant"
+ << int(QMetaType::QVariant) << "QVariant"
+ << QList<int>()
<< QList<QByteArray>()
<< QList<QByteArray>();
QTest::newRow("testFunction(foo)") << "method.2.qml"
<< "testFunction(QVariant)"
<< QMetaMethod::Slot
- << "QVariant"
+ << int(QMetaType::QVariant) << "QVariant"
+ << (QList<int>() << QMetaType::QVariant)
<< (QList<QByteArray>() << "QVariant")
<< (QList<QByteArray>() << "foo");
QTest::newRow("testFunction(foo, bar, baz)") << "method.3.qml"
<< "testFunction(QVariant,QVariant,QVariant)"
<< QMetaMethod::Slot
- << "QVariant"
+ << int(QMetaType::QVariant) << "QVariant"
+ << (QList<int>() << QMetaType::QVariant << QMetaType::QVariant << QMetaType::QVariant)
<< (QList<QByteArray>() << "QVariant" << "QVariant" << "QVariant")
<< (QList<QByteArray>() << "foo" << "bar" << "baz");
QTest::newRow("testSignal") << "signal.1.qml"
<< "testSignal()"
<< QMetaMethod::Signal
- << ""
+ << int(QMetaType::Void) << ""
+ << QList<int>()
<< QList<QByteArray>()
<< QList<QByteArray>();
QTest::newRow("testSignal(string foo)") << "signal.2.qml"
<< "testSignal(QString)"
<< QMetaMethod::Signal
- << ""
+ << int(QMetaType::Void) << ""
+ << (QList<int>() << QMetaType::QString)
<< (QList<QByteArray>() << "QString")
<< (QList<QByteArray>() << "foo");
QTest::newRow("testSignal(int foo, bool bar, real baz)") << "signal.3.qml"
<< "testSignal(int,bool,double)"
<< QMetaMethod::Signal
- << ""
+ << int(QMetaType::Void) << ""
+ << (QList<int>() << QMetaType::Int << QMetaType::Bool << QMetaType::Double)
<< (QList<QByteArray>() << "int" << "bool" << "double")
<< (QList<QByteArray>() << "foo" << "bar" << "baz");
QTest::newRow("testSignal(variant foo, var bar)") << "signal.4.qml"
<< "testSignal(QVariant,QVariant)"
<< QMetaMethod::Signal
- << ""
+ << int(QMetaType::Void) << ""
+ << (QList<int>() << QMetaType::QVariant << QMetaType::QVariant)
<< (QList<QByteArray>() << "QVariant" << "QVariant")
<< (QList<QByteArray>() << "foo" << "bar");
QTest::newRow("testSignal(color foo, date bar, url baz)") << "signal.5.qml"
<< "testSignal(QColor,QDateTime,QUrl)"
<< QMetaMethod::Signal
- << ""
+ << int(QMetaType::Void) << ""
+ << (QList<int>() << QMetaType::QColor << QMetaType::QDateTime << QMetaType::QUrl)
<< (QList<QByteArray>() << "QColor" << "QDateTime" << "QUrl")
<< (QList<QByteArray>() << "foo" << "bar" << "baz");
QTest::newRow("testSignal(double foo)") << "signal.6.qml"
<< "testSignal(double)"
<< QMetaMethod::Signal
- << ""
+ << int(QMetaType::Void) << ""
+ << (QList<int>() << QMetaType::Double)
<< (QList<QByteArray>() << "double")
<< (QList<QByteArray>() << "foo");
}
@@ -342,10 +356,13 @@ void tst_QQmlMetaObject::method()
QFETCH(QString, testFile);
QFETCH(QString, signature);
QFETCH(QMetaMethod::MethodType, methodType);
+ QFETCH(int, returnType);
QFETCH(QString, returnTypeName);
+ QFETCH(QList<int>, parameterTypes);
QFETCH(QList<QByteArray>, parameterTypeNames);
QFETCH(QList<QByteArray>, parameterNames);
+ QCOMPARE(parameterTypes.size(), parameterTypeNames.size());
QCOMPARE(parameterTypeNames.size(), parameterNames.size());
QQmlEngine engine;
@@ -361,12 +378,21 @@ void tst_QQmlMetaObject::method()
QMetaMethod method = mo->method(mo->methodOffset());
QCOMPARE(method.methodType(), methodType);
- QCOMPARE(QString::fromUtf8(method.signature()), signature);
+ QCOMPARE(QString::fromUtf8(method.methodSignature().constData()), signature);
QCOMPARE(method.access(), QMetaMethod::Protected);
+
+ QString computedName = signature.left(signature.indexOf('('));
+ QCOMPARE(QString::fromUtf8(method.name()), computedName);
+
+ QCOMPARE(method.parameterCount(), parameterTypes.size());
+ for (int i = 0; i < parameterTypes.size(); ++i)
+ QCOMPARE(method.parameterType(i), parameterTypes.at(i));
QCOMPARE(method.parameterTypes(), parameterTypeNames);
QCOMPARE(method.parameterNames(), parameterNames);
QCOMPARE(method.tag(), "");
+
QCOMPARE(QString::fromUtf8(method.typeName()), returnTypeName);
+ QCOMPARE(method.returnType(), returnType);
delete object;
}
diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
index 5ef8937dc1..aa22450bd3 100644
--- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
+++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
@@ -161,7 +161,7 @@ void tst_qqmlproperty::qmlmetaproperty()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QVERIFY(prop.method().signature() == 0);
+ QVERIFY(!prop.method().isValid());
QCOMPARE(prop.type(), QQmlProperty::Invalid);
QCOMPARE(prop.isProperty(), false);
QCOMPARE(prop.isWritable(), false);
@@ -264,7 +264,7 @@ void tst_qqmlproperty::qmlmetaproperty_object()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QVERIFY(prop.method().signature() == 0);
+ QVERIFY(!prop.method().isValid());
QCOMPARE(prop.type(), QQmlProperty::Invalid);
QCOMPARE(prop.isProperty(), false);
QCOMPARE(prop.isWritable(), false);
@@ -311,7 +311,7 @@ void tst_qqmlproperty::qmlmetaproperty_object()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QVERIFY(prop.method().signature() == 0);
+ QVERIFY(!prop.method().isValid());
QCOMPARE(prop.type(), QQmlProperty::Property);
QCOMPARE(prop.isProperty(), true);
QCOMPARE(prop.isWritable(), false);
@@ -365,7 +365,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_string()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QVERIFY(prop.method().signature() == 0);
+ QVERIFY(!prop.method().isValid());
QCOMPARE(prop.type(), QQmlProperty::Invalid);
QCOMPARE(prop.isProperty(), false);
QCOMPARE(prop.isWritable(), false);
@@ -412,7 +412,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_string()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QVERIFY(prop.method().signature() == 0);
+ QVERIFY(!prop.method().isValid());
QCOMPARE(prop.type(), QQmlProperty::Property);
QCOMPARE(prop.isProperty(), true);
QCOMPARE(prop.isWritable(), false);
@@ -461,7 +461,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_string()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QCOMPARE(QString(prop.method().signature()), QString("clicked()"));
+ QCOMPARE(QString(prop.method().methodSignature()), QString("clicked()"));
QCOMPARE(prop.type(), QQmlProperty::SignalProperty);
QCOMPARE(prop.isProperty(), false);
QCOMPARE(prop.isWritable(), false);
@@ -509,7 +509,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_string()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QCOMPARE(QString(prop.method().signature()), QString("oddlyNamedNotifySignal()"));
+ QCOMPARE(QString(prop.method().methodSignature()), QString("oddlyNamedNotifySignal()"));
QCOMPARE(prop.type(), QQmlProperty::SignalProperty);
QCOMPARE(prop.isProperty(), false);
QCOMPARE(prop.isWritable(), false);
@@ -562,7 +562,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_context()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QVERIFY(prop.method().signature() == 0);
+ QVERIFY(!prop.method().isValid());
QCOMPARE(prop.type(), QQmlProperty::Invalid);
QCOMPARE(prop.isProperty(), false);
QCOMPARE(prop.isWritable(), false);
@@ -609,7 +609,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_context()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QVERIFY(prop.method().signature() == 0);
+ QVERIFY(!prop.method().isValid());
QCOMPARE(prop.type(), QQmlProperty::Property);
QCOMPARE(prop.isProperty(), true);
QCOMPARE(prop.isWritable(), false);
@@ -663,7 +663,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QVERIFY(prop.method().signature() == 0);
+ QVERIFY(!prop.method().isValid());
QCOMPARE(prop.type(), QQmlProperty::Invalid);
QCOMPARE(prop.isProperty(), false);
QCOMPARE(prop.isWritable(), false);
@@ -710,7 +710,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QVERIFY(prop.method().signature() == 0);
+ QVERIFY(!prop.method().isValid());
QCOMPARE(prop.type(), QQmlProperty::Property);
QCOMPARE(prop.isProperty(), true);
QCOMPARE(prop.isWritable(), false);
@@ -759,7 +759,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QCOMPARE(QString(prop.method().signature()), QString("clicked()"));
+ QCOMPARE(QString(prop.method().methodSignature()), QString("clicked()"));
QCOMPARE(prop.type(), QQmlProperty::SignalProperty);
QCOMPARE(prop.isProperty(), false);
QCOMPARE(prop.isWritable(), false);
@@ -807,7 +807,7 @@ void tst_qqmlproperty::qmlmetaproperty_object_string_context()
QCOMPARE(prop.connectNotifySignal(0, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, obj->metaObject()->indexOfMethod("deleteLater()")), false);
QCOMPARE(prop.connectNotifySignal(obj, -1), false);
- QCOMPARE(QString(prop.method().signature()), QString("oddlyNamedNotifySignal()"));
+ QCOMPARE(QString(prop.method().methodSignature()), QString("oddlyNamedNotifySignal()"));
QCOMPARE(prop.type(), QQmlProperty::SignalProperty);
QCOMPARE(prop.isProperty(), false);
QCOMPARE(prop.isWritable(), false);
diff --git a/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.2.qml b/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.2.qml
new file mode 100644
index 0000000000..0da717ba5c
--- /dev/null
+++ b/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.2.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.0
+import Test 1.0
+
+MyTypeObject {
+ property int value: 10
+ rect.y: Qt.binding(function() { return value; }); // error.
+
+ Component.onCompleted: {
+ rect.x = 5;
+ rect.x = (function() { return value; }); // error.
+ }
+}
diff --git a/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml b/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml
index a65218669b..9b10803649 100644
--- a/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml
+++ b/tests/auto/qml/qqmlvaluetypes/data/bindingAssignment.qml
@@ -1,7 +1,12 @@
+import QtQuick 2.0
import Test 1.0
MyTypeObject {
property int value: 10
rect.x: value
+
+ Component.onCompleted: {
+ rect.y = Qt.binding(function() { return value + 5; });
+ }
}
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
index 0aa223e733..54791fc340 100644
--- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
+++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp
@@ -871,17 +871,37 @@ void tst_qqmlvaluetypes::color()
// Test bindings can write to value types
void tst_qqmlvaluetypes::bindingAssignment()
{
+ // binding declaration
+ {
QQmlComponent component(&engine, testFileUrl("bindingAssignment.qml"));
MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->rect().x(), 10);
+ QCOMPARE(object->rect().y(), 15);
object->setProperty("value", QVariant(92));
QCOMPARE(object->rect().x(), 92);
+ QCOMPARE(object->rect().y(), 97);
delete object;
+ }
+
+ // function assignment should fail without crashing
+ {
+ QString warning1 = testFileUrl("bindingAssignment.2.qml").toString() + QLatin1String(":6:13: Invalid use of Qt.binding() in a binding declaration.");
+ QString warning2 = testFileUrl("bindingAssignment.2.qml").toString() + QLatin1String(":10: Error: Cannot assign JavaScript function to value-type property");
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning1));
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warning2));
+ QQmlComponent component(&engine, testFileUrl("bindingAssignment.2.qml"));
+ MyTypeObject *object = qobject_cast<MyTypeObject *>(component.create());
+ QVERIFY(object != 0);
+ QCOMPARE(object->rect().x(), 5);
+ object->setProperty("value", QVariant(92));
+ QCOMPARE(object->rect().x(), 5);
+ delete object;
+ }
}
// Test bindings can read from value types
diff --git a/tests/auto/qml/qqmlimageprovider/qqmlimageprovider.pro b/tests/auto/quick/qquickimageprovider/qquickimageprovider.pro
index 9feeee15fd..269f06a046 100644
--- a/tests/auto/qml/qqmlimageprovider/qqmlimageprovider.pro
+++ b/tests/auto/quick/qquickimageprovider/qquickimageprovider.pro
@@ -1,8 +1,8 @@
CONFIG += testcase
-TARGET = tst_qqmlimageprovider
+TARGET = tst_qquickimageprovider
macx:CONFIG -= app_bundle
-SOURCES += tst_qqmlimageprovider.cpp
+SOURCES += tst_qquickimageprovider.cpp
CONFIG += parallel_test
diff --git a/tests/auto/qml/qqmlimageprovider/tst_qqmlimageprovider.cpp b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp
index bc53544566..7f9a0efb33 100644
--- a/tests/auto/qml/qqmlimageprovider/tst_qqmlimageprovider.cpp
+++ b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp
@@ -41,18 +41,18 @@
#include <qtest.h>
#include <QtTest/QtTest>
#include <QtQml/qqmlengine.h>
-#include <QtQml/qqmlimageprovider.h>
+#include <QtQuick/qquickimageprovider.h>
#include <private/qquickimage_p.h>
#include <QImageReader>
#include <QWaitCondition>
-Q_DECLARE_METATYPE(QQmlImageProvider*);
+Q_DECLARE_METATYPE(QQuickImageProvider*);
-class tst_qqmlimageprovider : public QObject
+class tst_qquickimageprovider : public QObject
{
Q_OBJECT
public:
- tst_qqmlimageprovider()
+ tst_qquickimageprovider()
{
}
@@ -74,15 +74,15 @@ private slots:
private:
QString newImageFileName() const;
void fillRequestTestsData(const QString &id);
- void runTest(bool async, QQmlImageProvider *provider);
+ void runTest(bool async, QQuickImageProvider *provider);
};
-class TestQImageProvider : public QQmlImageProvider
+class TestQImageProvider : public QQuickImageProvider
{
public:
TestQImageProvider(bool *deleteWatch = 0)
- : QQmlImageProvider(Image), deleteWatch(deleteWatch)
+ : QQuickImageProvider(Image), deleteWatch(deleteWatch)
{
}
@@ -115,11 +115,11 @@ public:
Q_DECLARE_METATYPE(TestQImageProvider*);
-class TestQPixmapProvider : public QQmlImageProvider
+class TestQPixmapProvider : public QQuickImageProvider
{
public:
TestQPixmapProvider(bool *deleteWatch = 0)
- : QQmlImageProvider(Pixmap), deleteWatch(deleteWatch)
+ : QQuickImageProvider(Pixmap), deleteWatch(deleteWatch)
{
}
@@ -152,7 +152,7 @@ public:
Q_DECLARE_METATYPE(TestQPixmapProvider*);
-QString tst_qqmlimageprovider::newImageFileName() const
+QString tst_qquickimageprovider::newImageFileName() const
{
// need to generate new filenames each time or else images are loaded
// from cache and we won't get loading status changes when testing
@@ -161,7 +161,7 @@ QString tst_qqmlimageprovider::newImageFileName() const
return QString("image://test/image-%1.png").arg(count++);
}
-void tst_qqmlimageprovider::fillRequestTestsData(const QString &id)
+void tst_qquickimageprovider::fillRequestTestsData(const QString &id)
{
QTest::addColumn<QString>("source");
QTest::addColumn<QString>("imageId");
@@ -207,7 +207,7 @@ void tst_qqmlimageprovider::fillRequestTestsData(const QString &id)
<< "file::2:1: QML Image: Invalid image provider: image://bogus/exists.png";
}
-void tst_qqmlimageprovider::runTest(bool async, QQmlImageProvider *provider)
+void tst_qquickimageprovider::runTest(bool async, QQuickImageProvider *provider)
{
QFETCH(QString, source);
QFETCH(QString, imageId);
@@ -260,46 +260,46 @@ void tst_qqmlimageprovider::runTest(bool async, QQmlImageProvider *provider)
delete obj;
}
-void tst_qqmlimageprovider::requestImage_sync_data()
+void tst_qquickimageprovider::requestImage_sync_data()
{
fillRequestTestsData("qimage|sync");
}
-void tst_qqmlimageprovider::requestImage_sync()
+void tst_qquickimageprovider::requestImage_sync()
{
bool deleteWatch = false;
runTest(false, new TestQImageProvider(&deleteWatch));
QVERIFY(deleteWatch);
}
-void tst_qqmlimageprovider::requestImage_async_data()
+void tst_qquickimageprovider::requestImage_async_data()
{
fillRequestTestsData("qimage|async");
}
-void tst_qqmlimageprovider::requestImage_async()
+void tst_qquickimageprovider::requestImage_async()
{
bool deleteWatch = false;
runTest(true, new TestQImageProvider(&deleteWatch));
QVERIFY(deleteWatch);
}
-void tst_qqmlimageprovider::requestPixmap_sync_data()
+void tst_qquickimageprovider::requestPixmap_sync_data()
{
fillRequestTestsData("qpixmap");
}
-void tst_qqmlimageprovider::requestPixmap_sync()
+void tst_qquickimageprovider::requestPixmap_sync()
{
bool deleteWatch = false;
runTest(false, new TestQPixmapProvider(&deleteWatch));
QVERIFY(deleteWatch);
}
-void tst_qqmlimageprovider::requestPixmap_async()
+void tst_qquickimageprovider::requestPixmap_async()
{
QQmlEngine engine;
- QQmlImageProvider *provider = new TestQPixmapProvider();
+ QQuickImageProvider *provider = new TestQPixmapProvider();
engine.addImageProvider("test", provider);
QVERIFY(engine.imageProvider("test") != 0);
@@ -314,17 +314,17 @@ void tst_qqmlimageprovider::requestPixmap_async()
delete obj;
}
-void tst_qqmlimageprovider::removeProvider_data()
+void tst_qquickimageprovider::removeProvider_data()
{
- QTest::addColumn<QQmlImageProvider*>("provider");
+ QTest::addColumn<QQuickImageProvider*>("provider");
- QTest::newRow("qimage") << static_cast<QQmlImageProvider*>(new TestQImageProvider);
- QTest::newRow("qpixmap") << static_cast<QQmlImageProvider*>(new TestQPixmapProvider);
+ QTest::newRow("qimage") << static_cast<QQuickImageProvider*>(new TestQImageProvider);
+ QTest::newRow("qpixmap") << static_cast<QQuickImageProvider*>(new TestQPixmapProvider);
}
-void tst_qqmlimageprovider::removeProvider()
+void tst_qquickimageprovider::removeProvider()
{
- QFETCH(QQmlImageProvider*, provider);
+ QFETCH(QQuickImageProvider*, provider);
QQmlEngine engine;
@@ -353,10 +353,10 @@ void tst_qqmlimageprovider::removeProvider()
delete obj;
}
-class TestThreadProvider : public QQmlImageProvider
+class TestThreadProvider : public QQuickImageProvider
{
public:
- TestThreadProvider() : QQmlImageProvider(Image), ok(false) {}
+ TestThreadProvider() : QQuickImageProvider(Image), ok(false) {}
~TestThreadProvider() {}
@@ -384,7 +384,7 @@ class TestThreadProvider : public QQmlImageProvider
};
-void tst_qqmlimageprovider::threadTest()
+void tst_qquickimageprovider::threadTest()
{
QQmlEngine engine;
@@ -419,6 +419,6 @@ void tst_qqmlimageprovider::threadTest()
}
-QTEST_MAIN(tst_qqmlimageprovider)
+QTEST_MAIN(tst_qquickimageprovider)
-#include "tst_qqmlimageprovider.moc"
+#include "tst_qquickimageprovider.moc"
diff --git a/tests/auto/quick/qquickloader/data/initialPropertyValues.binding.qml b/tests/auto/quick/qquickloader/data/initialPropertyValues.binding.qml
index e0df50a74a..2ee60b0b50 100644
--- a/tests/auto/quick/qquickloader/data/initialPropertyValues.binding.qml
+++ b/tests/auto/quick/qquickloader/data/initialPropertyValues.binding.qml
@@ -16,6 +16,6 @@ Item {
}
Component.onCompleted: {
- loader.setSource("InitialPropertyValuesComponent.qml", {"canary": (function() { return root.bindable })});
+ loader.setSource("InitialPropertyValuesComponent.qml", {"canary": Qt.binding(function() { return root.bindable })});
}
}
diff --git a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp
index 855322e376..8d2eb66e08 100644
--- a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp
+++ b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp
@@ -42,7 +42,7 @@
#include <QtTest/QtTest>
#include <QtQuick/private/qquickpixmapcache_p.h>
#include <QtQml/qqmlengine.h>
-#include <QtQml/qqmlimageprovider.h>
+#include <QtQuick/qquickimageprovider.h>
#include <QNetworkReply>
#include "../../shared/util.h"
#include "testhttpserver.h"
@@ -335,11 +335,11 @@ void tst_qquickpixmapcache::cancelcrash()
}
}
-class MyPixmapProvider : public QQmlImageProvider
+class MyPixmapProvider : public QQuickImageProvider
{
public:
MyPixmapProvider()
- : QQmlImageProvider(Pixmap) {}
+ : QQuickImageProvider(Pixmap) {}
virtual QPixmap requestPixmap(const QString &d, QSize *, const QSize &) {
Q_UNUSED(d)
diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp
index fc8194f6ca..7fd8fc4498 100644
--- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp
+++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp
@@ -245,7 +245,7 @@ void tst_qquickstates::basicChanges()
QMetaProperty prop = rect->metaObject()->property(rect->metaObject()->indexOfProperty("propertyWithNotify"));
QVERIFY(prop.hasNotifySignal());
- QString notifySignal = QByteArray(prop.notifySignal().signature());
+ QString notifySignal = prop.notifySignal().methodSignature();
QVERIFY(!notifySignal.startsWith("propertyWithNotifyChanged("));
QCOMPARE(rect->color(), QColor(Qt::red));
diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro
index c8014be820..654b1c86f0 100644
--- a/tests/auto/quick/quick.pro
+++ b/tests/auto/quick/quick.pro
@@ -15,6 +15,7 @@ PRIVATETESTS += \
qquickapplication \
qquickbehaviors \
qquickfontloader \
+ qquickimageprovider \
qquickpath \
qquicksmoothedanimation \
qquickspringanimation \
diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp
index cea29158f9..b3cc721bd4 100644
--- a/tools/qmlplugindump/main.cpp
+++ b/tools/qmlplugindump/main.cpp
@@ -386,10 +386,10 @@ public:
// for QObject, hide deleteLater() and onDestroyed
for (int index = meta->methodOffset(); index < meta->methodCount(); ++index) {
QMetaMethod method = meta->method(index);
- const char *signature(method.signature());
- if (signature == QLatin1String("destroyed(QObject*)")
- || signature == QLatin1String("destroyed()")
- || signature == QLatin1String("deleteLater()"))
+ QByteArray signature = method.methodSignature();
+ if (signature == QByteArrayLiteral("destroyed(QObject*)")
+ || signature == QByteArrayLiteral("destroyed()")
+ || signature == QByteArrayLiteral("deleteLater()"))
continue;
dump(method, implicitSignals);
}
@@ -500,12 +500,7 @@ private:
return; // nothing to do.
}
- QByteArray name = meth.signature();
- int lparenIndex = name.indexOf('(');
- if (lparenIndex == -1) {
- return; // invalid signature
- }
- name = name.left(lparenIndex);
+ QByteArray name = meth.name();
const QString typeName = convertToId(meth.typeName());
if (implicitSignals.contains(name)