diff options
author | Harald Fernengel <harald@trolltech.com> | 2009-08-20 13:37:55 (GMT) |
---|---|---|
committer | Harald Fernengel <harald@trolltech.com> | 2009-08-20 15:12:07 (GMT) |
commit | fe00645222c4a96a966c8f6938286cf136a6377a (patch) | |
tree | d640d30d2f1a854312f285f2dda631edb6cb3afa /src/gui/image/qpicture.cpp | |
parent | c2bde443f2510798de9d815af13d5947317fc7d1 (diff) | |
download | Qt-fe00645222c4a96a966c8f6938286cf136a6377a.zip Qt-fe00645222c4a96a966c8f6938286cf136a6377a.tar.gz Qt-fe00645222c4a96a966c8f6938286cf136a6377a.tar.bz2 |
Use QExplicitlySharedDataPointer wherever possible
Remove QScopedSharedPointer, this class will go soon.
Diffstat (limited to 'src/gui/image/qpicture.cpp')
-rw-r--r-- | src/gui/image/qpicture.cpp | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp index 1136a97..d821773 100644 --- a/src/gui/image/qpicture.cpp +++ b/src/gui/image/qpicture.cpp @@ -131,7 +131,6 @@ QPicture::QPicture(int formatVersion) d_ptr(new QPicturePrivate) { Q_D(QPicture); - d_ptr->q_ptr = this; if (formatVersion == 0) qWarning("QPicture: invalid format version 0"); @@ -141,8 +140,7 @@ QPicture::QPicture(int formatVersion) d->formatMajor = formatVersion; d->formatMinor = 0; d->formatOk = false; - } - else { + } else { d->resetFormat(); } } @@ -154,9 +152,8 @@ QPicture::QPicture(int formatVersion) */ QPicture::QPicture(const QPicture &pic) - : QPaintDevice(), d_ptr(pic.d_ptr.data()) + : QPaintDevice(), d_ptr(pic.d_ptr) { - d_func()->ref.ref(); } /*! \internal */ @@ -164,7 +161,6 @@ QPicture::QPicture(QPicturePrivate &dptr) : QPaintDevice(), d_ptr(&dptr) { - d_ptr->q_ptr = this; } /*! @@ -225,8 +221,7 @@ const char* QPicture::data() const void QPicture::detach() { - if (d_func()->ref != 1) - detach_helper(); + d_ptr.detach(); } bool QPicture::isDetached() const @@ -1012,22 +1007,16 @@ int QPicture::metric(PaintDeviceMetric m) const /*! \fn bool QPicture::isDetached() const \internal */ + +/*! \internal +### Qt 5 - remove me + */ void QPicture::detach_helper() { - Q_D(QPicture); - QPicturePrivate *x = new QPicturePrivate; - int pictsize = size(); - x->pictb.setData(data(), pictsize); - if (d->pictb.isOpen()) { - x->pictb.open(d->pictb.openMode()); - x->pictb.seek(d->pictb.pos()); - } - x->trecs = d->trecs; - x->formatOk = d->formatOk; - x->formatMinor = d->formatMinor; - x->brect = d->brect; - x->override_rect = d->override_rect; - d_ptr.reset(x); + // QExplicitelySharedDataPointer takes care of cloning using + // QPicturePrivate's copy constructor. Do not call detach_helper() anymore + // and remove in Qt 5, please. + Q_ASSERT_X(false, "QPicture::detach_helper()", "Do not call this function"); } /*! @@ -1036,7 +1025,7 @@ void QPicture::detach_helper() */ QPicture& QPicture::operator=(const QPicture &p) { - d_ptr.assign(p.d_ptr.data()); + d_ptr = p.d_ptr; return *this; } @@ -1046,10 +1035,28 @@ QPicture& QPicture::operator=(const QPicture &p) Constructs a QPicturePrivate */ QPicturePrivate::QPicturePrivate() - : in_memory_only(false), - q_ptr(0) + : in_memory_only(false) { - ref = 1; +} + +/*! + \internal + + Copy-Constructs a QPicturePrivate. Needed when detaching. +*/ +QPicturePrivate::QPicturePrivate(const QPicturePrivate &other) + : trecs(other.trecs), + formatOk(other.formatOk), + formatMinor(other.formatMinor), + brect(other.brect), + override_rect(other.override_rect), + in_memory_only(false) +{ + pictb.setData(other.pictb.data(), other.pictb.size()); + if (other.pictb.isOpen()) { + pictb.open(other.pictb.openMode()); + pictb.seek(other.pictb.pos()); + } } /*! |