summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qurl.cpp8
-rw-r--r--src/corelib/io/qurl.h2
-rw-r--r--src/corelib/kernel/qvariant.cpp8
-rw-r--r--src/corelib/kernel/qvariant.h2
-rw-r--r--src/corelib/tools/qhash.cpp1
-rw-r--r--src/corelib/tools/qmap.cpp1
-rw-r--r--src/corelib/tools/qregexp.cpp8
-rw-r--r--src/corelib/tools/qregexp.h1
-rw-r--r--src/gui/image/qbitmap.cpp8
-rw-r--r--src/gui/image/qbitmap.h1
-rw-r--r--src/gui/image/qicon.cpp8
-rw-r--r--src/gui/image/qicon.h2
-rw-r--r--src/gui/image/qimage.cpp8
-rw-r--r--src/gui/image/qimage.h1
-rw-r--r--src/gui/image/qpicture.cpp8
-rw-r--r--src/gui/image/qpicture.h1
-rw-r--r--src/gui/image/qpixmap.cpp8
-rw-r--r--src/gui/image/qpixmap.h2
-rw-r--r--src/gui/kernel/qkeysequence.cpp8
-rw-r--r--src/gui/kernel/qkeysequence.h1
-rw-r--r--src/gui/painting/qbrush.cpp9
-rw-r--r--src/gui/painting/qbrush.h2
-rw-r--r--src/gui/painting/qpainterpath.cpp8
-rw-r--r--src/gui/painting/qpainterpath.h1
-rw-r--r--src/gui/painting/qpen.cpp8
-rw-r--r--src/gui/painting/qpen.h1
-rw-r--r--src/gui/painting/qpolygon.cpp2
-rw-r--r--src/gui/painting/qregion.cpp8
-rw-r--r--src/gui/painting/qregion.h1
-rw-r--r--tests/auto/qbrush/tst_qbrush.cpp9
-rw-r--r--tests/auto/qicon/tst_qicon.cpp16
-rw-r--r--tests/auto/qimage/tst_qimage.cpp15
-rw-r--r--tests/auto/qkeysequence/tst_qkeysequence.cpp10
-rw-r--r--tests/auto/qpainterpath/tst_qpainterpath.cpp13
-rw-r--r--tests/auto/qpen/tst_qpen.cpp9
-rw-r--r--tests/auto/qpicture/tst_qpicture.cpp13
-rw-r--r--tests/auto/qpixmap/tst_qpixmap.cpp16
-rw-r--r--tests/auto/qregexp/tst_qregexp.cpp9
-rw-r--r--tests/auto/qregion/tst_qregion.cpp10
-rw-r--r--tests/auto/qurl/tst_qurl.cpp9
-rw-r--r--tests/auto/qvariant/tst_qvariant.cpp11
41 files changed, 267 insertions, 0 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 6452c0f..6ec5562 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -6048,6 +6048,14 @@ QUrl &QUrl::operator =(const QString &url)
return *this;
}
+/*!
+ \fn void QUrl::swap(QUrl &other)
+ \since 4.8
+
+ Swaps URL \a other with this URL. This operation is very
+ fast and never fails.
+*/
+
/*! \internal
Forces a detach.
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h
index 563be5f..63fe98d 100644
--- a/src/corelib/io/qurl.h
+++ b/src/corelib/io/qurl.h
@@ -100,6 +100,8 @@ public:
#endif
~QUrl();
+ inline void swap(QUrl &other) { qSwap(d, other.d); }
+
void setUrl(const QString &url);
void setUrl(const QString &url, ParsingMode mode);
// ### Qt 5: merge the two setUrl() functions, with mode = TolerantMode
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index feb85ce..aa070f1 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -1808,6 +1808,14 @@ QVariant& QVariant::operator=(const QVariant &variant)
}
/*!
+ \fn void QVariant::swap(QVariant &other)
+ \since 4.8
+
+ Swaps variant \a other with this variant. This operation is very
+ fast and never fails.
+*/
+
+/*!
\fn void QVariant::detach()
\internal
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h
index b267954..611db8b 100644
--- a/src/corelib/kernel/qvariant.h
+++ b/src/corelib/kernel/qvariant.h
@@ -224,6 +224,8 @@ class Q_CORE_EXPORT QVariant
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QVariant &other) { qSwap(d, other.d); }
+
Type type() const;
int userType() const;
const char *typeName() const;
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 5a8057d..3dc9c92 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -738,6 +738,7 @@ void QHashData::checkSanity()
*/
/*! \fn void QMultiHash::swap(QMultiHash<Key, T> &other)
+ \since 4.8
Swaps hash \a other with this hash. This operation is very
fast and never fails.
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp
index 7b814b3..5a5fffd 100644
--- a/src/corelib/tools/qmap.cpp
+++ b/src/corelib/tools/qmap.cpp
@@ -412,6 +412,7 @@ void QMapData::dump()
*/
/*! \fn void QMultiMap::swap(QMultiMap<Key, T> &other)
+ \since 4.8
Swaps map \a other with this map. This operation is very
fast and never fails.
diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp
index 7a26c4f..5d2a0e3 100644
--- a/src/corelib/tools/qregexp.cpp
+++ b/src/corelib/tools/qregexp.cpp
@@ -3858,6 +3858,14 @@ QRegExp &QRegExp::operator=(const QRegExp &rx)
}
/*!
+ \fn void QRegExp::swap(QRegExp &other)
+ \since 4.8
+
+ Swaps regular expression \a other with this regular
+ expression. This operation is very fast and never fails.
+*/
+
+/*!
Returns true if this regular expression is equal to \a rx;
otherwise returns false.
diff --git a/src/corelib/tools/qregexp.h b/src/corelib/tools/qregexp.h
index 0b4a702..4a74f90 100644
--- a/src/corelib/tools/qregexp.h
+++ b/src/corelib/tools/qregexp.h
@@ -80,6 +80,7 @@ public:
inline QRegExp &operator=(QRegExp &&other)
{ qSwap(priv,other.priv); return *this; }
#endif
+ inline void swap(QRegExp &other) { qSwap(priv, other.priv); }
bool operator==(const QRegExp &rx) const;
inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); }
diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp
index 91622f3..9d90b3f 100644
--- a/src/gui/image/qbitmap.cpp
+++ b/src/gui/image/qbitmap.cpp
@@ -227,6 +227,14 @@ QBitmap::~QBitmap()
}
/*!
+ \fn void QBitmap::swap(QBitmap &other)
+ \since 4.8
+
+ Swaps bitmap \a other with this bitmap. This operation is very
+ fast and never fails.
+*/
+
+/*!
Returns the bitmap as a QVariant.
*/
QBitmap::operator QVariant() const
diff --git a/src/gui/image/qbitmap.h b/src/gui/image/qbitmap.h
index 1bbe1cf..93be951 100644
--- a/src/gui/image/qbitmap.h
+++ b/src/gui/image/qbitmap.h
@@ -63,6 +63,7 @@ public:
~QBitmap();
QBitmap &operator=(const QPixmap &);
+ inline void swap(QBitmap &other) { QPixmap::swap(other); } // prevent QBitmap<->QPixmap swaps
operator QVariant() const;
inline void clear() { fill(Qt::color0); }
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index a2f429a..e54bb5f 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -613,6 +613,14 @@ QIcon &QIcon::operator=(const QIcon &other)
}
/*!
+ \fn void QIcon::swap(QIcon &other)
+ \since 4.8
+
+ Swaps icon \a other with this icon. This operation is very
+ fast and never fails.
+*/
+
+/*!
Returns the icon as a QVariant.
*/
QIcon::operator QVariant() const
diff --git a/src/gui/image/qicon.h b/src/gui/image/qicon.h
index fd591e6..5091d03 100644
--- a/src/gui/image/qicon.h
+++ b/src/gui/image/qicon.h
@@ -75,6 +75,8 @@ public:
inline QIcon &operator=(QIcon &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QIcon &other) { qSwap(d, other.d); }
+
operator QVariant() const;
QPixmap pixmap(const QSize &size, Mode mode = Normal, State state = Off) const;
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 5829fe8..d86021cb9 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -1329,6 +1329,14 @@ QImage &QImage::operator=(const QImage &image)
}
/*!
+ \fn void QImage::swap(QImage &other)
+ \since 4.8
+
+ Swaps image \a other with this image. This operation is very
+ fast and never fails.
+*/
+
+/*!
\internal
*/
int QImage::devType() const
diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h
index 003daea..c6a947e 100644
--- a/src/gui/image/qimage.h
+++ b/src/gui/image/qimage.h
@@ -144,6 +144,7 @@ public:
inline QImage &operator=(QImage &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QImage &other) { qSwap(d, other.d); }
bool isNull() const;
diff --git a/src/gui/image/qpicture.cpp b/src/gui/image/qpicture.cpp
index 48d2de3..fc81d23 100644
--- a/src/gui/image/qpicture.cpp
+++ b/src/gui/image/qpicture.cpp
@@ -1030,6 +1030,14 @@ QPicture& QPicture::operator=(const QPicture &p)
}
/*!
+ \fn void QPicture::swap(QPicture &other)
+ \since 4.8
+
+ Swaps picture \a other with this picture. This operation is very
+ fast and never fails.
+*/
+
+/*!
\internal
Constructs a QPicturePrivate
diff --git a/src/gui/image/qpicture.h b/src/gui/image/qpicture.h
index 49b0fd6..d24f23a 100644
--- a/src/gui/image/qpicture.h
+++ b/src/gui/image/qpicture.h
@@ -85,6 +85,7 @@ public:
inline QPicture &operator=(QPicture &&other)
{ qSwap(d_ptr, other.d_ptr); return *this; }
#endif
+ inline void swap(QPicture &other) { d_ptr.swap(other.d_ptr); }
void detach();
bool isDetached() const;
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp
index 5383b7c..1b370c0 100644
--- a/src/gui/image/qpixmap.cpp
+++ b/src/gui/image/qpixmap.cpp
@@ -440,6 +440,14 @@ QPixmap &QPixmap::operator=(const QPixmap &pixmap)
}
/*!
+ \fn void QPixmap::swap(QPixmap &other)
+ \since 4.8
+
+ Swaps pixmap \a other with this pixmap. This operation is very
+ fast and never fails.
+*/
+
+/*!
Returns the pixmap as a QVariant.
*/
QPixmap::operator QVariant() const
diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h
index e9f9365..15fe5fa 100644
--- a/src/gui/image/qpixmap.h
+++ b/src/gui/image/qpixmap.h
@@ -87,6 +87,8 @@ public:
inline QPixmap &operator=(QPixmap &&other)
{ qSwap(data, other.data); return *this; }
#endif
+ inline void swap(QPixmap &other) { qSwap(data, other.data); }
+
operator QVariant() const;
bool isNull() const; // ### Qt 5: make inline
diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp
index e14a9198..b4a360a 100644
--- a/src/gui/kernel/qkeysequence.cpp
+++ b/src/gui/kernel/qkeysequence.cpp
@@ -1521,6 +1521,14 @@ QKeySequence &QKeySequence::operator=(const QKeySequence &other)
}
/*!
+ \fn void QKeySequence::swap(QKeySequence &other)
+ \since 4.8
+
+ Swaps key sequence \a other with this key sequence. This operation is very
+ fast and never fails.
+*/
+
+/*!
\fn bool QKeySequence::operator!=(const QKeySequence &other) const
Returns true if this key sequence is not equal to the \a other
diff --git a/src/gui/kernel/qkeysequence.h b/src/gui/kernel/qkeysequence.h
index b47873d..a2352eb 100644
--- a/src/gui/kernel/qkeysequence.h
+++ b/src/gui/kernel/qkeysequence.h
@@ -183,6 +183,7 @@ public:
inline QKeySequence &operator=(QKeySequence &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QKeySequence &other) { qSwap(d, other.d); }
bool operator==(const QKeySequence &other) const;
inline bool operator!= (const QKeySequence &other) const
{ return !(*this == other); }
diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp
index d0788c7..5b35fc5 100644
--- a/src/gui/painting/qbrush.cpp
+++ b/src/gui/painting/qbrush.cpp
@@ -635,6 +635,15 @@ QBrush &QBrush::operator=(const QBrush &b)
return *this;
}
+
+/*!
+ \fn void QBrush::swap(QBrush &other)
+ \since 4.8
+
+ Swaps brush \a other with this brush. This operation is very
+ fast and never fails.
+*/
+
/*!
Returns the brush as a QVariant
*/
diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h
index efc720b..f9acded 100644
--- a/src/gui/painting/qbrush.h
+++ b/src/gui/painting/qbrush.h
@@ -96,6 +96,8 @@ public:
inline QBrush &operator=(QBrush &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QBrush &other) { qSwap(d, other.d); }
+
operator QVariant() const;
inline Qt::BrushStyle style() const;
diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp
index ffd0d5c..7d6ea12 100644
--- a/src/gui/painting/qpainterpath.cpp
+++ b/src/gui/painting/qpainterpath.cpp
@@ -576,6 +576,14 @@ QPainterPath &QPainterPath::operator=(const QPainterPath &other)
}
/*!
+ \fn void QPainterPath::swap(QPainterPath &other)
+ \since 4.8
+
+ Swaps painter path \a other with this painter path. This operation is very
+ fast and never fails.
+*/
+
+/*!
Destroys this QPainterPath object.
*/
QPainterPath::~QPainterPath()
diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h
index 9a7b60a..82facf8 100644
--- a/src/gui/painting/qpainterpath.h
+++ b/src/gui/painting/qpainterpath.h
@@ -100,6 +100,7 @@ public:
{ qSwap(d_ptr, other.d_ptr); return *this; }
#endif
~QPainterPath();
+ inline void swap(QPainterPath &other) { d_ptr.swap(other.d_ptr); }
void closeSubpath();
diff --git a/src/gui/painting/qpen.cpp b/src/gui/painting/qpen.cpp
index 2e43984..0137763 100644
--- a/src/gui/painting/qpen.cpp
+++ b/src/gui/painting/qpen.cpp
@@ -383,6 +383,14 @@ QPen &QPen::operator=(const QPen &p)
}
/*!
+ \fn void QPen::swap(QPen &other)
+ \since 4.8
+
+ Swaps pen \a other with this pen. This operation is very
+ fast and never fails.
+*/
+
+/*!
Returns the pen as a QVariant.
*/
QPen::operator QVariant() const
diff --git a/src/gui/painting/qpen.h b/src/gui/painting/qpen.h
index 4006112..a7b946c 100644
--- a/src/gui/painting/qpen.h
+++ b/src/gui/painting/qpen.h
@@ -78,6 +78,7 @@ public:
inline QPen &operator=(QPen &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QPen &other) { qSwap(d, other.d); }
Qt::PenStyle style() const;
void setStyle(Qt::PenStyle);
diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp
index 76b11d7..83323d0 100644
--- a/src/gui/painting/qpolygon.cpp
+++ b/src/gui/painting/qpolygon.cpp
@@ -709,6 +709,8 @@ QPolygon QPolygonF::toPolygon() const
/*!
\fn void QPolygonF::swap(QPolygonF &other)
+ \since 4.8
+
Swaps polygon \a other with this polygon. This operation is very
fast and never fails.
*/
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index c5d5dc9..cd997f4 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -391,6 +391,14 @@ void QRegion::exec(const QByteArray &buffer, int ver, QDataStream::ByteOrder byt
*/
/*!
+ \fn void QRegion::swap(QRegion &other)
+ \since 4.8
+
+ Swaps region \a other with this region. This operation is very
+ fast and never fails.
+*/
+
+/*!
\relates QRegion
Writes the region \a r to the stream \a s and returns a reference
diff --git a/src/gui/painting/qregion.h b/src/gui/painting/qregion.h
index 91d82e0..50052b3 100644
--- a/src/gui/painting/qregion.h
+++ b/src/gui/painting/qregion.h
@@ -85,6 +85,7 @@ public:
inline QRegion &operator=(QRegion &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QRegion &other) { qSwap(d, other.d); }
#ifdef QT3_SUPPORT
inline QT3_SUPPORT bool isNull() const { return isEmpty(); }
#endif
diff --git a/tests/auto/qbrush/tst_qbrush.cpp b/tests/auto/qbrush/tst_qbrush.cpp
index 7e94f37..c9be552 100644
--- a/tests/auto/qbrush/tst_qbrush.cpp
+++ b/tests/auto/qbrush/tst_qbrush.cpp
@@ -76,6 +76,7 @@ private slots:
void textures();
+ void swap();
void nullBrush();
void isOpaque();
void debug();
@@ -385,6 +386,14 @@ void tst_QBrush::textures()
QCOMPARE(image_brush.textureImage(), image_source);
}
+void tst_QBrush::swap()
+{
+ QBrush b1(Qt::black), b2(Qt::white);
+ b1.swap(b2);
+ QCOMPARE(b1.color(), QColor(Qt::white));
+ QCOMPARE(b2.color(), QColor(Qt::black));
+}
+
void tst_QBrush::nullBrush()
{
QBrush brush(QColor(100,0,0), Qt::NoBrush);
diff --git a/tests/auto/qicon/tst_qicon.cpp b/tests/auto/qicon/tst_qicon.cpp
index e68664c..6b35378 100644
--- a/tests/auto/qicon/tst_qicon.cpp
+++ b/tests/auto/qicon/tst_qicon.cpp
@@ -70,6 +70,7 @@ private slots:
void actualSize2();
void svgActualSize();
void isNull();
+ void swap();
void bestMatch();
void cacheKey();
void detach();
@@ -259,6 +260,21 @@ void tst_QIcon::isNull() {
QVERIFY(iconSupportedFormat.actualSize(QSize(32, 32)).isValid());
}
+void tst_QIcon::swap()
+{
+ QPixmap p1(1, 1), p2(2, 2);
+ p1.fill(Qt::black);
+ p2.fill(Qt::black);
+
+ QIcon i1(p1), i2(p2);
+ const qint64 i1k = i1.cacheKey();
+ const qint64 i2k = i2.cacheKey();
+ QVERIFY(i1k != i2k);
+ i1.swap(i2);
+ QCOMPARE(i1.cacheKey(), i2k);
+ QCOMPARE(i2.cacheKey(), i1k);
+}
+
void tst_QIcon::bestMatch()
{
QPixmap p1(1, 1);
diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp
index 6b8028c..6cce05cd1 100644
--- a/tests/auto/qimage/tst_qimage.cpp
+++ b/tests/auto/qimage/tst_qimage.cpp
@@ -69,6 +69,7 @@ public:
tst_QImage();
private slots:
+ void swap();
void create();
void createInvalidXPM();
void createFromUChar();
@@ -155,6 +156,20 @@ tst_QImage::tst_QImage()
{
}
+void tst_QImage::swap()
+{
+ QImage i1( 16, 16, QImage::Format_RGB32 ), i2( 32, 32, QImage::Format_RGB32 );
+ i1.fill( Qt::white );
+ i2.fill( Qt::black );
+ const qint64 i1k = i1.cacheKey();
+ const qint64 i2k = i2.cacheKey();
+ i1.swap(i2);
+ QCOMPARE(i1.cacheKey(), i2k);
+ QCOMPARE(i1.size(), QSize(32,32));
+ QCOMPARE(i2.cacheKey(), i1k);
+ QCOMPARE(i2.size(), QSize(16,16));
+}
+
// Test if QImage (or any functions called from QImage) throws an
// exception when creating an extremely large image.
// QImage::create() should return "false" in this case.
diff --git a/tests/auto/qkeysequence/tst_qkeysequence.cpp b/tests/auto/qkeysequence/tst_qkeysequence.cpp
index 60f022f..256f9f3 100644
--- a/tests/auto/qkeysequence/tst_qkeysequence.cpp
+++ b/tests/auto/qkeysequence/tst_qkeysequence.cpp
@@ -112,6 +112,7 @@ public:
virtual ~tst_QKeySequence();
private slots:
+ void swap();
void operatorQString_data();
void operatorQString();
void compareConstructors_data();
@@ -176,6 +177,15 @@ void tst_QKeySequence::initTestCase()
qtTranslator->load(":/qt_de");
}
+void tst_QKeySequence::swap()
+{
+ QKeySequence ks1(Qt::CTRL+Qt::Key_O);
+ QKeySequence ks2(Qt::CTRL+Qt::Key_L);
+ ks1.swap(ks2);
+ QCOMPARE(ks1[0], int(Qt::CTRL+Qt::Key_L));
+ QCOMPARE(ks2[0], int(Qt::CTRL+Qt::Key_O));
+}
+
void tst_QKeySequence::operatorQString_data()
{
QTest::addColumn<int>("modifiers");
diff --git a/tests/auto/qpainterpath/tst_qpainterpath.cpp b/tests/auto/qpainterpath/tst_qpainterpath.cpp
index d0cddda..19b3156 100644
--- a/tests/auto/qpainterpath/tst_qpainterpath.cpp
+++ b/tests/auto/qpainterpath/tst_qpainterpath.cpp
@@ -60,6 +60,8 @@ public:
private slots:
void getSetCheck();
+ void swap();
+
void contains_QPointF_data();
void contains_QPointF();
@@ -139,6 +141,17 @@ void tst_QPainterPath::getSetCheck()
QCOMPARE(qreal(1.1), obj1.curveThreshold());
}
+void tst_QPainterPath::swap()
+{
+ QPainterPath p1;
+ p1.addRect( 0, 0,10,10);
+ QPainterPath p2;
+ p2.addRect(10,10,10,10);
+ p1.swap(p2);
+ QCOMPARE(p1.boundingRect().toRect(), QRect(10,10,10,10));
+ QCOMPARE(p2.boundingRect().toRect(), QRect( 0, 0,10,10));
+}
+
Q_DECLARE_METATYPE(QPainterPath)
Q_DECLARE_METATYPE(QPointF)
Q_DECLARE_METATYPE(QRectF)
diff --git a/tests/auto/qpen/tst_qpen.cpp b/tests/auto/qpen/tst_qpen.cpp
index b0c2cad..674a520 100644
--- a/tests/auto/qpen/tst_qpen.cpp
+++ b/tests/auto/qpen/tst_qpen.cpp
@@ -59,6 +59,7 @@ public:
private slots:
void getSetCheck();
+ void swap();
void operator_eq_eq();
void operator_eq_eq_data();
@@ -95,6 +96,14 @@ void tst_QPen::getSetCheck()
}
}
+void tst_QPen::swap()
+{
+ QPen p1(Qt::black), p2(Qt::white);
+ p1.swap(p2);
+ QCOMPARE(p1.color(), QColor(Qt::white));
+ QCOMPARE(p2.color(), QColor(Qt::black));
+}
+
Q_DECLARE_METATYPE(QPen)
Q_DECLARE_METATYPE(QBrush)
diff --git a/tests/auto/qpicture/tst_qpicture.cpp b/tests/auto/qpicture/tst_qpicture.cpp
index 09f6503..10e5961 100644
--- a/tests/auto/qpicture/tst_qpicture.cpp
+++ b/tests/auto/qpicture/tst_qpicture.cpp
@@ -64,6 +64,7 @@ private slots:
void devType();
void paintingActive();
void boundingRect();
+ void swap();
void operator_lt_lt();
void save_restore();
@@ -155,6 +156,18 @@ void tst_QPicture::boundingRect()
}
}
+void tst_QPicture::swap()
+{
+ QPicture p1, p2;
+ QPainter(&p1).drawLine(0, 0, 5, 5);
+ QPainter(&p2).drawLine(0, 3, 3, 0);
+ QCOMPARE(p1.boundingRect(), QRect(0,0,5,5));
+ QCOMPARE(p2.boundingRect(), QRect(0,0,3,3));
+ p1.swap(p2);
+ QCOMPARE(p1.boundingRect(), QRect(0,0,3,3));
+ QCOMPARE(p2.boundingRect(), QRect(0,0,5,5));
+}
+
// operator<< and operator>>
void tst_QPicture::operator_lt_lt()
{
diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp
index fdf8311..551e261 100644
--- a/tests/auto/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/qpixmap/tst_qpixmap.cpp
@@ -95,6 +95,8 @@ public slots:
void cleanup();
private slots:
+ void swap();
+
void setAlphaChannel_data();
void setAlphaChannel();
@@ -247,6 +249,20 @@ void tst_QPixmap::cleanup()
{
}
+void tst_QPixmap::swap()
+{
+ QPixmap p1( 16, 16 ), p2( 32, 32 );
+ p1.fill( Qt::white );
+ p2.fill( Qt::black );
+ const qint64 p1k = p1.cacheKey();
+ const qint64 p2k = p2.cacheKey();
+ p1.swap(p2);
+ QCOMPARE(p1.cacheKey(), p2k);
+ QCOMPARE(p1.size(), QSize(32,32));
+ QCOMPARE(p2.cacheKey(), p1k);
+ QCOMPARE(p2.size(), QSize(16,16));
+}
+
void tst_QPixmap::setAlphaChannel_data()
{
QTest::addColumn<int>("red");
diff --git a/tests/auto/qregexp/tst_qregexp.cpp b/tests/auto/qregexp/tst_qregexp.cpp
index d0d26ee..52f2041 100644
--- a/tests/auto/qregexp/tst_qregexp.cpp
+++ b/tests/auto/qregexp/tst_qregexp.cpp
@@ -77,6 +77,7 @@ private slots:
void caretAnchoredOptimization();
void isEmpty();
void prepareEngineOptimization();
+ void swap();
void operator_eq();
/*
@@ -1290,6 +1291,14 @@ void tst_QRegExp::prepareEngineOptimization()
QCOMPARE(rx11.matchedLength(), -1);
}
+void tst_QRegExp::swap()
+{
+ QRegExp r1(QLatin1String(".*")), r2(QLatin1String("a*"));
+ r1.swap(r2);
+ QCOMPARE(r1.pattern(),QLatin1String("a*"));
+ QCOMPARE(r2.pattern(),QLatin1String(".*"));
+}
+
void tst_QRegExp::operator_eq()
{
const int I = 2;
diff --git a/tests/auto/qregion/tst_qregion.cpp b/tests/auto/qregion/tst_qregion.cpp
index 1716c94..f335051 100644
--- a/tests/auto/qregion/tst_qregion.cpp
+++ b/tests/auto/qregion/tst_qregion.cpp
@@ -64,6 +64,7 @@ public:
private slots:
void boundingRect();
void rects();
+ void swap();
void setRects();
void ellipseRegion();
void polygonRegion();
@@ -168,6 +169,15 @@ void tst_QRegion::rects()
}
}
+void tst_QRegion::swap()
+{
+ QRegion r1(QRect( 0, 0,10,10));
+ QRegion r2(QRect(10,10,10,10));
+ r1.swap(r2);
+ QCOMPARE(r1.rects().front(), QRect(10,10,10,10));
+ QCOMPARE(r2.rects().front(), QRect( 0, 0,10,10));
+}
+
void tst_QRegion::setRects()
{
{
diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp
index eff4658..c089a59 100644
--- a/tests/auto/qurl/tst_qurl.cpp
+++ b/tests/auto/qurl/tst_qurl.cpp
@@ -132,6 +132,7 @@ private slots:
void compat_encode();
void percentEncoding_data();
void percentEncoding();
+ void swap();
void symmetry();
void ipv6_data();
void ipv6();
@@ -2210,6 +2211,14 @@ void tst_QUrl::toPercentEncoding()
QCOMPARE(original, QUrl::fromPercentEncoding(encodedUrl));
}
+void tst_QUrl::swap()
+{
+ QUrl u1(QLatin1String("http://qt.nokia.com")), u2(QLatin1String("http://www.kdab.com"));
+ u1.swap(u2);
+ QCOMPARE(u2.host(),QLatin1String("qt.nokia.com"));
+ QCOMPARE(u1.host(),QLatin1String("www.kdab.com"));
+}
+
void tst_QUrl::symmetry()
{
QUrl url(QString::fromLatin1("http://www.räksmörgås.se/pub?a=b&a=dø&a=f#vræl"));
diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp
index 98d7436..159a806 100644
--- a/tests/auto/qvariant/tst_qvariant.cpp
+++ b/tests/auto/qvariant/tst_qvariant.cpp
@@ -100,6 +100,7 @@ private slots:
void constructor();
void copy_constructor();
void isNull();
+ void swap();
void canConvert_data();
void canConvert();
@@ -372,6 +373,16 @@ void tst_QVariant::isNull()
QVERIFY(var7.isNull());
}
+void tst_QVariant::swap()
+{
+ QVariant v1 = 1, v2 = 2.0;
+ v1.swap(v2);
+ QCOMPARE(v1.type(),QVariant::Double);
+ QCOMPARE(v1.toDouble(),2.0);
+ QCOMPARE(v2.type(),QVariant::Int);
+ QCOMPARE(v2.toInt(),1);
+}
+
void tst_QVariant::canConvert_data()
{
QTest::addColumn<QVariant>("val");