diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-07-29 11:23:01 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-08-30 22:59:25 +0200 |
commit | cd155f3390baea0f05fb15ef7d365d919a90ec40 (patch) | |
tree | b53be8e5a62352cf3eff860ba2ac1042307cb71d | |
parent | 042f227c3c3bfa7cf100db5cec886b3c18fcc710 (diff) | |
download | qtlocation-cd155f3390baea0f05fb15ef7d365d919a90ec40.tar.gz |
Modernize and clean up QGeoRoute(Leg)
Implement move semantics for QGeoRoute, make operators hidden friends,
and add noexcept to non-allocating functions.
Remove default-implemented constructors, operators, and destructor from
QGeoRouteLeg. That class would ideally go away so that we don't have to
subclass the QGeoRoute value type at all. The leg-data lives either way
in the QGeoRoutePrivate(Default), so making the design so that a route
can be a list of routes would remove the need for the Leg class.
However, that has repercussions to the QML types, tests, documentation
etc, and needs to be discussed further.
Task-number: QTBUG-105206
Change-Id: I4c451a74fbf42e06b1580df46bbccca4b0de1723
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit 9f40dfe98a7d7fc37e267160ce01a8e9dbd2282c)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | src/location/maps/qgeoroute.cpp | 60 | ||||
-rw-r--r-- | src/location/maps/qgeoroute.h | 30 |
2 files changed, 31 insertions, 59 deletions
diff --git a/src/location/maps/qgeoroute.cpp b/src/location/maps/qgeoroute.cpp index 42c34b39..d76073ae 100644 --- a/src/location/maps/qgeoroute.cpp +++ b/src/location/maps/qgeoroute.cpp @@ -53,6 +53,7 @@ QGeoRoutePrivate *QExplicitlySharedDataPointer<QGeoRoutePrivate>::clone() { return d->clone(); } +QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QGeoRoutePrivate) /*! \class QGeoRoute @@ -106,21 +107,18 @@ const QExplicitlySharedDataPointer<QGeoRoutePrivate> &QGeoRoute::const_d() const /*! Constructs a route object from the contents of \a other. */ -QGeoRoute::QGeoRoute(const QGeoRoute &other) - : d_ptr(other.d_ptr) {} +QGeoRoute::QGeoRoute(const QGeoRoute &other) noexcept = default; /*! Destroys this route object. */ -QGeoRoute::~QGeoRoute() -{ -} +QGeoRoute::~QGeoRoute() = default; /*! Assigns the contents of \a other to this route and returns a reference to this route. */ -QGeoRoute &QGeoRoute::operator= (const QGeoRoute & other) +QGeoRoute &QGeoRoute::operator=(const QGeoRoute & other) noexcept { if (this == &other) return *this; @@ -130,22 +128,24 @@ QGeoRoute &QGeoRoute::operator= (const QGeoRoute & other) } /*! - Returns whether this route and \a other are equal. + \fn bool QGeoRoute::operator==(const QGeoRoute &lhs, const QGeoRoute &rhs) noexcept + + Returns whether the routes \a lhs and \a rhs are equal. */ -bool QGeoRoute::operator ==(const QGeoRoute &other) const -{ - return ( (d_ptr.constData() == other.d_ptr.constData()) - || (*d_ptr) == (*other.d_ptr)); -} /*! - Returns whether this route and \a other are not equal. + \fn bool QGeoRoute::operator!=(const QGeoRoute &lhs, const QGeoRoute &rhs) noexcept + + Returns whether the routes \a lhs and \a rhs are not equal. */ -bool QGeoRoute::operator !=(const QGeoRoute &other) const + +bool QGeoRoute::isEqual(const QGeoRoute &other) const noexcept { - return !(operator==(other)); + return ( (d_ptr.constData() == other.d_ptr.constData()) + || (*d_ptr) == (*other.d_ptr)); } + /*! Sets the identifier of this route to \a id. @@ -720,31 +720,6 @@ QGeoRoute QGeoRoutePrivateDefault::containingRoute() const */ /*! - Constructs a route leg object. -*/ - -QGeoRouteLeg::QGeoRouteLeg() : QGeoRoute() -{ - -} - -/*! - Constructs a route leg object from the contents of \a other. -*/ -QGeoRouteLeg::QGeoRouteLeg(const QGeoRouteLeg &other) : QGeoRoute(other) -{ - -} - -/*! - Destroys this route object. -*/ -QGeoRouteLeg::~QGeoRouteLeg() -{ - -} - -/*! Sets the route leg index to \a idx. */ void QGeoRouteLeg::setLegIndex(int idx) @@ -777,9 +752,4 @@ QGeoRoute QGeoRouteLeg::overallRoute() const return const_d()->containingRoute(); } -QGeoRouteLeg::QGeoRouteLeg(const QExplicitlySharedDataPointer<QGeoRoutePrivate> &dd) : QGeoRoute(dd) -{ - -} - QT_END_NAMESPACE diff --git a/src/location/maps/qgeoroute.h b/src/location/maps/qgeoroute.h index ee1e8100..62d84b4b 100644 --- a/src/location/maps/qgeoroute.h +++ b/src/location/maps/qgeoroute.h @@ -50,20 +50,27 @@ QT_BEGIN_NAMESPACE class QGeoCoordinate; class QGeoRectangle; class QGeoRouteSegment; +class QGeoRouteLeg; class QGeoRoutePrivate; -class QGeoRouteLeg; +QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QGeoRoutePrivate, Q_LOCATION_EXPORT) class Q_LOCATION_EXPORT QGeoRoute { public: QGeoRoute(); - QGeoRoute(const QGeoRoute &other); - ~QGeoRoute(); // ### Qt6: make this virtual + QGeoRoute(const QGeoRoute &other) noexcept; + QGeoRoute(QGeoRoute &&other) noexcept = default; + ~QGeoRoute(); - QGeoRoute &operator = (const QGeoRoute &other); + QGeoRoute &operator=(const QGeoRoute &other) noexcept; + QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QGeoRoute) - bool operator == (const QGeoRoute &other) const; - bool operator != (const QGeoRoute &other) const; + void swap(QGeoRoute &other) noexcept { d_ptr.swap(other.d_ptr); } + + friend inline bool operator==(const QGeoRoute &lhs, const QGeoRoute &rhs) noexcept + { return lhs.isEqual(rhs); } + friend inline bool operator!=(const QGeoRoute &lhs, const QGeoRoute &rhs) noexcept + { return !lhs.isEqual(rhs); } void setRouteId(const QString &id); QString routeId() const; @@ -102,6 +109,8 @@ protected: private: QExplicitlySharedDataPointer<QGeoRoutePrivate> d_ptr; + bool isEqual(const QGeoRoute &other) const noexcept; + friend class QDeclarativeGeoRoute; friend class QGeoRoutePrivate; }; @@ -109,20 +118,13 @@ private: class Q_LOCATION_EXPORT QGeoRouteLeg: public QGeoRoute { public: - QGeoRouteLeg(); - QGeoRouteLeg(const QGeoRouteLeg &other); - QGeoRouteLeg &operator=(const QGeoRouteLeg &other) = default; - ~QGeoRouteLeg(); - void setLegIndex(int idx); int legIndex() const; void setOverallRoute(const QGeoRoute &route); QGeoRoute overallRoute() const; -protected: - QGeoRouteLeg(const QExplicitlySharedDataPointer<QGeoRoutePrivate> &dd); - +private: friend class QDeclarativeGeoRoute; friend class QGeoRoutePrivate; }; |