summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2012-02-06 14:24:39 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-07 15:25:51 +0100
commit7c4d304db929b70144f00bf6d0ab3f0a78d9b13f (patch)
tree4faa2a2a733def276d803ecfa7a2a60a66609837
parentdf51c688868c2155288da378d98f1b1511cb96e5 (diff)
downloadqtlocation-7c4d304db929b70144f00bf6d0ab3f0a78d9b13f.tar.gz
Add formattedAddress property to address.
The formatted address provides a formatted address in the format that one would find on an envelope. Task-number: QTBUG-23499 Change-Id: I176ad03a8666737a2db1d542c4f768c2116aba32 Reviewed-by: Alex <alex.blasche@nokia.com>
-rw-r--r--examples/declarative/places/content/places/PlaceDelegate.qml14
-rw-r--r--src/imports/location/qdeclarativegeoaddress.cpp23
-rw-r--r--src/imports/location/qdeclarativegeoaddress_p.h5
-rw-r--r--src/location/qgeoaddress.cpp28
-rw-r--r--src/location/qgeoaddress.h3
-rw-r--r--src/location/qgeoaddress_p.h1
-rw-r--r--tests/auto/qgeoaddress/tst_qgeoaddress.cpp13
7 files changed, 82 insertions, 5 deletions
diff --git a/examples/declarative/places/content/places/PlaceDelegate.qml b/examples/declarative/places/content/places/PlaceDelegate.qml
index e92dffe5..d5e4b33c 100644
--- a/examples/declarative/places/content/places/PlaceDelegate.qml
+++ b/examples/declarative/places/content/places/PlaceDelegate.qml
@@ -78,7 +78,19 @@ Item {
Group { text: qsTr("Address") }
Text { text: distance + "m away" }
- Text { text: place ? place.location.address.street : "" }
+ Text {
+ function placeAddress(place) {
+ if (!place)
+ return "";
+
+ if (place.location.address.formattedAddress.length > 0)
+ return place.location.address.formattedAddress;
+
+ return place.location.address.street;
+ }
+
+ text: placeAddress(place)
+ }
Group {
text: qsTr("Categories")
diff --git a/src/imports/location/qdeclarativegeoaddress.cpp b/src/imports/location/qdeclarativegeoaddress.cpp
index cc0f3e03..4afbe907 100644
--- a/src/imports/location/qdeclarativegeoaddress.cpp
+++ b/src/imports/location/qdeclarativegeoaddress.cpp
@@ -114,6 +114,7 @@ QGeoAddress QDeclarativeGeoAddress::address() const
void QDeclarativeGeoAddress::setAddress(const QGeoAddress& address)
{
// Elaborate but takes care of emiting needed signals
+ setFormattedAddress(address.formattedAddress());
setCountry(address.country());
setCountryCode(address.countryCode());
setState(address.state());
@@ -125,6 +126,28 @@ void QDeclarativeGeoAddress::setAddress(const QGeoAddress& address)
m_address = address;
}
+/*!
+ \qmlproperty string QtLocation5::Address::formattedAddress
+
+ This property holds the formatted address. This property may not always be set but if it is
+ it can be used to display a correctly formatted address. The format of the address is
+ typically what you would find on an envelope. The format of the string is provided by the
+ \l Plugin.
+*/
+QString QDeclarativeGeoAddress::formattedAddress() const
+{
+ return m_address.formattedAddress();
+}
+
+void QDeclarativeGeoAddress::setFormattedAddress(const QString &address)
+{
+ if (m_address.formattedAddress() == address)
+ return;
+
+ m_address.setFormattedAddress(address);
+ emit formattedAddressChanged();
+}
+
QString QDeclarativeGeoAddress::country() const
{
return m_address.country();
diff --git a/src/imports/location/qdeclarativegeoaddress_p.h b/src/imports/location/qdeclarativegeoaddress_p.h
index 640874d3..b3ec7a53 100644
--- a/src/imports/location/qdeclarativegeoaddress_p.h
+++ b/src/imports/location/qdeclarativegeoaddress_p.h
@@ -53,6 +53,7 @@ class QDeclarativeGeoAddress : public QObject
Q_OBJECT
Q_PROPERTY(QGeoAddress address READ address WRITE setAddress)
+ Q_PROPERTY(QString formattedAddress READ formattedAddress WRITE setFormattedAddress NOTIFY formattedAddressChanged)
Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged)
Q_PROPERTY(QString countryCode READ countryCode WRITE setCountryCode NOTIFY countryCodeChanged)
Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
@@ -68,6 +69,9 @@ public:
QGeoAddress address() const;
void setAddress(const QGeoAddress& address);
+ QString formattedAddress() const;
+ void setFormattedAddress(const QString &address);
+
QString country() const;
void setCountry(const QString& country);
QString countryCode() const;
@@ -86,6 +90,7 @@ public:
void setPostalCode(const QString& postalCode);
signals:
+ void formattedAddressChanged();
void countryChanged();
void countryCodeChanged();
void stateChanged();
diff --git a/src/location/qgeoaddress.cpp b/src/location/qgeoaddress.cpp
index 5d32cdca..de1aa413 100644
--- a/src/location/qgeoaddress.cpp
+++ b/src/location/qgeoaddress.cpp
@@ -1,4 +1,3 @@
-
/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
@@ -63,7 +62,8 @@ QGeoAddressPrivate::QGeoAddressPrivate(const QGeoAddressPrivate &other)
sCity(other.sCity),
sDistrict(other.sDistrict),
sStreet(other.sStreet),
- sPostalCode(other.sPostalCode)
+ sPostalCode(other.sPostalCode),
+ sFormattedAddress(other.sFormattedAddress)
{
}
@@ -141,7 +141,8 @@ bool QGeoAddress::operator==(const QGeoAddress &other) const
d->sCity == other.city() &&
d->sDistrict == other.district() &&
d->sStreet == other.street() &&
- d->sPostalCode == other.postalCode();
+ d->sPostalCode == other.postalCode() &&
+ d->sFormattedAddress == other.formattedAddress();
}
/*!
@@ -152,6 +153,23 @@ bool QGeoAddress::operator==(const QGeoAddress &other) const
*/
/*!
+ Returns the address as a formatted string. The format of the string is typically what you
+ would find on an envelope. The format of the string is provided by the plugin.
+*/
+QString QGeoAddress::formattedAddress() const
+{
+ return d->sFormattedAddress;
+}
+
+/*!
+ Sets the formatted address to \a address.
+*/
+void QGeoAddress::setFormattedAddress(const QString &address)
+{
+ d->sFormattedAddress = address;
+}
+
+/*!
Returns the country name.
*/
QString QGeoAddress::country() const
@@ -302,7 +320,8 @@ bool QGeoAddress::isEmpty() const
d->sCity.isEmpty() &&
d->sDistrict.isEmpty() &&
d->sStreet.isEmpty() &&
- d->sPostalCode.isEmpty();
+ d->sPostalCode.isEmpty() &&
+ d->sFormattedAddress.isEmpty();
}
@@ -319,6 +338,7 @@ void QGeoAddress::clear()
d->sDistrict.clear();
d->sStreet.clear();
d->sPostalCode.clear();
+ d->sFormattedAddress.clear();
}
QT_END_NAMESPACE
diff --git a/src/location/qgeoaddress.h b/src/location/qgeoaddress.h
index e464537b..c1c72783 100644
--- a/src/location/qgeoaddress.h
+++ b/src/location/qgeoaddress.h
@@ -67,6 +67,9 @@ public:
return !(other == *this);
}
+ QString formattedAddress() const;
+ void setFormattedAddress(const QString &address);
+
QString country() const;
void setCountry(const QString &country);
diff --git a/src/location/qgeoaddress_p.h b/src/location/qgeoaddress_p.h
index 6291accd..003e5ef1 100644
--- a/src/location/qgeoaddress_p.h
+++ b/src/location/qgeoaddress_p.h
@@ -73,6 +73,7 @@ public:
QString sDistrict; //!< district field
QString sStreet; //!< street name field
QString sPostalCode; //!< postal code field
+ QString sFormattedAddress;
};
QT_END_NAMESPACE
diff --git a/tests/auto/qgeoaddress/tst_qgeoaddress.cpp b/tests/auto/qgeoaddress/tst_qgeoaddress.cpp
index 8f52fae2..85abd079 100644
--- a/tests/auto/qgeoaddress/tst_qgeoaddress.cpp
+++ b/tests/auto/qgeoaddress/tst_qgeoaddress.cpp
@@ -55,6 +55,7 @@ public:
private Q_SLOTS:
void constructorTest();
+ void formattedAddress();
//TODO: there are various field we don't have yet in QGeoAddress
// will need to either remove or enable these tests
// void additionalDataTest();
@@ -90,6 +91,14 @@ void tst_QGeoAddress::constructorTest()
delete testObjPtr;
}
+void tst_QGeoAddress::formattedAddress()
+{
+ QGeoAddress address;
+ QVERIFY(address.formattedAddress().isEmpty());
+ address.setFormattedAddress(QLatin1String("123 Fake Street\nSpringfield"));
+ QCOMPARE(address.formattedAddress(), QLatin1String("123 Fake Street\nSpringfield"));
+}
+
void tst_QGeoAddress::cityTest()
{
QGeoAddress testObj;
@@ -238,6 +247,10 @@ void tst_QGeoAddress::emptyClearTest()
QVERIFY(!testObj.isEmpty());
testObj.clear();
+ testObj.setFormattedAddress(QLatin1String("formatted address"));
+ QVERIFY(!testObj.isEmpty());
+ testObj.clear();
+
QVERIFY(testObj.isEmpty());
}