summaryrefslogtreecommitdiff
path: root/src/declarative/util/qdeclarativepixmapcache_p.h
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-07-05 14:20:14 +1000
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-07-05 18:31:07 +1000
commit09f07b98dfdaec2e48749768b967a48e588d3f7f (patch)
treeafb3d254883bef441614a2c9453be8ac9bf51e5f /src/declarative/util/qdeclarativepixmapcache_p.h
parentb2aedd1d57a5a681b1185bf8908683ff563de4d6 (diff)
downloadqt4-tools-09f07b98dfdaec2e48749768b967a48e588d3f7f.tar.gz
Make declarative pixmap cache easier to use
The QDeclarativePixmapCache was both slow, and very trickey to use correctly. Many QML elements did not correctly cancel outstanding requests, which leads to pixmaps leaking indefinately. Other elements, such as Text, were subject to race conditions that meant they may never actually load all their images. QDeclarativePixmap is a single class than encapsulates the action of fetching a pixmap, as well as the pixmap itself and the responsibility of canceling outstanding requests. Rather than relying on Qt's pixmap cache that doesn't cache all the information QML needs, QDeclarativePixmap implements its own cache, that correctly degrades over time (unlike QPixmapCache that can stop expiring items in some conditions). Reviewed-by: Warwick Allison
Diffstat (limited to 'src/declarative/util/qdeclarativepixmapcache_p.h')
-rw-r--r--src/declarative/util/qdeclarativepixmapcache_p.h85
1 files changed, 43 insertions, 42 deletions
diff --git a/src/declarative/util/qdeclarativepixmapcache_p.h b/src/declarative/util/qdeclarativepixmapcache_p.h
index 33d9de13b2..8278c35648 100644
--- a/src/declarative/util/qdeclarativepixmapcache_p.h
+++ b/src/declarative/util/qdeclarativepixmapcache_p.h
@@ -42,69 +42,70 @@
#ifndef QDECLARATIVEPIXMAPCACHE_H
#define QDECLARATIVEPIXMAPCACHE_H
-#include <QtCore/QString>
-#include <QtGui/QPixmap>
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qstring.h>
+#include <QtGui/qpixmap.h>
#include <QtCore/qurl.h>
-#include <QtCore/QCoreApplication>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-class QDeclarativeEngine;
-class QNetworkReply;
-class QDeclarativeImageReader;
-class QDeclarativePixmapReplyPrivate;
-class Q_DECLARATIVE_EXPORT QDeclarativePixmapReply : public QObject
+class QDeclarativeEngine;
+class QDeclarativePixmapData;
+class Q_AUTOTEST_EXPORT QDeclarativePixmap
{
- Q_OBJECT
+ Q_DECLARE_TR_FUNCTIONS(QDeclarativePixmap)
public:
- ~QDeclarativePixmapReply();
+ QDeclarativePixmap();
+ QDeclarativePixmap(QDeclarativeEngine *, const QUrl &);
+ QDeclarativePixmap(QDeclarativeEngine *, const QUrl &, const QSize &);
+ ~QDeclarativePixmap();
- enum Status { Ready, Error, Unrequested, Loading };
- Status status() const;
- QString errorString() const;
+ enum Status { Null, Ready, Error, Loading };
+ bool isNull() const;
+ bool isReady() const;
+ bool isError() const;
+ bool isLoading() const;
+
+ Status status() const;
+ QString error() const;
const QUrl &url() const;
- int forcedWidth() const;
- int forcedHeight() const;
- QSize implicitSize() const;
+ const QSize &implicitSize() const;
+ const QSize &requestSize() const;
+ const QPixmap &pixmap() const;
+ void setPixmap(const QPixmap &);
-Q_SIGNALS:
- void finished();
- void downloadProgress(qint64, qint64);
+ QRect rect() const;
+ int width() const;
+ int height() const;
+ inline operator const QPixmap &() const;
-protected:
- bool event(QEvent *event);
+ void load(QDeclarativeEngine *, const QUrl &);
+ void load(QDeclarativeEngine *, const QUrl &, bool);
+ void load(QDeclarativeEngine *, const QUrl &, const QSize &);
+ void load(QDeclarativeEngine *, const QUrl &, const QSize &, bool);
-private:
- void addRef();
- bool release(bool defer=false);
- bool isLoading() const;
- void setLoading();
+ void clear();
+ void clear(QObject *);
+
+ bool connectFinished(QObject *, const char *);
+ bool connectFinished(QObject *, int);
+ bool connectDownloadProgress(QObject *, const char *);
+ bool connectDownloadProgress(QObject *, int);
private:
- QDeclarativePixmapReply(QDeclarativeImageReader *reader, const QUrl &url, int req_width, int req_height);
- Q_DISABLE_COPY(QDeclarativePixmapReply)
- Q_DECLARE_PRIVATE(QDeclarativePixmapReply)
- friend class QDeclarativeImageRequestHandler;
- friend class QDeclarativeImageReader;
- friend class QDeclarativePixmapCache;
+ Q_DISABLE_COPY(QDeclarativePixmap);
+ QDeclarativePixmapData *d;
};
-class Q_DECLARATIVE_EXPORT QDeclarativePixmapCache
+inline QDeclarativePixmap::operator const QPixmap &() const
{
- Q_DECLARE_TR_FUNCTIONS(QDeclarativePixmapCache)
-public:
- static QDeclarativePixmapReply::Status get(const QUrl& url, QPixmap *pixmap, QString *errorString, QSize *impsize=0, bool async=false, int req_width=0, int req_height=0);
- static QDeclarativePixmapReply *request(QDeclarativeEngine *, const QUrl& url, int req_width=0, int req_height=0);
- static void cancel(const QUrl& url, QObject *obj);
- static int pendingRequests();
-};
-
-
+ return pixmap();
+}
QT_END_NAMESPACE