From 33b1332d1b8593f488cf5f926315a6df68eee7df Mon Sep 17 00:00:00 2001 From: Yann Bodson Date: Tue, 31 Aug 2010 13:23:40 +1000 Subject: Revert "Add 'cached' property to Image." This will have to go in 4.8. This reverts commit 3928cb20ecc63ed21cdb122388b200c9ab8e7cad. --- .../photoviewer/PhotoViewerCore/PhotoDelegate.qml | 4 +-- .../graphicsitems/qdeclarativeborderimage.cpp | 14 ++--------- .../graphicsitems/qdeclarativeimage.cpp | 8 ------ .../graphicsitems/qdeclarativeimagebase.cpp | 25 +------------------ .../graphicsitems/qdeclarativeimagebase_p.h | 6 +---- .../graphicsitems/qdeclarativeimagebase_p_p.h | 4 +-- src/declarative/util/qdeclarativepixmapcache.cpp | 22 ++++++++-------- src/declarative/util/qdeclarativepixmapcache_p.h | 12 ++------- .../qdeclarativeimage/tst_qdeclarativeimage.cpp | 29 +++++++--------------- 9 files changed, 28 insertions(+), 96 deletions(-) diff --git a/demos/declarative/photoviewer/PhotoViewerCore/PhotoDelegate.qml b/demos/declarative/photoviewer/PhotoViewerCore/PhotoDelegate.qml index d1f0755..dadb409 100644 --- a/demos/declarative/photoviewer/PhotoViewerCore/PhotoDelegate.qml +++ b/demos/declarative/photoviewer/PhotoViewerCore/PhotoDelegate.qml @@ -88,11 +88,11 @@ Package { } BusyIndicator { anchors.centerIn: parent; on: originalImage.status != Image.Ready } Image { - id: originalImage; smooth: true; source: "http://" + Script.getImagePath(content); cached: false + id: originalImage; smooth: true; source: "http://" + Script.getImagePath(content) fillMode: Image.PreserveAspectFit; width: photoWrapper.width; height: photoWrapper.height } Image { - id: hqImage; smooth: true; source: ""; visible: false; cached: false + id: hqImage; smooth: true; source: ""; visible: false fillMode: Image.PreserveAspectFit; width: photoWrapper.width; height: photoWrapper.height } Binding { diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index 7299664..f16770b 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -211,12 +211,7 @@ void QDeclarativeBorderImage::load() } } else { - QDeclarativePixmap::Options options; - if (d->async) - options |= QDeclarativePixmap::Asynchronous; - if (d->cached) - options |= QDeclarativePixmap::Cached; - d->pix.load(qmlEngine(this), d->url, options); + d->pix.load(qmlEngine(this), d->url, d->async); if (d->pix.isLoading()) { d->pix.connectFinished(this, SLOT(requestFinished())); @@ -333,12 +328,7 @@ void QDeclarativeBorderImage::setGridScaledImage(const QDeclarativeGridScaledIma d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); - QDeclarativePixmap::Options options; - if (d->async) - options |= QDeclarativePixmap::Asynchronous; - if (d->cached) - options |= QDeclarativePixmap::Cached; - d->pix.load(qmlEngine(this), d->sciurl, options); + d->pix.load(qmlEngine(this), d->sciurl, d->async); if (d->pix.isLoading()) { static int thisRequestProgress = -1; diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 4ae0887..7a88e78 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -414,14 +414,6 @@ void QDeclarativeImage::geometryChanged(const QRectF &newGeometry, const QRectF are always loaded asynchonously. */ -/*! - \qmlproperty bool Image::cached - - Specifies that the image should be cached. The default value is - true. Setting \a cached to false is useful when dealing with large images, - to make sure that they aren't cached at the expense of small 'ui element' images. -*/ - void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QDeclarativeImage); diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index 2fc935f..416604b 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -126,24 +126,6 @@ QSize QDeclarativeImageBase::sourceSize() const return d->sourcesize.isValid() ? d->sourcesize : QSize(implicitWidth(),implicitHeight()); } -bool QDeclarativeImageBase::cached() const -{ - Q_D(const QDeclarativeImageBase); - return d->cached; -} - -void QDeclarativeImageBase::setCached(bool cached) -{ - Q_D(QDeclarativeImageBase); - if (d->cached == cached) - return; - - d->cached = cached; - emit cachedChanged(); - if (isComponentComplete()) - load(); -} - void QDeclarativeImageBase::load() { Q_D(QDeclarativeImageBase); @@ -168,12 +150,7 @@ void QDeclarativeImageBase::load() d->status = Loading; emit statusChanged(d->status); - QDeclarativePixmap::Options options; - if (d->async) - options |= QDeclarativePixmap::Asynchronous; - if (d->cached) - options |= QDeclarativePixmap::Cached; - d->pix.load(qmlEngine(this), d->url, d->sourcesize, options); + d->pix.load(qmlEngine(this), d->url, d->sourcesize, d->async); if (d->pix.isLoading()) { diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h index b6d2a44..f5896b1 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase_p.h +++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p.h @@ -58,7 +58,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeImageBase : public QDeclarativeItem Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged) - Q_PROPERTY(bool cached READ cached WRITE setCached NOTIFY cachedChanged) + Q_PROPERTY(QSize sourceSize READ sourceSize WRITE setSourceSize NOTIFY sourceSizeChanged) public: @@ -73,9 +73,6 @@ public: bool asynchronous() const; void setAsynchronous(bool); - bool cached() const; - void setCached(bool); - virtual void setSourceSize(const QSize&); QSize sourceSize() const; @@ -85,7 +82,6 @@ Q_SIGNALS: void statusChanged(Status); void progressChanged(qreal progress); void asynchronousChanged(); - void cachedChanged(); protected: virtual void load(); diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h b/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h index ba9f38f..aee8b28 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativeimagebase_p_p.h @@ -69,8 +69,7 @@ public: QDeclarativeImageBasePrivate() : status(QDeclarativeImageBase::Null), progress(0.0), - async(false), - cached(true) + async(false) { QGraphicsItemPrivate::flags = QGraphicsItemPrivate::flags & ~QGraphicsItem::ItemHasNoContents; } @@ -81,7 +80,6 @@ public: qreal progress; QSize sourcesize; bool async : 1; - bool cached : 1; }; QT_END_NAMESPACE diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index 1177d07..de2de21 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -956,20 +956,20 @@ QRect QDeclarativePixmap::rect() const void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url) { - load(engine, url, QSize(), QDeclarativePixmap::Cached); + load(engine, url, QSize(), false); } -void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, QDeclarativePixmap::Options options) +void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, bool async) { - load(engine, url, QSize(), options); + load(engine, url, QSize(), async); } void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, const QSize &size) { - load(engine, url, size, QDeclarativePixmap::Cached); + load(engine, url, size, false); } -void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, const QSize &requestSize, QDeclarativePixmap::Options options) +void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, const QSize &requestSize, bool async) { if (d) { d->release(); d = 0; } @@ -979,20 +979,19 @@ void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, const QHash::Iterator iter = store->m_cache.find(key); if (iter == store->m_cache.end()) { - if (options & QDeclarativePixmap::Asynchronous) { + if (async) { // pixmaps can only be loaded synchronously if (url.scheme() == QLatin1String("image") && QDeclarativeEnginePrivate::get(engine)->getImageProviderType(url) == QDeclarativeImageProvider::Pixmap) { - options &= ~QDeclarativePixmap::Asynchronous; + async = false; } } - if (!(options & QDeclarativePixmap::Asynchronous)) { + if (!async) { bool ok = false; d = createPixmapDataSync(engine, url, requestSize, &ok); if (ok) { - if (options & QDeclarativePixmap::Cached) - d->addToCache(); + d->addToCache(); return; } if (d) // loadable, but encountered error while loading @@ -1005,8 +1004,7 @@ void QDeclarativePixmap::load(QDeclarativeEngine *engine, const QUrl &url, const QDeclarativePixmapReader *reader = QDeclarativePixmapReader::instance(engine); d = new QDeclarativePixmapData(url, requestSize); - if (options & QDeclarativePixmap::Cached) - d->addToCache(); + d->addToCache(); d->reply = reader->getImage(d); } else { diff --git a/src/declarative/util/qdeclarativepixmapcache_p.h b/src/declarative/util/qdeclarativepixmapcache_p.h index 2c246c4..b4d88bd 100644 --- a/src/declarative/util/qdeclarativepixmapcache_p.h +++ b/src/declarative/util/qdeclarativepixmapcache_p.h @@ -66,12 +66,6 @@ public: enum Status { Null, Ready, Error, Loading }; - enum Option { - Asynchronous = 0x00000001, - Cached = 0x00000002 - }; - Q_DECLARE_FLAGS(Options, Option) - bool isNull() const; bool isReady() const; bool isError() const; @@ -91,9 +85,9 @@ public: inline operator const QPixmap &() const; void load(QDeclarativeEngine *, const QUrl &); - void load(QDeclarativeEngine *, const QUrl &, QDeclarativePixmap::Options options); + void load(QDeclarativeEngine *, const QUrl &, bool); void load(QDeclarativeEngine *, const QUrl &, const QSize &); - void load(QDeclarativeEngine *, const QUrl &, const QSize &, QDeclarativePixmap::Options options); + void load(QDeclarativeEngine *, const QUrl &, const QSize &, bool); void clear(); void clear(QObject *); @@ -113,8 +107,6 @@ inline QDeclarativePixmap::operator const QPixmap &() const return pixmap(); } -Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePixmap::Options) - QT_END_NAMESPACE QT_END_HEADER diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index 524736f..8cfb487 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -127,21 +127,19 @@ void tst_qdeclarativeimage::imageSource_data() QTest::addColumn("height"); QTest::addColumn("remote"); QTest::addColumn("async"); - QTest::addColumn("cached"); QTest::addColumn("error"); - QTest::newRow("local") << QUrl::fromLocalFile(SRCDIR "/data/colors.png").toString() << 120.0 << 120.0 << false << false << true << ""; - QTest::newRow("local no cache") << QUrl::fromLocalFile(SRCDIR "/data/colors.png").toString() << 120.0 << 120.0 << false << false << false << ""; - QTest::newRow("local async") << QUrl::fromLocalFile(SRCDIR "/data/colors1.png").toString() << 120.0 << 120.0 << false << true << true << ""; + QTest::newRow("local") << QUrl::fromLocalFile(SRCDIR "/data/colors.png").toString() << 120.0 << 120.0 << false << false << ""; + QTest::newRow("local async") << QUrl::fromLocalFile(SRCDIR "/data/colors1.png").toString() << 120.0 << 120.0 << false << true << ""; QTest::newRow("local not found") << QUrl::fromLocalFile(SRCDIR "/data/no-such-file.png").toString() << 0.0 << 0.0 << false - << false << true << "file::2:1: QML Image: Cannot open: " + QUrl::fromLocalFile(SRCDIR "/data/no-such-file.png").toString(); + << false << "file::2:1: QML Image: Cannot open: " + QUrl::fromLocalFile(SRCDIR "/data/no-such-file.png").toString(); QTest::newRow("local async not found") << QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString() << 0.0 << 0.0 << false - << true << true << "file::2:1: QML Image: Cannot open: " + QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString(); - QTest::newRow("remote") << SERVER_ADDR "/colors.png" << 120.0 << 120.0 << true << false << true << ""; - QTest::newRow("remote redirected") << SERVER_ADDR "/oldcolors.png" << 120.0 << 120.0 << true << false << false << ""; - QTest::newRow("remote svg") << SERVER_ADDR "/heart.svg" << 550.0 << 500.0 << true << false << false << ""; + << true << "file::2:1: QML Image: Cannot open: " + QUrl::fromLocalFile(SRCDIR "/data/no-such-file-1.png").toString(); + QTest::newRow("remote") << SERVER_ADDR "/colors.png" << 120.0 << 120.0 << true << false << ""; + QTest::newRow("remote redirected") << SERVER_ADDR "/oldcolors.png" << 120.0 << 120.0 << true << false << ""; + QTest::newRow("remote svg") << SERVER_ADDR "/heart.svg" << 550.0 << 500.0 << true << false << ""; QTest::newRow("remote not found") << SERVER_ADDR "/no-such-file.png" << 0.0 << 0.0 << true - << false << true << "file::2:1: QML Image: Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found"; + << false << "file::2:1: QML Image: Error downloading " SERVER_ADDR "/no-such-file.png - server replied: Not found"; } @@ -152,7 +150,6 @@ void tst_qdeclarativeimage::imageSource() QFETCH(double, height); QFETCH(bool, remote); QFETCH(bool, async); - QFETCH(bool, cached); QFETCH(QString, error); TestHTTPServer server(SERVER_PORT); @@ -166,8 +163,7 @@ void tst_qdeclarativeimage::imageSource() QTest::ignoreMessage(QtWarningMsg, error.toUtf8()); QString componentStr = "import Qt 4.7\nImage { source: \"" + source + "\"; asynchronous: " - + (async ? QLatin1String("true") : QLatin1String("false")) + "; cached: " - + (cached ? QLatin1String("true") : QLatin1String("false")) + " }"; + + (async ? QLatin1String("true") : QLatin1String("false")) + " }"; QDeclarativeComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); QDeclarativeImage *obj = qobject_cast(component.create()); @@ -175,13 +171,6 @@ void tst_qdeclarativeimage::imageSource() if (async) QVERIFY(obj->asynchronous() == true); - else - QVERIFY(obj->asynchronous() == false); - - if (cached) - QVERIFY(obj->cached() == true); - else - QVERIFY(obj->cached() == false); if (remote || async) TRY_WAIT(obj->status() == QDeclarativeImage::Loading); -- cgit v0.12