diff options
Diffstat (limited to 'src/declarative')
6 files changed, 69 insertions, 33 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp index 420ed90..be9d8bd 100644 --- a/src/declarative/graphicsitems/qdeclarativeborderimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeborderimage.cpp @@ -43,6 +43,7 @@ #include "private/qdeclarativeborderimage_p_p.h" #include <qdeclarativeengine.h> +#include <qdeclarativeinfo.h> #include <QNetworkRequest> #include <QNetworkReply> @@ -218,7 +219,8 @@ void QDeclarativeBorderImage::load() } } else { QSize impsize; - QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->pix, &impsize, d->async); + QString errorString; + QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async); if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) { QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->url); d->pendingPixmapCache = true; @@ -230,8 +232,10 @@ void QDeclarativeBorderImage::load() setImplicitWidth(impsize.width()); setImplicitHeight(impsize.height()); - if (d->pix.isNull()) + if (d->pix.isNull()) { d->status = Error; + qmlInfo(this) << errorString; + } if (d->status == Loading) d->status = Ready; d->progress = 1.0; @@ -338,7 +342,8 @@ void QDeclarativeBorderImage::setGridScaledImage(const QDeclarativeGridScaledIma d->sciurl = d->url.resolved(QUrl(sci.pixmapUrl())); QSize impsize; - QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->sciurl, &d->pix, &impsize, d->async); + QString errorString; + QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->sciurl, &d->pix, &errorString, &impsize, d->async); if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) { QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->sciurl); d->sciPendingPixmapCache = true; @@ -367,8 +372,10 @@ void QDeclarativeBorderImage::setGridScaledImage(const QDeclarativeGridScaledIma setImplicitWidth(impsize.width()); setImplicitHeight(impsize.height()); - if (d->pix.isNull()) + if (d->pix.isNull()) { d->status = Error; + qmlInfo(this) << errorString; + } if (d->status == Loading) d->status = Ready; d->progress = 1.0; @@ -386,11 +393,18 @@ void QDeclarativeBorderImage::requestFinished() QSize impsize; if (d->url.path().endsWith(QLatin1String(".sci"))) { d->sciPendingPixmapCache = false; - QDeclarativePixmapCache::get(d->sciurl, &d->pix, &impsize, d->async); + QString errorString; + if (QDeclarativePixmapCache::get(d->sciurl, &d->pix, &errorString, &impsize, d->async) != QDeclarativePixmapReply::Ready) { + d->status = Error; + qmlInfo(this) << errorString; + } } else { d->pendingPixmapCache = false; - if (QDeclarativePixmapCache::get(d->url, &d->pix, &impsize, d->async) != QDeclarativePixmapReply::Ready) + QString errorString; + if (QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async) != QDeclarativePixmapReply::Ready) { d->status = Error; + qmlInfo(this) << errorString; + } } setImplicitWidth(impsize.width()); setImplicitHeight(impsize.height()); diff --git a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp index 3acafe8..c3f8195 100644 --- a/src/declarative/graphicsitems/qdeclarativeimagebase.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimagebase.cpp @@ -43,6 +43,7 @@ #include "private/qdeclarativeimagebase_p_p.h" #include <qdeclarativeengine.h> +#include <qdeclarativeinfo.h> #include <qdeclarativepixmapcache_p.h> #include <QFile> @@ -154,7 +155,8 @@ void QDeclarativeImageBase::load() int reqwidth = d->sourcesize.width(); int reqheight = d->sourcesize.height(); QSize impsize; - QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->pix, &impsize, d->async, reqwidth, reqheight); + QString errorString; + QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async, reqwidth, reqheight); if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) { QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->url, reqwidth, reqheight); d->pendingPixmapCache = true; @@ -191,6 +193,7 @@ void QDeclarativeImageBase::load() emit sourceSizeChanged(); } else { d->status = Error; + qmlInfo(this) << errorString; } d->progress = 1.0; emit statusChanged(d->status); @@ -210,8 +213,11 @@ void QDeclarativeImageBase::requestFinished() d->pendingPixmapCache = false; QSize impsize; - if (QDeclarativePixmapCache::get(d->url, &d->pix, &impsize, d->async, d->sourcesize.width(), d->sourcesize.height()) != QDeclarativePixmapReply::Ready) + QString errorString; + if (QDeclarativePixmapCache::get(d->url, &d->pix, &errorString, &impsize, d->async, d->sourcesize.width(), d->sourcesize.height()) != QDeclarativePixmapReply::Ready) { d->status = Error; + qmlInfo(this) << errorString; + } setImplicitWidth(impsize.width()); setImplicitHeight(impsize.height()); diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 3b39fa4..a95c930 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -45,6 +45,7 @@ #include <qdeclarativeinfo.h> #include <qdeclarativepixmapcache_p.h> +#include <QSet> #include <QTextLayout> #include <QTextLine> #include <QTextDocument> @@ -75,14 +76,19 @@ protected: if (type == QTextDocument::ImageResource) { QPixmap pm; - QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(url, &pm, 0, true, 0, 0); + QString errorString; + QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(url, &pm, &errorString, 0, false, 0, 0); if (status == QDeclarativePixmapReply::Ready) return pm; - if (status != QDeclarativePixmapReply::Error) { + if (status == QDeclarativePixmapReply::Error) { + if (!errors.contains(url)) { + errors.insert(url); + qmlInfo(parent()) << errorString; + } + } else { QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(parent()), url); connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); outstanding++; - static_cast<QDeclarativeText*>(parent())->reloadWithResources(); } } @@ -93,13 +99,17 @@ private slots: void requestFinished() { outstanding--; - static_cast<QDeclarativeText*>(parent())->reloadWithResources(); + if (outstanding == 0) + static_cast<QDeclarativeText*>(parent())->reloadWithResources(); } private: int outstanding; + static QSet<QUrl> errors; }; +QSet<QUrl> QTextDocumentWithImageResources::errors; + /*! \qmlclass Text QDeclarativeText \since 4.7 @@ -958,17 +968,13 @@ void QDeclarativeText::reloadWithResources() Q_D(QDeclarativeText); if (!d->richText) return; - if (resourcesLoading()!=0) - return; - emit resourcesLoadingChanged(); d->doc->setHtml(d->text); d->updateLayout(); d->markImgDirty(); } /*! - \qmlproperty int Text::resourcesLoading - This property is the number of resources (images) that are being loaded asynchronously. + Returns the number of resources (images) that are being loaded asynchronously. */ int QDeclarativeText::resourcesLoading() const { @@ -976,7 +982,6 @@ int QDeclarativeText::resourcesLoading() const return d->doc ? d->doc->resourcesLoading() : 0; } - void QDeclarativeText::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QDeclarativeText); diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h index fcad898..4fd5e3a 100644 --- a/src/declarative/graphicsitems/qdeclarativetext_p.h +++ b/src/declarative/graphicsitems/qdeclarativetext_p.h @@ -72,7 +72,6 @@ class Q_DECLARATIVE_EXPORT QDeclarativeText : public QDeclarativeItem Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapModeChanged) Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode? - Q_PROPERTY(int resourcesLoading READ resourcesLoading NOTIFY resourcesLoadingChanged) public: QDeclarativeText(QDeclarativeItem *parent=0); @@ -139,7 +138,7 @@ public: virtual void componentComplete(); - int resourcesLoading() const; + int resourcesLoading() const; // mainly for testing Q_SIGNALS: void textChanged(const QString &text); @@ -153,7 +152,6 @@ Q_SIGNALS: void wrapModeChanged(); void textFormatChanged(TextFormat textFormat); void elideModeChanged(TextElideMode mode); - void resourcesLoadingChanged(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index 5e60819..4a96a2a 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -194,8 +194,8 @@ static bool readImage(const QUrl& url, QIODevice *dev, QImage *image, QString *e return true; } else { if (errorString) - *errorString = QLatin1String("Error decoding: ") + url.toString() - + QLatin1String(" \"") + imgio.errorString() + QLatin1String("\""); + *errorString = QDeclarativeImageRequestHandler::tr("Error decoding: %1: %2").arg(url.toString()) + .arg(imgio.errorString()); return false; } } @@ -264,7 +264,7 @@ bool QDeclarativeImageRequestHandler::event(QEvent *event) QString errorStr; if (image.isNull()) { errorCode = QDeclarativeImageReaderEvent::Loading; - errorStr = QLatin1String("Failed to get image from provider: ") + url.toString(); + errorStr = QDeclarativeImageRequestHandler::tr("Failed to get image from provider: %1").arg(url.toString()); } QCoreApplication::postEvent(runningJob, new QDeclarativeImageReaderEvent(errorCode, errorStr, image)); } else { @@ -283,7 +283,7 @@ bool QDeclarativeImageRequestHandler::event(QEvent *event) errorCode = QDeclarativeImageReaderEvent::Loading; } } else { - errorStr = QLatin1String("Cannot open: ") + url.toString(); + errorStr = QDeclarativeImageRequestHandler::tr("Cannot open: %1").arg(url.toString()); errorCode = QDeclarativeImageReaderEvent::Loading; } QCoreApplication::postEvent(runningJob, new QDeclarativeImageReaderEvent(errorCode, errorStr, image)); @@ -460,6 +460,7 @@ public: bool loading; QDeclarativeImageReader *reader; int forced_width, forced_height; + QString errorString; }; @@ -511,7 +512,7 @@ bool QDeclarativePixmapReply::event(QEvent *event) if (d->status == Ready) d->pixmap = QPixmap::fromImage(de->image); else - qWarning() << de->errorString; + d->errorString = de->errorString; QByteArray key = d->url.toEncoded(QUrl::FormattingOption(0x100)); QString strKey = QString::fromLatin1(key.constData(), key.count()); QPixmapCache::insert(strKey, d->pixmap); // note: may fail (returns false) @@ -523,6 +524,12 @@ bool QDeclarativePixmapReply::event(QEvent *event) return QObject::event(event); } +QString QDeclarativePixmapReply::errorString() const +{ + Q_D(const QDeclarativePixmapReply); + return d->errorString; +} + QDeclarativePixmapReply::Status QDeclarativePixmapReply::status() const { Q_D(const QDeclarativePixmapReply); @@ -586,7 +593,7 @@ bool QDeclarativePixmapReply::release(bool defer) Note that images sourced from the network will always be loaded and decoded asynchonously. */ -QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QPixmap *pixmap, QSize *impsize, bool async, int req_width, int req_height) +QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QPixmap *pixmap, QString *errorString, QSize *impsize, bool async, int req_width, int req_height) { QDeclarativePixmapReply::Status status = QDeclarativePixmapReply::Unrequested; QByteArray key = url.toEncoded(QUrl::FormattingOption(0x100)); @@ -609,17 +616,16 @@ QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QP QFile f(lf); QSize read_impsize; if (f.open(QIODevice::ReadOnly)) { - QString errorString; QImage image; - if (readImage(url, &f, &image, &errorString, &read_impsize, req_width, req_height)) { + if (readImage(url, &f, &image, errorString, &read_impsize, req_width, req_height)) { *pixmap = QPixmap::fromImage(image); } else { - qWarning() << errorString; *pixmap = QPixmap(); status = QDeclarativePixmapReply::Error; } } else { - qWarning() << "Cannot open" << url; + if (errorString) + *errorString = QDeclarativeImageRequestHandler::tr("Cannot open: %1").arg(url.toString()); *pixmap = QPixmap(); status = QDeclarativePixmapReply::Error; } @@ -650,9 +656,15 @@ QDeclarativePixmapReply::Status QDeclarativePixmapCache::get(const QUrl& url, QP } else if (QPixmapCache::find(strKey, pixmap)) { if (iter != qmlActivePixmapReplies()->end()) { status = (*iter)->status(); + if (errorString) + *errorString = (*iter)->errorString(); (*iter)->release(); + } else if (pixmap->isNull()) { + status = QDeclarativePixmapReply::Error; + if (errorString) + *errorString = QDeclarativeImageRequestHandler::tr("Unknown Error loading %1").arg(url); } else { - status = pixmap->isNull() ? QDeclarativePixmapReply::Error : QDeclarativePixmapReply::Ready; + status = QDeclarativePixmapReply::Ready; } } else if (iter != qmlActivePixmapReplies()->end()) { status = QDeclarativePixmapReply::Loading; diff --git a/src/declarative/util/qdeclarativepixmapcache_p.h b/src/declarative/util/qdeclarativepixmapcache_p.h index df71d65..7b94728 100644 --- a/src/declarative/util/qdeclarativepixmapcache_p.h +++ b/src/declarative/util/qdeclarativepixmapcache_p.h @@ -64,6 +64,7 @@ public: enum Status { Ready, Error, Unrequested, Loading }; Status status() const; + QString errorString() const; const QUrl &url() const; int forcedWidth() const; @@ -95,7 +96,7 @@ private: class Q_DECLARATIVE_EXPORT QDeclarativePixmapCache { public: - static QDeclarativePixmapReply::Status get(const QUrl& url, QPixmap *pixmap, QSize *impsize=0, bool async=false, int req_width=0, int req_height=0); + 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(); |