diff options
author | abcd <qt-info@nokia.com> | 2011-10-05 14:26:06 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-11 06:16:59 +0200 |
commit | 3dcb12116420cd29580b28c8e976c17ea605d185 (patch) | |
tree | dc803abea29a593f402ec81975e32dc8d31855ed /src/plugins/geoservices | |
parent | c3b41f8823e9f500bf2fde0213c6302c5ff0d12f (diff) | |
download | qtlocation-3dcb12116420cd29580b28c8e976c17ea605d185.tar.gz |
Add Icon support to Places
Change-Id: I559c96427db542dd71122f937dff90c900a02241
Reviewed-on: http://codereview.qt-project.org/6041
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron McCarthy <aaron.mccarthy@nokia.com>
Reviewed-by: abcd <qt_abcd1@ovi.com>
Diffstat (limited to 'src/plugins/geoservices')
19 files changed, 123 insertions, 55 deletions
diff --git a/src/plugins/geoservices/nokia/places/qplacecontentreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacecontentreplyimpl.cpp index 24d705d8..7a008ad5 100644 --- a/src/plugins/geoservices/nokia/places/qplacecontentreplyimpl.cpp +++ b/src/plugins/geoservices/nokia/places/qplacecontentreplyimpl.cpp @@ -58,16 +58,16 @@ QT_USE_NAMESPACE Constructor. */ QPlaceContentReplyImpl::QPlaceContentReplyImpl(QPlaceContent::Type type, QPlaceRestReply *reply, - QObject *parent) + QPlaceManager *manager, QObject *parent) : QPlaceContentReply(parent), restReply(reply), contentType(type), startNumber(0) { if (contentType == QPlaceContent::ImageType) parser = new QPlaceJSonMediaParser(this); else if (contentType == QPlaceContent::ReviewType) - parser = new QPlaceJSonReviewParser(this); + parser = new QPlaceJSonReviewParser(manager, this); else if (contentType == QPlaceContent::EditorialType) - parser = new QPlaceJSonDetailsParser(this); + parser = new QPlaceJSonDetailsParser(manager, this); else parser = 0; diff --git a/src/plugins/geoservices/nokia/places/qplacecontentreplyimpl.h b/src/plugins/geoservices/nokia/places/qplacecontentreplyimpl.h index 5f140aaf..d34bdcf1 100644 --- a/src/plugins/geoservices/nokia/places/qplacecontentreplyimpl.h +++ b/src/plugins/geoservices/nokia/places/qplacecontentreplyimpl.h @@ -64,7 +64,8 @@ class QPlaceContentReplyImpl : public QPlaceContentReply { Q_OBJECT public: - QPlaceContentReplyImpl(QPlaceContent::Type type, QPlaceRestReply *reply, QObject *parent = 0); + QPlaceContentReplyImpl(QPlaceContent::Type type, QPlaceRestReply *reply, + QPlaceManager *manager, QObject *parent = 0); ~QPlaceContentReplyImpl(); void abort(); void setStartNumber(int number); diff --git a/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.cpp index 52eaa5d6..00f49324 100644 --- a/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.cpp +++ b/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.cpp @@ -57,11 +57,11 @@ QT_USE_NAMESPACE /*! Constructor. */ -QPlaceDetailsReplyImpl::QPlaceDetailsReplyImpl(QPlaceRestReply *reply, QObject *parent) : +QPlaceDetailsReplyImpl::QPlaceDetailsReplyImpl(QPlaceRestReply *reply, QPlaceManager *manager, QObject *parent) : QPlaceDetailsReply(parent), restReply(reply) { - parser = new QPlaceJSonDetailsParser(this); + parser = new QPlaceJSonDetailsParser(manager, this); if (restReply) { restReply->setParent(this); diff --git a/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.h b/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.h index 94db02a8..d1787990 100644 --- a/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.h +++ b/src/plugins/geoservices/nokia/places/qplacedetailsreplyimpl.h @@ -55,6 +55,7 @@ #include <qplacedetailsreply.h> #include "qplacerestreply.h" #include "qplacejsondetailsparser.h" +#include <QtLocation/QPlaceManager> QT_BEGIN_NAMESPACE @@ -62,7 +63,7 @@ class QPlaceDetailsReplyImpl : public QPlaceDetailsReply { Q_OBJECT public: - explicit QPlaceDetailsReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + QPlaceDetailsReplyImpl(QPlaceRestReply *reply, QPlaceManager *manager, QObject *parent = 0); ~QPlaceDetailsReplyImpl(); void abort(); diff --git a/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp index 0c04c3dd..a0e2f7ce 100644 --- a/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp +++ b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.cpp @@ -185,8 +185,8 @@ static const char *place_premiumcontent_content_sunday = "SUN"; QT_USE_NAMESPACE -QPlaceJSonDetailsParser::QPlaceJSonDetailsParser(QObject *parent) : - QPlaceJSonParser(parent) +QPlaceJSonDetailsParser::QPlaceJSonDetailsParser(QPlaceManager *manager, QObject *parent) : + QPlaceJSonParser(parent), m_manager(manager) { } @@ -194,12 +194,19 @@ QPlaceJSonDetailsParser::~QPlaceJSonDetailsParser() { } -QPlace QPlaceJSonDetailsParser::buildPlace(const QScriptValue &placeValue) +QPlace QPlaceJSonDetailsParser::buildPlace(const QScriptValue &placeValue, QPlaceManager *manager) { QPlace newPlace; if (placeValue.isValid()) { buildPlace(placeValue, &newPlace); } + + if (!newPlace.icon().baseUrl().isEmpty() || !newPlace.icon().fullUrl().isEmpty()) { + QPlaceIcon icon = newPlace.icon(); + icon.setManager(manager); + newPlace.setIcon(icon); + } + return newPlace; } @@ -213,7 +220,7 @@ void QPlaceJSonDetailsParser::processJSonData(const QScriptValue &sv) if (sv.isValid()) { QScriptValue placeProperty = sv.property(place_place_element); if (placeProperty.isValid()) { - buildPlace(placeProperty, &place); + place = buildPlace(placeProperty, m_manager); emit finished(NoError, QString()); } else { emit finished(ParsingError, QString("JSON data are invalid")); @@ -278,7 +285,10 @@ void QPlaceJSonDetailsParser::processMainProvider(const QScriptValue &placeValue } value = placeValue.property(place_provider_url); if (value.isValid() && !value.toString().isEmpty()){ - sup.setSupplierIconUrl(value.toString()); + QPlaceIcon icon; + icon.setBaseUrl(value.toString()); + //Note: the icon manager is set in QPlaceJSonDetailsParser::buildPlace() + sup.setIcon(icon); } targetPlace->setSupplier(QPlaceSuppliersRepository::instance()->addSupplier(sup)); @@ -584,7 +594,13 @@ void QPlaceJSonDetailsParser::processPremiumContent(const QScriptValue &content, if (!name.isEmpty() || !id.isEmpty()) { supplier.setName(name); supplier.setSupplierId(id); - supplier.setSupplierIconUrl(iconUrl); + if (!iconUrl.isEmpty()) { + QPlaceIcon icon; + icon.setBaseUrl(iconUrl); + //note: the icon manager is set in QPlaceJSonDetailsParser::buildPlace() + supplier.setIcon(icon); + } + supplier = QPlaceSuppliersRepository::instance()->addSupplier(supplier); } processPremiumContentDescription(content, supplier, targetPlace); diff --git a/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.h b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.h index 9dd1037b..6a1c15eb 100644 --- a/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.h +++ b/src/plugins/geoservices/nokia/places/qplacejsondetailsparser.h @@ -66,10 +66,10 @@ class QPlaceJSonDetailsParser : public QPlaceJSonParser { Q_OBJECT public: - explicit QPlaceJSonDetailsParser(QObject *parent = 0); + explicit QPlaceJSonDetailsParser(QPlaceManager *manager, QObject *parent = 0); virtual ~QPlaceJSonDetailsParser(); - static QPlace buildPlace(const QScriptValue &place); + static QPlace buildPlace(const QScriptValue &place, QPlaceManager *manager); QPlace result(); private: @@ -113,6 +113,7 @@ private: private: QPlace place; + QPlaceManager *m_manager; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.cpp index 489778af..8973d555 100644 --- a/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.cpp +++ b/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.cpp @@ -66,8 +66,8 @@ static const char *recommendations_place_element = "place"; QT_USE_NAMESPACE -QPlaceJSonRecommendationParser::QPlaceJSonRecommendationParser(QObject *parent) : - QPlaceJSonParser(parent) +QPlaceJSonRecommendationParser::QPlaceJSonRecommendationParser(QPlaceManager *manager, QObject *parent) : + QPlaceJSonParser(parent), m_manager(manager) { } @@ -118,7 +118,7 @@ void QPlaceJSonRecommendationParser::processResultElement(const QScriptValue &va } QScriptValue place = value.property(recommendations_place_element); if (place.isValid()) { - QPlace newPlace = QPlaceJSonDetailsParser::buildPlace(place); + QPlace newPlace = QPlaceJSonDetailsParser::buildPlace(place, m_manager); result.setPlace(newPlace); searchResults.append(result); } diff --git a/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.h b/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.h index a9a224a7..39c711a3 100644 --- a/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.h +++ b/src/plugins/geoservices/nokia/places/qplacejsonrecommendationparser.h @@ -60,11 +60,13 @@ class QScriptValue; QT_BEGIN_NAMESPACE +class QPlaceManager; + class QPlaceJSonRecommendationParser : public QPlaceJSonParser { Q_OBJECT public: - explicit QPlaceJSonRecommendationParser(QObject *parent = 0); + explicit QPlaceJSonRecommendationParser(QPlaceManager *manager, QObject *parent = 0); virtual ~QPlaceJSonRecommendationParser(); QList<QPlaceSearchResult> results(); @@ -75,6 +77,7 @@ private: private: QList<QPlaceSearchResult> searchResults; + QPlaceManager *m_manager; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.cpp b/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.cpp index dcb3457f..a0bf281f 100644 --- a/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.cpp +++ b/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.cpp @@ -53,6 +53,8 @@ #include <QtScript/QScriptEngine> #include <QtScript/QScriptValue> #include <QtScript/QScriptValueIterator> +#include <QtLocation/QPlaceIcon> +#include <QtLocation/QPlaceManager> #include <qplacereview.h> #include <qplacesupplier.h> @@ -81,9 +83,9 @@ static const char *review_vendoricon_element = "vendorIconUrl"; QT_USE_NAMESPACE -QPlaceJSonReviewParser::QPlaceJSonReviewParser(QObject *parent) : +QPlaceJSonReviewParser::QPlaceJSonReviewParser(QPlaceManager *manager, QObject *parent) : QPlaceJSonParser(parent), - allReviews(0) + allReviews(0),m_manager(manager) { } @@ -101,7 +103,7 @@ int QPlaceJSonReviewParser::allReviewsCount() return allReviews; } -QPlaceReview QPlaceJSonReviewParser::buildReview(const QScriptValue &review) +QPlaceReview QPlaceJSonReviewParser::buildReview(const QScriptValue &review, QPlaceManager *manager) { QPlaceReview newReview; QScriptValue value = review.property(review_id_element); @@ -150,7 +152,12 @@ QPlaceReview QPlaceJSonReviewParser::buildReview(const QScriptValue &review) QPlaceSupplier sup; sup.setName(name); sup.setSupplierId(id); - sup.setSupplierIconUrl(QUrl::fromEncoded(icon.toAscii())); + if (!icon.toAscii().isEmpty()) { + QPlaceIcon supplierIcon; + supplierIcon.setBaseUrl(QUrl::fromEncoded(icon.toAscii())); + supplierIcon.setManager(manager); + sup.setIcon(supplierIcon); + } newReview.setSupplier(QPlaceSuppliersRepository::instance()->addSupplier(sup)); } @@ -192,11 +199,11 @@ void QPlaceJSonReviewParser::processReviews(const QScriptValue &reviewsElement) it.next(); // array contains count as last element if (it.name() != "length") { - reviews.append(buildReview(it.value())); + reviews.append(buildReview(it.value(), m_manager)); } } } else { - reviews.append(buildReview(value)); + reviews.append(buildReview(value, m_manager)); } } value = reviewsElement.property(review_count); diff --git a/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.h b/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.h index 183545b6..78991be5 100644 --- a/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.h +++ b/src/plugins/geoservices/nokia/places/qplacejsonreviewparser.h @@ -59,17 +59,18 @@ class QScriptEngine; class QScriptValue; QT_BEGIN_NAMESPACE +class QPlaceManager; class QPlaceJSonReviewParser : public QPlaceJSonParser { Q_OBJECT public: - explicit QPlaceJSonReviewParser(QObject *parent = 0); + explicit QPlaceJSonReviewParser(QPlaceManager *manager, QObject *parent = 0); virtual ~QPlaceJSonReviewParser(); QList<QPlaceReview> results(); int allReviewsCount(); - static QPlaceReview buildReview(const QScriptValue &place); + static QPlaceReview buildReview(const QScriptValue &place, QPlaceManager *manager); private: void processJSonData(const QScriptValue &sv); @@ -78,6 +79,7 @@ private: private: QList<QPlaceReview> reviews; int allReviews; + QPlaceManager *m_manager; }; QT_END_NAMESPACE diff --git a/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.cpp b/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.cpp index 546cf3eb..a2ec8a3f 100644 --- a/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.cpp +++ b/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.cpp @@ -57,11 +57,11 @@ QT_USE_NAMESPACE /*! Constructor. */ -QPlaceRecommendationReplyImpl::QPlaceRecommendationReplyImpl(QPlaceRestReply *reply, QObject *parent) : +QPlaceRecommendationReplyImpl::QPlaceRecommendationReplyImpl(QPlaceRestReply *reply, QPlaceManager * manager, QObject *parent) : QPlaceSearchReply(parent), restReply(reply) { - parser = new QPlaceJSonRecommendationParser(this); + parser = new QPlaceJSonRecommendationParser(manager, this); if (restReply) { restReply->setParent(this); diff --git a/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.h b/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.h index 69f0d47f..de4bd68f 100644 --- a/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.h +++ b/src/plugins/geoservices/nokia/places/qplacerecommendationreplyimpl.h @@ -62,7 +62,7 @@ class QPlaceRecommendationReplyImpl : public QPlaceSearchReply { Q_OBJECT public: - explicit QPlaceRecommendationReplyImpl(QPlaceRestReply *reply, QObject *parent = 0); + QPlaceRecommendationReplyImpl(QPlaceRestReply *reply, QPlaceManager *manager, QObject *parent = 0); ~QPlaceRecommendationReplyImpl(); void abort(); diff --git a/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.cpp b/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.cpp index 1f4ac22b..a2eada93 100644 --- a/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.cpp +++ b/src/plugins/geoservices/nokia/places/qplacesuppliersrepository.cpp @@ -92,16 +92,15 @@ QPlaceSupplier QPlaceSuppliersRepository::addSupplier(const QPlaceSupplier &src) void QPlaceSuppliersRepository::copyMissingData(const QPlaceSupplier &src, QPlaceSupplier &target) { - if (target.name().isEmpty() && !src.name().isEmpty()) { + if (target.name().isEmpty() && !src.name().isEmpty()) target.setName(src.name()); - } - if (target.supplierId().isEmpty() && !src.supplierId().isEmpty()) { + + if (target.supplierId().isEmpty() && !src.supplierId().isEmpty()) target.setSupplierId(src.supplierId()); - } - if (target.url().isEmpty() && !src.url().isEmpty()) { + + if (target.url().isEmpty() && !src.url().isEmpty()) target.setUrl(src.url()); - } - if (target.supplierIconUrl().isEmpty() && !src.supplierIconUrl().isEmpty()) { - target.setSupplierIconUrl(src.supplierIconUrl()); - } + + if (target.icon().isEmpty() && !src.icon().isEmpty()) + target.setIcon(src.icon()); } diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.cpp index b6dad2dd..a1b14bba 100644 --- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.cpp +++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.cpp @@ -100,7 +100,7 @@ QPlaceDetailsReply *QPlaceManagerEngineNokia::getPlaceDetails(const QString &pla QPlaceDetailsReplyImpl *reply = NULL; QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendPlaceRequest(placeId); if (restReply) { - reply = new QPlaceDetailsReplyImpl(restReply, this); + reply = new QPlaceDetailsReplyImpl(restReply, manager(), this); connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); connect(reply, SIGNAL(processingFinished(QPlaceReply*)), @@ -116,7 +116,7 @@ QPlaceContentReply *QPlaceManagerEngineNokia::getContent(const QPlace &place, co case QPlaceContent::ImageType: { QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendPlaceImagesRequest(place.placeId(), request); - reply = new QPlaceContentReplyImpl(request.contentType(), restReply, this); + reply = new QPlaceContentReplyImpl(request.contentType(), restReply, manager(), this); if (!restReply) QMetaObject::invokeMethod(reply, "restError", Qt::QueuedConnection, @@ -127,7 +127,7 @@ QPlaceContentReply *QPlaceManagerEngineNokia::getContent(const QPlace &place, co case QPlaceContent::ReviewType: { QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendPlaceReviewRequest(place.placeId(), request); - reply = new QPlaceContentReplyImpl(request.contentType(), restReply, this); + reply = new QPlaceContentReplyImpl(request.contentType(), restReply, manager(), this); if (!restReply) QMetaObject::invokeMethod(reply, "restError", Qt::QueuedConnection, @@ -139,7 +139,7 @@ QPlaceContentReply *QPlaceManagerEngineNokia::getContent(const QPlace &place, co QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendPlaceRequest(place.placeId()); - reply = new QPlaceContentReplyImpl(request.contentType(), restReply, this); + reply = new QPlaceContentReplyImpl(request.contentType(), restReply, manager(), this); if (!restReply) { QMetaObject::invokeMethod(reply, "restError", Qt::QueuedConnection, @@ -150,7 +150,7 @@ QPlaceContentReply *QPlaceManagerEngineNokia::getContent(const QPlace &place, co break; } default: { - reply = new QPlaceContentReplyImpl(request.contentType(), 0, this); + reply = new QPlaceContentReplyImpl(request.contentType(), 0, manager(), this); QMetaObject::invokeMethod(reply, "restError", Qt::QueuedConnection, Q_ARG(QPlaceReply::Error, QPlaceReply::UnsupportedError), Q_ARG(QString, QString("Retrieval of given content type not supported"))); @@ -207,7 +207,7 @@ QPlaceSearchReply *QPlaceManagerEngineNokia::recommendations(const QPlace &place newQuery.setSearchTerm(place.placeId()); QPlaceRestReply *restReply = QPlaceRestManager::instance()->sendRecommendationRequest(newQuery, QString()); if (restReply) { - reply = new QPlaceRecommendationReplyImpl(restReply, this); + reply = new QPlaceRecommendationReplyImpl(restReply, manager(), this); connect(reply, SIGNAL(processingError(QPlaceReply*,QPlaceReply::Error,QString)), this, SLOT(processingError(QPlaceReply*,QPlaceReply::Error,QString))); connect(reply, SIGNAL(processingFinished(QPlaceReply*)), @@ -301,6 +301,14 @@ void QPlaceManagerEngineNokia::setLocale(const QLocale &locale) QPlaceRestManager::instance()->setLocale(locale); } +QUrl QPlaceManagerEngineNokia::constructIconUrl(const QPlaceIcon &icon, const QSize &size, QPlaceIcon::IconFlags flags) +{ + Q_UNUSED(icon) + Q_UNUSED(size) + Q_UNUSED(flags) + return QUrl(); +} + void QPlaceManagerEngineNokia::processingError(QPlaceReply *reply, const QPlaceReply::Error &errorId, const QString &errorMessage) diff --git a/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.h b/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.h index 676d2ee2..d88bee9c 100644 --- a/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.h +++ b/src/plugins/geoservices/nokia/qplacemanagerengine_nokia.h @@ -90,6 +90,8 @@ public: QLocale locale() const; void setLocale(const QLocale &locale); + QUrl constructIconUrl(const QPlaceIcon &icon, const QSize &size, QPlaceIcon::IconFlags flags); + private slots: void processingError(QPlaceReply *reply, const QPlaceReply::Error &error, const QString &errorMessage); void processingFinished(QPlaceReply *reply); diff --git a/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.cpp b/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.cpp index 808843e6..f65e8e76 100644 --- a/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.cpp +++ b/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.cpp @@ -126,15 +126,21 @@ QVariant JsonDbHandler::convertToJsonVariant(const QPlace &place) map.insert(COORDINATE, coordMap); map.insert(ADDRESS, addressMap); + map.insert(ICON_URL, place.icon().fullUrl().toString()); + return map; } QVariant JsonDbHandler::convertToJsonVariant(const QPlaceCategory &category, bool isTopLevel) { QVariantMap map; + if (!category.categoryId().isEmpty()) + map.insert(UUID, category.categoryId()); + map.insert(TYPE, PLACE_CATEGORY_TYPE); map.insert(DISPLAY_NAME, category.name()); map.insert(TOP_LEVEL_CATEGORY, isTopLevel); + map.insert(ICON_URL, category.icon().fullUrl().toString()); return map; } @@ -211,6 +217,13 @@ QPlace JsonDbHandler::convertJsonVariantToPlace(const QVariant &variant) place.setLocation(location); + if (placeJson.keys().contains(ICON_URL) && !placeJson.value(ICON_URL).toString().isEmpty()) { + QPlaceIcon icon; + icon.setFullUrl(QUrl(placeJson.value(ICON_URL).toUrl())); + icon.setManager(m_engine->manager()); + place.setIcon(icon); + } + return place; } @@ -220,6 +233,14 @@ QPlaceCategory JsonDbHandler::convertJsonVariantToCategory(const QVariant &varia QPlaceCategory category; category.setName(categoryMap.value(DISPLAY_NAME).toString()); category.setCategoryId(categoryMap.value(UUID).toString()); + + if (categoryMap.keys().contains(ICON_URL) && !categoryMap.value(ICON_URL).toString().isEmpty()) { + QPlaceIcon icon; + icon.setFullUrl(QUrl(categoryMap.value(ICON_URL).toUrl())); + icon.setManager(m_engine->manager()); + category.setIcon(icon); + } + return category; } diff --git a/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.h b/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.h index f0d459a1..cf22f2a0 100644 --- a/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.h +++ b/src/plugins/geoservices/nokia_places_jsondb/jsondbhandler.h @@ -73,6 +73,8 @@ #define COUNTY "county" #define COUNTRY "country" +#define ICON_URL "iconUrl" + Q_ADDON_JSONDB_BEGIN_NAMESPACE class JsonDbClient; Q_ADDON_JSONDB_END_NAMESPACE @@ -86,7 +88,7 @@ class QPlaceCategory; class JsonDbHandler : public QObject { Q_OBJECT -#include <QVariant> + public: JsonDbHandler(QPlaceManagerEngineJsonDb *manager); @@ -102,10 +104,10 @@ public: static QVariant convertToJsonVariant(const QPlaceCategory &category, bool isTopLevel); static QString convertToQueryString(const QPlaceSearchRequest &query); - static QList<QPlace> convertJsonResponseToPlaces(const QVariant &response); - static QList<QPlaceCategory> convertJsonResponseToCategories(const QVariant &response); - static QPlace convertJsonVariantToPlace(const QVariant &variant); - static QPlaceCategory convertJsonVariantToCategory(const QVariant &variant); + QList<QPlace> convertJsonResponseToPlaces(const QVariant &response); + QList<QPlaceCategory> convertJsonResponseToCategories(const QVariant &response); + QPlace convertJsonVariantToPlace(const QVariant &variant); + QPlaceCategory convertJsonVariantToCategory(const QVariant &variant); bool isConnected(); diff --git a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp index fd51ca58..0eb65eeb 100644 --- a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp +++ b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.cpp @@ -230,8 +230,7 @@ QPlaceIdReply *QPlaceManagerEngineJsonDb::saveCategory(const QPlaceCategory &cat if (!isUpdate) { reqId = m_jsonDbHandler.write(JsonDbHandler::convertToJsonVariant(category, isTopLevel)); } else { - categoryMap.insert(DISPLAY_NAME, category.name()); - reqId = m_jsonDbHandler.update(categoryMap); + reqId = m_jsonDbHandler.update(JsonDbHandler::convertToJsonVariant(category, isTopLevel)); saveReply->setIsUpdate(); } @@ -359,7 +358,7 @@ QList<QPlaceCategory> QPlaceManagerEngineJsonDb::childCategories(const QString & } QVariantMap responseMap = m_jsonDbHandler.waitForRequest(reqId); - return JsonDbHandler::convertJsonResponseToCategories(responseMap); + return m_jsonDbHandler.convertJsonResponseToCategories(responseMap); } QLocale QPlaceManagerEngineJsonDb::locale() const @@ -372,6 +371,11 @@ void QPlaceManagerEngineJsonDb::setLocale(const QLocale &locale) Q_UNUSED(locale); } +QUrl QPlaceManagerEngineJsonDb::constructIconUrl(const QPlaceIcon &icon, const QSize &size, QPlaceIcon::IconFlags flags) +{ + return icon.fullUrl(); +} + void QPlaceManagerEngineJsonDb::processJsonDbResponse(int id, const QVariant &data) { QPlaceReply *reply = m_idReplyMap.value(id,0); @@ -472,7 +476,7 @@ void QPlaceManagerEngineJsonDb::processJsonDbResponse(int id, const QVariant &da } case QPlaceReply::SearchReply: { SearchReply *searchReply = qobject_cast<SearchReply *>(reply); - QList<QPlace> places = JsonDbHandler::convertJsonResponseToPlaces(data); + QList<QPlace> places = m_jsonDbHandler.convertJsonResponseToPlaces(data); QList<QPlaceSearchResult> results; QPlaceSearchResult result; result.setType(QPlaceSearchResult::PlaceResult); @@ -561,7 +565,7 @@ void QPlaceManagerEngineJsonDb::processJsonDbResponse(int id, const QVariant &da detailsReply->triggerDone(QPlaceReply::PlaceDoesNotExistError, tr("Specified place does not exist")); } else { - QList<QPlace> places = JsonDbHandler::convertJsonResponseToPlaces(data); + QList<QPlace> places = m_jsonDbHandler.convertJsonResponseToPlaces(data); Q_ASSERT(!places.isEmpty()); detailsReply->setPlace(places.first()); detailsReply->triggerDone(); diff --git a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h index 01b26f1f..37dc3b74 100644 --- a/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h +++ b/src/plugins/geoservices/nokia_places_jsondb/qplacemanagerengine_jsondb.h @@ -83,6 +83,7 @@ public: QLocale locale() const; void setLocale(const QLocale &locale); + QUrl constructIconUrl(const QPlaceIcon &icon, const QSize &size, QPlaceIcon::IconFlags flags); public slots: void processJsonDbResponse(int id, const QVariant &data); void processJsonDbError(int id, int code, const QString &data); |