diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-05-19 07:24:12 +0300 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-05-19 07:24:12 +0300 |
commit | bb5d10f926c51aa462a56ffb331afd4f9607855c (patch) | |
tree | b695ab2c64c7fa115fc250df4adb11aba85b0dd3 | |
parent | dcbd73cf3e8a07dbfa249d7db2257caafa83781b (diff) | |
parent | d955df6e78a8bb033adf4842c1bb205634de13b9 (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.5' into tqtc/lts-5.15-opensourcev5.15.5-lts-lgpl
Change-Id: I0ca57eebe4b56fcad4e0af474b9b409e79a5c6ef
-rw-r--r-- | .qmake.conf | 2 | ||||
-rw-r--r-- | src/scxml/qscxmlcompiler.cpp | 56 | ||||
-rw-r--r-- | tests/auto/auto.pro | 3 | ||||
-rw-r--r-- | tests/auto/qmltest/qmltest.pro | 14 | ||||
-rw-r--r-- | tests/auto/qmltest/statemachine.scxml | 45 | ||||
-rw-r--r-- | tests/auto/qmltest/tst_dynamic.qml | 52 | ||||
-rw-r--r-- | tests/auto/qmltest/tst_scxmlqml.cpp | 30 | ||||
-rw-r--r-- | tests/auto/qmltest/tst_scxmlqml.qrc | 5 |
8 files changed, 178 insertions, 29 deletions
diff --git a/.qmake.conf b/.qmake.conf index 44eb13b..4d5b540 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -4,4 +4,4 @@ CONFIG += warning_clean DEFINES += QT_NO_FOREACH QT_NO_JAVA_STYLE_ITERATORS QT_NO_LINKED_LIST -MODULE_VERSION = 5.15.4 +MODULE_VERSION = 5.15.5 diff --git a/src/scxml/qscxmlcompiler.cpp b/src/scxml/qscxmlcompiler.cpp index b9bd102..9ddb581 100644 --- a/src/scxml/qscxmlcompiler.cpp +++ b/src/scxml/qscxmlcompiler.cpp @@ -54,6 +54,14 @@ #include "qscxmltabledata_p.h" #include <private/qmetaobjectbuilder_p.h> +#if QT_CONFIG(scxml_ecmascriptdatamodel) +// In Qt5 the ecmascript datamodel brings in QML dependency. +// We use that to include the QML headers needed for invalidating +// property cache, even though strictly speaking these are distinct +// functionalities. +#include <private/qqmldata_p.h> +#include <private/qqmlpropertycache_p.h> +#endif #endif // BUILD_QSCXMLC #include <functional> @@ -485,31 +493,9 @@ private: class DynamicStateMachinePrivate : public QScxmlStateMachinePrivate { - struct DynamicMetaObject : public QAbstractDynamicMetaObject - { - QAbstractDynamicMetaObject *toDynamicMetaObject(QObject *) override - { - return this; - } - - int metaCall(QObject *o, QMetaObject::Call c, int id, void **a) override - { - return o->qt_metacall(c, id, a); - } - }; - public: DynamicStateMachinePrivate() : - QScxmlStateMachinePrivate(&QScxmlStateMachine::staticMetaObject) - { - metaObject = new DynamicMetaObject; - } - - void setDynamicMetaObject(const QMetaObject *m) { - // Prevent the QML engine from creating a property cache for this thing. - static_cast<DynamicMetaObject *>(metaObject)->d = m->d; - m_metaObject = m; - } + QScxmlStateMachinePrivate(&QScxmlStateMachine::staticMetaObject) {} }; class DynamicStateMachine: public QScxmlStateMachine, public QScxmlInternal::GeneratedTableData @@ -566,7 +552,7 @@ private: b.setClassName("DynamicStateMachine"); b.setSuperClass(&QScxmlStateMachine::staticMetaObject); b.setStaticMetacallFunction(qt_static_metacall); - d->setDynamicMetaObject(b.toMetaObject()); + d->m_metaObject = b.toMetaObject(); } void initDynamicParts(const MetaDataInfo &info) @@ -575,7 +561,7 @@ private: // Release the temporary QMetaObject. Q_ASSERT(d->m_metaObject != &QScxmlStateMachine::staticMetaObject); free(const_cast<QMetaObject *>(d->m_metaObject)); - d->setDynamicMetaObject(&QScxmlStateMachine::staticMetaObject); + d->m_metaObject = &QScxmlStateMachine::staticMetaObject; // Build the real one. QMetaObjectBuilder b; @@ -601,7 +587,7 @@ private: } // And we're done - d->setDynamicMetaObject(b.toMetaObject()); + d->m_metaObject = b.toMetaObject(); } public: @@ -609,8 +595,24 @@ public: { Q_D(DynamicStateMachine); if (d->m_metaObject != &QScxmlStateMachine::staticMetaObject) { +#if QT_CONFIG(scxml_ecmascriptdatamodel) + // Invalidate the QML property cache as we delete the dynamic + // metaobject, otherwise stale string accesses might occur. + // Important! This invalidation is a workaround and brittle at + // at best; while string cache will be cleared, the cache itself + // will not. Instead we rely on that the (only) user for the cache + // is gone as well. This workaround is specific to Qt5, in Qt6 + // we are able to fix the issue more properly by marking the + // metaobject dynamic => QML property caching will not be done. + // + // All further interaction with this property cache must be + // avoided. + QQmlData *ddata = QQmlData::get(this, false); + if (ddata && ddata->propertyCache) + ddata->propertyCache->invalidate(d->m_metaObject); +#endif free(const_cast<QMetaObject *>(d->m_metaObject)); - d->setDynamicMetaObject(&QScxmlStateMachine::staticMetaObject); + d->m_metaObject = &QScxmlStateMachine::staticMetaObject; } } diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 60576d5..acce986 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -5,4 +5,5 @@ SUBDIRS = cmake\ parser\ scion\ statemachine \ - statemachineinfo + statemachineinfo \ + qmltest diff --git a/tests/auto/qmltest/qmltest.pro b/tests/auto/qmltest/qmltest.pro new file mode 100644 index 0000000..c9649bf --- /dev/null +++ b/tests/auto/qmltest/qmltest.pro @@ -0,0 +1,14 @@ +TEMPLATE = app +TARGET = tst_scxmlqml +CONFIG += qmltestcase + +SOURCES += \ + $$PWD/tst_scxmlqml.cpp + +RESOURCES += tst_scxmlqml.qrc + +OTHER_FILES += \ + $$PWD/*.qml + +TESTDATA += \ + $$PWD/tst_* diff --git a/tests/auto/qmltest/statemachine.scxml b/tests/auto/qmltest/statemachine.scxml new file mode 100644 index 0000000..68c9768 --- /dev/null +++ b/tests/auto/qmltest/statemachine.scxml @@ -0,0 +1,45 @@ +<?xml version="1.0" ?> +<!-- +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtScxml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +--> +<scxml xmlns="http://www.w3.org/2005/07/scxml" + version="1.0" + name="ColorStepper" + initial="red"> + + <state id = "red"> + <transition target="yellow" event="step"/> + </state> + + <state id = "yellow"> + <transition target="green" event="step"/> + </state> + + <final id="green"/> +</scxml> diff --git a/tests/auto/qmltest/tst_dynamic.qml b/tests/auto/qmltest/tst_dynamic.qml new file mode 100644 index 0000000..f8c411d --- /dev/null +++ b/tests/auto/qmltest/tst_dynamic.qml @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtTest 1.15 +import QtScxml 5.15 + +TestCase { + id: testCase + + StateMachineLoader { + id: loader + source: "qrc:///statemachine.scxml" + } + + function test_overloaded_calls_with_dynamic_statemachine() + { + // This test calls "submitEvent" invokable function which has 3 + // overloads, differentiated both by parameter types and amounts. + // Test verifies that the overloads are callable while using + // a dynamic statemachine which has a dynamic metaobject under the hood + tryVerify(() => loader.stateMachine.activeStateNames()[0] === "red", 200) + loader.stateMachine.submitEvent("step") + tryVerify(() => loader.stateMachine.activeStateNames()[0] === "yellow", 200) + loader.stateMachine.submitEvent("step", "somedata") + tryVerify(() => loader.stateMachine.activeStateNames()[0] === "green", 200) + } +} diff --git a/tests/auto/qmltest/tst_scxmlqml.cpp b/tests/auto/qmltest/tst_scxmlqml.cpp new file mode 100644 index 0000000..a32c12a --- /dev/null +++ b/tests/auto/qmltest/tst_scxmlqml.cpp @@ -0,0 +1,30 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtQuickTest/quicktest.h> +QUICK_TEST_MAIN(tst_scxmlqml) diff --git a/tests/auto/qmltest/tst_scxmlqml.qrc b/tests/auto/qmltest/tst_scxmlqml.qrc new file mode 100644 index 0000000..241bd0b --- /dev/null +++ b/tests/auto/qmltest/tst_scxmlqml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>statemachine.scxml</file> + </qresource> +</RCC> |