From bc911923d096cc043fbe7b17e32fadd19339ccd3 Mon Sep 17 00:00:00 2001 From: Malte Langkabel Date: Sun, 22 Dec 2019 14:19:51 +0100 Subject: [PATCH] logic: improved handling of unloadable source group (#862) * improve comparison to respect all values * improved UI to display the source group type --- src/lib/CMakeLists.txt | 1 + .../type/SourceGroupSettingsUnloadable.cpp | 85 +++++++++++++++++++ .../type/SourceGroupSettingsUnloadable.h | 69 +++------------ .../QtProjectWizardContentUnloadable.cpp | 8 +- 4 files changed, 100 insertions(+), 63 deletions(-) create mode 100644 src/lib/settings/source_group/type/SourceGroupSettingsUnloadable.cpp diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 71cddbdf..c9624c28 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -354,6 +354,7 @@ add_files( settings/source_group/component/SourceGroupSettingsWithSourcePaths.cpp settings/source_group/component/SourceGroupSettingsWithSourcePaths.h + settings/source_group/type/SourceGroupSettingsUnloadable.cpp settings/source_group/type/SourceGroupSettingsUnloadable.h settings/source_group/SourceGroupSettings.cpp diff --git a/src/lib/settings/source_group/type/SourceGroupSettingsUnloadable.cpp b/src/lib/settings/source_group/type/SourceGroupSettingsUnloadable.cpp new file mode 100644 index 00000000..4467ea16 --- /dev/null +++ b/src/lib/settings/source_group/type/SourceGroupSettingsUnloadable.cpp @@ -0,0 +1,85 @@ +#include "SourceGroupSettingsUnloadable.h" + +#include "ConfigManager.h" +#include "utility.h" + +SourceGroupSettingsUnloadable::SourceGroupSettingsUnloadable( + const std::string& id, const ProjectSettings* projectSettings) + : SourceGroupSettings(SOURCE_GROUP_UNKNOWN, id, projectSettings) +{ +} + +std::string SourceGroupSettingsUnloadable::getTypeString() +{ + return m_typeString; +} + +std::shared_ptr SourceGroupSettingsUnloadable::createCopy() const +{ + return std::make_shared(*this); +} + +void SourceGroupSettingsUnloadable::loadSettings(const ConfigManager* config) +{ + const std::string key = s_keyPrefix + getId(); + + SourceGroupSettings::load(config, key); + setStatus(SOURCE_GROUP_STATUS_DISABLED); + + m_typeString = config->getValueOrDefault(key + "/type", ""); + + m_content.clear(); + + std::vector unprocessedKeys = {key}; + + while (!unprocessedKeys.empty()) + { + const std::string unprocessedKey = unprocessedKeys.back(); + unprocessedKeys.pop_back(); + for (const std::string& memberKey: config->getSublevelKeys(unprocessedKey)) + { + const std::vector values = config->getValuesOrDefaults( + memberKey, {}); + if (!values.empty()) + { + m_content[memberKey] = values; + } + else + { + unprocessedKeys.push_back(memberKey); + } + } + } +} + +void SourceGroupSettingsUnloadable::saveSettings(ConfigManager* config) +{ + for (auto it: m_content) + { + config->setValues(it.first, it.second); + } +} + +bool SourceGroupSettingsUnloadable::equalsSettings(const SourceGroupSettingsBase* other) +{ + if (!SourceGroupSettings::equals(other)) + { + return false; + } + + if (const SourceGroupSettingsUnloadable* otherUnloadable = + dynamic_cast(other)) + { + for (auto it: m_content) + { + auto otherIt = otherUnloadable->m_content.find(it.first); + if (otherIt == otherUnloadable->m_content.end() || + !utility::isPermutation(it.second, otherIt->second)) + { + return false; + } + } + return true; + } + return false; +} diff --git a/src/lib/settings/source_group/type/SourceGroupSettingsUnloadable.h b/src/lib/settings/source_group/type/SourceGroupSettingsUnloadable.h index 693e00d7..3fe3e5af 100644 --- a/src/lib/settings/source_group/type/SourceGroupSettingsUnloadable.h +++ b/src/lib/settings/source_group/type/SourceGroupSettingsUnloadable.h @@ -1,72 +1,23 @@ #ifndef SOURCE_GROUP_SETTINGS_UNLOADABLE_H #define SOURCE_GROUP_SETTINGS_UNLOADABLE_H +#include +#include + #include "SourceGroupSettings.h" class SourceGroupSettingsUnloadable: public SourceGroupSettings { public: - SourceGroupSettingsUnloadable(const std::string& id, const ProjectSettings* projectSettings) - : SourceGroupSettings(SOURCE_GROUP_UNKNOWN, id, projectSettings) - { - } - - std::shared_ptr createCopy() const override - { - return std::make_shared(*this); - } - - void loadSettings(const ConfigManager* config) override - { - const std::string key = s_keyPrefix + getId(); - - SourceGroupSettings::load(config, key); - setStatus(SOURCE_GROUP_STATUS_DISABLED); - - m_content.clear(); - - std::vector unprocessedKeys = {key}; - - while (!unprocessedKeys.empty()) - { - const std::string unprocessedKey = unprocessedKeys.back(); - unprocessedKeys.pop_back(); - for (const std::string& memberKey: config->getSublevelKeys(unprocessedKey)) - { - const std::vector values = config->getValuesOrDefaults( - memberKey, {}); - if (!values.empty()) - { - m_content[memberKey] = values; - } - else - { - unprocessedKeys.push_back(memberKey); - } - } - } - } - - void saveSettings(ConfigManager* config) override - { - for (auto it: m_content) - { - config->setValues(it.first, it.second); - } - } - - bool equalsSettings(const SourceGroupSettingsBase* other) override - { - if (!SourceGroupSettings::equals(other)) - { - return false; - } - // compare values - - return true; - } + SourceGroupSettingsUnloadable(const std::string& id, const ProjectSettings* projectSettings); + std::string getTypeString(); + std::shared_ptr createCopy() const override; + void loadSettings(const ConfigManager* config) override; + void saveSettings(ConfigManager* config) override; + bool equalsSettings(const SourceGroupSettingsBase* other) override; private: + std::string m_typeString; std::map> m_content; }; diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentUnloadable.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentUnloadable.cpp index 2a4be0b0..5ce35132 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentUnloadable.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentUnloadable.cpp @@ -7,7 +7,7 @@ #include "FileSystem.h" #include "ProjectSettings.h" -#include "SourceGroupSettingsCustomCommand.h" +#include "SourceGroupSettingsUnloadable.h" #include "SqliteIndexStorage.h" QtProjectWizardContentUnloadable::QtProjectWizardContentUnloadable( @@ -29,9 +29,9 @@ void QtProjectWizardContentUnloadable::populate(QGridLayout* layout, int& row) layoutHorz->addSpacing(60); - QLabel* infoLabel = new QLabel( - "

The selected item uses a Source Group type that is not supportetd by this version of " - "Sourcetrail.

"); + QLabel* infoLabel = new QLabel(QString::fromStdString( + "

The type \"" + m_settings->getTypeString() + + "\" of the selected Source Group is not supportetd by this version of Sourcetrail.

")); infoLabel->setObjectName("info"); infoLabel->setWordWrap(true); layoutHorz->addWidget(infoLabel);