diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2019-12-03 08:12:50 +0100 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2019-12-04 17:37:52 +0100 |
commit | 8652c79df0a47264a2d525424484e15744e2462b (patch) | |
tree | df140e9341f43a0771000b16749e44aed3db39a0 /src | |
parent | 0c29ebe374caad7e29c6a3d35c72c4eddaacc6af (diff) |
Remove QVariant::operator< and related operator
The operator does not have a total order
Change-Id: Ifd263c3495aca08c8ccceb9949596c308a76a6c1
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 119 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.h | 9 |
2 files changed, 0 insertions, 128 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 258da1a8d4..1fe6ca7b4e 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -3840,58 +3840,6 @@ bool QVariant::convert(const int type, void *ptr) const QMetaType::registerComparators(). */ -/*! - \fn bool QVariant::operator<(const QVariant &v) const - - Compares this QVariant with \a v and returns \c true if this is less than \a v. - - \note Comparability might not be availabe for the type stored in this QVariant - or in \a v. - - \warning To make this function work with a custom type registered with - qRegisterMetaType(), its comparison operator must be registered using - QMetaType::registerComparators(). -*/ - -/*! - \fn bool QVariant::operator<=(const QVariant &v) const - - Compares this QVariant with \a v and returns \c true if this is less or equal than \a v. - - \note Comparability might not be available for the type stored in this QVariant - or in \a v. - - \warning To make this function work with a custom type registered with - qRegisterMetaType(), its comparison operator must be registered using - QMetaType::registerComparators(). -*/ - -/*! - \fn bool QVariant::operator>(const QVariant &v) const - - Compares this QVariant with \a v and returns \c true if this is larger than \a v. - - \note Comparability might not be available for the type stored in this QVariant - or in \a v. - - \warning To make this function work with a custom type registered with - qRegisterMetaType(), its comparison operator must be registered using - QMetaType::registerComparators(). -*/ - -/*! - \fn bool QVariant::operator>=(const QVariant &v) const - - Compares this QVariant with \a v and returns \c true if this is larger or equal than \a v. - - \note Comparability might not be available for the type stored in this QVariant - or in \a v. - - \warning To make this function work with a custom type registered with - qRegisterMetaType(), its comparison operator must be registered using - QMetaType::registerComparators(). -*/ - static bool qIsNumericType(uint tp) { static const qulonglong numericTypeBits = @@ -4072,73 +4020,6 @@ bool QVariant::cmp(const QVariant &v) const /*! \internal */ -int QVariant::compare(const QVariant &v) const -{ - // try numerics first, with C++ type promotion rules (no conversion) - if (qIsNumericType(d.type) && qIsNumericType(v.d.type)) - return numericCompare(&d, &v.d); - - // check for equality next, as more types implement operator== than operator< - if (cmp(v)) - return 0; - - const QVariant *v1 = this; - const QVariant *v2 = &v; - QVariant converted1; - QVariant converted2; - - if (d.type != v.d.type) { - // if both types differ, try to convert - if (v2->canConvert(v1->d.type)) { - converted2 = *v2; - if (converted2.convert(v1->d.type)) - v2 = &converted2; - } - if (v1->d.type != v2->d.type && v1->canConvert(v2->d.type)) { - converted1 = *v1; - if (converted1.convert(v2->d.type)) - v1 = &converted1; - } - if (v1->d.type != v2->d.type) { - // if conversion fails, default to toString - int r = v1->toString().compare(v2->toString(), Qt::CaseInsensitive); - if (r == 0) { - // cmp(v) returned false, so we should try to agree with it. - return (v1->d.type < v2->d.type) ? -1 : 1; - } - return r; - } - - // did we end up with two numerics? If so, restart - if (qIsNumericType(v1->d.type) && qIsNumericType(v2->d.type)) - return v1->compare(*v2); - } - if (v1->d.type >= QMetaType::User) { - int result; - if (QMetaType::compare(QT_PREPEND_NAMESPACE(constData(d)), QT_PREPEND_NAMESPACE(constData(v2->d)), d.type, &result)) - return result; - } - switch (v1->d.type) { - case QVariant::Date: - return v1->toDate() < v2->toDate() ? -1 : 1; - case QVariant::Time: - return v1->toTime() < v2->toTime() ? -1 : 1; - case QVariant::DateTime: - return v1->toDateTime() < v2->toDateTime() ? -1 : 1; - case QVariant::StringList: - return v1->toStringList() < v2->toStringList() ? -1 : 1; - } - int r = v1->toString().compare(v2->toString(), Qt::CaseInsensitive); - if (r == 0) { - // cmp(v) returned false, so we should try to agree with it. - return (d.type < v.d.type) ? -1 : 1; - } - return r; -} - -/*! - \internal - */ const void *QVariant::constData() const { diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 331adea4e7..21802aee85 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -465,14 +465,6 @@ class Q_CORE_EXPORT QVariant { return cmp(v); } inline bool operator!=(const QVariant &v) const { return !cmp(v); } - inline bool operator<(const QVariant &v) const - { return compare(v) < 0; } - inline bool operator<=(const QVariant &v) const - { return compare(v) <= 0; } - inline bool operator>(const QVariant &v) const - { return compare(v) > 0; } - inline bool operator>=(const QVariant &v) const - { return compare(v) >= 0; } protected: friend inline bool operator==(const QVariant &, const QVariantComparisonHelper &); @@ -491,7 +483,6 @@ public: Private d; void create(int type, const void *copy); bool cmp(const QVariant &other) const; - int compare(const QVariant &other) const; bool convert(const int t, void *ptr) const; // ### Qt6: drop const private: |