summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-04-15 06:17:39 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-04-15 06:17:39 (GMT)
commitc24d3ce5d268e6e91bcecb155e4e2f5bd9c7dadd (patch)
treeffa44136301cc0f5772bbba48a32f8367f17d9b6 /src
parentaad82abd84022f5401c6b79ab15d24abebf082af (diff)
downloadQt-c24d3ce5d268e6e91bcecb155e4e2f5bd9c7dadd.zip
Qt-c24d3ce5d268e6e91bcecb155e4e2f5bd9c7dadd.tar.gz
Qt-c24d3ce5d268e6e91bcecb155e4e2f5bd9c7dadd.tar.bz2
Use qmlInfo for image loading errors, not qWarning().
Task-number: QTBUG-9908
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeborderimage.cpp26
-rw-r--r--src/declarative/graphicsitems/qdeclarativeimagebase.cpp10
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp14
-rw-r--r--src/declarative/util/qdeclarativepixmapcache.cpp34
-rw-r--r--src/declarative/util/qdeclarativepixmapcache_p.h3
-rw-r--r--src/imports/particles/qdeclarativeparticles.cpp10
6 files changed, 73 insertions, 24 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..9fcfd92 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,10 +76,16 @@ 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, true, 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++;
@@ -98,8 +105,11 @@ private slots:
private:
int outstanding;
+ static QSet<QUrl> errors;
};
+QSet<QUrl> QTextDocumentWithImageResources::errors;
+
/*!
\qmlclass Text QDeclarativeText
\since 4.7
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();
diff --git a/src/imports/particles/qdeclarativeparticles.cpp b/src/imports/particles/qdeclarativeparticles.cpp
index d17a8a1..264cba2 100644
--- a/src/imports/particles/qdeclarativeparticles.cpp
+++ b/src/imports/particles/qdeclarativeparticles.cpp
@@ -41,6 +41,7 @@
#include "qdeclarativeparticles_p.h"
+#include <qdeclarativeinfo.h>
#include <private/qdeclarativeitem_p.h>
#include <private/qdeclarativepixmapcache_p.h>
@@ -730,7 +731,9 @@ void QDeclarativeParticles::imageLoaded()
{
Q_D(QDeclarativeParticles);
d->pendingPixmapCache = false;
- QDeclarativePixmapCache::get(d->url, &d->image);
+ QString errorString;
+ if (QDeclarativePixmapCache::get(d->url, &d->image, &errorString)==QDeclarativePixmapReply::Error)
+ qmlInfo(this) << errorString;
d->paintItem->updateSize();
d->paintItem->update();
}
@@ -754,12 +757,15 @@ void QDeclarativeParticles::setSource(const QUrl &name)
} else {
d->url = name;
Q_ASSERT(!name.isRelative());
- QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->image);
+ QString errorString;
+ QDeclarativePixmapReply::Status status = QDeclarativePixmapCache::get(d->url, &d->image, &errorString);
if (status != QDeclarativePixmapReply::Ready && status != QDeclarativePixmapReply::Error) {
QDeclarativePixmapReply *reply = QDeclarativePixmapCache::request(qmlEngine(this), d->url);
connect(reply, SIGNAL(finished()), this, SLOT(imageLoaded()));
d->pendingPixmapCache = true;
} else {
+ if (status == QDeclarativePixmapReply::Error)
+ qmlInfo(this) << errorString;
//### unify with imageLoaded
d->paintItem->updateSize();
d->paintItem->update();