From 3f6afac6b115b74c7d7946082ff2c0771cc3ccce Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 3 Jul 2020 23:51:58 +0200 Subject: [PATCH] QPolygon: streamline constructors and special member functions Employ RO0; inherit the constructors from the base class; and do some code tidies as a drive by. The inherited constructors bring in goodies like initializer_list support. Change-Id: Ia00a3f9b0ccbf182bf837bc65ba2305110c8dc60 Reviewed-by: Lars Knoll --- src/gui/painting/qpolygon.h | 34 ++++++------------- .../gui/painting/qpolygon/tst_qpolygon.cpp | 31 ++++++++++++++--- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/gui/painting/qpolygon.h b/src/gui/painting/qpolygon.h index 5b3cd79c8c..80edd8d387 100644 --- a/src/gui/painting/qpolygon.h +++ b/src/gui/painting/qpolygon.h @@ -56,17 +56,12 @@ class QVariant; class QPolygon : public QList { public: - inline QPolygon() {} - inline ~QPolygon() {} - inline explicit QPolygon(int size); - inline /*implicit*/ QPolygon(const QList &v) : QList(v) { } - /*implicit*/ QPolygon(QList &&v) noexcept : QList(std::move(v)) { } - Q_GUI_EXPORT QPolygon(const QRect &r, bool closed=false); + using QList::QList; + QPolygon() = default; + /* implicit */ QPolygon(const QList &v) : QList(v) { } + /* implicit */ QPolygon(QList &&v) noexcept : QList(std::move(v)) { } + /* implicit */ Q_GUI_EXPORT QPolygon(const QRect &r, bool closed=false); Q_GUI_EXPORT QPolygon(int nPoints, const int *points); - QPolygon(const QPolygon &other) : QList(other) { } - QPolygon(QPolygon &&other) noexcept : QList(std::move(other)) { } - QPolygon &operator=(QPolygon &&other) noexcept { swap(other); return *this; } - QPolygon &operator=(const QPolygon &other) { QList::operator=(other); return *this; } void swap(QPolygon &other) noexcept { QList::swap(other); } // prevent QList<->QPolygon swaps Q_GUI_EXPORT operator QVariant() const; @@ -99,8 +94,6 @@ public: }; Q_DECLARE_SHARED(QPolygon) -inline QPolygon::QPolygon(int size) : QList(size) { } - #ifndef QT_NO_DEBUG_STREAM Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygon &); #endif @@ -137,17 +130,12 @@ class QRectF; class QPolygonF : public QList { public: - inline QPolygonF() {} - inline ~QPolygonF() {} - inline explicit QPolygonF(int size); - inline /*implicit*/ QPolygonF(const QList &v) : QList(v) { } + using QList::QList; + QPolygonF() = default; + /* implicit */ QPolygonF(const QList &v) : QList(v) { } /* implicit */ QPolygonF(QList &&v) noexcept : QList(std::move(v)) { } - Q_GUI_EXPORT QPolygonF(const QRectF &r); - /*implicit*/ Q_GUI_EXPORT QPolygonF(const QPolygon &a); - inline QPolygonF(const QPolygonF &a) : QList(a) { } - QPolygonF(QPolygonF &&other) noexcept : QList(std::move(other)) { } - QPolygonF &operator=(QPolygonF &&other) noexcept { swap(other); return *this; } - QPolygonF &operator=(const QPolygonF &other) { QList::operator=(other); return *this; } + /* implicit */ Q_GUI_EXPORT QPolygonF(const QRectF &r); + /* implicit */ Q_GUI_EXPORT QPolygonF(const QPolygon &a); inline void swap(QPolygonF &other) { QList::swap(other); } // prevent QList<->QPolygonF swaps Q_GUI_EXPORT operator QVariant() const; @@ -174,8 +162,6 @@ public: }; Q_DECLARE_SHARED(QPolygonF) -inline QPolygonF::QPolygonF(int size) : QList(size) { } - #ifndef QT_NO_DEBUG_STREAM Q_GUI_EXPORT QDebug operator<<(QDebug, const QPolygonF &); #endif diff --git a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp index 2187c1f141..a33e1559de 100644 --- a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp +++ b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp @@ -39,10 +39,8 @@ class tst_QPolygon : public QObject { Q_OBJECT -public: - tst_QPolygon(); - private slots: + void constructors(); void boundingRect_data(); void boundingRect(); void boundingRectF_data(); @@ -53,8 +51,33 @@ private slots: void intersections(); }; -tst_QPolygon::tst_QPolygon() +void constructors_helper(QPolygon) {} +void constructors_helperF(QPolygonF) {} + +void tst_QPolygon::constructors() { + constructors_helper(QPolygon()); + constructors_helper({}); + constructors_helper({ QPoint(1, 2), QPoint(3, 4)}); + constructors_helper({ {1, 2}, {3, 4} }); + constructors_helper(QPolygon(12)); + QList pointList; + constructors_helper(pointList); + constructors_helper(std::move(pointList)); + constructors_helper(QRect(1, 2, 3, 4)); + const int points[2] = { 10, 20 }; + constructors_helper(QPolygon(1, points)); + + constructors_helperF(QPolygonF()); + constructors_helperF({}); + constructors_helperF({ QPointF(1, 2), QPointF(3, 4)}); + constructors_helperF({ {1, 2}, {3, 4} }); + constructors_helperF(QPolygonF(12)); + constructors_helperF(QPolygon()); + QList pointFList; + constructors_helperF(pointFList); + constructors_helperF(std::move(pointFList)); + constructors_helperF(QRectF(1, 2, 3, 4)); } void tst_QPolygon::boundingRect_data()