Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickimageprovider.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
7#include "qquickpixmap_p.h"
8#include <QtQuick/private/qsgcontext_p.h>
9#include <private/qqmlglobal_p.h>
10#include <QtGui/qcolorspace.h>
11
13
35
43
63{
64 return QImage();
65}
66
84
85
86
135
142
147{
148 return QString();
149}
150
166
316
326
334
338QQuickImageProvider::Flags QQuickImageProvider::flags() const
339{
340 return d->flags;
341}
342
363{
364 Q_UNUSED(id);
365 Q_UNUSED(size);
366 Q_UNUSED(requestedSize);
367 if (d->type == Image)
368 qWarning("ImageProvider supports Image type but has not implemented requestImage()");
369 return QImage();
370}
371
392{
393 Q_UNUSED(id);
394 Q_UNUSED(size);
395 Q_UNUSED(requestedSize);
396 if (d->type == Pixmap)
397 qWarning("ImageProvider supports Pixmap type but has not implemented requestPixmap()");
398 return QPixmap();
399}
400
401
423{
424 Q_UNUSED(id);
425 Q_UNUSED(size);
426 Q_UNUSED(requestedSize);
427 if (d->type == Texture)
428 qWarning("ImageProvider supports Texture type but has not implemented requestTexture()");
429 return nullptr;
430}
431
443 : QQuickImageProvider(ImageResponse, ForceAsynchronousImageLoading)
444 , d(nullptr) // just as a placeholder in case we need it for the future
445{
446 Q_UNUSED(d);
447}
448
452
484
508
512
517
523
525{
526 return d->autoTransform == other.d->autoTransform &&
527 d->preserveAspectRatioCrop == other.d->preserveAspectRatioCrop &&
528 d->preserveAspectRatioFit == other.d->preserveAspectRatioFit &&
529 d->targetColorSpace == other.d->targetColorSpace;
530}
531
539
544
553
558
567
572
580
582{
583 d->targetColorSpace = colorSpace;
584}
585
593
598
601{
602 QQuickImageProvider::d->type = type;
603 QQuickImageProvider::d->flags = flags;
604 QQuickImageProvider::d->isProviderWithOptions = true;
605}
606
608{
609 return requestImage(id, size, requestedSize, QQuickImageProviderOptions());
610}
611
613{
614 return requestPixmap(id, size, requestedSize, QQuickImageProviderOptions());
615}
616
618{
619 return requestTexture(id, size, requestedSize, QQuickImageProviderOptions());
620}
621
623{
624 Q_UNUSED(options);
625 return QQuickAsyncImageProvider::requestImage(id, size, requestedSize);
626}
627
629{
630 Q_UNUSED(options);
631 return QQuickAsyncImageProvider::requestPixmap(id, size, requestedSize);
632}
633
635{
636 Q_UNUSED(options);
637 return QQuickAsyncImageProvider::requestTexture(id, size, requestedSize);
638}
639
641{
642 Q_UNUSED(id);
643 Q_UNUSED(requestedSize);
644 if (imageType() == ImageResponse)
645 qWarning("ImageProvider is of ImageResponse type but has not implemented requestImageResponse()");
646 return nullptr;
647}
648
650{
651 Q_UNUSED(options);
652 return requestImageResponse(id, requestedSize);
653}
654
662QSize QQuickImageProviderWithOptions::loadSize(const QSize &originalSize, const QSize &requestedSize, const QByteArray &format, const QQuickImageProviderOptions &options,
663 qreal devicePixelRatio)
664{
665 QSize res;
666 const bool formatIsScalable = (format == "svg" || format == "svgz" || format == "pdf");
667 const bool noRequestedSize = requestedSize.width() <= 0 && requestedSize.height() <= 0;
668 if ((noRequestedSize && !formatIsScalable) || originalSize.isEmpty())
669 return res;
670
671 // If no sourceSize was set and we're loading an SVG, ensure that we provide
672 // a default size that accounts for DPR so that the image isn't blurry.
673 if (noRequestedSize && formatIsScalable)
674 return originalSize * devicePixelRatio;
675
676 const bool preserveAspectCropOrFit = options.preserveAspectRatioCrop() || options.preserveAspectRatioFit();
677
678 if (!preserveAspectCropOrFit && formatIsScalable && !requestedSize.isEmpty())
679 return requestedSize;
680
681 qreal ratio = 0.0;
682 if (requestedSize.width() && (preserveAspectCropOrFit || formatIsScalable ||
683 requestedSize.width() < originalSize.width())) {
684 ratio = qreal(requestedSize.width()) / originalSize.width();
685 }
686 if (requestedSize.height() && (preserveAspectCropOrFit || formatIsScalable ||
687 requestedSize.height() < originalSize.height())) {
688 qreal hr = qreal(requestedSize.height()) / originalSize.height();
689 if (ratio == 0.0)
690 ratio = hr;
691 else if (!preserveAspectCropOrFit && (hr < ratio))
692 ratio = hr;
693 else if (preserveAspectCropOrFit && (hr > ratio))
694 ratio = hr;
695 }
696 if (ratio > 0.0) {
697 res.setHeight(qRound(originalSize.height() * ratio));
698 res.setWidth(qRound(originalSize.width() * ratio));
699 }
700 return res;
701}
702
704{
705 if (provider && provider->d && provider->d->isProviderWithOptions)
706 return static_cast<QQuickImageProviderWithOptions *>(provider);
707
708 return nullptr;
709}
710
712
713#include "moc_qquickimageprovider.cpp"
\inmodule QtCore
Definition qbytearray.h:57
The QColorSpace class provides a color space abstraction.
Definition qcolorspace.h:21
\inmodule QtGui
Definition qimage.h:37
\inmodule QtCore
Definition qobject.h:103
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
friend class QQuickImageProvider
Definition qqmlengine.h:40
ImageType
Defines the type of image supported by this image provider.
Definition qqmlengine.h:21
The QQuickAsyncImageProvider class provides an interface for asynchronous control of QML image reques...
QQuickImageProviderOptions::AutoTransform autoTransform
The QQuickImageProviderOptions class provides options for QQuickImageProviderWithOptions image reques...
bool operator==(const QQuickImageProviderOptions &) const
bool preserveAspectRatioFit() const
Returns whether the image request is for a PreserveAspectFit Image.
void setPreserveAspectRatioCrop(bool preserveAspectRatioCrop)
QColorSpace targetColorSpace() const
Returns the color space the image provider should return the image in.
void setSourceClipRect(const QRectF &rect)
AutoTransform
Whether the image provider should apply transformation metadata on read().
AutoTransform autoTransform() const
Returns whether the image provider should apply transformation metadata on read().
void setPreserveAspectRatioFit(bool preserveAspectRatioFit)
void setAutoTransform(AutoTransform autoTransform)
QQuickImageProviderOptions & operator=(const QQuickImageProviderOptions &)
QRectF sourceClipRect() const
Returns the requested source clip rect.
bool preserveAspectRatioCrop() const
Returns whether the image request is for a PreserveAspectCrop Image.
void setTargetColorSpace(const QColorSpace &colorSpace)
QQuickImageProvider::ImageType type
QQuickImageProvider::Flags flags
static QQuickImageProviderWithOptions * checkedCast(QQuickImageProvider *provider)
QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override
Implement this method to return the pixmap with id.
QQuickTextureFactory * requestTexture(const QString &id, QSize *size, const QSize &requestedSize) override
Implement this method to return the texture with id.
QQuickImageResponse * requestImageResponse(const QString &id, const QSize &requestedSize) override
Implement this method to return the job that will provide the texture with id.
static QSize loadSize(const QSize &originalSize, const QSize &requestedSize, const QByteArray &format, const QQuickImageProviderOptions &options, qreal devicePixelRatio=1.0)
Returns the recommended scaled image size for loading and storage.
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override
Implement this method to return the image with id.
The QQuickImageProvider class provides an interface for supporting pixmaps and threaded image request...
ImageType imageType() const override
Returns the image type supported by this provider.
virtual QQuickTextureFactory * requestTexture(const QString &id, QSize *size, const QSize &requestedSize)
Implement this method to return the texture with id.
Flags flags() const override
Returns the flags set for this provider.
friend class QQuickImageProviderWithOptions
virtual QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize)
Implement this method to return the image with id.
virtual QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
Implement this method to return the pixmap with id.
~QQuickImageProvider() override
Destroys the QQuickImageProvider.
The QQuickImageResponse class provides an interface for asynchronous image loading in QQuickAsyncImag...
virtual QString errorString() const
Returns the error string for the job execution.
void finished()
Signals that the job execution has finished (be it successfully, because an error happened or because...
~QQuickImageResponse() override
Destructs the image response.
QQuickImageResponse()
Constructs the image response.
virtual void cancel()
This method is used to communicate that the response is no longer required by the engine.
The QQuickTextureFactory class provides an interface for loading custom textures from QML....
~QQuickTextureFactory() override
Destroys the texture factory.
virtual QImage image() const
Returns an image version of this texture.
static QQuickTextureFactory * textureFactoryForImage(const QImage &image)
Returns a QQuickTextureFactory holding the given image.
QQuickTextureFactory()
Constructs a texture factory.
\inmodule QtCore\reentrant
Definition qrect.h:484
static QQuickTextureFactory * createTextureFactoryFromImage(const QImage &image)
Calls into the scene graph adaptation if available and creates a texture factory.
\inmodule QtCore
Definition qshareddata.h:19
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
Definition qsize.h:124
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
rect
[4]
Combined button and popup list for selecting options.
Definition image.cpp:4
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
Flags
#define qWarning
Definition qlogging.h:166
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum type
GLbitfield flags
GLenum GLuint texture
GLint GLsizei GLsizei GLenum format
GLuint res
XID Pixmap
#define qmlobject_connect(Sender, SenderType, Signal, Receiver, ReceiverType, Method)
Connect Signal of Sender to Method of Receiver.
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]