Add missing detach() in QPixmap::convertFromImage()

Task-number: QTBUG-18519
Change-Id: I5d929cf6eda3f34130314edac95487fb00a95db5
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
bb10
David Faure 2014-06-11 11:48:36 +02:00 committed by The Qt Project
parent d06c6d8a51
commit 11aaff3a57
2 changed files with 16 additions and 0 deletions

View File

@ -1098,6 +1098,7 @@ bool QPixmap::isDetached() const
*/
bool QPixmap::convertFromImage(const QImage &image, Qt::ImageConversionFlags flags)
{
detach();
if (image.isNull() || !data)
*this = QPixmap::fromImage(image, flags);
else

View File

@ -91,6 +91,7 @@ private slots:
void convertFromImage_data();
void convertFromImage();
void convertFromImageShouldDetach();
void testMetrics();
@ -343,6 +344,20 @@ void tst_QPixmap::convertFromImage()
QCOMPARE(pix, res);
}
void tst_QPixmap::convertFromImageShouldDetach()
{
const QString prefix = QFINDTESTDATA("convertFromImage");
QImage img1;
QImage img2;
QVERIFY(img1.load(prefix + "/task31722_0/img1.png"));
QVERIFY(img2.load(prefix + "/task31722_0/img2.png"));
QPixmap pix = QPixmap::fromImage(img1);
QPixmap pix1 = pix;
pix.convertFromImage(img2);
QCOMPARE(pix, QPixmap::fromImage(img2));
QCOMPARE(pix1, QPixmap::fromImage(img1)); // unchanged
}
void tst_QPixmap::scroll_data()
{
QTest::addColumn<QImage>("input");