summaryrefslogtreecommitdiff
path: root/src/imports/location/qdeclarativegeolocation.cpp
diff options
context:
space:
mode:
authorabcd <qt-info@nokia.com>2011-07-08 14:18:39 +1000
committerabcd <qt_abcd1@ovi.com>2011-07-11 08:12:22 +0200
commit18c805cfd418a74cb2656d0c4a0fd7676786fb44 (patch)
treeec5e2cbcf70a352a2eeae3a976bcf0d6a43f738f /src/imports/location/qdeclarativegeolocation.cpp
parentea02345aeeff589cc342e1afd170a07d110180d8 (diff)
downloadqtlocation-18c805cfd418a74cb2656d0c4a0fd7676786fb44.tar.gz
Refactoring to use QGeoLocation
This refactoring is comprised of 2 main tasks. 1) Use QGeoLocation instead of QPlaceLocation, which came from the qt4-prerelease. 2) Use QGeoLocation instead of QGeoPlace from mobility. QGeoPlace in mobility encapsulated an address + coordinate, QGeoLocation in qt5 now fulfills that role(with some extra data fields) Mostly the searchreply and searchmanagers have been refactored to use qgeolocation instead of qgeoplace. This change addresses the library, plugins and tests but only some of the qml. Note the geosearchmanager in future will need to be refactored into a geocodingmanager, and there is still work needed on the qml side of things. Aside: the namings of mobility were used over the namings of the qt4 preprelease eg QPlaceLocation::displayPosition->QGeoLocation::coordinate QPlaceLocatoin::mapView->QGeoLocation::viewport. Change-Id: I312cddcb835ff52e94256c1fa97c6a9027eb9312 Reviewed-on: http://codereview.qt.nokia.com/1339 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: abcd <qt_abcd1@ovi.com>
Diffstat (limited to 'src/imports/location/qdeclarativegeolocation.cpp')
-rw-r--r--src/imports/location/qdeclarativegeolocation.cpp336
1 files changed, 336 insertions, 0 deletions
diff --git a/src/imports/location/qdeclarativegeolocation.cpp b/src/imports/location/qdeclarativegeolocation.cpp
new file mode 100644
index 00000000..c8db0a2d
--- /dev/null
+++ b/src/imports/location/qdeclarativegeolocation.cpp
@@ -0,0 +1,336 @@
+#include "qdeclarativegeolocation_p.h"
+
+QTM_USE_NAMESPACE
+
+/*!
+ \qmlclass Location
+
+ \brief The Location element holds location data.
+ \inherits QObject
+
+ Location cointains many properties holding data of the location like geo coordinates,
+ address, etc.
+
+ \ingroup qml-places
+*/
+
+QDeclarativeGeoLocation::QDeclarativeGeoLocation(QObject* parent)
+ : QObject(parent)
+{
+}
+
+QDeclarativeGeoLocation::QDeclarativeGeoLocation(const QGeoLocation &src,
+ QObject *parent)
+ : QObject(parent),
+ m_src(src),
+ m_address(src.address()),
+ m_coordinate(src.coordinate()),
+ m_boundingBox(src.viewport())
+{
+ for (int i = 0; i < src.navigationPositions().count(); ++i) {
+ m_navigationPositions.append(new QDeclarativeCoordinate(src.navigationPositions().at(i)));
+ }
+}
+
+QDeclarativeGeoLocation::~QDeclarativeGeoLocation()
+{
+}
+
+void QDeclarativeGeoLocation::setLocation(const QGeoLocation &src)
+{
+ QGeoLocation previous = m_src;
+ m_src = src;
+
+ if (previous.additionalData() != m_src.additionalData()) {
+ emit additionalDataChanged();
+ }
+ if (previous.alternativeLabels() != m_src.alternativeLabels()) {
+ synchronizeAlternativeValues();
+ emit alternativeLabelsChanged();
+ }
+ if (previous.address() != m_src.address()) {
+ m_address.setAddress(m_src.address());
+ emit addressChanged();
+ }
+ if (previous.coordinate() != m_src.coordinate()) {
+ m_coordinate.setCoordinate(m_src.coordinate());
+ emit coordinateChanged();
+ }
+ if (previous.navigationPositions() != m_src.navigationPositions()) {
+ synchronizeNavigationPositions();
+ emit navigationPositionsChanged();
+ }
+ if (previous.label() != m_src.label()) {
+ emit labelChanged();
+ }
+ if (previous.locationId() != m_src.locationId()) {
+ emit locationIdChanged();
+ }
+ if (previous.locationScore() != m_src.locationScore()) {
+ emit locationScoreChanged();
+ }
+ if (previous.viewport() != m_src.viewport()) {
+ emit viewport();
+ }
+}
+
+QGeoLocation QDeclarativeGeoLocation::location() const
+{
+ return m_src;
+}
+
+/*!
+ \qmlproperty QVariantHash Location::additionalData
+
+ This property holds additional data for location. Those are pairs of strings (key/value).
+*/
+
+void QDeclarativeGeoLocation::setAdditionalData(const QVariantHash &additionalData)
+{
+ if (m_src.additionalData() != additionalData) {
+ m_src.setAdditionalData(additionalData);
+ emit additionalDataChanged();
+ }
+}
+
+QVariantHash QDeclarativeGeoLocation::additionalData() const
+{
+ return m_src.additionalData();
+}
+
+/*!
+ \qmlproperty string Location::address
+
+ This property holds address of the location.
+*/
+void QDeclarativeGeoLocation::setAddress(QDeclarativeGeoAddress *address)
+{
+ if (m_src.address() != address->address()) {
+ m_address.setAddress(address->address());
+ m_src.setAddress(address->address());
+ emit addressChanged();
+ }
+}
+
+QDeclarativeGeoAddress *QDeclarativeGeoLocation::address()
+{
+ return &m_address;
+}
+
+/*!
+ \qmlproperty string Location::coordinate
+
+ This property holds display coordinates of the location.
+*/
+void QDeclarativeGeoLocation::setCoordinate(QDeclarativeCoordinate *coordinate)
+{
+ if (m_src.coordinate() != coordinate->coordinate()) {
+ m_coordinate.setCoordinate(coordinate->coordinate());
+ m_src.setCoordinate(coordinate->coordinate());
+ emit coordinateChanged();
+ }
+}
+
+QDeclarativeCoordinate *QDeclarativeGeoLocation::coordinate()
+{
+ return &m_coordinate;
+}
+
+/*!
+ \qmlproperty string Location::label
+
+ This property holds label.
+*/
+void QDeclarativeGeoLocation::setLabel(const QString &label)
+{
+ if (m_src.label() != label) {
+ m_src.setLabel(label);
+ emit labelChanged();
+ }
+}
+
+QString QDeclarativeGeoLocation::label() const
+{
+ return m_src.label();
+}
+
+/*!
+ \qmlproperty string Location::locationId
+
+ This property holds location id.
+*/
+void QDeclarativeGeoLocation::setLocationId(const QString &locationId)
+{
+ if (m_src.locationId() != locationId) {
+ m_src.setLocationId(locationId);
+ emit locationIdChanged();
+ }
+}
+
+QString QDeclarativeGeoLocation::locationId() const
+{
+ return m_src.locationId();
+}
+
+/*!
+ \qmlproperty string Location::locationScore
+
+ This property holds location score.
+*/
+void QDeclarativeGeoLocation::setLocationScore(const int &locationScore)
+{
+ if (m_src.locationScore() != locationScore) {
+ m_src.setLocationScore(locationScore);
+ emit locationScoreChanged();
+ }
+}
+
+int QDeclarativeGeoLocation::locationScore() const
+{
+ return m_src.locationScore();
+}
+
+/*!
+ \qmlproperty string Location::viewport
+
+ This property holds bouding box of area on map ocupied by location.
+*/
+void QDeclarativeGeoLocation::setViewport(QDeclarativeGeoBoundingBox *viewport)
+{
+ if (m_src.viewport() != viewport->box()) {
+ m_boundingBox.setBox(viewport->box());
+ m_src.setViewport(viewport->box());
+ emit viewportChanged();
+ }
+}
+
+QDeclarativeGeoBoundingBox *QDeclarativeGeoLocation::viewport()
+{
+ return &m_boundingBox;
+}
+
+/*!
+ \qmlproperty QDeclarativeListProperty<QDeclarativeAlternativeValue> Location::alternativeLabels
+
+ This property alternative values for label property.
+*/
+QDeclarativeListProperty<QDeclarativeAlternativeValue> QDeclarativeGeoLocation::alternativeLabels()
+{
+ return QDeclarativeListProperty<QDeclarativeAlternativeValue>(this,
+ 0, // opaque data parameter
+ alternativeValue_append,
+ alternativeValue_count,
+ alternativeValue_at,
+ alternativeValue_clear);
+}
+
+void QDeclarativeGeoLocation::alternativeValue_append(QDeclarativeListProperty<QDeclarativeAlternativeValue> *prop,
+ QDeclarativeAlternativeValue *value)
+{
+ QDeclarativeGeoLocation* object = static_cast<QDeclarativeGeoLocation*>(prop->object);
+ QDeclarativeAlternativeValue *altValue = new QDeclarativeAlternativeValue(object);
+ altValue->setValueObject(value->valueObject());
+ object->m_alternativeValues.append(altValue);
+ QList<QPlaceAlternativeValue> list = object->m_src.alternativeLabels();
+ list.append(value->valueObject());
+ object->m_src.setAlternativeLabels(list);
+ emit object->alternativeLabelsChanged();
+}
+
+int QDeclarativeGeoLocation::alternativeValue_count(QDeclarativeListProperty<QDeclarativeAlternativeValue> *prop)
+{
+ return static_cast<QDeclarativeGeoLocation*>(prop->object)->m_alternativeValues.count();
+}
+
+QDeclarativeAlternativeValue* QDeclarativeGeoLocation::alternativeValue_at(QDeclarativeListProperty<QDeclarativeAlternativeValue> *prop,
+ int index)
+{
+ QDeclarativeGeoLocation* object = static_cast<QDeclarativeGeoLocation*>(prop->object);
+ QDeclarativeAlternativeValue *res = NULL;
+ if (object->m_alternativeValues.count() > index && index > -1) {
+ res = object->m_alternativeValues[index];
+ }
+ return res;
+}
+
+void QDeclarativeGeoLocation::alternativeValue_clear(QDeclarativeListProperty<QDeclarativeAlternativeValue> *prop)
+{
+ QDeclarativeGeoLocation* object = static_cast<QDeclarativeGeoLocation*>(prop->object);
+ qDeleteAll(object->m_alternativeValues);
+ object->m_alternativeValues.clear();
+ object->m_src.setAlternativeLabels(QList<QPlaceAlternativeValue>());
+ emit object->alternativeLabelsChanged();
+}
+
+/*!
+ \qmlproperty QDeclarativeListProperty<QDeclarativeCoordinate> Location::navigationPositions
+
+ This property navigation coordinates for location.
+*/
+QDeclarativeListProperty<QDeclarativeCoordinate> QDeclarativeGeoLocation::navigationPositions()
+{
+ return QDeclarativeListProperty<QDeclarativeCoordinate>(this,
+ 0, // opaque data parameter
+ navigationPosition_append,
+ navigationPosition_count,
+ navigationPosition_at,
+ navigationPosition_clear);
+}
+
+void QDeclarativeGeoLocation::navigationPosition_append(QDeclarativeListProperty<QDeclarativeCoordinate> *prop,
+ QDeclarativeCoordinate *value)
+{
+ QDeclarativeGeoLocation* object = static_cast<QDeclarativeGeoLocation*>(prop->object);
+ QDeclarativeCoordinate *altValue = new QDeclarativeCoordinate(object);
+ altValue->setCoordinate(value->coordinate());
+ object->m_navigationPositions.append(altValue);
+ QList<QGeoCoordinate> list = object->m_src.navigationPositions();
+ list.append(value->coordinate());
+ object->m_src.setNavigationPositions(list);
+ emit object->navigationPositionsChanged();
+}
+
+int QDeclarativeGeoLocation::navigationPosition_count(QDeclarativeListProperty<QDeclarativeCoordinate> *prop)
+{
+ return static_cast<QDeclarativeGeoLocation*>(prop->object)->m_navigationPositions.count();
+}
+
+QDeclarativeCoordinate* QDeclarativeGeoLocation::navigationPosition_at(QDeclarativeListProperty<QDeclarativeCoordinate> *prop,
+ int index)
+{
+ QDeclarativeGeoLocation* object = static_cast<QDeclarativeGeoLocation*>(prop->object);
+ QDeclarativeCoordinate *res = NULL;
+ if (object->m_navigationPositions.count() > index && index > -1) {
+ res = object->m_navigationPositions[index];
+ }
+ return res;
+}
+
+void QDeclarativeGeoLocation::navigationPosition_clear(QDeclarativeListProperty<QDeclarativeCoordinate> *prop)
+{
+ QDeclarativeGeoLocation* object = static_cast<QDeclarativeGeoLocation*>(prop->object);
+ qDeleteAll(object->m_navigationPositions);
+ object->m_navigationPositions.clear();
+ object->m_src.setNavigationPositions(QList<QGeoCoordinate>());
+ emit object->navigationPositionsChanged();
+}
+
+void QDeclarativeGeoLocation::synchronizeAlternativeValues()
+{
+ qDeleteAll(m_alternativeValues);
+ m_alternativeValues.clear();
+ foreach (QPlaceAlternativeValue value, m_src.alternativeLabels()) {
+ QDeclarativeAlternativeValue* declarativeValue = new QDeclarativeAlternativeValue(value, this);
+ m_alternativeValues.append(declarativeValue);
+ }
+}
+
+void QDeclarativeGeoLocation::synchronizeNavigationPositions()
+{
+ qDeleteAll(m_navigationPositions);
+ m_navigationPositions.clear();
+ foreach (QGeoCoordinate value, m_src.navigationPositions()) {
+ QDeclarativeCoordinate* declarativeValue = new QDeclarativeCoordinate(value, this);
+ m_navigationPositions.append(declarativeValue);
+ }
+}