diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-04-01 09:12:30 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-04-01 11:17:46 +0200 |
commit | 931f3115dab9141209aac9b8e87e25eba503b178 (patch) | |
tree | f15327fe431296628beedd2eb63b726edc86d882 /sources/pyside6 | |
parent | 4c0b1be1e2136b4c0c1f348cc1b80aeb9b179a11 (diff) |
Add QPyQmlParserStatus
[ChangeLog][PySide6] class QPyQmlParserStatus for handling
QML parser status changes has been added.
Fixes: PYSIDE-1876
Change-Id: Ic1066924ec85dc8633f959342921c1d03da1aee4
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside6')
-rw-r--r-- | sources/pyside6/PySide6/QtQml/CMakeLists.txt | 3 | ||||
-rw-r--r-- | sources/pyside6/PySide6/QtQml/QtQml_global.post.h.in | 1 | ||||
-rw-r--r-- | sources/pyside6/PySide6/QtQml/typesystem_qml.xml | 3 | ||||
-rw-r--r-- | sources/pyside6/PySide6/qpyqmlparserstatus.h | 60 | ||||
-rw-r--r-- | sources/pyside6/doc/extras/QtQml.QPyQmlParserStatus.rst | 10 | ||||
-rw-r--r-- | sources/pyside6/libpysideqml/pysideqmlregistertype.cpp | 26 | ||||
-rw-r--r-- | sources/pyside6/tests/QtQml/CMakeLists.txt | 1 | ||||
-rw-r--r-- | sources/pyside6/tests/QtQml/registerparserstatus.py | 85 | ||||
-rw-r--r-- | sources/pyside6/tests/QtQml/registerparserstatus.qml | 33 |
9 files changed, 215 insertions, 7 deletions
diff --git a/sources/pyside6/PySide6/QtQml/CMakeLists.txt b/sources/pyside6/PySide6/QtQml/CMakeLists.txt index c1d429be3..1826df947 100644 --- a/sources/pyside6/PySide6/QtQml/CMakeLists.txt +++ b/sources/pyside6/PySide6/QtQml/CMakeLists.txt @@ -1,8 +1,10 @@ project(QtQml) +qt_wrap_cpp(QPYQMLPARSERSTATUS_MOC "${pyside6_SOURCE_DIR}/qpyqmlparserstatus.h") qt_wrap_cpp(QPYQMLPROPERTYVALUESOURCE_MOC "${pyside6_SOURCE_DIR}/qpyqmlpropertyvaluesource.h") set(QtQml_static_sources "${QtQml_SOURCE_DIR}/pysideqmlvolatilebool.cpp" + "${QPYQMLPARSERSTATUS_MOC}" "${QPYQMLPROPERTYVALUESOURCE_MOC}") set(QtQml_SRC @@ -11,6 +13,7 @@ ${QtQml_GEN_DIR}/qjsmanagedvalue_wrapper.cpp ${QtQml_GEN_DIR}/qjsprimitivevalue_wrapper.cpp ${QtQml_GEN_DIR}/qjsvalue_wrapper.cpp ${QtQml_GEN_DIR}/qjsvalueiterator_wrapper.cpp +${QtQml_GEN_DIR}/qpyqmlparserstatus_wrapper.cpp ${QtQml_GEN_DIR}/qpyqmlpropertyvaluesource_wrapper.cpp ${QtQml_GEN_DIR}/qqmlabstracturlinterceptor_wrapper.cpp ${QtQml_GEN_DIR}/qqmlapplicationengine_wrapper.cpp diff --git a/sources/pyside6/PySide6/QtQml/QtQml_global.post.h.in b/sources/pyside6/PySide6/QtQml/QtQml_global.post.h.in index 5077a628d..64c563753 100644 --- a/sources/pyside6/PySide6/QtQml/QtQml_global.post.h.in +++ b/sources/pyside6/PySide6/QtQml/QtQml_global.post.h.in @@ -1 +1,2 @@ +#include "qpyqmlparserstatus.h" #include "qpyqmlpropertyvaluesource.h" diff --git a/sources/pyside6/PySide6/QtQml/typesystem_qml.xml b/sources/pyside6/PySide6/QtQml/typesystem_qml.xml index 18627f8d8..b880e5cdd 100644 --- a/sources/pyside6/PySide6/QtQml/typesystem_qml.xml +++ b/sources/pyside6/PySide6/QtQml/typesystem_qml.xml @@ -275,7 +275,8 @@ for the QML parts. <value-type name="QQmlListProperty"/>--> <value-type name="QQmlListReference"/> - <interface-type name="QQmlParserStatus"/> + <object-type name="QQmlParserStatus"/> + <object-type name="QPyQmlParserStatus"/> <value-type name="QQmlProperty"> <enum-type name="PropertyTypeCategory"/> <enum-type name="Type"/> diff --git a/sources/pyside6/PySide6/qpyqmlparserstatus.h b/sources/pyside6/PySide6/qpyqmlparserstatus.h new file mode 100644 index 000000000..52e9cd57a --- /dev/null +++ b/sources/pyside6/PySide6/qpyqmlparserstatus.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPYQMLPARSERSTATUS_H +#define QPYQMLPARSERSTATUS_H + +#include <QtCore/QObject> +#include <QtQml/QQmlParserStatus> + +#ifdef Q_MOC_RUN +Q_DECLARE_INTERFACE(QQmlParserStatus, "org.qt-project.Qt.QQmlParserStatus") +#endif + +// Inherit from QObject such that QQmlParserStatus can be found at +// a fixed offset (RegisterType::parserStatusCast). +class QPyQmlParserStatus : public QObject, public QQmlParserStatus +{ + Q_OBJECT + Q_INTERFACES(QQmlParserStatus) +public: + explicit QPyQmlParserStatus(QObject *parent = nullptr) : QObject(parent) {} +}; + +#endif // QPYQMLPARSERSTATUS_H diff --git a/sources/pyside6/doc/extras/QtQml.QPyQmlParserStatus.rst b/sources/pyside6/doc/extras/QtQml.QPyQmlParserStatus.rst new file mode 100644 index 000000000..58f609b03 --- /dev/null +++ b/sources/pyside6/doc/extras/QtQml.QPyQmlParserStatus.rst @@ -0,0 +1,10 @@ +.. currentmodule:: PySide6.QtQml +.. _QPyQmlParserStatus: + +QPyQmlParserStatus +****************** + +QPyQmlParserStatus is the base class for implementing +`QQmlParserStatus <https://doc.qt.io/qt-6/qqmlparserstatus.html>`_ + +It provides the required inheritance from **QObject**. diff --git a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp index bbcf63e98..f0be990de 100644 --- a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp +++ b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp @@ -99,16 +99,28 @@ static PyTypeObject *qQJSValueType() return result; } -// Check if o inherits from QPyQmlPropertyValueSource. -static bool isQmlPropertyValueSource(const QMetaObject *o) +// Check if o inherits from baseClass +static bool inheritsFrom(const QMetaObject *o, const char *baseClass) { for (auto *base = o->superClass(); base ; base = base->superClass()) { - if (qstrcmp(base->className(), "QPyQmlPropertyValueSource") == 0) + if (qstrcmp(base->className(), baseClass) == 0) return true; } return false; } +// Check if o inherits from QPyQmlPropertyValueSource. +static inline bool isQmlPropertyValueSource(const QMetaObject *o) +{ + return inheritsFrom(o, "QPyQmlPropertyValueSource"); +} + +// Check if o inherits from QQmlParserStatus. +static inline bool isQmlParserStatus(const QMetaObject *o) +{ + return inheritsFrom(o, "QPyQmlParserStatus"); +} + namespace PySide::Qml { int qmlRegisterType(PyObject *pyObj, const char *uri, int versionMajor, @@ -156,10 +168,12 @@ int qmlRegisterType(PyObject *pyObj, const char *uri, int versionMajor, type.attachedPropertiesMetaObject = info.metaObject; if (!isQuickType) { // values filled by the Quick registration - type.parserStatusCast = - QQmlPrivate::StaticCastSelector<QObject, QQmlParserStatus>::cast(); - // QPyQmlPropertyValueSource inherits QObject, QmlPropertyValueSource, so, + // QPyQmlParserStatus inherits QObject, QQmlParserStatus, so, // it is found behind the QObject. + type.parserStatusCast = isQmlParserStatus(metaObject) + ? int(sizeof(QObject)) + : QQmlPrivate::StaticCastSelector<QObject, QQmlParserStatus>::cast(); + // Similar for QPyQmlPropertyValueSource type.valueSourceCast = isQmlPropertyValueSource(metaObject) ? int(sizeof(QObject)) : QQmlPrivate::StaticCastSelector<QObject, QQmlPropertyValueSource>::cast(); diff --git a/sources/pyside6/tests/QtQml/CMakeLists.txt b/sources/pyside6/tests/QtQml/CMakeLists.txt index 0006accde..fc931c0f2 100644 --- a/sources/pyside6/tests/QtQml/CMakeLists.txt +++ b/sources/pyside6/tests/QtQml/CMakeLists.txt @@ -19,6 +19,7 @@ PYSIDE_TEST(qquickview_test.py) PYSIDE_TEST(connect_python_qml.py) PYSIDE_TEST(registerattached.py) PYSIDE_TEST(registerextended.py) +PYSIDE_TEST(registerparserstatus.py) PYSIDE_TEST(registertype.py) PYSIDE_TEST(registerforeign.py) PYSIDE_TEST(registerqmlfile.py) diff --git a/sources/pyside6/tests/QtQml/registerparserstatus.py b/sources/pyside6/tests/QtQml/registerparserstatus.py new file mode 100644 index 000000000..d19f09474 --- /dev/null +++ b/sources/pyside6/tests/QtQml/registerparserstatus.py @@ -0,0 +1,85 @@ +############################################################################# +## +## Copyright (C) 2022 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 os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide6.QtCore import (QCoreApplication, QUrl) +from PySide6.QtQml import (QQmlComponent, QQmlEngine, + QmlElement, QPyQmlParserStatus) + + +QML_IMPORT_NAME = "ParserStatus" +QML_IMPORT_MAJOR_VERSION = 1 + + +def component_error(component): + result = "" + for e in component.errors(): + if result: + result += "\n" + result += str(e) + return result + + +@QmlElement +class TestItem(QPyQmlParserStatus): + + def __init__(self, parent=None): + super().__init__(parent) + self.component_complete_called = False + self.class_begin_called = False + + def componentComplete(self): + self.component_complete_called = True + + def classBegin(self): + self.class_begin_called = True + + +class TestQmlAttached(unittest.TestCase): + def testIt(self): + app = QCoreApplication(sys.argv) + file = Path(__file__).resolve().parent / 'registerparserstatus.qml' + url = QUrl.fromLocalFile(file) + engine = QQmlEngine() + component = QQmlComponent(engine, url) + item = component.create() + self.assertTrue(item, component_error(component)) + self.assertTrue(item.component_complete_called) + self.assertTrue(item.class_begin_called) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/pyside6/tests/QtQml/registerparserstatus.qml b/sources/pyside6/tests/QtQml/registerparserstatus.qml new file mode 100644 index 000000000..68b12a9a8 --- /dev/null +++ b/sources/pyside6/tests/QtQml/registerparserstatus.qml @@ -0,0 +1,33 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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 ParserStatus + +TestItem { + id: item +} |