aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2017-03-24 09:36:22 +0100
committerEirik Aavitsland <eirik.aavitsland@qt.io>2017-04-28 14:15:23 +0000
commit4a4a8e911cfafcff069de0c1acb2462974166938 (patch)
treee832682afe281d507ea73e8fc0272c0738c8efd5 /src
parent3b798efeb0029bb5314c7bd960f43357b39a394a (diff)
Polish the shared image provider
When the new shared memory image provider was added, some of the issues identified during review were postponed to be fixed during stabilization phase. This commit deals with - Replace the kludge for registering plugin version - Add autotest - Place plugin in labs - Use QT_CONFIG instead of QT_NO_xxx - Use the new extended image provider api, in order to use the scaled-size calculation from Quick Change-Id: I75c01c7565650fcf859411dde9520ee65b2b0c64 Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/imports/sharedimage/plugin.cpp20
-rw-r--r--src/imports/sharedimage/qmldir2
-rw-r--r--src/imports/sharedimage/qsharedimageloader.cpp4
-rw-r--r--src/imports/sharedimage/qsharedimageloader_p.h5
-rw-r--r--src/imports/sharedimage/sharedimage.pro4
-rw-r--r--src/imports/sharedimage/sharedimageprovider.cpp60
-rw-r--r--src/imports/sharedimage/sharedimageprovider.h5
7 files changed, 46 insertions, 54 deletions
diff --git a/src/imports/sharedimage/plugin.cpp b/src/imports/sharedimage/plugin.cpp
index f20edc641c..53e95ef21a 100644
--- a/src/imports/sharedimage/plugin.cpp
+++ b/src/imports/sharedimage/plugin.cpp
@@ -43,7 +43,7 @@
/*!
- \qmlmodule QtQuick.SharedImage 1
+ \qmlmodule Qt.labs.sharedimage 1
\title Qt Quick Shared Image Provider
\ingroup qmlmodules
\brief Adds an image provider which utilizes shared CPU memory
@@ -62,7 +62,7 @@
To use this module, import it like this:
\code
- import QtQuick.SharedImage 1.0
+ import Qt.labs.sharedimage 1.0
\endcode
The sharing functionality is provided through a QQuickImageProvider. Use
@@ -99,13 +99,6 @@
The shared image module does not provide any directly usable QML types.
*/
-static void initResources()
-{
-#ifdef QT_STATIC
- Q_INIT_RESOURCE(qmake_QtQuick_SharedImage);
-#endif
-}
-
QT_BEGIN_NAMESPACE
class QtQuickSharedImagePlugin : public QQmlExtensionPlugin
@@ -113,13 +106,12 @@ class QtQuickSharedImagePlugin : public QQmlExtensionPlugin
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
- QtQuickSharedImagePlugin(QObject *parent = 0) : QQmlExtensionPlugin(parent) { initResources(); }
+ QtQuickSharedImagePlugin(QObject *parent = 0) : QQmlExtensionPlugin(parent) {}
- void registerTypes(const char *uri) Q_DECL_OVERRIDE
+ void registerTypes(const char *uri) override
{
- Q_ASSERT(uri == QStringLiteral("QtQuick.SharedImage"));
- // Need to register *something* to let our version number be known:
- qmlRegisterTypeNotAvailable(uri, 1, 0, "nosuchtype", QStringLiteral("Just a dummy type, do not use"));
+ Q_ASSERT(uri == QStringLiteral("Qt.labs.sharedimage"));
+ qmlRegisterModule(uri, 1, 0);
}
void initializeEngine(QQmlEngine *engine, const char *uri) override
diff --git a/src/imports/sharedimage/qmldir b/src/imports/sharedimage/qmldir
index 64a5aa8ac1..079399dc4e 100644
--- a/src/imports/sharedimage/qmldir
+++ b/src/imports/sharedimage/qmldir
@@ -1,3 +1,3 @@
-module QtQuick.SharedImage
+module Qt.labs.sharedimage
plugin sharedimageplugin
classname QtQuickSharedImagePlugin
diff --git a/src/imports/sharedimage/qsharedimageloader.cpp b/src/imports/sharedimage/qsharedimageloader.cpp
index 65cbd92bb4..fb96a79187 100644
--- a/src/imports/sharedimage/qsharedimageloader.cpp
+++ b/src/imports/sharedimage/qsharedimageloader.cpp
@@ -58,7 +58,7 @@ struct SharedImageHeader {
};
Q_STATIC_ASSERT(sizeof(SharedImageHeader) % 4 == 0);
-#ifndef QT_NO_SHAREDMEMORY
+#if QT_CONFIG(sharedmemory)
struct SharedImageInfo {
QString path;
QPointer<QSharedMemory> shmp;
@@ -160,7 +160,7 @@ QImage QSharedImageLoaderPrivate::createImageFromMem(const void *data, void *cle
QImage QSharedImageLoaderPrivate::load(const QString &path, QSharedImageLoader::ImageParameters *params)
{
-#ifndef QT_NO_SHAREDMEMORY
+#if QT_CONFIG(sharedmemory)
Q_Q(QSharedImageLoader);
QImage nil;
diff --git a/src/imports/sharedimage/qsharedimageloader_p.h b/src/imports/sharedimage/qsharedimageloader_p.h
index afb50e5088..38e2bd4d54 100644
--- a/src/imports/sharedimage/qsharedimageloader_p.h
+++ b/src/imports/sharedimage/qsharedimageloader_p.h
@@ -56,11 +56,6 @@ class QSharedImageLoader : public QObject
Q_DECLARE_PRIVATE(QSharedImageLoader)
public:
- enum ImageParameter {
- OriginalSize = 0,
- RequestedSize,
- NumImageParameters
- };
typedef QVector<QVariant> ImageParameters;
QSharedImageLoader(QObject *parent = Q_NULLPTR);
diff --git a/src/imports/sharedimage/sharedimage.pro b/src/imports/sharedimage/sharedimage.pro
index 523de66ac1..46a6a56ca5 100644
--- a/src/imports/sharedimage/sharedimage.pro
+++ b/src/imports/sharedimage/sharedimage.pro
@@ -1,9 +1,9 @@
CXX_MODULE = qml
TARGET = sharedimageplugin
-TARGETPATH = QtQuick/SharedImage
+TARGETPATH = Qt/labs/sharedimage
IMPORT_VERSION = 1.0
-QT *= quick qml gui-private core-private
+QT *= quick-private qml gui-private core-private
SOURCES += \
plugin.cpp \
diff --git a/src/imports/sharedimage/sharedimageprovider.cpp b/src/imports/sharedimage/sharedimageprovider.cpp
index 2dd3a130e9..f33057936d 100644
--- a/src/imports/sharedimage/sharedimageprovider.cpp
+++ b/src/imports/sharedimage/sharedimageprovider.cpp
@@ -39,18 +39,27 @@
#include <sharedimageprovider.h>
#include <qsharedimageloader_p.h>
-#include <qquickimageprovider.h>
+#include <private/qquickpixmapcache_p.h>
#include <private/qimage_p.h>
#include <QImageReader>
#include <QFileInfo>
#include <QDir>
+Q_DECLARE_METATYPE(QQuickImageProviderOptions)
+
class QuickSharedImageLoader : public QSharedImageLoader
{
Q_OBJECT
friend class SharedImageProvider;
public:
+ enum ImageParameter {
+ OriginalSize = 0,
+ RequestedSize,
+ ProviderOptions,
+ NumImageParameters
+ };
+
QuickSharedImageLoader(QObject *parent = Q_NULLPTR)
: QSharedImageLoader(parent)
{
@@ -61,29 +70,17 @@ protected:
{
QImageReader imgio(path);
QSize realSize = imgio.size();
- QSize requestSize = params ? params->value(RequestedSize).toSize() : QSize();
+ QSize requestSize;
+ QQuickImageProviderOptions options;
+ if (params) {
+ requestSize = params->value(RequestedSize).toSize();
+ options = params->value(ProviderOptions).value<QQuickImageProviderOptions>();
+ }
- // Following qquickpixmapcache's readImage, from here...
- const bool force_scale = imgio.format() == "svg" || imgio.format() == "svgz";
+ QSize scSize = QQuickImageProviderWithOptions::loadSize(imgio.size(), requestSize, imgio.format(), options);
- if (requestSize.width() > 0 || requestSize.height() > 0) {
- QSize s = realSize;
- qreal ratio = 0.0;
- if (requestSize.width() && (force_scale || requestSize.width() < s.width())) {
- ratio = qreal(requestSize.width())/s.width();
- }
- if (requestSize.height() && (force_scale || requestSize.height() < s.height())) {
- qreal hr = qreal(requestSize.height())/s.height();
- if (ratio == 0.0 || hr < ratio)
- ratio = hr;
- }
- if (ratio > 0.0) {
- s.setHeight(qRound(s.height() * ratio));
- s.setWidth(qRound(s.width() * ratio));
- imgio.setScaledSize(s);
- }
- }
- // ... to here
+ if (scSize.isValid())
+ imgio.setScaledSize(scSize);
QImage image;
if (imgio.read(&image)) {
@@ -108,11 +105,17 @@ protected:
QString key(const QString &path, ImageParameters *params) override
{
- QSize reqSz = params->value(RequestedSize).toSize();
+ 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").arg(reqSz.width()).arg(reqSz.height());
+ QString key = path + QStringLiteral("_%1x%2_%3").arg(reqSz.width()).arg(reqSz.height()).arg(aspect);
qCDebug(lcSharedImage) << "KEY:" << key;
return key;
}
@@ -120,19 +123,20 @@ protected:
SharedImageProvider::SharedImageProvider()
- : QQuickImageProvider(QQuickImageProvider::Image), loader(new QuickSharedImageLoader)
+ : QQuickImageProviderWithOptions(QQuickImageProvider::Image), loader(new QuickSharedImageLoader)
{
}
-QImage SharedImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
+QImage SharedImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options)
{
QFileInfo fi(QDir::root(), id);
QString path = fi.canonicalFilePath();
if (path.isEmpty())
return QImage();
- QSharedImageLoader::ImageParameters params(QSharedImageLoader::NumImageParameters);
- params[QSharedImageLoader::RequestedSize].setValue(requestedSize);
+ QSharedImageLoader::ImageParameters params(QuickSharedImageLoader::NumImageParameters);
+ params[QuickSharedImageLoader::RequestedSize].setValue(requestedSize);
+ params[QuickSharedImageLoader::ProviderOptions].setValue(options);
QImage img = loader->load(path, &params);
if (img.isNull()) {
diff --git a/src/imports/sharedimage/sharedimageprovider.h b/src/imports/sharedimage/sharedimageprovider.h
index a2f6b6ef2f..e6b6c77134 100644
--- a/src/imports/sharedimage/sharedimageprovider.h
+++ b/src/imports/sharedimage/sharedimageprovider.h
@@ -41,16 +41,17 @@
#define SHAREDIMAGEPROVIDER_H
#include <QQuickImageProvider>
+#include <private/qquickpixmapcache_p.h>
#include <QScopedPointer>
class QuickSharedImageLoader;
-class SharedImageProvider : public QQuickImageProvider
+class SharedImageProvider : public QQuickImageProviderWithOptions
{
public:
SharedImageProvider();
- QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
+ QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize, const QQuickImageProviderOptions &options) override;
protected:
QScopedPointer<QuickSharedImageLoader> loader;