diff options
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/templates/qquicktemplates2valuetypeprovider.cpp | 159 | ||||
-rw-r--r-- | src/imports/templates/qquicktemplates2valuetypeprovider_p.h | 68 | ||||
-rw-r--r-- | src/imports/templates/qtquicktemplates2plugin.cpp | 24 | ||||
-rw-r--r-- | src/imports/templates/templates.pro | 4 |
4 files changed, 11 insertions, 244 deletions
diff --git a/src/imports/templates/qquicktemplates2valuetypeprovider.cpp b/src/imports/templates/qquicktemplates2valuetypeprovider.cpp deleted file mode 100644 index 6debdbc4..00000000 --- a/src/imports/templates/qquicktemplates2valuetypeprovider.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qquicktemplates2valuetypeprovider_p.h" - -#include <QtQml/private/qqmlvaluetype_p.h> -#include <QtQuickTemplates2/private/qquickpalette_p.h> - -QT_BEGIN_NAMESPACE - -#if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) - #define ASSERT_VALID_SIZE(size, min) Q_UNUSED(size) -#else - #define ASSERT_VALID_SIZE(size, min) Q_ASSERT(size >= min) -#endif - -const QMetaObject *QQuickTemplates2ValueTypeProvider::getMetaObjectForMetaType(int type) -{ - switch (type) { - case QMetaType::QPalette: - return &QQuickPalette::staticMetaObject; - default: - break; - } - - return nullptr; -} - -bool QQuickTemplates2ValueTypeProvider::init(int type, QVariant& dst) -{ - switch (type) { - case QMetaType::QPalette: - dst.setValue<QPalette>(QPalette()); - return true; - default: break; - } - - return false; -} - -template<typename T> -bool typedEqual(const void *lhs, const QVariant& rhs) -{ - return (*(reinterpret_cast<const T *>(lhs)) == rhs.value<T>()); -} - -bool QQuickTemplates2ValueTypeProvider::equal(int type, const void *lhs, const QVariant &rhs) -{ - switch (type) { - case QMetaType::QPalette: - return typedEqual<QPalette>(lhs, rhs); - default: break; - } - - return false; -} - -template<typename T> -bool typedStore(const void *src, void *dst, size_t dstSize) -{ - ASSERT_VALID_SIZE(dstSize, sizeof(T)); - const T *srcT = reinterpret_cast<const T *>(src); - T *dstT = reinterpret_cast<T *>(dst); - new (dstT) T(*srcT); - return true; -} - -bool QQuickTemplates2ValueTypeProvider::store(int type, const void *src, void *dst, size_t dstSize) -{ - switch (type) { - case QMetaType::QPalette: - return typedStore<QPalette>(src, dst, dstSize); - default: break; - } - - return false; -} - -template<typename T> -bool typedRead(const QVariant& src, int dstType, void *dst) -{ - T *dstT = reinterpret_cast<T *>(dst); - if (src.type() == static_cast<uint>(dstType)) { - *dstT = src.value<T>(); - } else { - *dstT = T(); - } - return true; -} - -bool QQuickTemplates2ValueTypeProvider::read(const QVariant &src, void *dst, int dstType) -{ - switch (dstType) { - case QMetaType::QPalette: - return typedRead<QPalette>(src, dstType, dst); - default: break; - } - - return false; -} - -template<typename T> -bool typedWrite(const void *src, QVariant& dst) -{ - const T *srcT = reinterpret_cast<const T *>(src); - if (dst.value<T>() != *srcT) { - dst = *srcT; - return true; - } - return false; -} - -bool QQuickTemplates2ValueTypeProvider::write(int type, const void *src, QVariant& dst) -{ - switch (type) { - case QMetaType::QPalette: - return typedWrite<QPalette>(src, dst); - default: break; - } - - return false; -} - -#undef ASSERT_VALID_SIZE - -QT_END_NAMESPACE diff --git a/src/imports/templates/qquicktemplates2valuetypeprovider_p.h b/src/imports/templates/qquicktemplates2valuetypeprovider_p.h deleted file mode 100644 index 6b072029..00000000 --- a/src/imports/templates/qquicktemplates2valuetypeprovider_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL3$ -** 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 http://www.qt.io/terms-conditions. For further -** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free -** Software Foundation and appearing in the file LICENSE.GPL included in -** the packaging of this file. Please review the following information to -** ensure the GNU General Public License version 2.0 requirements will be -** met: http://www.gnu.org/licenses/gpl-2.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QQUICKTEMPLATES2VALUETYPEPROVIDER_P_H -#define QQUICKTEMPLATES2VALUETYPEPROVIDER_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 <QtQml/private/qqmlglobal_p.h> - -QT_BEGIN_NAMESPACE - -class QQuickTemplates2ValueTypeProvider : public QQmlValueTypeProvider -{ -public: - const QMetaObject *getMetaObjectForMetaType(int type) override; - bool init(int type, QVariant& dst) override; - bool equal(int type, const void *lhs, const QVariant &rhs) override; - bool store(int type, const void *src, void *dst, size_t dstSize) override; - bool read(const QVariant &src, void *dst, int dstType) override; - bool write(int type, const void *src, QVariant& dst) override; -}; - -QT_END_NAMESPACE - -#endif // QQUICKTEMPLATES2VALUETYPEPROVIDER_P_H diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp index ebd30bdc..b1a78e17 100644 --- a/src/imports/templates/qtquicktemplates2plugin.cpp +++ b/src/imports/templates/qtquicktemplates2plugin.cpp @@ -67,6 +67,7 @@ #include <QtQuickTemplates2/private/qquickoverlay_p.h> #include <QtQuickTemplates2/private/qquickpage_p.h> #include <QtQuickTemplates2/private/qquickpageindicator_p.h> +#include <QtQuickTemplates2/private/qquickpaletteprovider_p.h> #include <QtQuickTemplates2/private/qquickpane_p.h> #include <QtQuickTemplates2/private/qquickpopup_p.h> #include <QtQuickTemplates2/private/qquickprogressbar_p.h> @@ -98,8 +99,6 @@ #include <QtQuickTemplates2/private/qquicktumbler_p.h> #endif -#include "qquicktemplates2valuetypeprovider_p.h" - static inline void initResources() { #ifdef QT_STATIC @@ -116,20 +115,14 @@ extern void qt_quick_set_shortcut_context_matcher(ShortcutContextMatcher matcher QT_BEGIN_NAMESPACE -static QQmlValueTypeProvider *valueTypeProvider() -{ - static QQuickTemplates2ValueTypeProvider provider; - return &provider; -} - static void initProviders() { - QQml_addValueTypeProvider(valueTypeProvider()); + QQuickPaletteProvider::init(); } static void cleanupProviders() { - QQml_removeValueTypeProvider(valueTypeProvider()); + QQuickPaletteProvider::cleanup(); } class QtQuickTemplates2Plugin: public QQmlExtensionPlugin @@ -144,15 +137,16 @@ public: void registerTypes(const char *uri) override; private: + bool registered; #if QT_CONFIG(shortcut) ShortcutContextMatcher originalContextMatcher; #endif }; -QtQuickTemplates2Plugin::QtQuickTemplates2Plugin(QObject *parent) : QQmlExtensionPlugin(parent) +QtQuickTemplates2Plugin::QtQuickTemplates2Plugin(QObject *parent) + : QQmlExtensionPlugin(parent), registered(false) { initResources(); - initProviders(); #if QT_CONFIG(shortcut) originalContextMatcher = qt_quick_shortcut_context_matcher(); @@ -162,7 +156,8 @@ QtQuickTemplates2Plugin::QtQuickTemplates2Plugin(QObject *parent) : QQmlExtensio QtQuickTemplates2Plugin::~QtQuickTemplates2Plugin() { - cleanupProviders(); + if (registered) + cleanupProviders(); #if QT_CONFIG(shortcut) qt_quick_set_shortcut_context_matcher(originalContextMatcher); @@ -171,6 +166,9 @@ QtQuickTemplates2Plugin::~QtQuickTemplates2Plugin() void QtQuickTemplates2Plugin::registerTypes(const char *uri) { + registered = true; + initProviders(); + qmlRegisterModule(uri, 2, QT_VERSION_MINOR - 7); // Qt 5.7->2.0, 5.8->2.1, 5.9->2.2... // QtQuick.Templates 2.0 (originally introduced in Qt 5.7) diff --git a/src/imports/templates/templates.pro b/src/imports/templates/templates.pro index 4ff0a76e..9a95812b 100644 --- a/src/imports/templates/templates.pro +++ b/src/imports/templates/templates.pro @@ -10,11 +10,7 @@ DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII OTHER_FILES += \ qmldir -HEADERS += \ - $$PWD/qquicktemplates2valuetypeprovider_p.h - SOURCES += \ - $$PWD/qquicktemplates2valuetypeprovider.cpp \ $$PWD/qtquicktemplates2plugin.cpp CONFIG += no_cxx_module |