aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-01-21 16:11:08 +0100
committerMaximilian Goldstein <max.goldstein@qt.io>2021-01-25 11:22:04 +0100
commitcd8ae755c2762cedc98f7f389f13ab827e125e11 (patch)
tree39dd5be850fad42f66cf2c344bf8bd33feb77f86 /src
parent9eda73354c6caf0b974febc7bdbee136d59a4e36 (diff)
Qt.labs.sharedimage: Make plugin optional
This moves the sharedimage types into a new library and is meant to make them availabe to the QML compiler at some point in the future. Task-number: QTBUG-90487 Change-Id: If79425a43cb8c1831422631791d35c1f329c7e80 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/sharedimage/CMakeLists.txt10
-rw-r--r--src/imports/sharedimage/plugin.cpp7
-rw-r--r--src/labs/CMakeLists.txt4
-rw-r--r--src/labs/sharedimage/CMakeLists.txt24
-rw-r--r--src/labs/sharedimage/qsharedimageloader.cpp (renamed from src/imports/sharedimage/qsharedimageloader.cpp)0
-rw-r--r--src/labs/sharedimage/qsharedimageloader_p.h (renamed from src/imports/sharedimage/qsharedimageloader_p.h)15
-rw-r--r--src/labs/sharedimage/qsharedimageprovider.cpp (renamed from src/imports/sharedimage/sharedimageprovider.cpp)117
-rw-r--r--src/labs/sharedimage/qsharedimageprovider_p.h (renamed from src/imports/sharedimage/sharedimageprovider.h)44
-rw-r--r--src/labs/sharedimage/qtlabssharedimageglobal_p.h73
9 files changed, 207 insertions, 87 deletions
diff --git a/src/imports/sharedimage/CMakeLists.txt b/src/imports/sharedimage/CMakeLists.txt
index 90020be7ee..70f3abb76e 100644
--- a/src/imports/sharedimage/CMakeLists.txt
+++ b/src/imports/sharedimage/CMakeLists.txt
@@ -9,19 +9,13 @@ qt_internal_add_qml_module(sharedimageplugin
VERSION "${CMAKE_PROJECT_VERSION}"
CLASSNAME QtQuickSharedImagePlugin
SKIP_TYPE_REGISTRATION
- GENERATE_QMLTYPES
- INSTALL_QMLTYPES
+ PLUGIN_OPTIONAL
SOURCES
plugin.cpp
- qsharedimageloader.cpp qsharedimageloader_p.h
- sharedimageprovider.cpp sharedimageprovider.h
PUBLIC_LIBRARIES
Qt::Core
- Qt::CorePrivate
- Qt::Gui
- Qt::GuiPrivate
Qt::Qml
- Qt::QuickPrivate
+ Qt::LabsSharedImagePrivate
)
#### Keys ignored in scope 1:.:.:sharedimage.pro:<TRUE>:
diff --git a/src/imports/sharedimage/plugin.cpp b/src/imports/sharedimage/plugin.cpp
index 3245635b2d..dab04efd92 100644
--- a/src/imports/sharedimage/plugin.cpp
+++ b/src/imports/sharedimage/plugin.cpp
@@ -37,10 +37,11 @@
**
****************************************************************************/
+#include <QtLabsSharedImage/private/qtlabssharedimageglobal_p.h>
+#include <QtLabsSharedImage/private/qsharedimageprovider_p.h>
+
#include <qqmlextensionplugin.h>
#include <qqmlengine.h>
-#include <sharedimageprovider.h>
-
/*!
\qmlmodule Qt.labs.sharedimage 1
@@ -99,8 +100,6 @@
The shared image module does not provide any directly usable QML types.
*/
-extern void qml_register_types_Qt_labs_sharedimage();
-
QT_BEGIN_NAMESPACE
class QtQuickSharedImagePlugin : public QQmlEngineExtensionPlugin
diff --git a/src/labs/CMakeLists.txt b/src/labs/CMakeLists.txt
index 2680ae8d11..9a984ccfb9 100644
--- a/src/labs/CMakeLists.txt
+++ b/src/labs/CMakeLists.txt
@@ -12,3 +12,7 @@ endif()
if(QT_FEATURE_quick_shadereffect AND TARGET Qt::Quick)
add_subdirectory(wavefrontmesh)
endif()
+
+if(QT_FEATURE_systemsemaphore AND TARGET Qt::Quick)
+ add_subdirectory(sharedimage)
+endif()
diff --git a/src/labs/sharedimage/CMakeLists.txt b/src/labs/sharedimage/CMakeLists.txt
new file mode 100644
index 0000000000..217f688599
--- /dev/null
+++ b/src/labs/sharedimage/CMakeLists.txt
@@ -0,0 +1,24 @@
+qt_internal_add_module(LabsSharedImage
+ GENERATE_METATYPES
+ SOURCES
+ qsharedimageloader.cpp qsharedimageloader_p.h
+ qsharedimageprovider.cpp qsharedimageprovider_p.h
+ qtlabssharedimageglobal_p.h
+ DEFINES
+ QT_BUILD_LABSSHAREDIMAGE_LIB
+ PUBLIC_LIBRARIES
+ Qt::CorePrivate
+ Qt::GuiPrivate
+ Qt::QuickPrivate
+)
+
+
+set_target_properties(LabsSharedImage PROPERTIES
+ QT_QML_MODULE_INSTALL_QMLTYPES TRUE
+ QT_QML_MODULE_VERSION ${CMAKE_PROJECT_VERSION}
+ QT_QML_MODULE_URI Qt.labs.sharedimage
+ QT_QMLTYPES_FILENAME plugins.qmltypes
+ QT_QML_MODULE_INSTALL_DIR "${INSTALL_QMLDIR}/Qt/labs/sharedimage"
+)
+
+qt6_qml_type_registration(LabsSharedImage)
diff --git a/src/imports/sharedimage/qsharedimageloader.cpp b/src/labs/sharedimage/qsharedimageloader.cpp
index c9e3ef3eb3..c9e3ef3eb3 100644
--- a/src/imports/sharedimage/qsharedimageloader.cpp
+++ b/src/labs/sharedimage/qsharedimageloader.cpp
diff --git a/src/imports/sharedimage/qsharedimageloader_p.h b/src/labs/sharedimage/qsharedimageloader_p.h
index ce10d0d72c..3c6dabc871 100644
--- a/src/imports/sharedimage/qsharedimageloader_p.h
+++ b/src/labs/sharedimage/qsharedimageloader_p.h
@@ -40,6 +40,19 @@
#ifndef QSHAREDIMAGELOADER_H
#define QSHAREDIMAGELOADER_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 "qtlabssharedimageglobal_p.h"
+
#include <QImage>
#include <QVariant>
#include <QLoggingCategory>
@@ -51,7 +64,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcSharedImage);
class QSharedImageLoaderPrivate;
-class QSharedImageLoader : public QObject
+class Q_LABSSHAREDIMAGE_PRIVATE_EXPORT QSharedImageLoader : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QSharedImageLoader)
diff --git a/src/imports/sharedimage/sharedimageprovider.cpp b/src/labs/sharedimage/qsharedimageprovider.cpp
index aad6ea3b78..74822a4e87 100644
--- a/src/imports/sharedimage/sharedimageprovider.cpp
+++ b/src/labs/sharedimage/qsharedimageprovider.cpp
@@ -37,8 +37,7 @@
**
****************************************************************************/
-#include <sharedimageprovider.h>
-#include <qsharedimageloader_p.h>
+#include <qsharedimageprovider_p.h>
#include <private/qquickpixmapcache_p.h>
#include <private/qimage_p.h>
#include <QImageReader>
@@ -47,80 +46,62 @@
Q_DECLARE_METATYPE(QQuickImageProviderOptions)
-class QuickSharedImageLoader : public QSharedImageLoader
+
+QuickSharedImageLoader::QuickSharedImageLoader(QObject *parent) : QSharedImageLoader(parent) {}
+
+QImage QuickSharedImageLoader::loadFile(const QString &path, ImageParameters *params)
{
- Q_OBJECT
- friend class SharedImageProvider;
-
-public:
- enum ImageParameter {
- OriginalSize = 0,
- RequestedSize,
- ProviderOptions,
- NumImageParameters
- };
-
- QuickSharedImageLoader(QObject *parent = nullptr)
- : QSharedImageLoader(parent)
- {
+ QImageReader imgio(path);
+ QSize realSize = imgio.size();
+ QSize requestSize;
+ QQuickImageProviderOptions options;
+ if (params) {
+ requestSize = params->value(RequestedSize).toSize();
+ options = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
}
-protected:
- QImage loadFile(const QString &path, ImageParameters *params) override
- {
- QImageReader imgio(path);
- QSize realSize = imgio.size();
- QSize requestSize;
- QQuickImageProviderOptions options;
- if (params) {
- requestSize = params->value(RequestedSize).toSize();
- options = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
- }
-
- QSize scSize = QQuickImageProviderWithOptions::loadSize(imgio.size(), requestSize, imgio.format(), options);
-
- if (scSize.isValid())
- imgio.setScaledSize(scSize);
-
- QImage image;
- if (imgio.read(&image)) {
- if (realSize.isEmpty())
- realSize = image.size();
- // Make sure we have acceptable format for texture uploader, or it will convert & lose sharing
- // This mimics the testing & conversion normally done by the quick pixmapcache & texturefactory
- if (image.format() != QImage::Format_RGB32 && image.format() != QImage::Format_ARGB32_Premultiplied) {
- QImage::Format newFmt = QImage::Format_RGB32;
- if (image.hasAlphaChannel() && image.data_ptr()->checkForAlphaPixels())
- newFmt = QImage::Format_ARGB32_Premultiplied;
- qCDebug(lcSharedImage) << "Convert on load from format" << image.format() << "to" << newFmt;
- image = image.convertToFormat(newFmt);
- }
+ QSize scSize = QQuickImageProviderWithOptions::loadSize(imgio.size(), requestSize, imgio.format(), options);
+
+ if (scSize.isValid())
+ imgio.setScaledSize(scSize);
+
+ QImage image;
+ if (imgio.read(&image)) {
+ if (realSize.isEmpty())
+ realSize = image.size();
+ // Make sure we have acceptable format for texture uploader, or it will convert & lose sharing
+ // This mimics the testing & conversion normally done by the quick pixmapcache & texturefactory
+ if (image.format() != QImage::Format_RGB32 && image.format() != QImage::Format_ARGB32_Premultiplied) {
+ QImage::Format newFmt = QImage::Format_RGB32;
+ if (image.hasAlphaChannel() && image.data_ptr()->checkForAlphaPixels())
+ newFmt = QImage::Format_ARGB32_Premultiplied;
+ qCDebug(lcSharedImage) << "Convert on load from format" << image.format() << "to" << newFmt;
+ image = image.convertToFormat(newFmt);
}
-
- if (params && params->count() > OriginalSize)
- params->replace(OriginalSize, realSize);
-
- return image;
}
- QString key(const QString &path, ImageParameters *params) override
- {
- QSize reqSz;
- QQuickImageProviderOptions opts;
- if (params) {
- reqSz = params->value(RequestedSize).toSize();
- opts = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
- }
- if (!reqSz.isValid())
- return path;
- int aspect = opts.preserveAspectRatioCrop() || opts.preserveAspectRatioFit() ? 1 : 0;
+ if (params && params->count() > OriginalSize)
+ params->replace(OriginalSize, realSize);
+
+ return image;
+}
- QString key = path + QStringLiteral("_%1x%2_%3").arg(reqSz.width()).arg(reqSz.height()).arg(aspect);
- qCDebug(lcSharedImage) << "KEY:" << key;
- return key;
+QString QuickSharedImageLoader::key(const QString &path, ImageParameters *params)
+{
+ QSize reqSz;
+ QQuickImageProviderOptions opts;
+ if (params) {
+ reqSz = params->value(RequestedSize).toSize();
+ opts = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
}
-};
+ if (!reqSz.isValid())
+ return path;
+ int aspect = opts.preserveAspectRatioCrop() || opts.preserveAspectRatioFit() ? 1 : 0;
+ QString key = path + QStringLiteral("_%1x%2_%3").arg(reqSz.width()).arg(reqSz.height()).arg(aspect);
+ qCDebug(lcSharedImage) << "KEY:" << key;
+ return key;
+}
SharedImageProvider::SharedImageProvider()
: QQuickImageProviderWithOptions(QQuickImageProvider::Image), loader(new QuickSharedImageLoader)
@@ -156,5 +137,3 @@ QImage SharedImageProvider::requestImage(const QString &id, QSize *size, const Q
return img;
}
-
-#include "sharedimageprovider.moc"
diff --git a/src/imports/sharedimage/sharedimageprovider.h b/src/labs/sharedimage/qsharedimageprovider_p.h
index e6b6c77134..f8bea9e784 100644
--- a/src/imports/sharedimage/sharedimageprovider.h
+++ b/src/labs/sharedimage/qsharedimageprovider_p.h
@@ -37,16 +37,50 @@
**
****************************************************************************/
-#ifndef SHAREDIMAGEPROVIDER_H
-#define SHAREDIMAGEPROVIDER_H
+#ifndef QSHAREDIMAGEPROVIDER_H
+#define QSHAREDIMAGEPROVIDER_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 "qtlabssharedimageglobal_p.h"
#include <QQuickImageProvider>
#include <private/qquickpixmapcache_p.h>
#include <QScopedPointer>
-class QuickSharedImageLoader;
+#include "qsharedimageloader_p.h"
+
+class SharedImageProvider;
+
+class QuickSharedImageLoader : public QSharedImageLoader
+{
+ Q_OBJECT
+ friend class SharedImageProvider;
+
+public:
+ enum ImageParameter {
+ OriginalSize = 0,
+ RequestedSize,
+ ProviderOptions,
+ NumImageParameters
+ };
+
+ QuickSharedImageLoader(QObject *parent = nullptr);
+protected:
+ QImage loadFile(const QString &path, ImageParameters *params) override;
+ QString key(const QString &path, ImageParameters *params) override;
+};
-class SharedImageProvider : public QQuickImageProviderWithOptions
+class Q_LABSSHAREDIMAGE_PRIVATE_EXPORT SharedImageProvider : public QQuickImageProviderWithOptions
{
public:
SharedImageProvider();
@@ -56,4 +90,4 @@ public:
protected:
QScopedPointer<QuickSharedImageLoader> loader;
};
-#endif // SHAREDIMAGEPROVIDER_H
+#endif // QSHAREDIMAGEPROVIDER_H
diff --git a/src/labs/sharedimage/qtlabssharedimageglobal_p.h b/src/labs/sharedimage/qtlabssharedimageglobal_p.h
new file mode 100644
index 0000000000..c67be432dd
--- /dev/null
+++ b/src/labs/sharedimage/qtlabssharedimageglobal_p.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtQml 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 QTLABSSHAREDIMAGEGLOBAL_P_H
+#define QTLABSSHAREDIMAGEGLOBAL_P_H
+
+#include <QtCore/qglobal.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.
+//
+
+QT_BEGIN_NAMESPACE
+
+#if !defined(QT_STATIC)
+# if defined(QT_BUILD_LABSSHAREDIMAGE_LIB)
+# define Q_LABSSHAREDIMAGE_EXPORT Q_DECL_EXPORT
+# else
+# define Q_LABSSHAREDIMAGE_EXPORT Q_DECL_IMPORT
+# endif
+#else
+# define Q_LABSSHAREDIMAGE_EXPORT
+#endif
+#define Q_LABSSHAREDIMAGE_PRIVATE_EXPORT Q_LABSSHAREDIMAGE_EXPORT
+
+QT_END_NAMESPACE
+
+void Q_LABSSHAREDIMAGE_PRIVATE_EXPORT qml_register_types_Qt_labs_sharedimage();
+
+#endif // QTLABSSHAREDIMAGEGLOBAL_P_H