logic: improved handling of unloadable source group (#862)
* improve comparison to respect all values * improved UI to display the source group type
This commit is contained in:
@@ -354,6 +354,7 @@ add_files(
|
|||||||
settings/source_group/component/SourceGroupSettingsWithSourcePaths.cpp
|
settings/source_group/component/SourceGroupSettingsWithSourcePaths.cpp
|
||||||
settings/source_group/component/SourceGroupSettingsWithSourcePaths.h
|
settings/source_group/component/SourceGroupSettingsWithSourcePaths.h
|
||||||
|
|
||||||
|
settings/source_group/type/SourceGroupSettingsUnloadable.cpp
|
||||||
settings/source_group/type/SourceGroupSettingsUnloadable.h
|
settings/source_group/type/SourceGroupSettingsUnloadable.h
|
||||||
|
|
||||||
settings/source_group/SourceGroupSettings.cpp
|
settings/source_group/SourceGroupSettings.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<SourceGroupSettings> SourceGroupSettingsUnloadable::createCopy() const
|
||||||
|
{
|
||||||
|
return std::make_shared<SourceGroupSettingsUnloadable>(*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<std::string>(key + "/type", "");
|
||||||
|
|
||||||
|
m_content.clear();
|
||||||
|
|
||||||
|
std::vector<std::string> 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<std::string> values = config->getValuesOrDefaults<std::string>(
|
||||||
|
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<const SourceGroupSettingsUnloadable*>(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;
|
||||||
|
}
|
||||||
@@ -1,72 +1,23 @@
|
|||||||
#ifndef SOURCE_GROUP_SETTINGS_UNLOADABLE_H
|
#ifndef SOURCE_GROUP_SETTINGS_UNLOADABLE_H
|
||||||
#define SOURCE_GROUP_SETTINGS_UNLOADABLE_H
|
#define SOURCE_GROUP_SETTINGS_UNLOADABLE_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "SourceGroupSettings.h"
|
#include "SourceGroupSettings.h"
|
||||||
|
|
||||||
class SourceGroupSettingsUnloadable: public SourceGroupSettings
|
class SourceGroupSettingsUnloadable: public SourceGroupSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SourceGroupSettingsUnloadable(const std::string& id, const ProjectSettings* projectSettings)
|
SourceGroupSettingsUnloadable(const std::string& id, const ProjectSettings* projectSettings);
|
||||||
: SourceGroupSettings(SOURCE_GROUP_UNKNOWN, id, projectSettings)
|
std::string getTypeString();
|
||||||
{
|
std::shared_ptr<SourceGroupSettings> createCopy() const override;
|
||||||
}
|
void loadSettings(const ConfigManager* config) override;
|
||||||
|
void saveSettings(ConfigManager* config) override;
|
||||||
std::shared_ptr<SourceGroupSettings> createCopy() const override
|
bool equalsSettings(const SourceGroupSettingsBase* other) override;
|
||||||
{
|
|
||||||
return std::make_shared<SourceGroupSettingsUnloadable>(*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<std::string> 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<std::string> values = config->getValuesOrDefaults<std::string>(
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string m_typeString;
|
||||||
std::map<std::string, std::vector<std::string>> m_content;
|
std::map<std::string, std::vector<std::string>> m_content;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "ProjectSettings.h"
|
#include "ProjectSettings.h"
|
||||||
#include "SourceGroupSettingsCustomCommand.h"
|
#include "SourceGroupSettingsUnloadable.h"
|
||||||
#include "SqliteIndexStorage.h"
|
#include "SqliteIndexStorage.h"
|
||||||
|
|
||||||
QtProjectWizardContentUnloadable::QtProjectWizardContentUnloadable(
|
QtProjectWizardContentUnloadable::QtProjectWizardContentUnloadable(
|
||||||
@@ -29,9 +29,9 @@ void QtProjectWizardContentUnloadable::populate(QGridLayout* layout, int& row)
|
|||||||
|
|
||||||
layoutHorz->addSpacing(60);
|
layoutHorz->addSpacing(60);
|
||||||
|
|
||||||
QLabel* infoLabel = new QLabel(
|
QLabel* infoLabel = new QLabel(QString::fromStdString(
|
||||||
"<p>The selected item uses a Source Group type that is not supportetd by this version of "
|
"<p>The type \"" + m_settings->getTypeString() +
|
||||||
"Sourcetrail.</p>");
|
"\" of the selected Source Group is not supportetd by this version of Sourcetrail.</p>"));
|
||||||
infoLabel->setObjectName("info");
|
infoLabel->setObjectName("info");
|
||||||
infoLabel->setWordWrap(true);
|
infoLabel->setWordWrap(true);
|
||||||
layoutHorz->addWidget(infoLabel);
|
layoutHorz->addWidget(infoLabel);
|
||||||
|
|||||||
Reference in New Issue
Block a user