diff options
author | Juha Vuolle <juha.vuolle@insta.fi> | 2021-01-29 12:33:00 +0200 |
---|---|---|
committer | Juha Vuolle <juha.vuolle@insta.fi> | 2021-02-01 15:37:06 +0200 |
commit | 4fe43e74a2eebdc40529cd0478d19a79a71a4508 (patch) | |
tree | 3d420a1b1e012923fd959d5c7a60b4fd5c3e1fa7 | |
parent | 35ea838b469e95825a7e34651724f609ca2202c9 (diff) |
Make Scxml QML plugin optional
This change adds a small regular library that handles the Scxml
QML element registration. The current QML plugin now links against this
new library, and the QML plugin is optional. In addition
there are few other sanitising changes:
-The QScxmlEvent is registered as an element instead of getting just
the metatypeid. Tested that tests still compile with MSVC2019.
The original reason for the registration was that tests did not
compile with MSVC2015 (but testing Qt6 against that version is not
feasible, hence MSVC2019)
-A compiler warning removal about QString concatenation on MSVC
-Reduce unnecessary dependencies to “Private” libraries. Library
compiles and tests/examples work without them
Task-number: QTBUG-89832
Change-Id: Iede6a7a9a82e40c3dbb868d9129847590769ca40
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/imports/scxmlstatemachine/CMakeLists.txt | 15 | ||||
-rw-r--r-- | src/imports/scxmlstatemachine/plugin.cpp | 17 | ||||
-rw-r--r-- | src/imports/scxmlstatemachine/qmldir | 5 | ||||
-rw-r--r-- | src/imports/scxmlstatemachine/scxmlstatemachine.pro | 23 | ||||
-rw-r--r-- | src/scxml/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/scxmlqml/CMakeLists.txt | 25 | ||||
-rw-r--r-- | src/scxmlqml/eventconnection.cpp (renamed from src/imports/scxmlstatemachine/eventconnection.cpp) | 0 | ||||
-rw-r--r-- | src/scxmlqml/eventconnection_p.h (renamed from src/imports/scxmlstatemachine/eventconnection_p.h) | 14 | ||||
-rw-r--r-- | src/scxmlqml/invokedservices.cpp (renamed from src/imports/scxmlstatemachine/invokedservices.cpp) | 0 | ||||
-rw-r--r-- | src/scxmlqml/invokedservices_p.h (renamed from src/imports/scxmlstatemachine/invokedservices_p.h) | 4 | ||||
-rw-r--r-- | src/scxmlqml/qscxmlqmlglobals_p.h | 74 | ||||
-rw-r--r-- | src/scxmlqml/statemachineextended.cpp (renamed from src/imports/scxmlstatemachine/statemachineextended.cpp) | 0 | ||||
-rw-r--r-- | src/scxmlqml/statemachineextended_p.h (renamed from src/imports/scxmlstatemachine/statemachineextended_p.h) | 7 | ||||
-rw-r--r-- | src/scxmlqml/statemachineloader.cpp (renamed from src/imports/scxmlstatemachine/statemachineloader.cpp) | 2 | ||||
-rw-r--r-- | src/scxmlqml/statemachineloader_p.h (renamed from src/imports/scxmlstatemachine/statemachineloader_p.h) | 4 | ||||
-rw-r--r-- | sync.profile | 1 |
17 files changed, 132 insertions, 64 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1c98c3e..c6335df 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,5 +3,6 @@ add_subdirectory(scxml) add_subdirectory(statemachine) if(TARGET Qt::Qml) + add_subdirectory(scxmlqml) add_subdirectory(imports) endif() diff --git a/src/imports/scxmlstatemachine/CMakeLists.txt b/src/imports/scxmlstatemachine/CMakeLists.txt index 01585ed..d6e7162 100644 --- a/src/imports/scxmlstatemachine/CMakeLists.txt +++ b/src/imports/scxmlstatemachine/CMakeLists.txt @@ -1,3 +1,4 @@ + # Generated from scxmlstatemachine.pro. ##################################################################### @@ -9,18 +10,14 @@ qt_internal_add_qml_module(declarative_scxml # special case VERSION "${CMAKE_PROJECT_VERSION}" CLASSNAME QScxmlStateMachinePlugin SKIP_TYPE_REGISTRATION - GENERATE_QMLTYPES - INSTALL_QMLTYPES + PLUGIN_OPTIONAL SOURCES - eventconnection.cpp eventconnection_p.h - invokedservices.cpp invokedservices_p.h plugin.cpp - statemachineextended.cpp statemachineextended_p.h - statemachineloader.cpp statemachineloader_p.h PUBLIC_LIBRARIES - Qt::CorePrivate - Qt::QmlPrivate - Qt::Scxml + Qt::Core + Qt::Qml + LIBRARIES + Qt::ScxmlQmlPrivate ) #### Keys ignored in scope 1:.:.:scxmlstatemachine.pro:<TRUE>: diff --git a/src/imports/scxmlstatemachine/plugin.cpp b/src/imports/scxmlstatemachine/plugin.cpp index e494422..9812406 100644 --- a/src/imports/scxmlstatemachine/plugin.cpp +++ b/src/imports/scxmlstatemachine/plugin.cpp @@ -37,17 +37,10 @@ ** ****************************************************************************/ -#include "statemachineloader_p.h" -#include "eventconnection_p.h" -#include "qscxmlevent.h" -#include "statemachineextended_p.h" -#include "invokedservices_p.h" - +#include <QtScxmlQml/private/qscxmlqmlglobals_p.h> #include <QtQml/qqmlextensionplugin.h> #include <QtQml/qqml.h> -extern void qml_register_types_QtScxml(); - QT_BEGIN_NAMESPACE class QScxmlStateMachinePlugin : public QQmlExtensionPlugin @@ -59,14 +52,6 @@ public: QScxmlStateMachinePlugin(QObject *parent = nullptr) : QQmlExtensionPlugin(parent) { } void registerTypes(const char *) override { - // Do not rely on RegisterMethodArgumentMetaType meta-call to register the QScxmlEvent type. - // This registration is required for the receiving end of the signal emission that carries - // parameters of this type to be able to treat them correctly as a gadget. This is because the - // receiving end of the signal is a generic method in the QML engine, at which point it's too late - // to do a meta-type registration. - static const int qScxmlEventMetaTypeId = qMetaTypeId<QScxmlEvent>(); - Q_UNUSED(qScxmlEventMetaTypeId); - // Build-time generated registration function volatile auto registration = &qml_register_types_QtScxml; Q_UNUSED(registration); diff --git a/src/imports/scxmlstatemachine/qmldir b/src/imports/scxmlstatemachine/qmldir deleted file mode 100644 index e836ddd..0000000 --- a/src/imports/scxmlstatemachine/qmldir +++ /dev/null @@ -1,5 +0,0 @@ -module QtScxml -plugin declarative_scxml -classname QScxmlStateMachinePlugin -typeinfo plugins.qmltypes - diff --git a/src/imports/scxmlstatemachine/scxmlstatemachine.pro b/src/imports/scxmlstatemachine/scxmlstatemachine.pro deleted file mode 100644 index 9bc7c72..0000000 --- a/src/imports/scxmlstatemachine/scxmlstatemachine.pro +++ /dev/null @@ -1,23 +0,0 @@ -TARGET = scxml -TARGETPATH = QtScxml -IMPORT_VERSION = 5.$$QT_MINOR_VERSION - -QT = scxml qml-private core-private - -SOURCES = \ - $$PWD/plugin.cpp \ - $$PWD/statemachineloader.cpp \ - $$PWD/eventconnection.cpp \ - $$PWD/statemachineextended.cpp \ - $$PWD/invokedservices.cpp - -HEADERS = \ - $$PWD/eventconnection_p.h \ - $$PWD/invokedservices_p.h \ - $$PWD/statemachineextended_p.h \ - $$PWD/statemachineloader_p.h - - -load(qml_plugin) - -OTHER_FILES += plugins.qmltypes qmldir diff --git a/src/scxml/CMakeLists.txt b/src/scxml/CMakeLists.txt index cdba643..d96f7f7 100644 --- a/src/scxml/CMakeLists.txt +++ b/src/scxml/CMakeLists.txt @@ -22,12 +22,8 @@ qt_internal_add_module(Scxml DEFINES QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII - LIBRARIES - Qt::CorePrivate PUBLIC_LIBRARIES Qt::Core - PRIVATE_MODULE_INTERFACE - Qt::CorePrivate ) # This allows QML element registration outside of this module with the "QML_ELEMENT" & friends diff --git a/src/scxmlqml/CMakeLists.txt b/src/scxmlqml/CMakeLists.txt new file mode 100644 index 0000000..0ddc9fc --- /dev/null +++ b/src/scxmlqml/CMakeLists.txt @@ -0,0 +1,25 @@ +qt_internal_add_module(ScxmlQml + GENERATE_METATYPES + SOURCES + eventconnection.cpp eventconnection_p.h + invokedservices.cpp invokedservices_p.h + statemachineextended.cpp statemachineextended_p.h + statemachineloader.cpp statemachineloader_p.h + qscxmlqmlglobals_p.h + DEFINES + QT_BUILD_SCXMLQML_LIB + PUBLIC_LIBRARIES + Qt::Core + Qt::Qml + Qt::Scxml +) + +set_target_properties(ScxmlQml PROPERTIES + QT_QML_MODULE_INSTALL_QMLTYPES TRUE + QT_QML_MODULE_VERSION ${CMAKE_PROJECT_VERSION} + QT_QML_MODULE_URI QtScxml + QT_QMLTYPES_FILENAME plugins.qmltypes + QT_QML_MODULE_INSTALL_DIR "${INSTALL_QMLDIR}/QtScxml" +) + +qt6_qml_type_registration(ScxmlQml) diff --git a/src/imports/scxmlstatemachine/eventconnection.cpp b/src/scxmlqml/eventconnection.cpp index 2a073bd..2a073bd 100644 --- a/src/imports/scxmlstatemachine/eventconnection.cpp +++ b/src/scxmlqml/eventconnection.cpp diff --git a/src/imports/scxmlstatemachine/eventconnection_p.h b/src/scxmlqml/eventconnection_p.h index 1bdf104..f2a8f60 100644 --- a/src/imports/scxmlstatemachine/eventconnection_p.h +++ b/src/scxmlqml/eventconnection_p.h @@ -51,14 +51,26 @@ // We mean it. // +#include "qscxmlqmlglobals_p.h" + #include <QtScxml/qscxmlstatemachine.h> +#include <QtScxml/qscxmlevent.h> #include <QtCore/qobject.h> #include <QtQml/qqmlparserstatus.h> #include <QtQml/qqml.h> QT_BEGIN_NAMESPACE -class QScxmlEventConnection : public QObject, public QQmlParserStatus +// QScxmlEvent is used as signal parameter, and defined in the cpp lib +struct Q_SCXMLQML_PRIVATE_EXPORT QScxmlEventForeign +{ + Q_GADGET + QML_ANONYMOUS + QML_FOREIGN(QScxmlEvent) + QML_ADDED_IN_VERSION(5,8) +}; + +class Q_SCXMLQML_PRIVATE_EXPORT QScxmlEventConnection : public QObject, public QQmlParserStatus { Q_OBJECT Q_PROPERTY(QStringList events READ events WRITE setEvents NOTIFY eventsChanged) diff --git a/src/imports/scxmlstatemachine/invokedservices.cpp b/src/scxmlqml/invokedservices.cpp index 53cac0e..53cac0e 100644 --- a/src/imports/scxmlstatemachine/invokedservices.cpp +++ b/src/scxmlqml/invokedservices.cpp diff --git a/src/imports/scxmlstatemachine/invokedservices_p.h b/src/scxmlqml/invokedservices_p.h index 9d49f77..7436f00 100644 --- a/src/imports/scxmlstatemachine/invokedservices_p.h +++ b/src/scxmlqml/invokedservices_p.h @@ -51,6 +51,8 @@ // We mean it. // +#include "qscxmlqmlglobals_p.h" + #include <QtQml/qqmlparserstatus.h> #include <QtQml/qqmllist.h> #include <QtQml/qqml.h> @@ -58,7 +60,7 @@ QT_BEGIN_NAMESPACE -class QScxmlInvokedServices : public QObject, public QQmlParserStatus +class Q_SCXMLQML_PRIVATE_EXPORT QScxmlInvokedServices : public QObject, public QQmlParserStatus { Q_OBJECT Q_PROPERTY(QScxmlStateMachine *stateMachine READ stateMachine WRITE setStateMachine diff --git a/src/scxmlqml/qscxmlqmlglobals_p.h b/src/scxmlqml/qscxmlqmlglobals_p.h new file mode 100644 index 0000000..b59a03a --- /dev/null +++ b/src/scxmlqml/qscxmlqmlglobals_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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: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 QSCXMLQMLGLOBALS_P_H +#define QSCXMLQMLGLOBALS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qglobal.h> + +QT_BEGIN_NAMESPACE + +#if !defined(QT_STATIC) +# if defined(QT_BUILD_SCXMLQML_LIB) +# define Q_SCXMLQML_EXPORT Q_DECL_EXPORT +# else +# define Q_SCXMLQML_EXPORT Q_DECL_IMPORT +# endif +#else +# define Q_SCXMLQML_EXPORT +#endif + +#define Q_SCXMLQML_PRIVATE_EXPORT Q_SCXMLQML_EXPORT + +QT_END_NAMESPACE + +void Q_SCXMLQML_PRIVATE_EXPORT qml_register_types_QtScxml(); + +#endif // QSCXMLQMLGLOBALS_P_H diff --git a/src/imports/scxmlstatemachine/statemachineextended.cpp b/src/scxmlqml/statemachineextended.cpp index 4434931..4434931 100644 --- a/src/imports/scxmlstatemachine/statemachineextended.cpp +++ b/src/scxmlqml/statemachineextended.cpp diff --git a/src/imports/scxmlstatemachine/statemachineextended_p.h b/src/scxmlqml/statemachineextended_p.h index 8e0d0e4..47167fd 100644 --- a/src/imports/scxmlstatemachine/statemachineextended_p.h +++ b/src/scxmlqml/statemachineextended_p.h @@ -51,7 +51,8 @@ // We mean it. // -#include <QtScxml/qscxmlglobals.h> +#include "qscxmlqmlglobals_p.h" + #include <QtScxml/qscxmlstatemachine.h> #include <QtCore/qobject.h> #include <QtQml/qqmllist.h> @@ -60,7 +61,7 @@ QT_BEGIN_NAMESPACE /* Allow State Machines created from QML to have children. */ -class QScxmlStateMachineExtended : public QObject +class Q_SCXMLQML_PRIVATE_EXPORT QScxmlStateMachineExtended : public QObject { Q_OBJECT Q_PROPERTY(QQmlListProperty<QObject> children READ children) @@ -74,7 +75,7 @@ private: }; // The QScxmlStateMachine is defined in the scxml library -struct QScxmlStateMachineForeign +struct Q_SCXMLQML_PRIVATE_EXPORT QScxmlStateMachineForeign { Q_GADGET QML_UNCREATABLE("Only created through derived types") diff --git a/src/imports/scxmlstatemachine/statemachineloader.cpp b/src/scxmlqml/statemachineloader.cpp index 1d312a5..5ef9643 100644 --- a/src/imports/scxmlstatemachine/statemachineloader.cpp +++ b/src/scxmlqml/statemachineloader.cpp @@ -167,7 +167,7 @@ bool QScxmlStateMachineLoader::parse(const QUrl &source) if (source.isLocalFile()) { fileName = source.toLocalFile(); } else if (source.scheme() == QStringLiteral("qrc")) { - fileName = ":" + source.path(); + fileName = QStringLiteral(":") + source.path(); } else { qmlWarning(this) << QStringLiteral("%1 is neither a local nor a resource URL.") .arg(source.url()) diff --git a/src/imports/scxmlstatemachine/statemachineloader_p.h b/src/scxmlqml/statemachineloader_p.h index 09d8270..ff9d867 100644 --- a/src/imports/scxmlstatemachine/statemachineloader_p.h +++ b/src/scxmlqml/statemachineloader_p.h @@ -51,13 +51,15 @@ // We mean it. // +#include "qscxmlqmlglobals_p.h" + #include <QtCore/qurl.h> #include <QtScxml/qscxmlstatemachine.h> #include <private/qqmlengine_p.h> QT_BEGIN_NAMESPACE -class QScxmlStateMachineLoader: public QObject +class Q_SCXMLQML_PRIVATE_EXPORT QScxmlStateMachineLoader: public QObject { Q_OBJECT Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) diff --git a/sync.profile b/sync.profile index 8cb4265..557bcc3 100644 --- a/sync.profile +++ b/sync.profile @@ -1,5 +1,6 @@ %modules = ( # path to module name map "QtScxml" => "$basedir/src/scxml", + "QtScxmlQml" => "$basedir/src/scxmlqml", "QtStateMachine" => "$basedir/src/statemachine", ); %moduleheaders = ( # restrict the module headers to those found in relative path |