aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllanguage/data/singleton
diff options
context:
space:
mode:
authorAntti Piira <apiira@blackberry.com>2013-08-22 12:08:37 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-21 01:20:55 +0200
commit200a869441562d62e7fc0867599097e0599f0411 (patch)
tree982dc3c5a9c22bdea24a21054dd2b434fcea1147 /tests/auto/qml/qqmllanguage/data/singleton
parentb365471f0abc79f08bf0d852aea3be0a601c6901 (diff)
Add Singleton support for QML
This introduces Singleton support for QML (Composite Singleton). For now, the Singleton support is only availabe for QML types in modules or (remote and local) directories with qmldir file. However, in the future this support may be expanded to arbitrary QML file imports without by leaving out the qmldir requirement. You define a QML type as a Singleton with the following two steps: 1. By adding a pragma Singleton to a type's QML file: pragma Singleton The pragma and import statements can be mixed and their order does not matter. Singleton is the only supported pragma for now. Others will generate errors. 2. By specifying a qmldir file for the directory of your imported type and prepending the type with "singleton" keyword as follows: singleton TestTypeSingleton TestTypeSingleton.qml Alternatively you may specify a qmldir file for a module and specify your type as a singleton as follows: singleton TestTypeSingleton 1.0 TestTypeSingleton.qml Composite Singletons may be included in a module and may be used with a local namespace qualifier when imported with: "import xxx as NameSpace" A singleton instance is created at first use and stored into the QmlEngine (one instance per engine) and eventually released by the engine's destructor. CompositeSingletonType has a dual nature and will return true to both isComposite() and isSingleton() calls. In most cases its enough to check for just isComposite() or isSingleton(). However, there is a isCompositeSingleton() available as well. I used "qlalr --no-debug --no-lines --qt qqmljs.g" to generate the qqmljsparser and qqmljsgrammar files from qqmljs.g. Unit tests are included. Change-Id: I91b303612c5e132143b325b9a8f982e9355bc90e Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Diffstat (limited to 'tests/auto/qml/qqmllanguage/data/singleton')
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/SingletonType.qml18
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/js/jspragma.js43
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/NonSingletonType.qml17
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/NonSingletonType25.qml17
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/SingletonType.qml18
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/SingletonType22.qml18
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/qmldir5
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/qmldir3
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/qmldir-error/SType2.qml18
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/qmldir-error/qmldir1
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/qualified/SingletonType.qml17
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/registeredComposite/CompositeType.qml19
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/remote/RemoteSingletonType2.qml18
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/remote/qmldir1
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/subdir/ErrorSingletonType.qml17
-rw-r--r--tests/auto/qml/qqmllanguage/data/singleton/subdir/qmldir3
16 files changed, 233 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/SingletonType.qml b/tests/auto/qml/qqmllanguage/data/singleton/SingletonType.qml
new file mode 100644
index 0000000000..a2f1a4eeb7
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/SingletonType.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+pragma Singleton
+
+Item {
+ id: singletonId
+
+ property int testProp1: 125
+ property int testProp2: 25
+ property int testProp3: -55
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+} \ No newline at end of file
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/js/jspragma.js b/tests/auto/qml/qqmllanguage/data/singleton/js/jspragma.js
new file mode 100644
index 0000000000..b652689a48
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/js/jspragma.js
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the examples 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 Digia Plc 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$
+**
+****************************************************************************/
+
+.pragma library
+
+var value = 333
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/NonSingletonType.qml b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/NonSingletonType.qml
new file mode 100644
index 0000000000..9a3b7abbd6
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/NonSingletonType.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+
+Item {
+ id: singletonId
+
+ property int testProp1: 125
+ property int testProp2: 25
+ property int testProp3: -55
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+} \ No newline at end of file
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/NonSingletonType25.qml b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/NonSingletonType25.qml
new file mode 100644
index 0000000000..ca4d87faf7
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/NonSingletonType25.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+
+Item {
+ id: singletonId
+
+ property int testProp1: 225
+ property int testProp2: 125
+ property int testProp3: 55
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+} \ No newline at end of file
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/SingletonType.qml b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/SingletonType.qml
new file mode 100644
index 0000000000..a2f1a4eeb7
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/SingletonType.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+pragma Singleton
+
+Item {
+ id: singletonId
+
+ property int testProp1: 125
+ property int testProp2: 25
+ property int testProp3: -55
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+} \ No newline at end of file
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/SingletonType22.qml b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/SingletonType22.qml
new file mode 100644
index 0000000000..2ca61b0fcc
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/SingletonType22.qml
@@ -0,0 +1,18 @@
+pragma Singleton
+import QtQuick 2.0
+
+Item {
+ id: singletonId
+
+ property int testProp1: 225
+ property int testProp2: 125
+ property int testProp3: 55
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+} \ No newline at end of file
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/qmldir b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/qmldir
new file mode 100644
index 0000000000..91fc8f9139
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/module/org/qtproject/SingletonTest/qmldir
@@ -0,0 +1,5 @@
+module org.qtproject.SingletonTest
+singleton SingletonType 1.0 SingletonType.qml
+singleton SingletonType 2.2 SingletonType22.qml
+NonSingletonType 1.0 NonSingletonType.qml
+NonSingletonType 2.5 NonSingletonType25.qml
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/qmldir b/tests/auto/qml/qqmllanguage/data/singleton/qmldir
new file mode 100644
index 0000000000..533fb6999a
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/qmldir
@@ -0,0 +1,3 @@
+singleton SingletonType SingletonType.qml
+
+
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/qmldir-error/SType2.qml b/tests/auto/qml/qqmllanguage/data/singleton/qmldir-error/SType2.qml
new file mode 100644
index 0000000000..43450afcec
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/qmldir-error/SType2.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+pragma Singleton
+
+Item {
+ id: singletonId
+
+ property int testProp1: 125
+ property int testProp2: 25
+ property int testProp3: -55
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+}
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/qmldir-error/qmldir b/tests/auto/qml/qqmllanguage/data/singleton/qmldir-error/qmldir
new file mode 100644
index 0000000000..0f499f9dce
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/qmldir-error/qmldir
@@ -0,0 +1 @@
+singleton SType2
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/qualified/SingletonType.qml b/tests/auto/qml/qqmllanguage/data/singleton/qualified/SingletonType.qml
new file mode 100644
index 0000000000..9a3b7abbd6
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/qualified/SingletonType.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+
+Item {
+ id: singletonId
+
+ property int testProp1: 125
+ property int testProp2: 25
+ property int testProp3: -55
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+} \ No newline at end of file
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/registeredComposite/CompositeType.qml b/tests/auto/qml/qqmllanguage/data/singleton/registeredComposite/CompositeType.qml
new file mode 100644
index 0000000000..5c86c21ffb
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/registeredComposite/CompositeType.qml
@@ -0,0 +1,19 @@
+import QtQuick 2.0
+pragma Singleton
+
+Item {
+ id: singletonId
+
+ property int testProp1: 325
+ property int testProp2: 225
+ property int testProp3: 155
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+}
+
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/remote/RemoteSingletonType2.qml b/tests/auto/qml/qqmllanguage/data/singleton/remote/RemoteSingletonType2.qml
new file mode 100644
index 0000000000..41d619a275
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/remote/RemoteSingletonType2.qml
@@ -0,0 +1,18 @@
+import QtQuick 2.0
+pragma Singleton
+
+Item {
+ id: singletonId
+
+ property int testProp1: 525
+ property int testProp2: 425
+ property int testProp3: 355
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+}
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/remote/qmldir b/tests/auto/qml/qqmllanguage/data/singleton/remote/qmldir
new file mode 100644
index 0000000000..c73782b825
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/remote/qmldir
@@ -0,0 +1 @@
+singleton RemoteSingletonType2 RemoteSingletonType2.qml \ No newline at end of file
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/subdir/ErrorSingletonType.qml b/tests/auto/qml/qqmllanguage/data/singleton/subdir/ErrorSingletonType.qml
new file mode 100644
index 0000000000..9a3b7abbd6
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/subdir/ErrorSingletonType.qml
@@ -0,0 +1,17 @@
+import QtQuick 2.0
+
+Item {
+ id: singletonId
+
+ property int testProp1: 125
+ property int testProp2: 25
+ property int testProp3: -55
+
+ width: 25; height: 25
+
+ Rectangle {
+ id: rectangle
+ border.color: "white"
+ anchors.fill: parent
+ }
+} \ No newline at end of file
diff --git a/tests/auto/qml/qqmllanguage/data/singleton/subdir/qmldir b/tests/auto/qml/qqmllanguage/data/singleton/subdir/qmldir
new file mode 100644
index 0000000000..eb702eccaf
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/singleton/subdir/qmldir
@@ -0,0 +1,3 @@
+singleton ErrorSingletonType ErrorSingletonType.qml
+
+