aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2019-01-08 13:32:41 +0100
committerMaximilian Goldstein <[email protected]>2020-07-24 08:30:52 +0000
commitcc91eb893e53ea2516d895bd1861c1159d5a5c90 (patch)
tree5c9611f52052050671ec72ff6be1d906114a7840 /sources/pyside2/tests
parent9c6e82e2857e4ce45c578b73807de4b3b941ab38 (diff)
PySide2: Add qmlRegisterUncreatableType()
Extend the Quick register helper function by the bool creatable and string noCreationReason parameters, extract a QML helper taking the same parameters and add the overload. Task-number: PYSIDE-574 Change-Id: I955dbd158c7b22d2637bbac464937f9fda6d7901 Reviewed-by: Friedemann Kleint <[email protected]> Reviewed-by: Cristian Maureira-Fredes <[email protected]>
Diffstat (limited to 'sources/pyside2/tests')
-rw-r--r--sources/pyside2/tests/QtQml/registertype.py36
-rw-r--r--sources/pyside2/tests/QtQml/registeruncreatable.qml43
2 files changed, 75 insertions, 4 deletions
diff --git a/sources/pyside2/tests/QtQml/registertype.py b/sources/pyside2/tests/QtQml/registertype.py
index 7e6fe8d29..53425b1b6 100644
--- a/sources/pyside2/tests/QtQml/registertype.py
+++ b/sources/pyside2/tests/QtQml/registertype.py
@@ -36,11 +36,26 @@ init_test_paths(False)
from helper.helper import adjust_filename
-from PySide2.QtCore import Property, QTimer, QUrl
+from PySide2.QtCore import Property, QObject, QTimer, QUrl
from PySide2.QtGui import QGuiApplication, QPen, QColor, QPainter
-from PySide2.QtQml import qmlRegisterType, ListProperty
+from PySide2.QtQml import qmlRegisterType, qmlRegisterUncreatableType, ListProperty
from PySide2.QtQuick import QQuickView, QQuickItem, QQuickPaintedItem
+noCreationReason = 'Cannot create an item of type: Uncreatable (expected)';
+
+class Uncreatable(QObject):
+ def __init__(self, parent = None):
+ QObject.__init__(self, parent)
+ self._name = 'uncreatable'
+
+ def getName(self):
+ return self._name
+
+ def setName(self, value):
+ self._name = value
+
+ name = Property(str, getName, setName)
+
class PieSlice (QQuickPaintedItem):
def __init__(self, parent = None):
QQuickPaintedItem.__init__(self, parent)
@@ -108,8 +123,10 @@ class TestQmlSupport(unittest.TestCase):
def testIt(self):
app = QGuiApplication([])
- qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart');
- qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice");
+ qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart')
+ self.assertTrue(qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice") > 0);
+ self.assertTrue(qmlRegisterUncreatableType(Uncreatable, 'Charts', 1, 0,
+ 'Uncreatable', noCreationReason) > 0);
view = QQuickView()
view.setSource(QUrl.fromLocalFile(adjust_filename('registertype.qml', __file__)))
@@ -119,5 +136,16 @@ class TestQmlSupport(unittest.TestCase):
self.assertTrue(appendCalled)
self.assertTrue(paintCalled)
+ # Check that the uncreatable item produces the correct error
+ view.setSource(QUrl.fromLocalFile(helper.adjust_filename('registeruncreatable.qml', __file__)))
+ self.assertEqual(view.status(), QQuickView.Error)
+ errorFound = False
+ for e in view.errors():
+ if noCreationReason in e.toString():
+ errorFound = True
+ break
+ self.assertTrue(errorFound)
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/pyside2/tests/QtQml/registeruncreatable.qml b/sources/pyside2/tests/QtQml/registeruncreatable.qml
new file mode 100644
index 000000000..347a8117a
--- /dev/null
+++ b/sources/pyside2/tests/QtQml/registeruncreatable.qml
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of Qt for Python.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import Charts 1.0
+
+Item {
+ width: 300; height: 200
+
+ Uncreatable {
+ name : 'uncreatable'
+ }
+
+ PieChart {
+ anchors.centerIn: parent
+ width: 100; height: 100
+ }
+}