mirror of https://github.com/qt/qtbase.git
QMetaMethod: use new comparison helper macros
Replace public friend operators operator==(), operator!=() of QMetaMethod to friend method comparesEqual() and Q_DECLARE_EQUALITY_COMPARABLE macro. Task-number: QTBUG-120304 Change-Id: Idb3f880a1db4850d73a58ed37f8cbd3454dd5ea2 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
9ac7e8f408
commit
51420d910b
|
@ -1798,6 +1798,7 @@ bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *
|
|||
function.
|
||||
|
||||
\ingroup objectmodel
|
||||
\compares equality
|
||||
|
||||
A QMetaMethod has a methodType(), a methodSignature(), a list of
|
||||
parameterTypes() and parameterNames(), a return typeName(), a
|
||||
|
@ -1825,19 +1826,19 @@ bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *
|
|||
invoked), otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*! \fn bool QMetaMethod::operator==(const QMetaMethod &m1, const QMetaMethod &m2)
|
||||
/*! \fn bool QMetaMethod::operator==(const QMetaMethod &lhs, const QMetaMethod &rhs)
|
||||
\since 5.0
|
||||
\overload
|
||||
|
||||
Returns \c true if method \a m1 is equal to method \a m2,
|
||||
Returns \c true if method \a lhs is equal to method \a rhs,
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
|
||||
/*! \fn bool QMetaMethod::operator!=(const QMetaMethod &m1, const QMetaMethod &m2)
|
||||
/*! \fn bool QMetaMethod::operator!=(const QMetaMethod &lhs, const QMetaMethod &rhs)
|
||||
\since 5.0
|
||||
\overload
|
||||
|
||||
Returns \c true if method \a m1 is not equal to method \a m2,
|
||||
Returns \c true if method \a lhs is not equal to method \a rhs,
|
||||
otherwise returns \c false.
|
||||
*/
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define QMETAOBJECT_H
|
||||
|
||||
#include <QtCore/qobjectdefs.h>
|
||||
#include <QtCore/qcompare.h>
|
||||
#include <QtCore/qvariant.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -251,10 +252,11 @@ protected:
|
|||
friend struct QMetaObject;
|
||||
friend struct QMetaObjectPrivate;
|
||||
friend class QObject;
|
||||
friend bool operator==(const QMetaMethod &m1, const QMetaMethod &m2) noexcept
|
||||
{ return m1.data == m2.data; }
|
||||
friend bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2) noexcept
|
||||
{ return !(m1 == m2); }
|
||||
|
||||
private:
|
||||
friend bool comparesEqual(const QMetaMethod &lhs, const QMetaMethod &rhs) noexcept
|
||||
{ return lhs.data == rhs.data; }
|
||||
Q_DECLARE_EQUALITY_COMPARABLE(QMetaMethod)
|
||||
};
|
||||
Q_DECLARE_TYPEINFO(QMetaMethod, Q_RELOCATABLE_TYPE);
|
||||
|
||||
|
|
|
@ -14,4 +14,6 @@ endif()
|
|||
qt_internal_add_test(tst_qmetamethod
|
||||
SOURCES
|
||||
tst_qmetamethod.cpp
|
||||
LIBRARIES
|
||||
Qt::TestPrivate
|
||||
)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
|
||||
#include <QTest>
|
||||
#include <QtTest/private/qcomparisontesthelper_p.h>
|
||||
#include <QTypeRevision>
|
||||
|
||||
#include <qobject.h>
|
||||
|
@ -14,6 +15,7 @@ class tst_QMetaMethod : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void compareCompiles();
|
||||
void method_data();
|
||||
void method();
|
||||
|
||||
|
@ -166,6 +168,11 @@ QVariant MethodTestObject::qvariantSlotBoolIntUIntLonglongULonglongDoubleLongSho
|
|||
}
|
||||
void MethodTestObject::voidSlotNoParameterNames(bool, int) {}
|
||||
|
||||
void tst_QMetaMethod::compareCompiles()
|
||||
{
|
||||
QTestPrivate::testEqualityOperatorsCompile<QMetaMethod>();
|
||||
}
|
||||
|
||||
void tst_QMetaMethod::method_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("signature");
|
||||
|
@ -647,6 +654,8 @@ void tst_QMetaMethod::method()
|
|||
// Bogus indexes
|
||||
QCOMPARE(method.parameterType(-1), 0);
|
||||
QCOMPARE(method.parameterType(parameterTypes.size()), 0);
|
||||
QT_TEST_EQUALITY_OPS(method, QMetaMethod(), false);
|
||||
QT_TEST_EQUALITY_OPS(QMetaMethod(), QMetaMethod(), true);
|
||||
}
|
||||
|
||||
void tst_QMetaMethod::invalidMethod()
|
||||
|
@ -659,6 +668,9 @@ void tst_QMetaMethod::invalidMethod()
|
|||
|
||||
QMetaMethod method3 = staticMetaObject.method(-1);
|
||||
QVERIFY(!method3.isValid());
|
||||
QT_TEST_EQUALITY_OPS(method, method2, true);
|
||||
QT_TEST_EQUALITY_OPS(method2, method3, true);
|
||||
QT_TEST_EQUALITY_OPS(method, method3, true);
|
||||
}
|
||||
|
||||
void tst_QMetaMethod::comparisonOperators()
|
||||
|
@ -673,16 +685,9 @@ void tst_QMetaMethod::comparisonOperators()
|
|||
QMetaMethod other = x ? mo->constructor(j) : mo->method(j);
|
||||
bool expectedEqual = ((methodMo == other.enclosingMetaObject())
|
||||
&& (i == j));
|
||||
QCOMPARE(method == other, expectedEqual);
|
||||
QCOMPARE(method != other, !expectedEqual);
|
||||
QCOMPARE(other == method, expectedEqual);
|
||||
QCOMPARE(other != method, !expectedEqual);
|
||||
QT_TEST_EQUALITY_OPS(method, other, expectedEqual);
|
||||
}
|
||||
|
||||
QVERIFY(method != QMetaMethod());
|
||||
QVERIFY(QMetaMethod() != method);
|
||||
QVERIFY(!(method == QMetaMethod()));
|
||||
QVERIFY(!(QMetaMethod() == method));
|
||||
QT_TEST_EQUALITY_OPS(method, QMetaMethod(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -691,8 +696,7 @@ void tst_QMetaMethod::comparisonOperators()
|
|||
for (int i = 0; i < qMin(mo->methodCount(), mo->constructorCount()); ++i) {
|
||||
QMetaMethod method = mo->method(i);
|
||||
QMetaMethod constructor = mo->constructor(i);
|
||||
QVERIFY(method != constructor);
|
||||
QVERIFY(!(method == constructor));
|
||||
QT_TEST_EQUALITY_OPS(method, constructor, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -748,6 +752,7 @@ void tst_QMetaMethod::gadget()
|
|||
QMetaMethod getValueMethod = MyGadget::staticMetaObject.method(idx);
|
||||
QVERIFY(getValueMethod.isValid());
|
||||
|
||||
QT_TEST_EQUALITY_OPS(setValueMethod, getValueMethod, false);
|
||||
{
|
||||
MyGadget gadget;
|
||||
QString string;
|
||||
|
|
Loading…
Reference in New Issue