diff options
author | abcd <amos.choy@nokia.com> | 2011-12-19 15:24:01 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-21 02:57:22 +0100 |
commit | df0106a250363e535ddfbff5486e9743e21dc49e (patch) | |
tree | fd4110c1f8b307df1ba4a9369484aa75e4e8e81d /src/imports | |
parent | 34e23060498f33308065e79d917355d59665474e (diff) | |
download | qtlocation-df0106a250363e535ddfbff5486e9743e21dc49e.tar.gz |
Add QML locale functionality to Places
Change-Id: I0380f3b6e7945909eee7c00230a976da0ac53d6e
Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/location/qdeclarativegeoserviceprovider.cpp | 72 | ||||
-rw-r--r-- | src/imports/location/qdeclarativegeoserviceprovider_p.h | 8 |
2 files changed, 72 insertions, 8 deletions
diff --git a/src/imports/location/qdeclarativegeoserviceprovider.cpp b/src/imports/location/qdeclarativegeoserviceprovider.cpp index 8f413b50..ae77cb35 100644 --- a/src/imports/location/qdeclarativegeoserviceprovider.cpp +++ b/src/imports/location/qdeclarativegeoserviceprovider.cpp @@ -64,6 +64,7 @@ QDeclarativeGeoServiceProvider::QDeclarativeGeoServiceProvider(QObject *parent) supportsReverseGeocoding_(false), supportsRouting_(false), supportsMapping_(false), supportsPlaces_(false), complete_(false) { + locales_.append(QLocale().name()); } QDeclarativeGeoServiceProvider::~QDeclarativeGeoServiceProvider() @@ -85,11 +86,11 @@ void QDeclarativeGeoServiceProvider::setName(const QString &name) delete sharedProvider_; sharedProvider_ = 0; if (complete_) - updateSupportStatus(); + update(); emit nameChanged(name_); } -void QDeclarativeGeoServiceProvider::updateSupportStatus() +void QDeclarativeGeoServiceProvider::update() { QGeoServiceProvider *serviceProvider = sharedGeoServiceProvider(); if (!serviceProvider || serviceProvider->error() != QGeoServiceProvider::NoError) { @@ -102,6 +103,10 @@ void QDeclarativeGeoServiceProvider::updateSupportStatus() return; } + if (locales_.isEmpty()) + locales_.append(QLocale().name()); + + Q_ASSERT(!locales_.isEmpty()); QGeocodingManager* geocodingManager = serviceProvider->geocodingManager(); if (!geocodingManager || serviceProvider->error() != QGeoServiceProvider::NoError) { setSupportsGeocoding(false); @@ -109,19 +114,26 @@ void QDeclarativeGeoServiceProvider::updateSupportStatus() } else { setSupportsGeocoding(geocodingManager->supportsGeocoding()); setSupportsReverseGeocoding(geocodingManager->supportsReverseGeocoding()); + geocodingManager->setLocale(QLocale(locales_.at(0))); } + QGeoRoutingManager* routingManager = serviceProvider->routingManager(); - if (!routingManager || serviceProvider->error() != QGeoServiceProvider::NoError) + if (!routingManager || serviceProvider->error() != QGeoServiceProvider::NoError) { setSupportsRouting(false); - else + } else { setSupportsRouting(true); + routingManager->setLocale(QLocale(locales_.at(0))); + } + QGeoMappingManager* mappingManager = serviceProvider->mappingManager(); - if (!mappingManager || serviceProvider->error() != QGeoServiceProvider::NoError) + if (!mappingManager || serviceProvider->error() != QGeoServiceProvider::NoError) { setSupportsMapping(false); - else + } else { setSupportsMapping(true); + mappingManager->setLocale(QLocale(locales_.at(0))); + } QPlaceManager *placeManager = serviceProvider->placeManager(); if (!placeManager || serviceProvider->error() != QGeoServiceProvider::NoError) { @@ -130,6 +142,12 @@ void QDeclarativeGeoServiceProvider::updateSupportStatus() } else { setSupportedPlacesFeatures(static_cast<QDeclarativeGeoServiceProvider::PlacesFeatures> ((int)placeManager->supportedFeatures())); setSupportsPlaces(true); + + QList<QLocale> localePreferences; + foreach (const QString &locale, locales_) + localePreferences.append(locale); + + placeManager->setLocales(localePreferences); } } @@ -190,7 +208,7 @@ void QDeclarativeGeoServiceProvider::componentComplete() { complete_ = true; if (!name_.isEmpty()) - updateSupportStatus(); + update(); } QString QDeclarativeGeoServiceProvider::name() const @@ -305,6 +323,46 @@ QGeoServiceProvider *QDeclarativeGeoServiceProvider::sharedGeoServiceProvider() } /*! + \qmlproperty stringlist Plugin::locales + + This property holds a set of locale preferences. If the first locale cannot be accommodated, then + the backend falls back to using the second, and so on. By default the locales property contains the system locale. + + The locales are specified as strings which have the format + "language[_script][_country]" or "C", where: + + \list + \i language is a lowercase, two-letter, ISO 639 language code, + \i script is a titlecase, four-letter, ISO 15924 script code, + \i country is an uppercase, two- or three-letter, ISO 3166 country code (also "419" as defined by United Nations), + \endlist + + + The following code demonstrates how to set a single and multiple locales: + \snippet snippets/declarative/plugin.qml Plugin locale +*/ +QStringList QDeclarativeGeoServiceProvider::locales() const +{ + return locales_; +} + +void QDeclarativeGeoServiceProvider::setLocales(const QStringList &locales) +{ + if (locales_ == locales) + return; + + locales_ = locales; + + if (locales_.isEmpty()) + locales_.append(QLocale().name()); + + if (complete_) + update(); + + emit localesChanged(); +} + +/*! \qmlproperty list<PluginParameter> Plugin::parameters \default diff --git a/src/imports/location/qdeclarativegeoserviceprovider_p.h b/src/imports/location/qdeclarativegeoserviceprovider_p.h index 6a095c75..973b308b 100644 --- a/src/imports/location/qdeclarativegeoserviceprovider_p.h +++ b/src/imports/location/qdeclarativegeoserviceprovider_p.h @@ -94,6 +94,7 @@ class QDeclarativeGeoServiceProvider : public QObject, public QDeclarativeParser Q_PROPERTY(bool supportsMapping READ supportsMapping NOTIFY supportsMappingChanged) Q_PROPERTY(bool supportsPlaces READ supportsPlaces NOTIFY supportsPlacesChanged) Q_PROPERTY(PlacesFeatures supportedPlacesFeatures READ supportedPlacesFeatures NOTIFY supportedPlacesFeaturesChanged) + Q_PROPERTY(QStringList locales READ locales WRITE setLocales NOTIFY localesChanged) Q_CLASSINFO("DefaultProperty", "parameters") Q_INTERFACES(QDeclarativeParserStatus) @@ -139,6 +140,9 @@ public: QGeoServiceProvider *sharedGeoServiceProvider(); + QStringList locales() const; + void setLocales(const QStringList &locales); + Q_SIGNALS: void nameChanged(const QString &name); void supportsGeocodingChanged(); @@ -147,13 +151,14 @@ Q_SIGNALS: void supportsMappingChanged(); void supportsPlacesChanged(); void supportedPlacesFeaturesChanged(); + void localesChanged(); private: static void parameter_append(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop, QDeclarativeGeoServiceProviderParameter *mapObject); static int parameter_count(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop); static QDeclarativeGeoServiceProviderParameter* parameter_at(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop, int index); static void parameter_clear(QDeclarativeListProperty<QDeclarativeGeoServiceProviderParameter> *prop); - void updateSupportStatus(); + void update(); void setSupportsGeocoding(bool supports); void setSupportsReverseGeocoding(bool supports); void setSupportsRouting(bool supports); @@ -170,6 +175,7 @@ private: bool supportsMapping_; bool supportsPlaces_; bool complete_; + QStringList locales_; PlacesFeatures placesFeatures_; Q_DISABLE_COPY(QDeclarativeGeoServiceProvider) }; |