summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2010-01-20 08:29:08 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2010-01-20 09:41:49 (GMT)
commit8721d060a67a01ac891cab9d3d17aacf7373bcf0 (patch)
treeea6158b84dd0f96de1c8fc2695f7a436e20daf7d
parent7127f5ba2cc5729cfa12f5705e2dcfdcb99e1b91 (diff)
downloadQt-8721d060a67a01ac891cab9d3d17aacf7373bcf0.zip
Qt-8721d060a67a01ac891cab9d3d17aacf7373bcf0.tar.gz
Qt-8721d060a67a01ac891cab9d3d17aacf7373bcf0.tar.bz2
Fixed QBitmap::load to load into bitmap format again.
Task: http://bugreports.qt.nokia.com/browse/QTBUG-7468 Reviewed-by: Trond
-rw-r--r--src/gui/image/qpixmap.cpp21
-rw-r--r--tests/auto/qpixmap/tst_qpixmap.cpp38
2 files changed, 52 insertions, 7 deletions
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index 7b522f5..5a43de7 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -833,14 +833,21 @@ bool QPixmap::load(const QString &fileName, const char *format, Qt::ImageConvers
if (QPixmapCache::find(key, *this))
return true;
- QPixmapData *tmp = QPixmapData::create(0, 0, QPixmapData::PixmapType);
- if (tmp->fromFile(fileName, format, flags)) {
- data = tmp;
- QPixmapCache::insert(key, *this);
- return true;
+ bool ok;
+
+ if (data) {
+ ok = data->fromFile(fileName, format, flags);
+ } else {
+ QScopedPointer<QPixmapData> tmp(QPixmapData::create(0, 0, QPixmapData::PixmapType));
+ ok = tmp->fromFile(fileName, format, flags);
+ if (ok)
+ data = tmp.take();
}
- delete tmp;
- return false;
+
+ if (ok)
+ QPixmapCache::insert(key, *this);
+
+ return ok;
}
/*!
diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp
index 0164c9d..0d60ed0 100644
--- a/tests/auto/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/qpixmap/tst_qpixmap.cpp
@@ -171,6 +171,8 @@ private slots:
void preserveDepth();
void splash_crash();
+
+ void loadAsBitmapOrPixmap();
};
static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
@@ -1510,5 +1512,41 @@ void tst_QPixmap::preserveDepth()
QCOMPARE(depth, source.depth());
}
+void tst_QPixmap::loadAsBitmapOrPixmap()
+{
+ QImage tmp(10, 10, QImage::Format_RGB32);
+ tmp.save("tmp.png");
+
+ bool ok;
+
+ // Check that we can load the pixmap as a pixmap and that it then turns into a pixmap
+ QPixmap pixmap("tmp.png");
+ QVERIFY(!pixmap.isNull());
+ QVERIFY(pixmap.depth() > 1);
+ QVERIFY(!pixmap.isQBitmap());
+
+ pixmap = QPixmap();
+ ok = pixmap.load("tmp.png");
+ QVERIFY(ok);
+ QVERIFY(!pixmap.isNull());
+ QVERIFY(pixmap.depth() > 1);
+ QVERIFY(!pixmap.isQBitmap());
+
+ // The do the same check for bitmaps..
+ QBitmap bitmap("tmp.png");
+ QVERIFY(!bitmap.isNull());
+ QVERIFY(bitmap.depth() == 1);
+ QVERIFY(bitmap.isQBitmap());
+
+ bitmap = QBitmap();
+ ok = bitmap.load("tmp.png");
+ QVERIFY(ok);
+ QVERIFY(!bitmap.isNull());
+ QVERIFY(bitmap.depth() == 1);
+ QVERIFY(bitmap.isQBitmap());
+}
+
+
+
QTEST_MAIN(tst_QPixmap)
#include "tst_qpixmap.moc"