summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Fernengel <harald@trolltech.com>2009-08-20 13:37:55 (GMT)
committerHarald Fernengel <harald@trolltech.com>2009-08-20 15:12:07 (GMT)
commitfe00645222c4a96a966c8f6938286cf136a6377a (patch)
treed640d30d2f1a854312f285f2dda631edb6cb3afa /src
parentc2bde443f2510798de9d815af13d5947317fc7d1 (diff)
downloadQt-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')
-rw-r--r--src/gui/image/qbitmap.h2
-rw-r--r--src/gui/image/qpicture.cpp59
-rw-r--r--src/gui/image/qpicture.h9
-rw-r--r--src/gui/image/qpicture_p.h4
-rw-r--r--src/gui/image/qpixmap.cpp47
-rw-r--r--src/gui/image/qpixmap.h5
-rw-r--r--src/gui/image/qpixmap_qws.cpp8
-rw-r--r--src/gui/image/qpixmapcache_p.h2
-rw-r--r--src/gui/image/qpixmapdata_p.h1
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp6
-rw-r--r--src/gui/text/qfont.cpp24
-rw-r--r--src/gui/text/qfont.h4
12 files changed, 77 insertions, 94 deletions
diff --git a/src/gui/image/qbitmap.h b/src/gui/image/qbitmap.h
index 8738d65..89d3171 100644
--- a/src/gui/image/qbitmap.h
+++ b/src/gui/image/qbitmap.h
@@ -82,6 +82,8 @@ public:
QT3_SUPPORT_CONSTRUCTOR QBitmap(const QImage &image) { *this = fromImage(image); }
QT3_SUPPORT QBitmap &operator=(const QImage &image) { *this = fromImage(image); return *this; }
#endif
+
+ typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr;
};
Q_DECLARE_SHARED(QBitmap)
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());
+ }
}
/*!
diff --git a/src/gui/image/qpicture.h b/src/gui/image/qpicture.h
index 1e80ab7..6effae7 100644
--- a/src/gui/image/qpicture.h
+++ b/src/gui/image/qpicture.h
@@ -42,8 +42,9 @@
#ifndef QPICTURE_H
#define QPICTURE_H
-#include <QtGui/qpaintdevice.h>
#include <QtCore/qstringlist.h>
+#include <QtCore/qsharedpointer.h>
+#include <QtGui/qpaintdevice.h>
QT_BEGIN_HEADER
@@ -106,15 +107,15 @@ private:
bool exec(QPainter *p, QDataStream &ds, int i);
void detach_helper();
- QScopedSharedPointer<QPicturePrivate> d_ptr;
+ QExplicitlySharedDataPointer<QPicturePrivate> d_ptr;
friend class QPicturePaintEngine;
friend class Q3Picture;
friend class QAlphaPaintEngine;
friend class QPreviewPaintEngine;
public:
- typedef QPicturePrivate* DataPtr;
- inline DataPtr &data_ptr() { return d_ptr.data_ptr(); }
+ typedef QExplicitlySharedDataPointer<QPicturePrivate> DataPtr;
+ inline DataPtr &data_ptr() { return d_ptr; }
};
Q_DECLARE_SHARED(QPicture)
diff --git a/src/gui/image/qpicture_p.h b/src/gui/image/qpicture_p.h
index f405d7f..0ab181c 100644
--- a/src/gui/image/qpicture_p.h
+++ b/src/gui/image/qpicture_p.h
@@ -71,7 +71,6 @@ extern const char *qt_mfhdr_tag;
class QPicturePrivate
{
- Q_DECLARE_PUBLIC(QPicture)
friend class QPicturePaintEngine;
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &s, const QPicture &r);
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &s, QPicture &r);
@@ -144,6 +143,7 @@ public:
};
QPicturePrivate();
+ QPicturePrivate(const QPicturePrivate &other);
QAtomicInt ref;
bool checkFormat();
@@ -162,8 +162,6 @@ public:
QList<QPixmap> pixmap_list;
QList<QBrush> brush_list;
QList<QPen> pen_list;
-
- QPicture *q_ptr;
};
QT_END_NAMESPACE
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index 79b1f17..7328853 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -120,7 +120,6 @@ void QPixmap::init(int w, int h, int type)
data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type));
data->resize(w, h);
- data->ref.ref();
}
/*!
@@ -222,7 +221,6 @@ QPixmap::QPixmap(const QSize &s, int type)
QPixmap::QPixmap(QPixmapData *d)
: QPaintDevice(), data(d)
{
- data->ref.ref();
}
/*!
@@ -261,12 +259,7 @@ QPixmap::QPixmap(const QString& fileName, const char *format, Qt::ImageConversio
if (!qt_pixmap_thread_test())
return;
- QT_TRY {
- load(fileName, format, flags);
- } QT_CATCH(...) {
- deref();
- QT_RETHROW;
- }
+ load(fileName, format, flags);
}
/*!
@@ -283,11 +276,9 @@ QPixmap::QPixmap(const QPixmap &pixmap)
return;
}
if (pixmap.paintingActive()) { // make a deep copy
- data = 0;
operator=(pixmap.copy());
} else {
data = pixmap.data;
- data->ref.ref();
}
}
@@ -314,17 +305,12 @@ QPixmap::QPixmap(const char * const xpm[])
if (!xpm)
return;
- QT_TRY {
- QImage image(xpm);
- if (!image.isNull()) {
- if (data->pixelType() == QPixmapData::BitmapType)
- *this = QBitmap::fromImage(image);
- else
- *this = fromImage(image);
- }
- } QT_CATCH(...) {
- deref();
- QT_RETHROW;
+ QImage image(xpm);
+ if (!image.isNull()) {
+ if (data->pixelType() == QPixmapData::BitmapType)
+ *this = QBitmap::fromImage(image);
+ else
+ *this = fromImage(image);
}
}
#endif
@@ -336,7 +322,6 @@ QPixmap::QPixmap(const char * const xpm[])
QPixmap::~QPixmap()
{
- deref();
}
/*!
@@ -381,7 +366,7 @@ QPixmap QPixmap::copy(const QRect &rect) const
else
d = QGraphicsSystem::createDefaultPixmapData(data->pixelType());
- d->copy(data, r);
+ d->copy(data.data(), r);
return QPixmap(d);
}
@@ -454,8 +439,6 @@ QPixmap &QPixmap::operator=(const QPixmap &pixmap)
if (pixmap.paintingActive()) { // make a deep copy
*this = pixmap.copy();
} else {
- pixmap.data->ref.ref(); // avoid 'x = x'
- deref();
data = pixmap.data;
}
return *this;
@@ -1362,14 +1345,12 @@ bool QPixmap::isDetached() const
return data->ref == 1;
}
+/*! \internal
+ ### Qt5 - remove me.
+*/
void QPixmap::deref()
{
- if (data && !data->ref.deref()) { // Destroy image if last ref
- if (data->is_cached)
- QImagePixmapCleanupHooks::executePixmapHooks(this);
- delete data;
- data = 0;
- }
+ Q_ASSERT_X(false, "QPixmap::deref()", "Do not call this function anymore!");
}
/*!
@@ -1928,7 +1909,7 @@ void QPixmap::detach()
{
QPixmapData::ClassId id = data->classId();
if (id == QPixmapData::RasterClass) {
- QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data);
+ QRasterPixmapData *rasterData = static_cast<QRasterPixmapData*>(data.data());
rasterData->image.detach();
}
@@ -2038,7 +2019,7 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags)
*/
QPixmapData* QPixmap::pixmapData() const
{
- return data;
+ return data.data();
}
/*!
diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h
index bce1f5e..961008f 100644
--- a/src/gui/image/qpixmap.h
+++ b/src/gui/image/qpixmap.h
@@ -46,6 +46,7 @@
#include <QtGui/qcolor.h>
#include <QtCore/qnamespace.h>
#include <QtCore/qstring.h> // char*->QString conversion
+#include <QtCore/qsharedpointer.h>
#include <QtGui/qimage.h>
#include <QtGui/qtransform.h>
@@ -227,7 +228,7 @@ public:
#endif
private:
- QPixmapData *data;
+ QExplicitlySharedDataPointer<QPixmapData> data;
bool doImageIO(QImageWriter *io, int quality) const;
@@ -272,7 +273,7 @@ public:
QPixmapData* pixmapData() const;
public:
- typedef QPixmapData * DataPtr;
+ typedef QExplicitlySharedDataPointer<QPixmapData> DataPtr;
inline DataPtr &data_ptr() { return data; }
};
diff --git a/src/gui/image/qpixmap_qws.cpp b/src/gui/image/qpixmap_qws.cpp
index b106610..e549900 100644
--- a/src/gui/image/qpixmap_qws.cpp
+++ b/src/gui/image/qpixmap_qws.cpp
@@ -112,7 +112,7 @@ QPixmap QPixmap::grabWindow(WId window, int x, int y, int w, int h)
QRgb* QPixmap::clut() const
{
if (data->classId() == QPixmapData::RasterClass) {
- const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data);
+ const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.colorTable().data();
}
@@ -122,7 +122,7 @@ QRgb* QPixmap::clut() const
int QPixmap::numCols() const
{
if (data->classId() == QPixmapData::RasterClass) {
- const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data);
+ const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.numColors();
}
@@ -132,7 +132,7 @@ int QPixmap::numCols() const
const uchar* QPixmap::qwsBits() const
{
if (data->classId() == QPixmapData::RasterClass) {
- const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data);
+ const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.bits();
}
@@ -142,7 +142,7 @@ const uchar* QPixmap::qwsBits() const
int QPixmap::qwsBytesPerLine() const
{
if (data->classId() == QPixmapData::RasterClass) {
- const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data);
+ const QRasterPixmapData *d = static_cast<const QRasterPixmapData*>(data.data());
return d->image.bytesPerLine();
}
diff --git a/src/gui/image/qpixmapcache_p.h b/src/gui/image/qpixmapcache_p.h
index cbfc3e8..511c852 100644
--- a/src/gui/image/qpixmapcache_p.h
+++ b/src/gui/image/qpixmapcache_p.h
@@ -82,7 +82,7 @@ public:
QDetachedPixmap(const QPixmap &pix) : QPixmap(pix)
{
if (data && data->classId() == QPixmapData::RasterClass) {
- QRasterPixmapData *d = static_cast<QRasterPixmapData*>(data);
+ QRasterPixmapData *d = static_cast<QRasterPixmapData*>(data.data());
if (!d->image.isNull() && d->image.d->paintEngine
&& !d->image.d->paintEngine->isActive())
{
diff --git a/src/gui/image/qpixmapdata_p.h b/src/gui/image/qpixmapdata_p.h
index 1c3e422..70890c0 100644
--- a/src/gui/image/qpixmapdata_p.h
+++ b/src/gui/image/qpixmapdata_p.h
@@ -117,6 +117,7 @@ private:
friend class QGLContextPrivate;
friend class QX11PixmapData;
friend class QGLTextureCache; //Needs to check the reference count
+ friend class QExplicitlySharedDataPointer<QPixmapData>;
QAtomicInt ref;
int detach_no;
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index 8679e15..72bb164 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -2368,7 +2368,7 @@ void QRasterPaintEngine::drawPixmap(const QPointF &pos, const QPixmap &pixmap)
#endif
if (pixmap.data->classId() == QPixmapData::RasterClass) {
- const QImage &image = ((QRasterPixmapData *) pixmap.data)->image;
+ const QImage &image = static_cast<QRasterPixmapData *>(pixmap.data.data())->image;
if (image.depth() == 1) {
Q_D(QRasterPaintEngine);
QRasterPaintEngineState *s = state();
@@ -2406,7 +2406,7 @@ void QRasterPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pixmap, cons
#endif
if (pixmap.data->classId() == QPixmapData::RasterClass) {
- const QImage &image = ((QRasterPixmapData *) pixmap.data)->image;
+ const QImage &image = static_cast<QRasterPixmapData *>(pixmap.data.data())->image;
if (image.depth() == 1) {
Q_D(QRasterPaintEngine);
QRasterPaintEngineState *s = state();
@@ -2716,7 +2716,7 @@ void QRasterPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap,
QImage image;
if (pixmap.data->classId() == QPixmapData::RasterClass) {
- image = ((QRasterPixmapData *) pixmap.data)->image;
+ image = static_cast<QRasterPixmapData *>(pixmap.data.data())->image;
} else {
image = pixmap.toImage();
}
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp
index 96905d0..3443a64 100644
--- a/src/gui/text/qfont.cpp
+++ b/src/gui/text/qfont.cpp
@@ -217,7 +217,6 @@ QFontPrivate::QFontPrivate()
rawMode(false), underline(false), overline(false), strikeOut(false), kerning(true),
capital(0), letterSpacingIsAbsolute(false), scFont(0)
{
- ref = 1;
#ifdef Q_WS_X11
if (QX11Info::display())
screen = QX11Info::appScreen();
@@ -237,7 +236,6 @@ QFontPrivate::QFontPrivate(const QFontPrivate &other)
letterSpacing(other.letterSpacing), wordSpacing(other.wordSpacing),
scFont(other.scFont)
{
- ref = 1;
#ifdef Q_WS_WIN
hdc = other.hdc;
#endif
@@ -721,11 +719,11 @@ QFont::QFont(const QFont &font, QPaintDevice *pd)
const int screen = 0;
#endif
if (font.d->dpi != dpi || font.d->screen != screen ) {
- d.reset(new QFontPrivate(*font.d));
+ d = new QFontPrivate(*font.d);
d->dpi = dpi;
d->screen = screen;
} else {
- d.assign(font.d.data());
+ d = font.d.data();
}
#ifdef Q_WS_WIN
if (pd->devType() == QInternal::Printer && pd->getDC())
@@ -737,9 +735,8 @@ QFont::QFont(const QFont &font, QPaintDevice *pd)
\internal
*/
QFont::QFont(QFontPrivate *data)
- : resolve_mask(QFont::AllPropertiesResolved)
+ : d(data), resolve_mask(QFont::AllPropertiesResolved)
{
- d.assign(data);
}
/*! \internal
@@ -766,9 +763,8 @@ void QFont::detach()
\sa QApplication::setFont(), QApplication::font()
*/
QFont::QFont()
- :resolve_mask(0)
+ : d(QApplication::font().d.data()), resolve_mask(0)
{
- d.assign(QApplication::font().d.data());
}
/*!
@@ -790,10 +786,8 @@ QFont::QFont()
setStyleHint() QApplication::font()
*/
QFont::QFont(const QString &family, int pointSize, int weight, bool italic)
+ : d(new QFontPrivate()), resolve_mask(QFont::FamilyResolved)
{
- d.reset(new QFontPrivate());
- resolve_mask = QFont::FamilyResolved;
-
if (pointSize <= 0) {
#ifdef Q_OS_SYMBIAN
pointSize = 7;
@@ -821,9 +815,8 @@ QFont::QFont(const QString &family, int pointSize, int weight, bool italic)
Constructs a font that is a copy of \a font.
*/
QFont::QFont(const QFont &font)
+ : d(font.d.data()), resolve_mask(font.resolve_mask)
{
- d.assign(font.d.data());
- resolve_mask = font.resolve_mask;
}
/*!
@@ -838,7 +831,7 @@ QFont::~QFont()
*/
QFont &QFont::operator=(const QFont &font)
{
- d.assign(font.d.data());
+ d = font.d.data();
resolve_mask = font.resolve_mask;
return *this;
}
@@ -2197,8 +2190,7 @@ QDataStream &operator<<(QDataStream &s, const QFont &font)
*/
QDataStream &operator>>(QDataStream &s, QFont &font)
{
- font.d.assign(0);
- font.d.reset(new QFontPrivate);
+ font.d = new QFontPrivate;
font.resolve_mask = QFont::AllPropertiesResolved;
quint8 styleHint, styleStrategy = QFont::PreferDefault, charSet, weight, bits;
diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h
index 10ec062..e91e017 100644
--- a/src/gui/text/qfont.h
+++ b/src/gui/text/qfont.h
@@ -44,7 +44,7 @@
#include <QtGui/qwindowdefs.h>
#include <QtCore/qstring.h>
-#include <QtCore/qscopedpointer.h>
+#include <QtCore/qsharedpointer.h>
#if defined(Q_WS_X11) || defined(Q_WS_QWS)
typedef struct FT_FaceRec_* FT_Face;
@@ -313,7 +313,7 @@ private:
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QFont &);
#endif
- QScopedSharedPointer<QFontPrivate> d;
+ QExplicitlySharedDataPointer<QFontPrivate> d;
uint resolve_mask;
};