summaryrefslogtreecommitdiffstats
path: root/src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp
diff options
context:
space:
mode:
authorabcd <qt-info@nokia.com>2011-08-22 20:24:43 +1000
committerabcd <qt_abcd1@ovi.com>2011-08-24 09:30:54 +0200
commit631783858474a28a219bcdd704efad5ef72d0f34 (patch)
tree210ddfd11f1d78b113dd8c3ecac72ab6df6a86a5 /src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp
parente6dbdfbbad070c5ca7a4e14bdd917ee2c7b52f71 (diff)
Use content mechanism to retrieve reviews
This means we no longer need the qplacereviewreply or the paginationlist. We also create a QPlaceContentRequest class to specialize in requesting content. It follows the same pattern that QPlaceContent does where the private classes use inheritance to mirror the public classes so that we only have a single d pointer instance per class(as opposed to a dpointer for QPlaceRequest and a dpointer for QPlaceContentRequest). QPlaceSeachRequest has been modified like this as well. Also in the nokia plugin we rename the qplaceimagereplyimpl class to the qplacecontentreplyimpl class. We use this to get the reviews as well as images and we no longer need the qplacereviewreplyimpl class. Change-Id: I0aa1254a4df3d136bf81f9faf0f6ec06a0773100 Reviewed-on: http://codereview.qt.nokia.com/3305 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: abcd <qt_abcd1@ovi.com>
Diffstat (limited to 'src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp')
-rw-r--r--src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp76
1 files changed, 61 insertions, 15 deletions
diff --git a/src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp b/src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp
index 8fbd9410..5bbee737 100644
--- a/src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp
+++ b/src/imports/location/declarativeplaces/qdeclarativereviewmodel.cpp
@@ -155,21 +155,22 @@ void QDeclarativeReviewModel::fetchMore(const QModelIndex &parent)
return;
}
- QPlaceRequest query;
+ QPlaceContentRequest request;
+ request.setContentType(QPlaceContent::ReviewType);
if (m_reviewCount == -1) {
- query.setOffset(0);
- query.setLimit(m_batchSize);
+ request.setOffset(0);
+ request.setLimit(m_batchSize);
} else {
QPair<int, int> missing = findMissingKey(m_reviews);
- query.setOffset(missing.first);
+ request.setOffset(missing.first);
if (missing.second == -1)
- query.setLimit(m_batchSize);
+ request.setLimit(m_batchSize);
else
- query.setLimit(qMin(m_batchSize, missing.second - missing.first + 1));
+ request.setLimit(qMin(m_batchSize, missing.second - missing.first + 1));
}
- m_reply = placeManager->getReviews(m_place->place(), query);
+ m_reply = placeManager->getContent(m_place->place(), request);
connect(m_reply, SIGNAL(finished()), this, SLOT(fetchFinished()), Qt::QueuedConnection);
}
@@ -196,7 +197,7 @@ void QDeclarativeReviewModel::componentComplete()
void QDeclarativeReviewModel::fetchFinished()
{
- QPlaceReviewReply *reply = m_reply;
+ QPlaceContentReply *reply = m_reply;
m_reply = 0;
if (m_reviewCount != reply->totalCount()) {
@@ -204,15 +205,60 @@ void QDeclarativeReviewModel::fetchFinished()
emit totalCountChanged();
}
- if (reply->reviews().items() > 0) {
- int startIndex = reply->reviews().start();
+ if (!reply->content().isEmpty()) {
+ QPlaceContent::Collection reviews = reply->content();
+
+ //find out which indexes are new and which ones have changed.
+ QMapIterator<int, QPlaceContent> reviewsIter(reviews);
+ QList<int> changedIndexes;
+ QList<int> newIndexes;
+ while (reviewsIter.hasNext()) {
+ reviewsIter.next();
+ if (!m_reviews.contains(reviewsIter.key())) {
+ newIndexes.append(reviewsIter.key());
+ } else if (reviewsIter.value() != m_reviews.value(reviewsIter.key())->review()) {
+ changedIndexes.append(reviewsIter.key());
+ } else {
+ //review item at given index has not changed, do nothing
+ }
+ }
- QList<QPlaceReview> reviews = reply->reviews().data();
+ //insert new indexes in blocks where within each
+ //block, the indexes are consecutive.
+ QListIterator<int> newIndexesIter(newIndexes);
+ int startIndex = -1;
+ while (newIndexesIter.hasNext()) {
+ int currentIndex = newIndexesIter.next();
+ if (startIndex == -1)
+ startIndex = currentIndex;
+
+ if (!newIndexesIter.hasNext() || (newIndexesIter.hasNext() && (newIndexesIter.peekNext() > (currentIndex + 1)))) {
+ beginInsertRows(QModelIndex(),startIndex,currentIndex);
+ for (int i = startIndex; i <= currentIndex; ++i)
+ m_reviews.insert(i, new QDeclarativeReview(reviews.value(i), this));
+ endInsertRows();
+ startIndex = -1;
+ }
+ }
- beginInsertRows(QModelIndex(), startIndex, startIndex + reviews.length() - 1);
- for (int i = 0; i < reviews.length(); ++i)
- m_reviews.insert(startIndex + i, new QDeclarativeReview(reviews.at(i), this));
- endInsertRows();
+ //modify changed indexes in blocks where within each
+ //block, the indexes are consecutive.
+ startIndex = -1;
+ QListIterator<int> changedIndexesIter(changedIndexes);
+ while (changedIndexesIter.hasNext()) {
+ int currentIndex = changedIndexesIter.next();
+ if (startIndex == -1)
+ startIndex = currentIndex;
+
+ if (!changedIndexesIter.hasNext() || (changedIndexesIter.hasNext() && changedIndexesIter.peekNext() > (currentIndex +1))) {
+ for (int i = startIndex; i <= currentIndex; ++i) {
+ m_reviews.remove(i);
+ m_reviews.insert(i, new QDeclarativeReview(reviews.value(i), this));
+ }
+ emit dataChanged(index(startIndex),index(currentIndex));
+ startIndex = -1;
+ }
+ }
}
reply->deleteLater();