diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-16 13:46:56 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-22 18:09:06 +0200 |
commit | 359a2b2be21d3a8b209c1a7953675a5e2d002f5b (patch) | |
tree | 8587d15465d12e0d3d44a032db416064de5f6aad | |
parent | 8af951a0832d3262459c6e75ef2522ca0077c29e (diff) | |
download | qtlocation-359a2b2be21d3a8b209c1a7953675a5e2d002f5b.tar.gz |
Cleanup: Remove duplicate storage of values from declarative wrappers
QPlace and QPlaceCategory already store the icon, ratings, supplier etc
as values. The declarative wrappers have to emit signals when those
change, but that can only happen when either the QPlaceCategory or
QPlace itself changes, or when the individual sub-properties are changed
through the setters of the declarative type.
So we can remove the double-book-keeping and treat those value types
like all other values (e.g. QPlace::name).
Change-Id: I2703529ee625e23937b3d12ec57e60500f8e1e62
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
4 files changed, 39 insertions, 61 deletions
diff --git a/src/location/declarativeplaces/qdeclarativecategory.cpp b/src/location/declarativeplaces/qdeclarativecategory.cpp index e4ca6168..a8bcf10c 100644 --- a/src/location/declarativeplaces/qdeclarativecategory.cpp +++ b/src/location/declarativeplaces/qdeclarativecategory.cpp @@ -165,12 +165,12 @@ void QDeclarativeCategory::setCategory(const QPlaceCategory &category) if (category.categoryId() != previous.categoryId()) emit categoryIdChanged(); - setIcon(m_category.icon()); + if (category.icon() != previous.icon()) + emit iconChanged(); } QPlaceCategory QDeclarativeCategory::category() { - m_category.setIcon(m_icon); return m_category; } @@ -262,16 +262,15 @@ void QDeclarativeCategory::setVisibility(Visibility visibility) */ QPlaceIcon QDeclarativeCategory::icon() const { - return m_icon; + return m_category.icon(); } void QDeclarativeCategory::setIcon(const QPlaceIcon &icon) { - if (m_icon == icon) - return; - - m_icon = icon; - emit iconChanged(); + if (m_category.icon() != icon) { + m_category.setIcon(icon); + emit iconChanged(); + } } /*! diff --git a/src/location/declarativeplaces/qdeclarativecategory_p.h b/src/location/declarativeplaces/qdeclarativecategory_p.h index e762b726..c4a0b4f3 100644 --- a/src/location/declarativeplaces/qdeclarativecategory_p.h +++ b/src/location/declarativeplaces/qdeclarativecategory_p.h @@ -141,7 +141,6 @@ private: QPlaceManager *manager(); QPlaceCategory m_category; - QPlaceIcon m_icon; QDeclarativeGeoServiceProvider *m_plugin = nullptr; QPlaceReply *m_reply = nullptr; bool m_complete = false; diff --git a/src/location/declarativeplaces/qdeclarativeplace.cpp b/src/location/declarativeplaces/qdeclarativeplace.cpp index 5cdb7649..f4b14f9c 100644 --- a/src/location/declarativeplaces/qdeclarativeplace.cpp +++ b/src/location/declarativeplaces/qdeclarativeplace.cpp @@ -324,34 +324,28 @@ void QDeclarativePlace::setPlace(const QPlace &src) emit locationChanged(); } - setRatings(m_src.ratings()); - setSupplier(m_src.supplier()); - setIcon(m_src.icon()); - - if (previous.name() != m_src.name()) { + if (previous.ratings() != m_src.ratings()) + emit ratingsChanged(); + if (previous.supplier() != m_src.supplier()) + emit supplierChanged(); + if (previous.icon() != m_src.icon()) + emit iconChanged(); + if (previous.name() != m_src.name()) emit nameChanged(); - } - if (previous.placeId() != m_src.placeId()) { + if (previous.placeId() != m_src.placeId()) emit placeIdChanged(); - } - if (previous.attribution() != m_src.attribution()) { + if (previous.attribution() != m_src.attribution()) emit attributionChanged(); - } - if (previous.detailsFetched() != m_src.detailsFetched()) { + if (previous.detailsFetched() != m_src.detailsFetched()) emit detailsFetchedChanged(); - } - if (previous.primaryPhone() != m_src.primaryPhone()) { + if (previous.primaryPhone() != m_src.primaryPhone()) emit primaryPhoneChanged(); - } - if (previous.primaryFax() != m_src.primaryFax()) { + if (previous.primaryFax() != m_src.primaryFax()) emit primaryFaxChanged(); - } - if (previous.primaryEmail() != m_src.primaryEmail()) { + if (previous.primaryEmail() != m_src.primaryEmail()) emit primaryEmailChanged(); - } - if (previous.primaryWebsite() != m_src.primaryWebsite()) { + if (previous.primaryWebsite() != m_src.primaryWebsite()) emit primaryWebsiteChanged(); - } if (m_reviewModel && m_src.totalContentCount(QPlaceContent::ReviewType) >= 0) { m_reviewModel->initializeCollection(m_src.totalContentCount(QPlaceContent::ReviewType), @@ -372,7 +366,9 @@ void QDeclarativePlace::setPlace(const QPlace &src) QPlace QDeclarativePlace::place() const { - // The following properties are not stored in m_src but instead stored in QDeclarative* objects + // The properties handled explicirly here are not stored in m_src, but + // but are instead stored in QDeclarative* objects which we need to update + // explicitly. QPlace result = m_src; @@ -386,15 +382,6 @@ QPlace QDeclarativePlace::place() const // Location result.setLocation(m_location ? m_location->location() : QGeoLocation()); - // Rating - result.setRatings(m_ratings); - - // Supplier - result.setSupplier(m_supplier); - - // Icon - result.setIcon(m_icon); - //contact details QList<QPlaceContactDetail> cppDetails; for (const QString &key : m_contactDetails->keys()) { @@ -443,17 +430,15 @@ QDeclarativeGeoLocation *QDeclarativePlace::location() const */ void QDeclarativePlace::setRatings(const QPlaceRatings &rating) { - if (m_ratings == rating) - return; - - m_ratings = rating; - emit ratingsChanged(); + if (m_src.ratings() != rating) { + m_src.setRatings(rating); + emit ratingsChanged(); + } } QPlaceRatings QDeclarativePlace::ratings() const { - - return m_ratings; + return m_src.ratings(); } /*! @@ -464,16 +449,15 @@ QPlaceRatings QDeclarativePlace::ratings() const */ void QDeclarativePlace::setSupplier(const QPlaceSupplier &supplier) { - if (m_supplier == supplier) - return; - - m_supplier = supplier; - emit supplierChanged(); + if (m_src.supplier() != supplier) { + m_src.setSupplier(supplier); + emit supplierChanged(); + } } QPlaceSupplier QDeclarativePlace::supplier() const { - return m_supplier; + return m_src.supplier(); } /*! @@ -483,16 +467,15 @@ QPlaceSupplier QDeclarativePlace::supplier() const */ QPlaceIcon QDeclarativePlace::icon() const { - return m_icon; + return m_src.icon(); } void QDeclarativePlace::setIcon(const QPlaceIcon &icon) { - if (m_icon == icon) - return; - - m_icon = icon; - emit iconChanged(); + if (m_src.icon() != icon) { + m_src.setIcon(icon); + emit iconChanged(); + } } /*! diff --git a/src/location/declarativeplaces/qdeclarativeplace_p.h b/src/location/declarativeplaces/qdeclarativeplace_p.h index 9774b8eb..e4d94017 100644 --- a/src/location/declarativeplaces/qdeclarativeplace_p.h +++ b/src/location/declarativeplaces/qdeclarativeplace_p.h @@ -226,9 +226,6 @@ private: QList<QDeclarativeCategory *> m_categories; QDeclarativeGeoLocation *m_location = nullptr; - QPlaceRatings m_ratings; - QPlaceSupplier m_supplier; - QPlaceIcon m_icon; QDeclarativePlaceReviewModel *m_reviewModel = nullptr; QDeclarativePlaceImageModel *m_imageModel = nullptr; QDeclarativePlaceEditorialModel *m_editorialModel = nullptr; |