diff options
author | Joona Petrell <joona.t.petrell@nokia.com> | 2010-11-30 01:37:09 (GMT) |
---|---|---|
committer | Joona Petrell <joona.t.petrell@nokia.com> | 2010-11-30 02:08:20 (GMT) |
commit | 282441f72a7704aadc5525a360430d0c3d49aea6 (patch) | |
tree | 45e07dd72accbcaf5c75550f7e7b292010f13a56 | |
parent | e960316477982d21061ca8894109f1f8426b2dec (diff) | |
download | Qt-282441f72a7704aadc5525a360430d0c3d49aea6.zip Qt-282441f72a7704aadc5525a360430d0c3d49aea6.tar.gz Qt-282441f72a7704aadc5525a360430d0c3d49aea6.tar.bz2 |
Don't draw null pixmap in QDeclarativeImage paint function
Task-number: QTBUG-15690
Reviewed-by: Martin Jones
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeimage.cpp | 2 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeimage.cpp b/src/declarative/graphicsitems/qdeclarativeimage.cpp index 3b08a9b..aa74716 100644 --- a/src/declarative/graphicsitems/qdeclarativeimage.cpp +++ b/src/declarative/graphicsitems/qdeclarativeimage.cpp @@ -461,7 +461,7 @@ QRectF QDeclarativeImage::boundingRect() const void QDeclarativeImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { Q_D(QDeclarativeImage); - if (d->pix.isNull()) + if (d->pix.pixmap().isNull() ) return; bool oldAA = p->testRenderHint(QPainter::Antialiasing); diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp index bf779ad..447210d 100644 --- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp +++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp @@ -87,6 +87,7 @@ private slots: void noLoading(); void paintedWidthHeight(); void sourceSize_QTBUG_14303(); + void nullPixmapPaint(); private: template<typename T> @@ -540,6 +541,35 @@ void tst_qdeclarativeimage::sourceSize_QTBUG_14303() QTRY_COMPARE(sourceSizeSpy.count(), 2); } +static int numberOfWarnings = 0; +static void checkWarnings(QtMsgType, const char *) +{ + numberOfWarnings++; +} + +// QTBUG-15690 +void tst_qdeclarativeimage::nullPixmapPaint() +{ + QString componentStr = QString("import QtQuick 1.0\nImage { width: 10; height:10; fillMode: Image.PreserveAspectFit; source: \"") + + SERVER_ADDR + QString("/no-such-file.png\" }"); + QDeclarativeComponent component(&engine); + component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); + QDeclarativeImage *image = qobject_cast<QDeclarativeImage*>(component.create()); + + QTRY_VERIFY(image != 0); + + QtMsgHandler previousMsgHandler = qInstallMsgHandler(checkWarnings); + + QPixmap pm(100, 100); + QPainter p(&pm); + + // used to print "QTransform::translate with NaN called" + image->paint(&p, 0, 0); + qInstallMsgHandler(previousMsgHandler); + QVERIFY(numberOfWarnings == 0); + delete image; +} + /* Find an item with the specified objectName. If index is supplied then the item must also evaluate the {index} expression equal to index |