summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorTatiana Borisova <tatiana.borisova@qt.io>2024-04-19 14:43:25 +0200
committerTatiana Borisova <tatiana.borisova@qt.io>2024-04-30 17:46:34 +0200
commit5dbd6a44d81d6eb062878fbc0d14c19464308d21 (patch)
tree0cf6e456a2aecc3b540b66fb41c2f38bf8778e35 /src/corelib
parent9ed9ef5502dd552ee6e2b69b8e2f93288be56fb8 (diff)
QMimeType: use modernize comparisons
Replace class operators operator==(), operator!=() of QMimeType to friend method comparesEqual() and Q_DECLARE_EQUALITY_COMPARABLE macro. Use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of current comparison methods and replace them with a friend. Task-number: QTBUG-120304 Change-Id: I9776e98c8a3b14d599733c91af61fbc12b1f0e57 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/compat/removed_api.cpp7
-rw-r--r--src/corelib/mimetypes/qmimetype.cpp15
-rw-r--r--src/corelib/mimetypes/qmimetype.h8
3 files changed, 22 insertions, 8 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp
index 6101e71f79..7d3d3b5bd6 100644
--- a/src/corelib/compat/removed_api.cpp
+++ b/src/corelib/compat/removed_api.cpp
@@ -1006,6 +1006,13 @@ bool QJsonValue::operator!=(const QJsonValue &other) const
return !comparesEqual(*this, other);
}
+#include "qmimetype.h"
+
+bool QMimeType::operator==(const QMimeType &other) const
+{
+ return comparesEqual(*this, other);
+}
+
#include "qobject.h"
int QObject::startTimer(std::chrono::milliseconds time, Qt::TimerType timerType)
diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp
index ad3c484f30..e26c8b898d 100644
--- a/src/corelib/mimetypes/qmimetype.cpp
+++ b/src/corelib/mimetypes/qmimetype.cpp
@@ -24,6 +24,7 @@ using namespace Qt::StringLiterals;
\brief The QMimeType class describes types of file or data, represented by a MIME type string.
\since 5.0
+ \compares equality
For instance a file named "readme.txt" has the MIME type "text/plain".
The MIME type can be determined from the file name, or from the file
@@ -111,14 +112,15 @@ QMimeType::~QMimeType()
}
/*!
- \fn bool QMimeType::operator==(const QMimeType &other) const;
- Returns \c true if \a other equals this QMimeType object, otherwise returns \c false.
+ \fn bool QMimeType::operator==(const QMimeType &lhs, const QMimeType &rhs);
+ Returns \c true if \a lhs equals to the \a rhs QMimeType object, otherwise
+ returns \c false.
The name is the unique identifier for a mimetype, so two mimetypes with
the same name, are equal.
*/
-bool QMimeType::operator==(const QMimeType &other) const
+bool comparesEqual(const QMimeType &lhs, const QMimeType &rhs) noexcept
{
- return d == other.d || d->name == other.d->name;
+ return lhs.d == rhs.d || lhs.d->name == rhs.d->name;
}
/*!
@@ -134,8 +136,9 @@ size_t qHash(const QMimeType &key, size_t seed) noexcept
}
/*!
- \fn bool QMimeType::operator!=(const QMimeType &other) const;
- Returns \c true if \a other does not equal this QMimeType object, otherwise returns \c false.
+ \fn bool QMimeType::operator!=(const QMimeType &lhs, const QMimeType &rhs);
+ Returns \c true if QMimeType \a lhs is not equal to QMimeType \a rhs,
+ otherwise returns \c false.
*/
/*!
diff --git a/src/corelib/mimetypes/qmimetype.h b/src/corelib/mimetypes/qmimetype.h
index 3421638f5b..508a5cfb53 100644
--- a/src/corelib/mimetypes/qmimetype.h
+++ b/src/corelib/mimetypes/qmimetype.h
@@ -49,14 +49,14 @@ public:
}
explicit QMimeType(const QMimeTypePrivate &dd);
~QMimeType();
-
+#if QT_CORE_REMOVED_SINCE(6, 8)
bool operator==(const QMimeType &other) const;
inline bool operator!=(const QMimeType &other) const
{
return !operator==(other);
}
-
+#endif
bool isValid() const;
bool isDefault() const;
@@ -86,6 +86,10 @@ protected:
friend Q_CORE_EXPORT size_t qHash(const QMimeType &key, size_t seed) noexcept;
QExplicitlySharedDataPointer<QMimeTypePrivate> d;
+
+private:
+ friend Q_CORE_EXPORT bool comparesEqual(const QMimeType &lhs, const QMimeType &rhs) noexcept;
+ Q_DECLARE_EQUALITY_COMPARABLE(QMimeType)
};
Q_DECLARE_SHARED(QMimeType)