summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-07-21 11:27:32 +0200
committerIvan Solovev <ivan.solovev@qt.io>2021-07-22 11:05:13 +0200
commit90d252f97c24d342eda3f1e62dc4c52fbd200067 (patch)
treece6eb6167141c182ade6b80571845ba976b96922
parentf30b06cd5dbbbbc8a724c279b36d4e09e74e2346 (diff)
downloadqtlocation-90d252f97c24d342eda3f1e62dc4c52fbd200067.tar.gz
QGeoLocation: support move operations
Add move-constructor and move-assignment operator, as well as a swap method. Specialize the type as shared using Q_DECLARE_SHARED. Task-number: QTBUG-95163 Pick-to: 6.2 Change-Id: Idcb42414b3d60526e7cd55ea3ead53324c7cbc58 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/positioning/qgeolocation.cpp25
-rw-r--r--src/positioning/qgeolocation.h8
-rw-r--r--tests/auto/qgeolocation/tst_qgeolocation.cpp45
-rw-r--r--tests/auto/qgeolocation/tst_qgeolocation.h2
4 files changed, 78 insertions, 2 deletions
diff --git a/src/positioning/qgeolocation.cpp b/src/positioning/qgeolocation.cpp
index 2d958f4c..38de9d04 100644
--- a/src/positioning/qgeolocation.cpp
+++ b/src/positioning/qgeolocation.cpp
@@ -108,12 +108,25 @@ QGeoLocation::QGeoLocation(const QGeoLocation &other)
}
/*!
+ \fn QGeoLocation::QGeoLocation(QGeoLocation &&other)
+ \since 6.2
+
+ Constructs a geo location object by moving from \a other.
+
+ \note The moved-from QGeoLocation object can only be destroyed or
+ assigned to. The effect of calling other functions than the destructor
+ or one of the assignment operators is undefined.
+*/
+
+/*!
Destroys the location object.
*/
QGeoLocation::~QGeoLocation()
{
}
+QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QGeoLocationPrivate)
+
/*!
Assigns \a other to this location and returns a reference to this location.
*/
@@ -127,6 +140,18 @@ QGeoLocation &QGeoLocation::operator =(const QGeoLocation &other)
}
/*!
+ \fn QGeoLocation &QGeoLocation::operator=(QGeoLocation &&other)
+ \since 6.2
+
+ Move-assings \a other to this location and returns a reference to this
+ location.
+
+ \note The moved-from QGeoLocation object can only be destroyed or
+ assigned to. The effect of calling other functions than the destructor
+ or one of the assignment operators is undefined.
+*/
+
+/*!
\fn bool QGeoLocation::operator==(const QGeoLocation &lhs, const QGeoLocation &rhs)
Returns \c true if the \a lhs location is equal to \a rhs, otherwise
diff --git a/src/positioning/qgeolocation.h b/src/positioning/qgeolocation.h
index a189d121..0c86be26 100644
--- a/src/positioning/qgeolocation.h
+++ b/src/positioning/qgeolocation.h
@@ -50,16 +50,20 @@ class QGeoAddress;
class QGeoCoordinate;
class QGeoShape;
class QGeoLocationPrivate;
+QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(QGeoLocationPrivate, Q_POSITIONING_EXPORT)
class Q_POSITIONING_EXPORT QGeoLocation
{
public:
QGeoLocation();
QGeoLocation(const QGeoLocation &other);
-
+ QGeoLocation(QGeoLocation &&other) noexcept = default;
~QGeoLocation();
QGeoLocation &operator=(const QGeoLocation &other);
+ QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QGeoLocation)
+
+ void swap(QGeoLocation &other) noexcept { d.swap(other.d); }
friend bool operator==(const QGeoLocation &lhs, const QGeoLocation &rhs)
{
@@ -86,7 +90,7 @@ private:
QSharedDataPointer<QGeoLocationPrivate> d;
};
-Q_DECLARE_TYPEINFO(QGeoLocation, Q_RELOCATABLE_TYPE);
+Q_DECLARE_SHARED(QGeoLocation)
QT_END_NAMESPACE
diff --git a/tests/auto/qgeolocation/tst_qgeolocation.cpp b/tests/auto/qgeolocation/tst_qgeolocation.cpp
index d0d64df9..e2935b4c 100644
--- a/tests/auto/qgeolocation/tst_qgeolocation.cpp
+++ b/tests/auto/qgeolocation/tst_qgeolocation.cpp
@@ -68,6 +68,51 @@ void tst_QGeoLocation::copy_constructor()
QCOMPARE(m_location, *qgeolocationcopy);
}
+void tst_QGeoLocation::move_constructor()
+{
+ QGeoAddress address;
+ address.setCity("Berlin");
+ address.setCountry("Germany");
+ address.setCountryCode("DEU");
+ address.setDistrict("Adlershof");
+ address.setPostalCode("12489");
+ address.setStreet("Erich-Thilo-Strasse");
+
+ QGeoLocation location;
+ location.setAddress(address);
+ location.setCoordinate(QGeoCoordinate(1.3, 2.4, 3.1));
+ location.setBoundingShape(QGeoCircle(QGeoCoordinate(1.3, 2.4), 100));
+
+ QGeoLocation locationCopy = location;
+ QCOMPARE(std::move(location), locationCopy);
+}
+
+void tst_QGeoLocation::move_assignment()
+{
+ QGeoAddress address;
+ address.setCity("Berlin");
+ address.setCountry("Germany");
+ address.setCountryCode("DEU");
+ address.setDistrict("Adlershof");
+ address.setPostalCode("12489");
+ address.setStreet("Erich-Thilo-Strasse");
+
+ QGeoLocation location;
+ location.setAddress(address);
+ location.setCoordinate(QGeoCoordinate(1.3, 2.4, 3.1));
+ location.setBoundingShape(QGeoCircle(QGeoCoordinate(1.3, 2.4), 100));
+
+ QGeoLocation locationCopy = location;
+
+ QGeoLocation otherLocation;
+ otherLocation = std::move(location);
+ QCOMPARE(otherLocation, locationCopy);
+
+ // Check that (move)assignment to a moved-from object is fine
+ location = std::move(locationCopy);
+ QCOMPARE(location, otherLocation);
+}
+
void tst_QGeoLocation::destructor()
{
QGeoLocation *qgeolocationcopy;
diff --git a/tests/auto/qgeolocation/tst_qgeolocation.h b/tests/auto/qgeolocation/tst_qgeolocation.h
index 1b281c24..a603503f 100644
--- a/tests/auto/qgeolocation/tst_qgeolocation.h
+++ b/tests/auto/qgeolocation/tst_qgeolocation.h
@@ -58,6 +58,8 @@ private Q_SLOTS:
//Start Unit Tests for qgeolocation.h
void constructor();
void copy_constructor();
+ void move_constructor();
+ void move_assignment();
void destructor();
void address();
void coordinate();