diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2010-12-06 13:06:56 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2010-12-06 14:14:28 (GMT) |
commit | 9a63863d6f0c614c041c3d4b375bf88d93148ef7 (patch) | |
tree | 73397d058acc2051261f6550b46d97a31faa8195 /src | |
parent | 6ae84f1183e91c910ca92a55e37f8254ace805c0 (diff) | |
download | Qt-9a63863d6f0c614c041c3d4b375bf88d93148ef7.zip Qt-9a63863d6f0c614c041c3d4b375bf88d93148ef7.tar.gz Qt-9a63863d6f0c614c041c3d4b375bf88d93148ef7.tar.bz2 |
Make sure to do a deep copy of a QImage when it's being painted on.
Not doing so can produce some hard-to-track-down bugs in the app.
Task-number: QTBUG-15749
Reviewed-by: Gunnar Sletta
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/image/qimage.cpp | 25 | ||||
-rw-r--r-- | src/gui/image/qpixmap_raster.cpp | 8 |
2 files changed, 25 insertions, 8 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 1157b93..6ba3858 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1121,9 +1121,14 @@ QImage::QImage(const char * const xpm[]) QImage::QImage(const QImage &image) : QPaintDevice() { - d = image.d; - if (d) - d->ref.ref(); + if (image.paintingActive()) { + d = 0; + operator=(image.copy()); + } else { + d = image.d; + if (d) + d->ref.ref(); + } } #ifdef QT3_SUPPORT @@ -1320,11 +1325,15 @@ QImage::~QImage() QImage &QImage::operator=(const QImage &image) { - if (image.d) - image.d->ref.ref(); - if (d && !d->ref.deref()) - delete d; - d = image.d; + if (image.paintingActive()) { + operator=(image.copy()); + } else { + if (image.d) + image.d->ref.ref(); + if (d && !d->ref.deref()) + delete d; + d = image.d; + } return *this; } diff --git a/src/gui/image/qpixmap_raster.cpp b/src/gui/image/qpixmap_raster.cpp index 53f3559..f080687 100644 --- a/src/gui/image/qpixmap_raster.cpp +++ b/src/gui/image/qpixmap_raster.cpp @@ -44,6 +44,7 @@ #include "qpixmap_raster_p.h" #include "qnativeimage_p.h" #include "qimage_p.h" +#include "qpaintengine.h" #include "qbitmap.h" #include "qimage.h" @@ -302,6 +303,13 @@ bool QRasterPixmapData::hasAlphaChannel() const QImage QRasterPixmapData::toImage() const { + if (image.paintEngine() + && image.paintEngine()->isActive() + && image.paintEngine()->paintDevice() == &image) + { + return image.copy(); + } + return image; } |