diff options
author | Aaron McCarthy <aaron.mccarthy@jollamobile.com> | 2014-01-16 14:32:21 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-20 02:11:24 +0100 |
commit | 1d0966c6924876655c52725e779a7aa24866ff60 (patch) | |
tree | bb7220ab3ccce1d057b80af33dbb8dd784d5782e /src/imports/location/declarativeplaces | |
parent | 86db3df8cea7b9ac1e4ae078639de5fb5a43ca69 (diff) | |
download | qtlocation-1d0966c6924876655c52725e779a7aa24866ff60.tar.gz |
Remove offset attribute from place search requests.
Not all service providers support arbitrary search offsets. The offset
attribute has been removed, instead service providers can supply a
previous and next search query in the form of a QPlaceSearchRequest.
Change-Id: If68e969b06f909f3fa62718656cbef70d1bf84a6
Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
Diffstat (limited to 'src/imports/location/declarativeplaces')
3 files changed, 98 insertions, 25 deletions
diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp index b8275da5..d773c3b9 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.cpp @@ -120,41 +120,37 @@ void QDeclarativeSearchModelBase::setSearchArea(const QVariant &searchArea) /*! \internal */ -int QDeclarativeSearchModelBase::offset() const +int QDeclarativeSearchModelBase::limit() const { - return m_request.offset(); + return m_request.limit(); } /*! \internal */ -void QDeclarativeSearchModelBase::setOffset(int offset) +void QDeclarativeSearchModelBase::setLimit(int limit) { - if (m_request.offset() == offset) + if (m_request.limit() == limit) return; - m_request.setOffset(offset); - emit offsetChanged(); + m_request.setLimit(limit); + emit limitChanged(); } /*! \internal */ -int QDeclarativeSearchModelBase::limit() const +bool QDeclarativeSearchModelBase::previousPagesAvailable() const { - return m_request.limit(); + return m_previousPageRequest != QPlaceSearchRequest(); } /*! \internal */ -void QDeclarativeSearchModelBase::setLimit(int limit) +bool QDeclarativeSearchModelBase::nextPagesAvailable() const { - if (m_request.limit() == limit) - return; - - m_request.setLimit(limit); - emit limitChanged(); + return m_nextPageRequest != QPlaceSearchRequest(); } /*! @@ -263,6 +259,30 @@ QString QDeclarativeSearchModelBase::errorString() const /*! \internal */ +void QDeclarativeSearchModelBase::previousPage() +{ + if (m_previousPageRequest == QPlaceSearchRequest()) + return; + + m_request = m_previousPageRequest; + update(); +} + +/*! + \internal +*/ +void QDeclarativeSearchModelBase::nextPage() +{ + if (m_nextPageRequest == QPlaceSearchRequest()) + return; + + m_request = m_nextPageRequest; + update(); +} + +/*! + \internal +*/ void QDeclarativeSearchModelBase::clearData(bool suppressSignal) { Q_UNUSED(suppressSignal) @@ -320,3 +340,24 @@ void QDeclarativeSearchModelBase::pluginNameChanged() { initializePlugin(m_plugin); } + +/*! + \internal +*/ +void QDeclarativeSearchModelBase::setPreviousPageRequest(const QPlaceSearchRequest &previous) +{ + if (m_previousPageRequest == previous) + return; + + m_previousPageRequest = previous; + emit previousPagesAvailableChanged(); +} + +void QDeclarativeSearchModelBase::setNextPageRequest(const QPlaceSearchRequest &next) +{ + if (m_nextPageRequest == next) + return; + + m_nextPageRequest = next; + emit nextPagesAvailableChanged(); +} diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.h b/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.h index 5b3b831c..a9516407 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.h +++ b/src/imports/location/declarativeplaces/qdeclarativesearchmodelbase.h @@ -63,8 +63,9 @@ class QDeclarativeSearchModelBase : public QAbstractListModel, public QQmlParser Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged) Q_PROPERTY(QVariant searchArea READ searchArea WRITE setSearchArea NOTIFY searchAreaChanged) - Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged) Q_PROPERTY(int limit READ limit WRITE setLimit NOTIFY limitChanged) + Q_PROPERTY(bool previousPagesAvailable READ previousPagesAvailable NOTIFY previousPagesAvailableChanged) + Q_PROPERTY(bool nextPagesAvailable READ nextPagesAvailable NOTIFY nextPagesAvailableChanged) Q_PROPERTY(Status status READ status NOTIFY statusChanged) Q_ENUMS(Status) @@ -88,12 +89,12 @@ public: QVariant searchArea() const; void setSearchArea(const QVariant &searchArea); - int offset() const; - void setOffset(int offset); - int limit() const; void setLimit(int limit); + bool previousPagesAvailable() const; + bool nextPagesAvailable() const; + Status status() const; void setStatus(Status status, const QString &errorString = QString()); @@ -104,6 +105,9 @@ public: Q_INVOKABLE QString errorString() const; + Q_INVOKABLE void previousPage(); + Q_INVOKABLE void nextPage(); + virtual void clearData(bool suppressSignal = false); // From QQmlParserStatus @@ -113,8 +117,9 @@ public: Q_SIGNALS: void pluginChanged(); void searchAreaChanged(); - void offsetChanged(); void limitChanged(); + void previousPagesAvailableChanged(); + void nextPagesAvailableChanged(); void statusChanged(); protected: @@ -128,6 +133,8 @@ private Q_SLOTS: protected: virtual QPlaceReply *sendQuery(QPlaceManager *manager, const QPlaceSearchRequest &request) = 0; + void setPreviousPageRequest(const QPlaceSearchRequest &previous); + void setNextPageRequest(const QPlaceSearchRequest &next); QPlaceSearchRequest m_request; QDeclarativeGeoServiceProvider *m_plugin; @@ -137,6 +144,8 @@ private: bool m_complete; Status m_status; QString m_errorString; + QPlaceSearchRequest m_previousPageRequest; + QPlaceSearchRequest m_nextPageRequest; }; QT_END_NAMESPACE diff --git a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp index d9492ca2..f36f1d78 100644 --- a/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp +++ b/src/imports/location/declarativeplaces/qdeclarativesearchresultmodel.cpp @@ -223,19 +223,25 @@ QT_USE_NAMESPACE */ /*! - \qmlproperty int PlaceSearchModel::offset + \qmlproperty int PlaceSearchModel::limit - This property holds the index of the first search result in the model. + This property holds the limit of the number of items that will be returned. +*/ + +/*! + \qmlproperty bool PlaceSearchModel::previousPagesAvailable - \sa limit + This property holds whether there is one or more previous pages of search results available. + + \sa previousPage() */ /*! - \qmlproperty int PlaceSearchModel::limit + \qmlproperty bool PlaceSearchModel::nextPagesAvailable - This property holds the limit of the number of items that will be returned. + This property holds whether there is one or more additional pages of search results available. - \sa offset + \sa nextPage() */ /*! @@ -325,6 +331,20 @@ QT_USE_NAMESPACE textual representation. */ +/*! + \qmlmethod PlaceSearchModel::previousPage() + + Updates the model to display the previous page of search results. If there is no previous page + then this method does nothing. +*/ + +/*! + \qmlmethod PlaceSearchModel::nextPage() + + Updates the model to display the next page of search results. If there is no next page then + this method does nothing. +*/ + QDeclarativeSearchResultModel::QDeclarativeSearchResultModel(QObject *parent) : QDeclarativeSearchModelBase(parent), m_favoritesPlugin(0) { @@ -730,6 +750,9 @@ void QDeclarativeSearchResultModel::queryFinished() Q_ASSERT(searchReply); m_resultsBuffer = searchReply->results(); + setPreviousPageRequest(searchReply->previousPageRequest()); + setNextPageRequest(searchReply->nextPageRequest()); + reply->deleteLater(); if (!m_favoritesPlugin) { |