From b97070f2c489877b650283842fbbdea708102a40 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 5 Apr 2012 14:49:02 +0200 Subject: [PATCH] QtCore: add member-swap to shared classes Implemented as in other shared classes (e.g. QPen). Special case: QUrlQuery: document existing swap(). Change-Id: I4b36cc9577fbf2232d4b2a2d8822d26e41e22cad Reviewed-by: Thiago Macieira --- src/corelib/io/qdebug.cpp | 8 ++++++++ src/corelib/io/qdebug.h | 2 ++ src/corelib/io/qdir.cpp | 8 ++++++++ src/corelib/io/qdir.h | 3 +++ src/corelib/io/qfileinfo.cpp | 8 ++++++++ src/corelib/io/qfileinfo.h | 4 ++++ src/corelib/io/qprocess.cpp | 8 ++++++++ src/corelib/io/qprocess.h | 2 ++ src/corelib/io/qurlquery.cpp | 7 +++++++ src/corelib/itemmodels/qabstractitemmodel.cpp | 7 +++++++ src/corelib/itemmodels/qabstractitemmodel.h | 1 + src/corelib/tools/qdatetime.cpp | 7 +++++++ src/corelib/tools/qdatetime.h | 2 ++ 13 files changed, 67 insertions(+) diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 8c17a61b7e..5769323d57 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -124,6 +124,14 @@ Flushes any pending data to be written and destroys the debug stream. */ +/*! + \fn QDebug::swap(QDebug &other) + \since 5.0 + + Swaps this debug stream instance with \a other. This function is + very fast and never fails. +*/ + /*! \fn QDebug &QDebug::space() diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 6b0eaef9e8..f0e59c8c65 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -91,6 +91,8 @@ public: delete stream; } } + inline void swap(QDebug &other) { qSwap(stream, other.stream); } + inline QDebug &space() { stream->space = true; stream->ts << ' '; return *this; } inline QDebug &nospace() { stream->space = false; return *this; } inline QDebug &maybeSpace() { if (stream->space) stream->ts << ' '; return *this; } diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 9a66ca2d40..b92f03a3c8 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -1710,6 +1710,14 @@ QDir &QDir::operator=(const QString &path) return *this; } +/*! + \fn void QDir::swap(QDir &other) + \since 5.0 + + Swaps this QDir instance with \a other. This function is very fast + and never fails. +*/ + /*! \fn bool QDir::operator!=(const QDir &dir) const diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index a5105fe2fb..a6f9b326ad 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -115,6 +115,9 @@ public: { qSwap(d_ptr, other.d_ptr); return *this; } #endif + inline void swap(QDir &other) + { qSwap(d_ptr, other.d_ptr); } + void setPath(const QString &path); QString path() const; QString absolutePath() const; diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 4973ecb773..ac87e23301 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -429,6 +429,14 @@ QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo) return *this; } +/*! + \fn void QFileInfo::swap(QFileInfo &other) + \since 5.0 + + Swaps this file info with \a other. This function is very fast and + never fails. +*/ + /*! Sets the file that the QFileInfo provides information about to \a file. diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index 0f43ebd439..41db9d711d 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -74,6 +74,10 @@ public: inline QFileInfo&operator=(QFileInfo &&other) { qSwap(d_ptr, other.d_ptr); return *this; } #endif + + inline void swap(QFileInfo &other) + { qSwap(d_ptr, other.d_ptr); } + bool operator==(const QFileInfo &fileinfo) const; inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); } diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 7228ceca78..04597f198f 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -236,6 +236,14 @@ QProcessEnvironment &QProcessEnvironment::operator=(const QProcessEnvironment &o return *this; } +/*! + \fn void QProcessEnvironment::swap(QProcessEnvironment &other) + \since 5.0 + + Swaps this process environment instance with \a other. This + function is very fast and never fails. +*/ + /*! \fn bool QProcessEnvironment::operator !=(const QProcessEnvironment &other) const diff --git a/src/corelib/io/qprocess.h b/src/corelib/io/qprocess.h index fe5e84ccec..dbc226ef81 100644 --- a/src/corelib/io/qprocess.h +++ b/src/corelib/io/qprocess.h @@ -72,6 +72,8 @@ public: ~QProcessEnvironment(); QProcessEnvironment &operator=(const QProcessEnvironment &other); + inline void swap(QProcessEnvironment &other) { qSwap(d, other.d); } + bool operator==(const QProcessEnvironment &other) const; inline bool operator!=(const QProcessEnvironment &other) const { return !(*this == other); } diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp index f5ba15a6e8..24742e4390 100644 --- a/src/corelib/io/qurlquery.cpp +++ b/src/corelib/io/qurlquery.cpp @@ -358,6 +358,13 @@ QUrlQuery &QUrlQuery::operator =(const QUrlQuery &other) return *this; } +/*! + \fn void QUrlQuery::swap(QUrlQuery &other) + + Swaps this URL query instance with \a other. This function is very + fast and never fails. +*/ + /*! Destroys this QUrlQuery object. */ diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index c94b3cb540..c78287759b 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -213,6 +213,13 @@ QPersistentModelIndex &QPersistentModelIndex::operator=(const QPersistentModelIn if (d) d->ref.ref(); return *this; } +/*! + \fn void QPersistentModelIndex::swap(QPersistentModelIndex &other) + \since 5.0 + + Swaps this persistent modelindex with \a other. This function is + very fast and never fails. +*/ /*! Sets the persistent model index to refer to the same item in a model diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 976c1600c6..df39c33611 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -116,6 +116,7 @@ public: inline bool operator!=(const QPersistentModelIndex &other) const { return !operator==(other); } QPersistentModelIndex &operator=(const QPersistentModelIndex &other); + inline void swap(QPersistentModelIndex &other) { qSwap(d, other.d); } bool operator==(const QModelIndex &other) const; bool operator!=(const QModelIndex &other) const; QPersistentModelIndex &operator=(const QModelIndex &other); diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 1343600369..b76f4e3493 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -2208,6 +2208,13 @@ QDateTime &QDateTime::operator=(const QDateTime &other) d = other.d; return *this; } +/*! + \fn void QDateTime::swap(QDateTime &other) + \since 5.0 + + Swaps this date-time with \a other. This operation is very fast + and never fails. +*/ /*! Returns true if both the date and the time are null; otherwise diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index a648285e89..c38e780dfb 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -210,6 +210,8 @@ public: QDateTime &operator=(const QDateTime &other); + inline void swap(QDateTime &other) { qSwap(d, other.d); } + bool isNull() const; bool isValid() const;