Create qdoc macros for C++ class docs 1.1: member-swap(), traditional phrasing

We have some patterns for how to document certain functions, but we
also vary the sentences a lot, and you have to look up one
documentation piece and copy it, essentially. If we ever want to
change them, we end up with shotgun surgery.

So apply DRY to the documentation and start a collection of macros to
help with repetitive C++ class documentation tasks.

The first macro is for member-swap(), and the first patch is for
documentation that used the traditional phrasing ("Swaps the X \a
other with this X.").

This doesn't change the documentation, except as follows:

* adds the "very fast and never fails" blurb, if it was missing
* changes the function's argument name to `other`, as required by
  the macro.

Task-number: QTBUG-129573
Pick-to: 6.8 6.7 6.5 6.2
Change-Id: Ib494bd218334724b3b43796ba6f71fb52b83aa94
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Marc Mutz 2024-10-02 18:46:01 +02:00
parent 152cb77f83
commit 3ccb4ce781
46 changed files with 65 additions and 143 deletions

View File

@ -0,0 +1,15 @@
# Macros for documenting repetitive aspects of C++ classes
# Sort groups alphabetically
#
# Macros for swap()
#
# \memberswap{what}
# what - a prose version of the type of object (e.g. "string", "collator", "pen")
# The function's argument name must be \a other.
macro.memberswap = \
"\n\n" \
"Swaps \1 \\a{other} with this \1. This operation is very fast and never fails." \
"\n\n"

View File

@ -174,3 +174,4 @@ macro.qtpolicydeprecatedbehavior = "\\note The \\c{OLD} behavior of a policy is
macro.techpreview = "(Technical preview)\n\n\\meta status {Technical preview}\n\\ingroup tech_preview\n" macro.techpreview = "(Technical preview)\n\n\\meta status {Technical preview}\n\\ingroup tech_preview\n"
include(grid.qdocconf) include(grid.qdocconf)
include(cpp-doc-macros.qdocconf)

View File

@ -191,10 +191,7 @@ QTemporaryDir::QTemporaryDir(const QString &templatePath)
/*! /*!
\fn void QTemporaryDir::swap(QTemporaryDir &other) \fn void QTemporaryDir::swap(QTemporaryDir &other)
\memberswap{temporary-dir}
Swaps temporary-dir \a other with this temporary-dir. This operation is
very fast and never fails.
\since 6.4 \since 6.4
*/ */

View File

@ -3229,9 +3229,7 @@ QUrl &QUrl::operator =(const QString &url)
/*! /*!
\fn void QUrl::swap(QUrl &other) \fn void QUrl::swap(QUrl &other)
\since 4.8 \since 4.8
\memberswap{URL}
Swaps URL \a other with this URL. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -87,9 +87,7 @@ QT_BEGIN_NAMESPACE
/*! /*!
\fn QBasicTimer::swap(QBasicTimer &other) \fn QBasicTimer::swap(QBasicTimer &other)
\since 5.14 \since 5.14
\memberswap{timer}
Swaps the timer \a other with this timer.
This operation is very fast and never fails.
*/ */
/*! /*!

View File

@ -729,8 +729,7 @@ QDeadlineTimer operator+(QDeadlineTimer dt, qint64 msecs)
/*! /*!
\fn void QDeadlineTimer::swap(QDeadlineTimer &other) \fn void QDeadlineTimer::swap(QDeadlineTimer &other)
\memberswap{deadline timer}
Swaps this deadline timer with the \a other deadline timer.
*/ */
/*! /*!

View File

@ -1074,9 +1074,7 @@ QVariant &QVariant::operator=(const QVariant &variant)
/*! /*!
\fn void QVariant::swap(QVariant &other) \fn void QVariant::swap(QVariant &other)
\since 4.8 \since 4.8
\memberswap{variant}
Swaps variant \a other with this variant. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -1397,9 +1397,7 @@ QByteArray &QByteArray::operator=(const char *str)
/*! \fn void QByteArray::swap(QByteArray &other) /*! \fn void QByteArray::swap(QByteArray &other)
\since 4.8 \since 4.8
\memberswap{byte array}
Swaps byte array \a other with this byte array. This operation is very
fast and never fails.
*/ */
/*! \fn qsizetype QByteArray::size() const /*! \fn qsizetype QByteArray::size() const

View File

@ -1251,9 +1251,7 @@ bool QLocale::equals(const QLocale &other) const noexcept
/*! /*!
\fn void QLocale::swap(QLocale &other) \fn void QLocale::swap(QLocale &other)
\since 5.6 \since 5.6
\memberswap{locale}
Swaps locale \a other with this locale. This operation is very fast and
never fails.
*/ */
/*! /*!

View File

@ -1389,9 +1389,7 @@ QRegularExpression &QRegularExpression::operator=(const QRegularExpression &re)
/*! /*!
\fn void QRegularExpression::swap(QRegularExpression &other) \fn void QRegularExpression::swap(QRegularExpression &other)
\memberswap{reglar expression}
Swaps the regular expression \a other with this regular expression. This
operation is very fast and never fails.
*/ */
/*! /*!
@ -2160,9 +2158,7 @@ QRegularExpressionMatch &QRegularExpressionMatch::operator=(const QRegularExpres
/*! /*!
\fn void QRegularExpressionMatch::swap(QRegularExpressionMatch &other) \fn void QRegularExpressionMatch::swap(QRegularExpressionMatch &other)
\memberswap{match result}
Swaps the match result \a other with this match result. This
operation is very fast and never fails.
*/ */
/*! /*!

View File

@ -2596,9 +2596,7 @@ QString::QString(QChar ch)
/*! \fn void QString::swap(QString &other) /*! \fn void QString::swap(QString &other)
\since 4.8 \since 4.8
\memberswap{string}
Swaps string \a other with this string. This operation is very fast and
never fails.
*/ */
/*! \fn void QString::detach() /*! \fn void QString::detach()

View File

@ -289,6 +289,5 @@
*/ */
/*! \fn template<typename T> void QPromise<T>::swap(QPromise<T> &other) noexcept /*! \fn template<typename T> void QPromise<T>::swap(QPromise<T> &other) noexcept
\memberswap{promise}
Swaps promise \a other with this promise. This operation is very fast and never fails.
*/ */

View File

@ -496,9 +496,7 @@ quint32 QBitArray::toUInt32(QSysInfo::Endian endianness, bool *ok) const noexcep
/*! \fn void QBitArray::swap(QBitArray &other) /*! \fn void QBitArray::swap(QBitArray &other)
\since 4.8 \since 4.8
\memberswap{bit array}
Swaps bit array \a other with this bit array. This operation is very
fast and never fails.
*/ */
/*! \fn bool QBitArray::operator==(const QBitArray &lhs, const QBitArray &rhs) /*! \fn bool QBitArray::operator==(const QBitArray &lhs, const QBitArray &rhs)

View File

@ -197,9 +197,7 @@ QCommandLineOption &QCommandLineOption::operator=(const QCommandLineOption &othe
/*! /*!
\fn void QCommandLineOption::swap(QCommandLineOption &other) \fn void QCommandLineOption::swap(QCommandLineOption &other)
\memberswap{option}
Swaps option \a other with this option. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -164,9 +164,7 @@ void QContiguousCacheData::freeData(QContiguousCacheData *data)
/*! \fn template<typename T> void QContiguousCache<T>::swap(QContiguousCache<T> &other) /*! \fn template<typename T> void QContiguousCache<T>::swap(QContiguousCache<T> &other)
\since 4.8 \since 4.8
\memberswap{cache}
Swaps cache \a other with this cache. This operation is very
fast and never fails.
*/ */
/*! \fn template<typename T> bool QContiguousCache<T>::operator==(const QContiguousCache<T> &other) const /*! \fn template<typename T> bool QContiguousCache<T>::operator==(const QContiguousCache<T> &other) const

View File

@ -467,10 +467,7 @@ QCryptographicHash::~QCryptographicHash()
/*! /*!
\fn void QCryptographicHash::swap(QCryptographicHash &other) \fn void QCryptographicHash::swap(QCryptographicHash &other)
\memberswap{cryptographic hash}
Swaps cryptographic hash \a other with this cryptographic hash. This
operation is very fast and never fails.
\since 6.5 \since 6.5
*/ */
@ -1479,10 +1476,7 @@ QMessageAuthenticationCode::~QMessageAuthenticationCode()
/*! /*!
\fn void QMessageAuthenticationCode::swap(QMessageAuthenticationCode &other) \fn void QMessageAuthenticationCode::swap(QMessageAuthenticationCode &other)
\memberswap{message authentication code}
Swaps message authentication code \a other with this message authentication
code. This operation is very fast and never fails.
\since 6.6 \since 6.6
*/ */

View File

@ -1147,9 +1147,7 @@ QEasingCurve::~QEasingCurve()
/*! /*!
\fn void QEasingCurve::swap(QEasingCurve &other) \fn void QEasingCurve::swap(QEasingCurve &other)
\since 5.0 \since 5.0
\memberswap{curve}
Swaps curve \a other with this curve. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -1795,16 +1795,12 @@ size_t qHash(long double key, size_t seed) noexcept
/*! \fn template <class Key, class T> void QHash<Key, T>::swap(QHash &other) /*! \fn template <class Key, class T> void QHash<Key, T>::swap(QHash &other)
\since 4.8 \since 4.8
\memberswap{hash}
Swaps hash \a other with this hash. This operation is very
fast and never fails.
*/ */
/*! \fn template <class Key, class T> void QMultiHash<Key, T>::swap(QMultiHash &other) /*! \fn template <class Key, class T> void QMultiHash<Key, T>::swap(QMultiHash &other)
\since 4.8 \since 4.8
\memberswap{multi-hash}
Swaps hash \a other with this hash. This operation is very
fast and never fails.
*/ */
/*! \fn template <class Key, class T> bool QHash<Key, T>::operator==(const QHash &lhs, const QHash &rhs) /*! \fn template <class Key, class T> bool QHash<Key, T>::operator==(const QHash &lhs, const QHash &rhs)

View File

@ -342,9 +342,7 @@
/*! \fn template <typename T> void QList<T>::swap(QList<T> &other) /*! \fn template <typename T> void QList<T>::swap(QList<T> &other)
\since 4.8 \since 4.8
\memberswap{list}
Swaps list \a other with this list. This operation is very fast and
never fails.
*/ */
/*! \fn template <typename T> void QList<T>::swapItemsAt(qsizetype i, qsizetype j) /*! \fn template <typename T> void QList<T>::swapItemsAt(qsizetype i, qsizetype j)

View File

@ -172,9 +172,7 @@
/*! \fn template <class Key, class T> void QMap<Key, T>::swap(QMap<Key, T> &other) noexcept /*! \fn template <class Key, class T> void QMap<Key, T>::swap(QMap<Key, T> &other) noexcept
\since 4.8 \since 4.8
\memberswap{map}
Swaps map \a other with this map. This operation is very
fast and never fails.
*/ */
/*! \fn template <class Key, class T> QMap<Key, T>::QMap(std::initializer_list<std::pair<Key,T> > list) /*! \fn template <class Key, class T> QMap<Key, T>::QMap(std::initializer_list<std::pair<Key,T> > list)

View File

@ -218,9 +218,7 @@
/*! \fn template <class Key, class T> void QMultiMap<Key, T>::swap(QMultiMap<Key, T> &other) /*! \fn template <class Key, class T> void QMultiMap<Key, T>::swap(QMultiMap<Key, T> &other)
\since 4.8 \since 4.8
\memberswap{multi map}
Swaps multi map \a other with this multi map. This operation is very
fast and never fails.
*/ */
/*! \fn template<class Key, class T> bool QMultiMap<Key, T>::operator==(const QMultiMap<Key, T> &lhs, const QMultiMap<Key, T> &rhs) /*! \fn template<class Key, class T> bool QMultiMap<Key, T>::operator==(const QMultiMap<Key, T> &lhs, const QMultiMap<Key, T> &rhs)

View File

@ -43,9 +43,7 @@
/*! /*!
\fn template <class T> void QQueue<T>::swap(QQueue<T> &other) \fn template <class T> void QQueue<T>::swap(QQueue<T> &other)
\since 4.8 \since 4.8
\memberswap{queue}
Swaps queue \a other with this queue. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -100,9 +100,7 @@
/*! /*!
\fn template <class T> void QSet<T>::swap(QSet<T> &other) \fn template <class T> void QSet<T>::swap(QSet<T> &other)
\memberswap{set}
Swaps set \a other with this set. This operation is very fast and
never fails.
*/ */
/*! /*!

View File

@ -43,9 +43,7 @@
/*! /*!
\fn template<class T> void QStack<T>::swap(QStack<T> &other) \fn template<class T> void QStack<T>::swap(QStack<T> &other)
\since 4.8 \since 4.8
\memberswap{stack}
Swaps stack \a other with this stack. This operation is very fast and
never fails.
*/ */
/*! /*!

View File

@ -129,9 +129,7 @@ QBitmap::QBitmap(const QString& fileName, const char *format)
/*! /*!
\fn void QBitmap::swap(QBitmap &other) \fn void QBitmap::swap(QBitmap &other)
\memberswap{bitmap}
Swaps bitmap \a other with this bitmap. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -827,9 +827,7 @@ QIcon &QIcon::operator=(const QIcon &other)
/*! /*!
\fn void QIcon::swap(QIcon &other) \fn void QIcon::swap(QIcon &other)
\memberswap{icon}
Swaps icon \a other with this icon. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -1091,9 +1091,7 @@ QImage &QImage::operator=(const QImage &image)
/*! /*!
\fn void QImage::swap(QImage &other) \fn void QImage::swap(QImage &other)
\memberswap{image}
Swaps image \a other with this image. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -925,9 +925,7 @@ QPicture& QPicture::operator=(const QPicture &p)
/*! /*!
\fn void QPicture::swap(QPicture &other) \fn void QPicture::swap(QPicture &other)
\memberswap{picture}
Swaps picture \a other with this picture. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -368,9 +368,7 @@ QPixmap &QPixmap::operator=(const QPixmap &pixmap)
/*! /*!
\fn void QPixmap::swap(QPixmap &other) \fn void QPixmap::swap(QPixmap &other)
\memberswap{pixmap}
Swaps pixmap \a other with this pixmap. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -137,8 +137,7 @@ QT_BEGIN_NAMESPACE
/*! /*!
\fn void QCursor::swap(QCursor &other) \fn void QCursor::swap(QCursor &other)
\memberswap{cursor}
Swaps this cursor with the \a other cursor.
\since 5.7 \since 5.7
*/ */

View File

@ -1385,9 +1385,7 @@ QKeySequence &QKeySequence::operator=(const QKeySequence &other)
/*! /*!
\fn void QKeySequence::swap(QKeySequence &other) \fn void QKeySequence::swap(QKeySequence &other)
\since 4.8 \since 4.8
\memberswap{key sequence}
Swaps key sequence \a other with this key sequence. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -625,9 +625,7 @@ QBrush &QBrush::operator=(const QBrush &b)
/*! /*!
\fn void QBrush::swap(QBrush &other) \fn void QBrush::swap(QBrush &other)
\since 4.8 \since 4.8
\memberswap{brush}
Swaps brush \a other with this brush. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -783,9 +783,7 @@ QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QColorSpacePrivate)
QColorSpace::QColorSpace(const QColorSpace &colorSpace) noexcept = default; QColorSpace::QColorSpace(const QColorSpace &colorSpace) noexcept = default;
/*! \fn void QColorSpace::swap(QColorSpace &other) /*! \fn void QColorSpace::swap(QColorSpace &other)
\memberswap{color space}
Swaps color space \a other with this color space. This operation is very fast and
never fails.
*/ */
/*! /*!

View File

@ -563,9 +563,7 @@ QPainterPath &QPainterPath::operator=(const QPainterPath &other)
/*! /*!
\fn void QPainterPath::swap(QPainterPath &other) \fn void QPainterPath::swap(QPainterPath &other)
\since 4.8 \since 4.8
\memberswap{painer path}
Swaps painter path \a other with this painter path. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -80,9 +80,7 @@ QPdfOutputIntent::~QPdfOutputIntent() = default;
/*! /*!
\fn void QPdfOutputIntent::swap(QPdfOutputIntent &other) noexcept \fn void QPdfOutputIntent::swap(QPdfOutputIntent &other) noexcept
\memberswap{output intent}
Swaps the output intent \a other with this output intent. This
operation is very fast and never fails.
*/ */
/*! /*!

View File

@ -341,9 +341,7 @@ QPen &QPen::operator=(const QPen &p) noexcept
/*! /*!
\fn void QPen::swap(QPen &other) \fn void QPen::swap(QPen &other)
\since 4.8 \since 4.8
\memberswap{pen}
Swaps pen \a other with this pen. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -623,17 +623,13 @@ QPolygon QPolygonF::toPolygon() const
/*! /*!
\fn void QPolygon::swap(QPolygon &other) \fn void QPolygon::swap(QPolygon &other)
\since 4.8 \since 4.8
\memberswap{polygon}
Swaps polygon \a other with this polygon. This operation is very
fast and never fails.
*/ */
/*! /*!
\fn void QPolygonF::swap(QPolygonF &other) \fn void QPolygonF::swap(QPolygonF &other)
\since 4.8 \since 4.8
\memberswap{polygon}
Swaps polygon \a other with this polygon. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -296,9 +296,7 @@ void QRegion::exec(const QByteArray &buffer, int ver, QDataStream::ByteOrder byt
/*! /*!
\fn void QRegion::swap(QRegion &other) \fn void QRegion::swap(QRegion &other)
\since 4.8 \since 4.8
\memberswap{region}
Swaps region \a other with this region. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -332,9 +332,7 @@ QShader::~QShader()
/*! /*!
\fn void QShader::swap(QShader &other) \fn void QShader::swap(QShader &other)
\since 6.7 \since 6.7
\memberswap{shader}
Swaps shader \a other with this shader. This operation is very fast and
never fails.
*/ */
/*! /*!

View File

@ -198,8 +198,7 @@ bool QHstsPolicy::isExpired() const
/*! /*!
\fn void QHstsPolicy::swap(QHstsPolicy &other) \fn void QHstsPolicy::swap(QHstsPolicy &other)
\memberswap{policy}
Swaps this policy with the \a other policy.
*/ */
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -281,7 +281,7 @@ unsigned QHttp2Configuration::maxConcurrentStreams() const
} }
/*! /*!
Swaps this configuration with the \a other configuration. \memberswap{configuration}
*/ */
void QHttp2Configuration::swap(QHttp2Configuration &other) noexcept void QHttp2Configuration::swap(QHttp2Configuration &other) noexcept
{ {

View File

@ -249,10 +249,7 @@ int QHostInfo::lookupHost(const QString &name, const QObject *receiver, const ch
/*! /*!
\fn void QHostInfo::swap(QHostInfo &other) \fn void QHostInfo::swap(QHostInfo &other)
\memberswap{host-info}
Swaps host-info \a other with this host-info. This operation is
very fast and never fails.
\since 5.10 \since 5.10
*/ */

View File

@ -216,9 +216,7 @@ QOpenGLBuffer &QOpenGLBuffer::operator=(const QOpenGLBuffer &other)
/*! /*!
\fn QOpenGLBuffer::swap(QOpenGLBuffer &other) \fn QOpenGLBuffer::swap(QOpenGLBuffer &other)
\since 6.5 \since 6.5
\memberswap{buffer}
Swaps buffer \a other with this buffer. This operation is very fast and
never fails.
*/ */
/*! /*!

View File

@ -846,10 +846,8 @@ QOpenGLDebugMessage &QOpenGLDebugMessage::operator=(const QOpenGLDebugMessage &d
*/ */
/*! /*!
\fn void QOpenGLDebugMessage::swap(QOpenGLDebugMessage &debugMessage) \fn void QOpenGLDebugMessage::swap(QOpenGLDebugMessage &other)
\memberswap{message]
Swaps the message \a debugMessage with this message. This operation is very
fast and never fails.
*/ */
/*! /*!

View File

@ -78,9 +78,7 @@ QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QSqlErrorPrivate)
*/ */
/*! \fn QSqlError::swap(QSqlError &other) /*! \fn QSqlError::swap(QSqlError &other)
Swaps error \a other with this error. This operation is very fast \memberswap{error}
and never fails.
\since 5.10 \since 5.10
*/ */

View File

@ -130,9 +130,7 @@ QSqlRecord::QSqlRecord(const QSqlRecord &other)
/*! /*!
\fn void QSqlRecord::swap(QSqlRecord &other) \fn void QSqlRecord::swap(QSqlRecord &other)
\since 6.6 \since 6.6
\memberswap{SQL record}
Swaps SQL record \a other with this SQL record. This operation is very fast
and never fails.
*/ */