QEasingCurve: use comparison helper macros
Like with the QLine(F) case, we have to use QT_CORE_REMOVED_SINCE to remove the old member operators, but also need to guard the new friend functions with !(QT_CORE_REMOVED_SINCE), because QEasingCurve is also one of the core types, and on Windows the metatype interface for it is instantiated in removed_api.cpp. Task-number: QTBUG-120308 Change-Id: I1bd66f7230afd3eba868d05fd496ab13a0331178 Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
This commit is contained in:
parent
473d06970d
commit
a4341827ac
@ -952,6 +952,13 @@ bool QDir::operator==(const QDir &dir) const
|
||||
return comparesEqual(*this, dir);
|
||||
}
|
||||
|
||||
#include "qeasingcurve.h"
|
||||
|
||||
bool QEasingCurve::operator==(const QEasingCurve &other) const
|
||||
{
|
||||
return comparesEqual(*this, other);
|
||||
}
|
||||
|
||||
#include "qfileinfo.h" // inlined API
|
||||
|
||||
bool QFileInfo::operator==(const QFileInfo &fileinfo) const
|
||||
|
@ -1153,32 +1153,37 @@ QEasingCurve::~QEasingCurve()
|
||||
*/
|
||||
|
||||
/*!
|
||||
Compare this easing curve with \a other and returns \c true if they are
|
||||
equal. It will also compare the properties of a curve.
|
||||
*/
|
||||
bool QEasingCurve::operator==(const QEasingCurve &other) const
|
||||
{
|
||||
bool res = d_ptr->func == other.d_ptr->func
|
||||
&& d_ptr->type == other.d_ptr->type;
|
||||
if (res) {
|
||||
if (d_ptr->config && other.d_ptr->config) {
|
||||
// catch the config content
|
||||
res = d_ptr->config->operator==(*(other.d_ptr->config));
|
||||
\fn bool QEasingCurve::operator==(const QEasingCurve &lhs, const QEasingCurve &rhs)
|
||||
|
||||
} else if (d_ptr->config || other.d_ptr->config) {
|
||||
Compares easing curve \a lhs with \a rhs and returns \c true if they are
|
||||
equal; otherwise returns \c false.
|
||||
It will also compare the properties of the curves.
|
||||
*/
|
||||
bool comparesEqual(const QEasingCurve &lhs, const QEasingCurve &rhs) noexcept
|
||||
{
|
||||
bool res = lhs.d_ptr->func == rhs.d_ptr->func
|
||||
&& lhs.d_ptr->type == rhs.d_ptr->type;
|
||||
if (res) {
|
||||
if (lhs.d_ptr->config && rhs.d_ptr->config) {
|
||||
// catch the config content
|
||||
res = lhs.d_ptr->config->operator==(*(rhs.d_ptr->config));
|
||||
|
||||
} else if (lhs.d_ptr->config || rhs.d_ptr->config) {
|
||||
// one one has a config object, which could contain default values
|
||||
res = qFuzzyCompare(amplitude(), other.amplitude())
|
||||
&& qFuzzyCompare(period(), other.period())
|
||||
&& qFuzzyCompare(overshoot(), other.overshoot());
|
||||
res = qFuzzyCompare(lhs.amplitude(), rhs.amplitude())
|
||||
&& qFuzzyCompare(lhs.period(), rhs.period())
|
||||
&& qFuzzyCompare(lhs.overshoot(), rhs.overshoot());
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool QEasingCurve::operator!=(const QEasingCurve &other) const
|
||||
Compare this easing curve with \a other and returns \c true if they are not equal.
|
||||
It will also compare the properties of a curve.
|
||||
\fn bool QEasingCurve::operator!=(const QEasingCurve &lhs, const QEasingCurve &rhs)
|
||||
|
||||
Compares easing curve \a lhs with \a rhs and returns \c true if they are
|
||||
not equal; otherwise returns \c false.
|
||||
It will also compare the properties of the curves.
|
||||
|
||||
\sa operator==()
|
||||
*/
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
QT_REQUIRE_CONFIG(easingcurve);
|
||||
|
||||
#include <QtCore/qcompare.h>
|
||||
#include <QtCore/qlist.h>
|
||||
#include <QtCore/qobjectdefs.h>
|
||||
|
||||
@ -47,9 +48,11 @@ public:
|
||||
|
||||
void swap(QEasingCurve &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
|
||||
|
||||
#if QT_CORE_REMOVED_SINCE(6, 8)
|
||||
bool operator==(const QEasingCurve &other) const;
|
||||
inline bool operator!=(const QEasingCurve &other) const
|
||||
{ return !(this->operator==(other)); }
|
||||
#endif
|
||||
|
||||
qreal amplitude() const;
|
||||
void setAmplitude(qreal amplitude);
|
||||
@ -80,6 +83,11 @@ private:
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QEasingCurve &);
|
||||
friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QEasingCurve &);
|
||||
#endif
|
||||
friend Q_CORE_EXPORT bool
|
||||
comparesEqual(const QEasingCurve &lhs, const QEasingCurve &rhs) noexcept;
|
||||
#if !QT_CORE_REMOVED_SINCE(6, 8)
|
||||
Q_DECLARE_EQUALITY_COMPARABLE(QEasingCurve)
|
||||
#endif
|
||||
};
|
||||
Q_DECLARE_SHARED(QEasingCurve)
|
||||
|
@ -14,4 +14,6 @@ endif()
|
||||
qt_internal_add_test(tst_qeasingcurve
|
||||
SOURCES
|
||||
tst_qeasingcurve.cpp
|
||||
LIBRARIES
|
||||
Qt::TestPrivate
|
||||
)
|
||||
|
@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||
|
||||
#include <QTest>
|
||||
#include <private/qcomparisontesthelper_p.h>
|
||||
|
||||
#include <qeasingcurve.h>
|
||||
|
||||
@ -16,6 +17,7 @@ private slots:
|
||||
void valueForProgress_data();
|
||||
void valueForProgress();
|
||||
void setCustomType();
|
||||
void comparisonCompiles();
|
||||
void operators();
|
||||
void properties();
|
||||
void metaTypes();
|
||||
@ -420,6 +422,11 @@ void tst_QEasingCurve::setCustomType()
|
||||
QCOMPARE(curve.valueForProgress(0.99), 0.99);
|
||||
}
|
||||
|
||||
void tst_QEasingCurve::comparisonCompiles()
|
||||
{
|
||||
QTestPrivate::testEqualityOperatorsCompile<QEasingCurve>();
|
||||
}
|
||||
|
||||
void tst_QEasingCurve::operators()
|
||||
{
|
||||
{ // member-swap()
|
||||
@ -447,28 +454,28 @@ void tst_QEasingCurve::operators()
|
||||
curve2 = curve;
|
||||
curve2.setOvershoot(qreal(1.70158));
|
||||
QCOMPARE(curve.overshoot(), curve2.overshoot());
|
||||
QVERIFY(curve2 == curve);
|
||||
QT_TEST_EQUALITY_OPS(curve2, curve, true);
|
||||
|
||||
curve.setOvershoot(3.0);
|
||||
QVERIFY(curve2 != curve);
|
||||
QT_TEST_EQUALITY_OPS(curve2, curve, false);
|
||||
curve2.setOvershoot(3.0);
|
||||
QVERIFY(curve2 == curve);
|
||||
QT_TEST_EQUALITY_OPS(curve2, curve, true);
|
||||
|
||||
curve2.setType(QEasingCurve::Linear);
|
||||
QCOMPARE(curve.overshoot(), curve2.overshoot());
|
||||
QVERIFY(curve2 != curve);
|
||||
QT_TEST_EQUALITY_OPS(curve2, curve, false);
|
||||
curve2.setType(QEasingCurve::InBack);
|
||||
QCOMPARE(curve.overshoot(), curve2.overshoot());
|
||||
QVERIFY(curve2 == curve);
|
||||
QT_TEST_EQUALITY_OPS(curve2, curve, true);
|
||||
|
||||
QEasingCurve curve3;
|
||||
QEasingCurve curve4;
|
||||
curve4.setAmplitude(curve4.amplitude());
|
||||
QEasingCurve curve5;
|
||||
curve5.setAmplitude(0.12345);
|
||||
QVERIFY(curve3 == curve4); // default value and not assigned
|
||||
QVERIFY(curve3 != curve5); // unassinged and other value
|
||||
QVERIFY(curve4 != curve5);
|
||||
QT_TEST_EQUALITY_OPS(curve3, curve4, true); // default value and not assigned
|
||||
QT_TEST_EQUALITY_OPS(curve3, curve5, false); // unassinged and other value
|
||||
QT_TEST_EQUALITY_OPS(curve4, curve5, false);
|
||||
}
|
||||
|
||||
class tst_QEasingProperties : public QObject
|
||||
@ -890,7 +897,7 @@ void tst_QEasingCurve::streamInOut()
|
||||
dsw << orig;
|
||||
dsr >> copy;
|
||||
|
||||
QCOMPARE(copy == orig, equality);
|
||||
QT_TEST_EQUALITY_OPS(copy, orig, equality);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QEasingCurve)
|
||||
|
Loading…
x
Reference in New Issue
Block a user