From daf9d0eaa7e762ad8571f91a266098631b1843e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 14 Dec 2017 02:22:20 +0100 Subject: NOISSUE do not override already loaded metadata entities with partial data --- api/logic/meta/BaseEntity.h | 1 - api/logic/meta/Index.cpp | 4 ++-- api/logic/meta/Index.h | 2 +- api/logic/meta/JsonFormat.cpp | 6 +++--- api/logic/meta/Version.cpp | 42 +++++++++++++++++++++++------------------- api/logic/meta/Version.h | 3 ++- api/logic/meta/VersionList.cpp | 31 ++++++++++++++++++++++--------- api/logic/meta/VersionList.h | 3 ++- 8 files changed, 55 insertions(+), 37 deletions(-) (limited to 'api/logic') diff --git a/api/logic/meta/BaseEntity.h b/api/logic/meta/BaseEntity.h index 4c74b1a7..9120b844 100644 --- a/api/logic/meta/BaseEntity.h +++ b/api/logic/meta/BaseEntity.h @@ -46,7 +46,6 @@ public: /* types */ public: virtual ~BaseEntity(); - virtual void merge(const std::shared_ptr &other) = 0; virtual void parse(const QJsonObject &obj) = 0; virtual QString localFilename() const = 0; diff --git a/api/logic/meta/Index.cpp b/api/logic/meta/Index.cpp index 0749651a..c67ab48c 100644 --- a/api/logic/meta/Index.cpp +++ b/api/logic/meta/Index.cpp @@ -103,7 +103,7 @@ void Index::parse(const QJsonObject& obj) parseIndex(obj, this); } -void Index::merge(const Ptr &other) +void Index::merge(const std::shared_ptr &other) { const QVector lists = std::dynamic_pointer_cast(other)->m_lists; // initial load, no need to merge @@ -124,7 +124,7 @@ void Index::merge(const Ptr &other) { if (m_uids.contains(list->uid())) { - m_uids[list->uid()]->merge(list); + m_uids[list->uid()]->mergeFromIndex(list); } else { diff --git a/api/logic/meta/Index.h b/api/logic/meta/Index.h index 9811e152..d820f825 100644 --- a/api/logic/meta/Index.h +++ b/api/logic/meta/Index.h @@ -58,7 +58,7 @@ public: QVector lists() const { return m_lists; } public: // for usage by parsers only - void merge(const BaseEntity::Ptr &other) override; + void merge(const std::shared_ptr &other); void parse(const QJsonObject &obj) override; private: diff --git a/api/logic/meta/JsonFormat.cpp b/api/logic/meta/JsonFormat.cpp index 2c313478..832743ed 100644 --- a/api/logic/meta/JsonFormat.cpp +++ b/api/logic/meta/JsonFormat.cpp @@ -29,7 +29,7 @@ namespace Meta { // Index -static BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj) +static std::shared_ptr parseIndexInternal(const QJsonObject &obj) { const QVector objects = requireIsArrayOf(obj, "packages"); QVector lists; @@ -59,7 +59,7 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj) return version; } -static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj) +static std::shared_ptr parseVersionInternal(const QJsonObject &obj) { VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj); @@ -70,7 +70,7 @@ static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj) } // Version list / package -static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj) +static std::shared_ptr parseVersionListInternal(const QJsonObject &obj) { const QString uid = requireString(obj, "uid"); diff --git a/api/logic/meta/Version.cpp b/api/logic/meta/Version.cpp index d82878a1..55b92966 100644 --- a/api/logic/meta/Version.cpp +++ b/api/logic/meta/Version.cpp @@ -54,43 +54,47 @@ void Meta::Version::parse(const QJsonObject& obj) parseVersion(obj, this); } -void Meta::Version::merge(const std::shared_ptr &other) +void Meta::Version::mergeFromList(const Meta::VersionPtr& other) { - VersionPtr version = std::dynamic_pointer_cast(other); - if(version->m_providesRecommendations) + if(other->m_providesRecommendations) { - if(m_recommended != version->m_recommended) + if(m_recommended != other->m_recommended) { - setRecommended(version->m_recommended); + setRecommended(other->m_recommended); } } - if (m_type != version->m_type) + if (m_type != other->m_type) { - setType(version->m_type); + setType(other->m_type); } - if (m_time != version->m_time) + if (m_time != other->m_time) { - setTime(version->m_time); + setTime(other->m_time); } - if (m_requires != version->m_requires) + if (m_requires != other->m_requires) { - m_requires = version->m_requires; + m_requires = other->m_requires; } - if (m_conflicts != version->m_conflicts) + if (m_conflicts != other->m_conflicts) { - m_conflicts = version->m_conflicts; + m_conflicts = other->m_conflicts; } - if (m_parentUid != version->m_parentUid) + if (m_parentUid != other->m_parentUid) { - setParentUid(version->m_parentUid); + setParentUid(other->m_parentUid); } - if(m_volatile != version->m_volatile) + if(m_volatile != other->m_volatile) { - setVolatile(version->m_volatile); + setVolatile(other->m_volatile); } - if(version->m_data) +} + +void Meta::Version::merge(const VersionPtr &other) +{ + mergeFromList(other); + if(other->m_data) { - setData(version->m_data); + setData(other->m_data); } } diff --git a/api/logic/meta/Version.h b/api/logic/meta/Version.h index 61f253c6..debdf20a 100644 --- a/api/logic/meta/Version.h +++ b/api/logic/meta/Version.h @@ -84,7 +84,8 @@ public: /* con/des */ return m_data != nullptr; } - void merge(const std::shared_ptr &other) override; + void merge(const VersionPtr &other); + void mergeFromList(const VersionPtr &other); void parse(const QJsonObject &obj) override; QString localFilename() const override; diff --git a/api/logic/meta/VersionList.cpp b/api/logic/meta/VersionList.cpp index 1387f282..4963f235 100644 --- a/api/logic/meta/VersionList.cpp +++ b/api/logic/meta/VersionList.cpp @@ -19,6 +19,7 @@ #include "Version.h" #include "JsonFormat.h" +#include "Version.h" namespace Meta { @@ -189,32 +190,44 @@ static const Meta::VersionPtr &getBetterVersion(const Meta::VersionPtr &a, const return (a->type() == "release" ? a : b); } -void VersionList::merge(const BaseEntity::Ptr &other) +void VersionList::mergeFromIndex(const VersionListPtr &other) +{ + if (m_name != other->m_name) + { + setName(other->m_name); + } + + if(m_parentUid != other->m_parentUid) + { + setParentUid(other->m_parentUid); + } +} + +void VersionList::merge(const VersionListPtr &other) { - const VersionListPtr list = std::dynamic_pointer_cast(other); - if (m_name != list->m_name) + if (m_name != other->m_name) { - setName(list->m_name); + setName(other->m_name); } - if(m_parentUid != list->m_parentUid) + if(m_parentUid != other->m_parentUid) { - setParentUid(list->m_parentUid); + setParentUid(other->m_parentUid); } // TODO: do not reset the whole model. maybe? beginResetModel(); m_versions.clear(); - if(list->m_versions.isEmpty()) + if(other->m_versions.isEmpty()) { qWarning() << "Empty list loaded ..."; } - for (const VersionPtr &version : list->m_versions) + for (const VersionPtr &version : other->m_versions) { // we already have the version. merge the contents if (m_lookup.contains(version->version())) { - m_lookup.value(version->version())->merge(version); + m_lookup.value(version->version())->mergeFromList(version); } else { diff --git a/api/logic/meta/VersionList.h b/api/logic/meta/VersionList.h index e8016314..c4a2b757 100644 --- a/api/logic/meta/VersionList.h +++ b/api/logic/meta/VersionList.h @@ -80,7 +80,8 @@ public: // for usage only by parsers void setName(const QString &name); void setParentUid(const QString &parentUid); void setVersions(const QVector &versions); - void merge(const BaseEntity::Ptr &other) override; + void merge(const VersionListPtr &other); + void mergeFromIndex(const VersionListPtr &other); void parse(const QJsonObject &obj) override; signals: -- cgit v1.2.3