diff options
author | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2011-07-22 14:03:53 +1000 |
---|---|---|
committer | Aaron McCarthy <aaron.mccarthy@nokia.com> | 2011-07-29 07:51:06 +0200 |
commit | 1d7195981caf1bf1d0bf0b0d1a047bc13b140d6f (patch) | |
tree | 5b06e91da400b7f0310db40454511951fca77679 /src/location | |
parent | f7131b42e6b997680ed4ebcc3d19becc1ef6da0e (diff) | |
download | qtlocation-1d7195981caf1bf1d0bf0b0d1a047bc13b140d6f.tar.gz |
Incorporate places/nokia plugin into geoservices/nokia plugin.
This brings the usage of the Places API inline with the rest of the
functional groups in QtLocation.
Removes the PlaceManager element.
Change-Id: I6d7259fe7ea1e55dcf97b95025e0c78748e82b9f
Reviewed-on: http://codereview.qt.nokia.com/2245
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Diffstat (limited to 'src/location')
-rw-r--r-- | src/location/maps/qgeoserviceprovider.cpp | 53 | ||||
-rw-r--r-- | src/location/maps/qgeoserviceprovider.h | 3 | ||||
-rw-r--r-- | src/location/maps/qgeoserviceprovider_p.h | 3 | ||||
-rw-r--r-- | src/location/maps/qgeoserviceproviderfactory.cpp | 25 | ||||
-rw-r--r-- | src/location/maps/qgeoserviceproviderfactory.h | 3 | ||||
-rw-r--r-- | src/location/places/places.pri | 3 | ||||
-rw-r--r-- | src/location/places/qplacemanager.cpp | 20 | ||||
-rw-r--r-- | src/location/places/qplacemanager.h | 9 | ||||
-rw-r--r-- | src/location/places/qplacemanager_p.cpp | 39 | ||||
-rw-r--r-- | src/location/places/qplacemanager_p.h | 5 | ||||
-rw-r--r-- | src/location/places/qplacemanagerengine.cpp | 100 | ||||
-rw-r--r-- | src/location/places/qplacemanagerengine.h | 17 | ||||
-rw-r--r-- | src/location/places/qplacemanagerengine_p.h | 75 |
13 files changed, 300 insertions, 55 deletions
diff --git a/src/location/maps/qgeoserviceprovider.cpp b/src/location/maps/qgeoserviceprovider.cpp index fd175c22..360514ea 100644 --- a/src/location/maps/qgeoserviceprovider.cpp +++ b/src/location/maps/qgeoserviceprovider.cpp @@ -46,9 +46,11 @@ #include "qgeosearchmanager.h" #include "qgeomappingmanager.h" #include "qgeoroutingmanager.h" +#include "qplacemanager.h" #include "qgeosearchmanagerengine.h" #include "qgeomappingmanagerengine.h" #include "qgeoroutingmanagerengine.h" +#include "qplacemanagerengine.h" #include <QList> #include <QString> @@ -292,6 +294,52 @@ QGeoRoutingManager* QGeoServiceProvider::routingManager() const } /*! + Returns the QPlaceManager made available by the service provider. + + This function will return 0 if the service provider does not provide + any place searching services. + + This function will attempt to construct a QPlaceManager instance + when it is called for the first time. If the attempt is successful the + QPlaceManager will be cached, otherwise each call of this function + will attempt to construct a QPlace instance until the + construction is successful. + + After this function has been called, error() and errorString() will + report any errors which occurred during the construction of the QPlaceManager. +*/ +QPlaceManager *QGeoServiceProvider::placeManager() const +{ + if (!d_ptr->factory || (d_ptr->placeError != QGeoServiceProvider::NoError)) + return 0; + + if (!d_ptr->placeManager) { + QPlaceManagerEngine *engine = d_ptr->factory->createPlaceManagerEngine(d_ptr->parameterMap, + &(d_ptr->placeError), + &(d_ptr->placeErrorString)); + + if (engine) { + engine->setManagerName(d_ptr->factory->providerName()); + engine->setManagerVersion(d_ptr->factory->providerVersion()); + d_ptr->placeManager = new QPlaceManager(engine); + } else { + d_ptr->placeError = QGeoServiceProvider::NotSupportedError; + d_ptr->placeErrorString = QLatin1String("The service provider does not support placeManager()."); + } + + if (d_ptr->placeError != QGeoServiceProvider::NoError) { + if (d_ptr->placeManager) + delete d_ptr->placeManager; + d_ptr->placeManager = 0; + d_ptr->error = d_ptr->placeError; + d_ptr->errorString = d_ptr->placeErrorString; + } + } + + return d_ptr->placeManager; +} + +/*! Returns an error code describing the error which occurred during the last operation that was performed by this class. */ @@ -317,9 +365,11 @@ QGeoServiceProviderPrivate::QGeoServiceProviderPrivate() searchManager(0), routingManager(0), mappingManager(0), + placeManager(0), searchError(QGeoServiceProvider::NoError), routingError(QGeoServiceProvider::NoError), mappingError(QGeoServiceProvider::NoError), + placeError(QGeoServiceProvider::NoError), error(QGeoServiceProvider::NoError) {} QGeoServiceProviderPrivate::~QGeoServiceProviderPrivate() @@ -332,6 +382,9 @@ QGeoServiceProviderPrivate::~QGeoServiceProviderPrivate() if (mappingManager) delete mappingManager; + + if (placeManager) + delete placeManager; } void QGeoServiceProviderPrivate::loadPlugin(const QString &providerName, const QMap<QString, QVariant> ¶meters) diff --git a/src/location/maps/qgeoserviceprovider.h b/src/location/maps/qgeoserviceprovider.h index 8fbe8ee6..ebda46c7 100644 --- a/src/location/maps/qgeoserviceprovider.h +++ b/src/location/maps/qgeoserviceprovider.h @@ -57,9 +57,11 @@ class QStringList; class QGeoSearchManager; class QGeoMappingManager; class QGeoRoutingManager; +class QPlaceManager; class QGeoSearchManagerEngine; class QGeoMappingManagerEngine; class QGeoRoutingManagerEngine; +class QPlaceManagerEngine; class QGeoServiceProviderPrivate; class Q_LOCATION_EXPORT QGeoServiceProvider @@ -81,6 +83,7 @@ public: QGeoSearchManager* searchManager() const; QGeoMappingManager* mappingManager() const; QGeoRoutingManager* routingManager() const; + QPlaceManager *placeManager() const; Error error() const; QString errorString() const; diff --git a/src/location/maps/qgeoserviceprovider_p.h b/src/location/maps/qgeoserviceprovider_p.h index 3d564481..bb194e09 100644 --- a/src/location/maps/qgeoserviceprovider_p.h +++ b/src/location/maps/qgeoserviceprovider_p.h @@ -80,14 +80,17 @@ public: QGeoSearchManager *searchManager; QGeoRoutingManager *routingManager; QGeoMappingManager *mappingManager; + QPlaceManager *placeManager; QGeoServiceProvider::Error searchError; QGeoServiceProvider::Error routingError; QGeoServiceProvider::Error mappingError; + QGeoServiceProvider::Error placeError; QString searchErrorString; QString routingErrorString; QString mappingErrorString; + QString placeErrorString; QGeoServiceProvider::Error error; QString errorString; diff --git a/src/location/maps/qgeoserviceproviderfactory.cpp b/src/location/maps/qgeoserviceproviderfactory.cpp index 6c8fe013..196f6877 100644 --- a/src/location/maps/qgeoserviceproviderfactory.cpp +++ b/src/location/maps/qgeoserviceproviderfactory.cpp @@ -160,4 +160,29 @@ QGeoRoutingManagerEngine* QGeoServiceProviderFactory::createRoutingManagerEngine return 0; } +/*! + Returns a new QPlaceManagerEngine instance, initialized with \a + parameters, which implements the place searching functionality. + + If \a error is not 0 it should be set to QGeoServiceProvider::NoError on + success or an appropriate QGeoServiceProvider::Error on failure. + + If \a errorString is not 0 it should be set to a string describing any + error which occurred. + + The default implementation returns 0, which causes a + QGeoServiceProvider::NotSupportedError in QGeoServiceProvider. +*/ +QPlaceManagerEngine* QGeoServiceProviderFactory::createPlaceManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const + +{ + Q_UNUSED(parameters) + Q_UNUSED(error) + Q_UNUSED(errorString) + + return 0; +} + QT_END_NAMESPACE diff --git a/src/location/maps/qgeoserviceproviderfactory.h b/src/location/maps/qgeoserviceproviderfactory.h index 1e457d7f..d8a80dd4 100644 --- a/src/location/maps/qgeoserviceproviderfactory.h +++ b/src/location/maps/qgeoserviceproviderfactory.h @@ -68,6 +68,9 @@ public: virtual QGeoRoutingManagerEngine* createRoutingManagerEngine(const QMap<QString, QVariant> ¶meters, QGeoServiceProvider::Error *error, QString *errorString) const; + virtual QPlaceManagerEngine *createPlaceManagerEngine(const QMap<QString, QVariant> ¶meters, + QGeoServiceProvider::Error *error, + QString *errorString) const; }; QT_END_NAMESPACE diff --git a/src/location/places/places.pri b/src/location/places/places.pri index 121dff31..1adb463e 100644 --- a/src/location/places/places.pri +++ b/src/location/places/places.pri @@ -46,7 +46,8 @@ PRIVATE_HEADERS += \ places/qplaceweekdayhours_p.h \ places/qplacesearchresult_p.h \ places/qplacereply_p.h \ - places/qplacemanager_p.h + places/qplacemanager_p.h \ + places/qplacemanagerengine_p.h SOURCES += \ #data classes diff --git a/src/location/places/qplacemanager.cpp b/src/location/places/qplacemanager.cpp index d9266293..b53ea641 100644 --- a/src/location/places/qplacemanager.cpp +++ b/src/location/places/qplacemanager.cpp @@ -95,11 +95,19 @@ users should acquire instances of QGeoRoutingManager with QGeoServiceProvider::routingManager(); */ -QPlaceManager::QPlaceManager(QObject *parent) - : QObject(parent),d(new QPlaceManagerPrivate) +QPlaceManager::QPlaceManager(QPlaceManagerEngine *engine, QObject *parent) + : QObject(parent), d(new QPlaceManagerPrivate) { - d->q_ptr = this; - d->createEngine(QLatin1String("nokia")); + d->engine = engine; + if (d->engine) { + d->engine->setParent(this); + + connect(d->engine, SIGNAL(finished(QPlaceReply*)), this, SIGNAL(finished(QPlaceReply*))); + connect(d->engine, SIGNAL(error(QPlaceReply*,QPlaceReply::Error)), + this, SIGNAL(error(QPlaceReply*,QPlaceReply::Error))); + } else { + qFatal("The place manager engine that was set for this place manager was NULL."); + } } /*! @@ -137,9 +145,9 @@ QPlaceMediaReply *QPlaceManager::getMedia(const QGeoPlace &place, const QPlaceQu /*! Posts a \a rating to a \a place. */ -QPlaceReply* QPlaceManager::postRating(const QGeoPlace &place, qreal rating) +QPlaceReply* QPlaceManager::postRating(const QString &placeId, qreal rating) { - return d->engine->postRating(place, rating); + return d->engine->postRating(placeId, rating); } /*! diff --git a/src/location/places/qplacemanager.h b/src/location/places/qplacemanager.h index a2198402..b856148b 100644 --- a/src/location/places/qplacemanager.h +++ b/src/location/places/qplacemanager.h @@ -100,12 +100,13 @@ public: NotSupportedError }; - QPlaceManager(QObject *parent = 0); ~QPlaceManager(); + QString managerName() const; + int managerVersion() const; QPlaceDetailsReply *getPlaceDetails(const QString &placeId) const; - QPlaceReply *postRating(const QGeoPlace &place, qreal value); + QPlaceReply *postRating(const QString &placeId, qreal value); QPlaceReviewReply *getReviews(const QGeoPlace &place, const QPlaceQuery &query) const; @@ -138,9 +139,13 @@ Q_SIGNALS: void error(QPlaceReply *, QPlaceReply::Error error, const QString &errorString = QString()); private: + QPlaceManager(QPlaceManagerEngine *engine, QObject *parent = 0); + Q_DISABLE_COPY(QPlaceManager) QPlaceManagerPrivate* d; Q_DECLARE_PRIVATE(QPlaceManager) + + friend class QGeoServiceProvider; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QPlaceManager::VisibilityScopes); diff --git a/src/location/places/qplacemanager_p.cpp b/src/location/places/qplacemanager_p.cpp index 3410ac87..677a64ee 100644 --- a/src/location/places/qplacemanager_p.cpp +++ b/src/location/places/qplacemanager_p.cpp @@ -55,47 +55,10 @@ QT_USE_NAMESPACE QPlaceManagerPrivate::QPlaceManagerPrivate() - : engine(0), - errorCode(QPlaceManager::NoError), - isConnected(false), - q_ptr(0) +: engine(0), errorCode(QPlaceManager::NoError), isConnected(false) { } -void QPlaceManagerPrivate::createEngine(const QString &managerName, const QMap<QString,QString> ¶meters) -{ - Q_Q(QPlaceManager); - - if (!q->availableManagers().contains(managerName)) { - errorCode = QPlaceManager::NotSupportedError; - errorString = QString::fromLatin1("The places manager, %1, was not found").arg(managerName); - qWarning() << errorString; - engine = 0; - return; - } - - QList<QPlaceManagerEngineFactory *> candidates = QPlaceManagerPrivate::factories().values(managerName); - - foreach (QPlaceManagerEngineFactory *f, candidates) - { - engine = f->engine(parameters, &errorCode, &errorString); - if (engine) - break; - } - - if (!engine) { - if (errorCode == QPlaceManager::NoError) { - errorCode = QPlaceManager::NotSupportedError; - errorString = QLatin1String("The place manager could not return the requested engine instance"); - } - } - - // connect signals from engine to public class - q_ptr->connect(engine, SIGNAL(finished(QPlaceReply*)), SIGNAL(finished(QPlaceReply*))); - q_ptr->connect(engine, SIGNAL(error(QPlaceReply*,QPlaceReply::Error)), - SIGNAL(error(QPlaceReply*,QPlaceReply::Error))); -} - QPlaceManagerEngine* QPlaceManagerPrivate::getEngine(const QPlaceManager* manager) { if (manager) diff --git a/src/location/places/qplacemanager_p.h b/src/location/places/qplacemanager_p.h index a4fe5ed2..e140e454 100644 --- a/src/location/places/qplacemanager_p.h +++ b/src/location/places/qplacemanager_p.h @@ -68,7 +68,6 @@ class QPlaceManagerPrivate { public: QPlaceManagerPrivate(); - void createEngine(const QString &managerName, const QMap<QString,QString> ¶meters = (QMap<QString, QString>())); QPlaceManagerEngine *engine; mutable QPlaceManager::Error errorCode; @@ -81,8 +80,8 @@ public: static void loadStaticFactories (QHash<QString, QPlaceManagerEngineFactory*> *factories); bool isConnected;//identifies whether connections have been made to the notification signals - QPlaceManager *q_ptr; - Q_DECLARE_PUBLIC(QPlaceManager) +private: + Q_DISABLE_COPY(QPlaceManagerPrivate) }; QT_END_NAMESPACE diff --git a/src/location/places/qplacemanagerengine.cpp b/src/location/places/qplacemanagerengine.cpp index 3c28ae44..f2ae288c 100644 --- a/src/location/places/qplacemanagerengine.cpp +++ b/src/location/places/qplacemanagerengine.cpp @@ -40,16 +40,112 @@ ****************************************************************************/ #include "qplacemanagerengine.h" +#include "qplacemanagerengine_p.h" #include "qplacecategory_p.h" QT_USE_NAMESPACE -QPlaceManagerEngine::QPlaceManagerEngine(QObject *parent) - : QObject(parent) +/*! + \class QPlaceManagerEngine + + \brief The QPlaceManagerEngine class provides an interface and convenience methods to + implementers of QGeoServiceProvider plugins who want to provide access to place search + functionality. + + \inmodule QtLocation + \since 5.0 + + \ingroup maps-impl + + Subclasses of QPlaceManagerEngine need to provide an implementation of getPlaceDetails(), + getMedia(), postRating(), getReviews(), searchForPlaces(), supportedSearchVisibilityScopes(), + recommendations(), textPredictions(), connectivityMode(), setConnectivityMode(), + supportedConnectivityModes(), savePlace(), supportedSaveVisibilityScopes(), removePlace(), + initializeCategories() and categories(). + + \sa QPlaceManager +*/ + +/*! + Constructs a new engine with the specified \a parent, using \a parameters to pass any + implementation specific data to the engine. +*/ +QPlaceManagerEngine::QPlaceManagerEngine(const QMap<QString, QVariant> ¶meters, + QObject *parent) +: QObject(parent), d_ptr(new QPlaceManagerEnginePrivate) { + Q_UNUSED(parameters) } +/*! + Destroys this engine. +*/ QPlaceManagerEngine::~QPlaceManagerEngine() { + delete d_ptr; +} + +/*! + Sets the name which this engine implementation uses to distinguish itself + from the implementations provided by other plugins to \a managerName. + + The combination of managerName() and managerVersion() should be unique + amongst plugin implementations. +*/ +void QPlaceManagerEngine::setManagerName(const QString &managerName) +{ + d_ptr->managerName = managerName; +} + +/*! + Returns the name which this engine implementation uses to distinguish + itself from the implementations provided by other plugins. + + The combination of managerName() and managerVersion() should be unique + amongst plugin implementations. +*/ +QString QPlaceManagerEngine::managerName() const +{ + return d_ptr->managerName; +} + +/*! + Sets the version of this engine implementation to \a managerVersion. + + The combination of managerName() and managerVersion() should be unique + amongst plugin implementations. +*/ +void QPlaceManagerEngine::setManagerVersion(int managerVersion) +{ + d_ptr->managerVersion = managerVersion; } + +/*! + Returns the version of this engine implementation. + + The combination of managerName() and managerVersion() should be unique + amongst plugin implementations. +*/ +int QPlaceManagerEngine::managerVersion() const +{ + return d_ptr->managerVersion; +} + + + + + +QPlaceManagerEnginePrivate::QPlaceManagerEnginePrivate() +: managerVersion(-1) +{ +} + +QPlaceManagerEnginePrivate::~QPlaceManagerEnginePrivate() +{ +} + +#include "moc_qplacemanagerengine.cpp" + +QT_END_NAMESPACE + diff --git a/src/location/places/qplacemanagerengine.h b/src/location/places/qplacemanagerengine.h index 4d6536b6..a436b4d8 100644 --- a/src/location/places/qplacemanagerengine.h +++ b/src/location/places/qplacemanagerengine.h @@ -46,21 +46,24 @@ QT_BEGIN_NAMESPACE +class QPlaceManagerEnginePrivate; + class Q_LOCATION_EXPORT QPlaceManagerEngine : public QObject { Q_OBJECT public: - QPlaceManagerEngine(QObject *parent = 0); + QPlaceManagerEngine(const QMap<QString, QVariant> ¶meters, QObject *parent = 0); virtual ~QPlaceManagerEngine(); - virtual QString managerName() const = 0; + QString managerName() const; + int managerVersion() const; virtual QPlaceDetailsReply *getPlaceDetails(const QString &placeId) = 0; virtual QPlaceMediaReply *getMedia(const QGeoPlace &place, const QPlaceQuery &query) = 0; - virtual QPlaceReply *postRating(const QGeoPlace &place, qreal value) = 0; + virtual QPlaceReply *postRating(const QString &placeId, qreal value) = 0; virtual QPlaceReviewReply *getReviews(const QGeoPlace &place, const QPlaceQuery &query) = 0; @@ -86,6 +89,14 @@ Q_SIGNALS: void finished(QPlaceReply *reply); void error(QPlaceReply *, QPlaceReply::Error error, QString errorString = QString()); +private: + void setManagerName(const QString &managerName); + void setManagerVersion(int managerVersion); + + QPlaceManagerEnginePrivate *d_ptr; + Q_DISABLE_COPY(QPlaceManagerEngine) + + friend class QGeoServiceProvider; }; QT_END_NAMESPACE diff --git a/src/location/places/qplacemanagerengine_p.h b/src/location/places/qplacemanagerengine_p.h new file mode 100644 index 00000000..ded52b38 --- /dev/null +++ b/src/location/places/qplacemanagerengine_p.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLACEMANAGERENGINE_P_H +#define QPLACEMANAGERENGINE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/QString> + +QT_BEGIN_NAMESPACE + +class QPlaceManagerEnginePrivate +{ +public: + QPlaceManagerEnginePrivate(); + ~QPlaceManagerEnginePrivate(); + + QString managerName; + int managerVersion; + +private: + Q_DISABLE_COPY(QPlaceManagerEnginePrivate) +}; + +QT_END_NAMESPACE + +#endif // QPLACEMANAGERENGINE_P_H |