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/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp | |
parent | f7131b42e6b997680ed4ebcc3d19becc1ef6da0e (diff) |
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/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp')
-rw-r--r-- | src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp index 6364a4c6..89f562e3 100644 --- a/src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp @@ -1,5 +1,9 @@ #include "qdeclarativereviewmodel_p.h" -#include <qdeclarativeplace_p.h> +#include "qdeclarativegeoserviceprovider_p.h" +#include "qdeclarativeplace_p.h" + +#include <QtDeclarative/QDeclarativeInfo> +#include <QtLocation/QGeoServiceProvider> QT_USE_NAMESPACE @@ -19,8 +23,8 @@ QT_USE_NAMESPACE */ QDeclarativeReviewModel::QDeclarativeReviewModel(QObject* parent) -: QAbstractListModel(parent), m_place(0), m_batchSize(1), m_reviewCount(-1), - m_manager(new QPlaceManager(this)), m_reply(0) +: QAbstractListModel(parent), m_place(0), m_batchSize(1), m_reviewCount(-1), m_reply(0), + m_plugin(0), m_complete(false) { QHash<int, QByteArray> roleNames; roleNames.insert(ReviewRole, "review"); @@ -32,6 +36,28 @@ QDeclarativeReviewModel::~QDeclarativeReviewModel() qDeleteAll(m_reviews); } +void QDeclarativeReviewModel::setPlugin(QDeclarativeGeoServiceProvider *plugin) +{ + if (m_plugin == plugin) + return; + + reset(); // reset the model + m_plugin = plugin; + if (m_complete) + emit pluginChanged(); + QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider(); + QPlaceManager *placeManager = serviceProvider->placeManager(); + if (!placeManager || serviceProvider->error() != QGeoServiceProvider::NoError) { + qmlInfo(this) << tr("Warning: Plugin does not support places."); + return; + } +} + +QDeclarativeGeoServiceProvider* QDeclarativeReviewModel::plugin() const +{ + return m_plugin; +} + /*! \qmlproperty Place ReviewModel::place @@ -52,10 +78,15 @@ void QDeclarativeReviewModel::setPlace(QDeclarativePlace *place) m_reply = 0; } qDeleteAll(m_reviews); + m_reviews.clear(); endResetModel(); - m_reviewCount = -1; - emit totalCountChanged(); + if (m_reviewCount != -1) { + m_reviewCount = -1; + emit totalCountChanged(); + } + + setPlugin(place->plugin()); m_place = place; emit placeChanged(); @@ -134,6 +165,21 @@ void QDeclarativeReviewModel::fetchMore(const QModelIndex &parent) if (m_reply) return; + if (!m_plugin) { + qmlInfo(this) << "plugin not set."; + return; + } + + QGeoServiceProvider *serviceProvider = m_plugin->sharedGeoServiceProvider(); + if (!serviceProvider) + return; + + QPlaceManager *placeManager = serviceProvider->placeManager(); + if (!placeManager) { + qmlInfo(this) << tr("Places not supported by %1 Plugin.").arg(m_plugin->name()); + return; + } + QPlaceQuery query; if (m_reviewCount == -1) { @@ -148,7 +194,7 @@ void QDeclarativeReviewModel::fetchMore(const QModelIndex &parent) query.setLimit(qMin(m_batchSize, missing.second - missing.first + 1)); } - m_reply = m_manager->getReviews(m_place->place(), query); + m_reply = placeManager->getReviews(m_place->place(), query); connect(m_reply, SIGNAL(finished()), this, SLOT(fetchFinished()), Qt::QueuedConnection); } @@ -169,6 +215,7 @@ void QDeclarativeReviewModel::classBegin() void QDeclarativeReviewModel::componentComplete() { + m_complete = true; fetchMore(QModelIndex()); } |