Skip to content

Commit

Permalink
replace QVariantMap by Utils::Store in to/from mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrauch committed Nov 11, 2023
1 parent c6be458 commit 58a22a7
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 102 deletions.
17 changes: 8 additions & 9 deletions src/project_manager/ros_build_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,19 @@ void ROSBuildConfiguration::initialize(const ProjectExplorer::BuildInfo &info)
}
}

QVariantMap ROSBuildConfiguration::toMap() const
void ROSBuildConfiguration::toMap(Utils::Store &map) const
{
QVariantMap map(BuildConfiguration::toMap());
BuildConfiguration::toMap(map);

map.insert(QLatin1String(ROS_BC_BUILD_SYSTEM), (int)m_buildSystem);
map.insert(QLatin1String(ROS_BC_CMAKE_BUILD_TYPE), (int)m_cmakeBuildType);
return map;
map.insert(ROS_BC_BUILD_SYSTEM, (int)m_buildSystem);
map.insert(ROS_BC_CMAKE_BUILD_TYPE, (int)m_cmakeBuildType);
}

bool ROSBuildConfiguration::fromMap(const QVariantMap &map)
void ROSBuildConfiguration::fromMap(const Utils::Store &map)
{
m_buildSystem = (ROSUtils::BuildSystem)map.value(QLatin1String(ROS_BC_BUILD_SYSTEM)).toInt();
m_cmakeBuildType = (ROSUtils::BuildType)map.value(QLatin1String(ROS_BC_CMAKE_BUILD_TYPE)).toInt();
return BuildConfiguration::fromMap(map);
m_buildSystem = (ROSUtils::BuildSystem)map.value(ROS_BC_BUILD_SYSTEM).toInt();
m_cmakeBuildType = (ROSUtils::BuildType)map.value(ROS_BC_CMAKE_BUILD_TYPE).toInt();
BuildConfiguration::fromMap(map);
}

ROSUtils::BuildSystem ROSBuildConfiguration::rosBuildSystem() const
Expand Down
4 changes: 2 additions & 2 deletions src/project_manager/ros_build_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ROSBuildConfiguration : public ProjectExplorer::BuildConfiguration

BuildType buildType() const override;

QVariantMap toMap() const override;
void toMap(Utils::Store &map) const override;

ROSUtils::BuildSystem rosBuildSystem() const;
void setBuildSystem(const ROSUtils::BuildSystem &buildSystem);
Expand All @@ -87,7 +87,7 @@ class ROSBuildConfiguration : public ProjectExplorer::BuildConfiguration
void cmakeBuildTypeChanged(const ROSUtils::BuildType &buildType);

protected:
bool fromMap(const QVariantMap &map) override;
void fromMap(const Utils::Store &map) override;

friend class ROSBuildSettingsWidget;

Expand Down
25 changes: 12 additions & 13 deletions src/project_manager/ros_catkin_make_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,24 @@ void ROSCatkinMakeStep::setupOutputFormatter(Utils::OutputFormatter *formatter)
AbstractProcessStep::setupOutputFormatter(formatter);
}

QVariantMap ROSCatkinMakeStep::toMap() const
void ROSCatkinMakeStep::toMap(Utils::Store &map) const
{
QVariantMap map(AbstractProcessStep::toMap());
AbstractProcessStep::toMap(map);

map.insert(QLatin1String(ROS_CMS_TARGET_KEY), m_target);
map.insert(QLatin1String(ROS_CMS_CATKIN_MAKE_ARGUMENTS_KEY), m_catkinMakeArguments);
map.insert(QLatin1String(ROS_CMS_CMAKE_ARGUMENTS_KEY), m_cmakeArguments);
map.insert(QLatin1String(ROS_CMS_MAKE_ARGUMENTS_KEY), m_makeArguments);
return map;
map.insert(ROS_CMS_TARGET_KEY, m_target);
map.insert(ROS_CMS_CATKIN_MAKE_ARGUMENTS_KEY, m_catkinMakeArguments);
map.insert(ROS_CMS_CMAKE_ARGUMENTS_KEY, m_cmakeArguments);
map.insert(ROS_CMS_MAKE_ARGUMENTS_KEY, m_makeArguments);
}

bool ROSCatkinMakeStep::fromMap(const QVariantMap &map)
void ROSCatkinMakeStep::fromMap(const Utils::Store &map)
{
m_target = (BuildTargets)map.value(QLatin1String(ROS_CMS_TARGET_KEY)).toInt();
m_catkinMakeArguments = map.value(QLatin1String(ROS_CMS_CATKIN_MAKE_ARGUMENTS_KEY)).toString();
m_cmakeArguments = map.value(QLatin1String(ROS_CMS_CMAKE_ARGUMENTS_KEY)).toString();
m_makeArguments = map.value(QLatin1String(ROS_CMS_MAKE_ARGUMENTS_KEY)).toString();
m_target = (BuildTargets)map.value(ROS_CMS_TARGET_KEY).toInt();
m_catkinMakeArguments = map.value(ROS_CMS_CATKIN_MAKE_ARGUMENTS_KEY).toString();
m_cmakeArguments = map.value(ROS_CMS_CMAKE_ARGUMENTS_KEY).toString();
m_makeArguments = map.value(ROS_CMS_MAKE_ARGUMENTS_KEY).toString();

return BuildStep::fromMap(map);
BuildStep::fromMap(map);
}

QWidget *ROSCatkinMakeStep::createConfigWidget()
Expand Down
4 changes: 2 additions & 2 deletions src/project_manager/ros_catkin_make_step.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class ROSCatkinMakeStep : public ProjectExplorer::AbstractProcessStep
QString allArguments(ROSUtils::BuildType buildType, bool includeDefault = true) const;
Utils::CommandLine makeCommand(const QString &args) const;

QVariantMap toMap() const override;
void toMap(Utils::Store &map) const override;

protected:
QStringList automaticallyAddedArguments() const;
bool fromMap(const QVariantMap &map) override;
void fromMap(const Utils::Store &map) override;
QWidget *createConfigWidget() override;

private:
Expand Down
39 changes: 19 additions & 20 deletions src/project_manager/ros_catkin_tools_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,34 +152,33 @@ void ROSCatkinToolsStep::setupOutputFormatter(Utils::OutputFormatter *formatter)
AbstractProcessStep::setupOutputFormatter(formatter);
}

QVariantMap ROSCatkinToolsStep::toMap() const
void ROSCatkinToolsStep::toMap(Utils::Store &map) const
{
QVariantMap map(AbstractProcessStep::toMap());
AbstractProcessStep::toMap(map);

map.insert(QLatin1String(ROS_CTS_TARGET_KEY), m_target);
map.insert(QLatin1String(ROS_CTS_ACTIVE_PROFILE_KEY), m_activeProfile);
map.insert(QLatin1String(ROS_CTS_CATKIN_TOOLS_ARGUMENTS_KEY), m_catkinToolsArguments);
map.insert(QLatin1String(ROS_CTS_CATKIN_MAKE_ARGUMENTS_KEY), m_catkinMakeArguments);
map.insert(QLatin1String(ROS_CTS_CMAKE_ARGUMENTS_KEY), m_cmakeArguments);
map.insert(QLatin1String(ROS_CTS_MAKE_ARGUMENTS_KEY), m_makeArguments);
map.insert(QLatin1String(ROS_CTS_CATKIN_TOOLS_WORKING_DIR_KEY), m_catkinToolsWorkingDir);
return map;
map.insert(ROS_CTS_TARGET_KEY, m_target);
map.insert(ROS_CTS_ACTIVE_PROFILE_KEY, m_activeProfile);
map.insert(ROS_CTS_CATKIN_TOOLS_ARGUMENTS_KEY, m_catkinToolsArguments);
map.insert(ROS_CTS_CATKIN_MAKE_ARGUMENTS_KEY, m_catkinMakeArguments);
map.insert(ROS_CTS_CMAKE_ARGUMENTS_KEY, m_cmakeArguments);
map.insert(ROS_CTS_MAKE_ARGUMENTS_KEY, m_makeArguments);
map.insert(ROS_CTS_CATKIN_TOOLS_WORKING_DIR_KEY, m_catkinToolsWorkingDir);
}

bool ROSCatkinToolsStep::fromMap(const QVariantMap &map)
void ROSCatkinToolsStep::fromMap(const Utils::Store &map)
{
m_target = (BuildTargets)map.value(QLatin1String(ROS_CTS_TARGET_KEY)).toInt();
m_activeProfile = map.value(QLatin1String(ROS_CTS_ACTIVE_PROFILE_KEY)).toString();
m_catkinToolsArguments = map.value(QLatin1String(ROS_CTS_CATKIN_TOOLS_ARGUMENTS_KEY)).toString();
m_catkinMakeArguments = map.value(QLatin1String(ROS_CTS_CATKIN_MAKE_ARGUMENTS_KEY)).toString();
m_cmakeArguments = map.value(QLatin1String(ROS_CTS_CMAKE_ARGUMENTS_KEY)).toString();
m_makeArguments = map.value(QLatin1String(ROS_CTS_MAKE_ARGUMENTS_KEY)).toString();
m_catkinToolsWorkingDir = map.value(QLatin1String(ROS_CTS_CATKIN_TOOLS_WORKING_DIR_KEY)).toString();
m_target = (BuildTargets)map.value(ROS_CTS_TARGET_KEY).toInt();
m_activeProfile = map.value(ROS_CTS_ACTIVE_PROFILE_KEY).toString();
m_catkinToolsArguments = map.value(ROS_CTS_CATKIN_TOOLS_ARGUMENTS_KEY).toString();
m_catkinMakeArguments = map.value(ROS_CTS_CATKIN_MAKE_ARGUMENTS_KEY).toString();
m_cmakeArguments = map.value(ROS_CTS_CMAKE_ARGUMENTS_KEY).toString();
m_makeArguments = map.value(ROS_CTS_MAKE_ARGUMENTS_KEY).toString();
m_catkinToolsWorkingDir = map.value(ROS_CTS_CATKIN_TOOLS_WORKING_DIR_KEY).toString();

if (m_catkinToolsWorkingDir.isEmpty())
m_catkinToolsWorkingDir = Constants::ROS_DEFAULT_WORKING_DIR;

return BuildStep::fromMap(map);
BuildStep::fromMap(map);
}

QWidget *ROSCatkinToolsStep::createConfigWidget()
Expand Down Expand Up @@ -280,7 +279,7 @@ ROSCatkinToolsStepWidget::ROSCatkinToolsStepWidget(ROSCatkinToolsStep *makeStep)
m_ui->makeArgumentsLineEdit->setText(m_makeStep->m_makeArguments);

m_ui->catkinToolsWorkingDirWidget->setPath(m_makeStep->m_catkinToolsWorkingDir);
m_ui->catkinToolsWorkingDirWidget->setHistoryCompleter(QLatin1String("Qt.WorkingDir.History"));
m_ui->catkinToolsWorkingDirWidget->setHistoryCompleter("Qt.WorkingDir.History");
m_ui->catkinToolsWorkingDirWidget->setExpectedKind(Utils::PathChooser::Directory);
m_ui->catkinToolsWorkingDirWidget->setFilePath(makeStep->rosBuildConfiguration()->project()->projectDirectory());

Expand Down
4 changes: 2 additions & 2 deletions src/project_manager/ros_catkin_tools_step.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ class ROSCatkinToolsStep : public ProjectExplorer::AbstractProcessStep
QString allArguments(ROSUtils::BuildType buildType, bool includeDefault = true) const;
Utils::CommandLine makeCommand(const QString &args) const;

QVariantMap toMap() const override;
void toMap(Utils::Store &map) const override;

protected:
QStringList automaticallyAddedArguments() const;
bool fromMap(const QVariantMap &map) override;
void fromMap(const Utils::Store &map) override;
QWidget *createConfigWidget() override;

private:
Expand Down
25 changes: 12 additions & 13 deletions src/project_manager/ros_colcon_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,24 @@ void ROSColconStep::setupOutputFormatter(Utils::OutputFormatter *formatter)
AbstractProcessStep::setupOutputFormatter(formatter);
}

QVariantMap ROSColconStep::toMap() const
void ROSColconStep::toMap(Utils::Store &map) const
{
QVariantMap map(AbstractProcessStep::toMap());
AbstractProcessStep::toMap(map);

map.insert(QLatin1String(ROS_COLCON_STEP), m_target);
map.insert(QLatin1String(ROS_COLCON_STEP_ARGUMENTS_KEY), m_colconArguments);
map.insert(QLatin1String(ROS_COLCON_STEP_CMAKE_ARGUMENTS_KEY), m_cmakeArguments);
map.insert(QLatin1String(ROS_COLCON_STEP_MAKE_ARGUMENTS_KEY), m_makeArguments);
return map;
map.insert(ROS_COLCON_STEP, m_target);
map.insert(ROS_COLCON_STEP_ARGUMENTS_KEY, m_colconArguments);
map.insert(ROS_COLCON_STEP_CMAKE_ARGUMENTS_KEY, m_cmakeArguments);
map.insert(ROS_COLCON_STEP_MAKE_ARGUMENTS_KEY, m_makeArguments);
}

bool ROSColconStep::fromMap(const QVariantMap &map)
void ROSColconStep::fromMap(const Utils::Store &map)
{
m_target = (BuildTargets)map.value(QLatin1String(ROS_COLCON_STEP)).toInt();
m_colconArguments = map.value(QLatin1String(ROS_COLCON_STEP_ARGUMENTS_KEY)).toString();
m_cmakeArguments = map.value(QLatin1String(ROS_COLCON_STEP_CMAKE_ARGUMENTS_KEY)).toString();
m_makeArguments = map.value(QLatin1String(ROS_COLCON_STEP_MAKE_ARGUMENTS_KEY)).toString();
m_target = (BuildTargets)map.value(ROS_COLCON_STEP).toInt();
m_colconArguments = map.value(ROS_COLCON_STEP_ARGUMENTS_KEY).toString();
m_cmakeArguments = map.value(ROS_COLCON_STEP_CMAKE_ARGUMENTS_KEY).toString();
m_makeArguments = map.value(ROS_COLCON_STEP_MAKE_ARGUMENTS_KEY).toString();

return BuildStep::fromMap(map);
BuildStep::fromMap(map);
}

QWidget *ROSColconStep::createConfigWidget()
Expand Down
4 changes: 2 additions & 2 deletions src/project_manager/ros_colcon_step.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ class ROSColconStep : public ProjectExplorer::AbstractProcessStep
QString allArguments(ROSUtils::BuildType buildType, bool includeDefault = true) const;
Utils::CommandLine makeCommand(const QString &args) const;

QVariantMap toMap() const override;
void toMap(Utils::Store &map) const override;

protected:
QStringList automaticallyAddedArguments() const;
bool fromMap(const QVariantMap &map) override;
void fromMap(const Utils::Store &map) override;
QWidget *createConfigWidget() override;

private:
Expand Down
9 changes: 4 additions & 5 deletions src/project_manager/ros_generic_run_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ void ROSGenericRunStep::run()
#endif
}

QVariantMap ROSGenericRunStep::toMap() const
void ROSGenericRunStep::toMap(Utils::Store &map) const
{
QVariantMap map(RunStep::toMap());
RunStep::toMap(map);

map.insert(ROS_GENERIC_COMMAND_KEY, m_command);
map.insert(ROS_GENERIC_PACKAGE_KEY, m_package);
Expand All @@ -139,10 +139,9 @@ QVariantMap ROSGenericRunStep::toMap() const
map.insert(ROS_GENERIC_TARGET_PATH_KEY, m_targetPath);
map.insert(ROS_GENERIC_ARGUMENTS_KEY, m_arguments);
map.insert(ROS_GENERIC_DEBUG_CONTINUE_ON_ATTACH_KEY, m_debugContinueOnAttach);
return map;
}

bool ROSGenericRunStep::fromMap(const QVariantMap &map)
void ROSGenericRunStep::fromMap(const Utils::Store &map)
{
m_command = map.value(ROS_GENERIC_COMMAND_KEY).toString();
m_package = map.value(ROS_GENERIC_PACKAGE_KEY).toString();
Expand All @@ -152,7 +151,7 @@ bool ROSGenericRunStep::fromMap(const QVariantMap &map)
m_arguments = map.value(ROS_GENERIC_ARGUMENTS_KEY).toString();
m_debugContinueOnAttach = map.value(ROS_GENERIC_DEBUG_CONTINUE_ON_ATTACH_KEY).toBool();

return RunStep::fromMap(map);
RunStep::fromMap(map);
}

ROSRunConfiguration *ROSGenericRunStep::rosRunConfiguration() const
Expand Down
4 changes: 2 additions & 2 deletions src/project_manager/ros_generic_run_step.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ROSGenericRunStep : public RunStep

RunStepConfigWidget *createConfigWidget() override;

QVariantMap toMap() const override;
void toMap(Utils::Store &map) const override;

ROSRunConfiguration *rosRunConfiguration() const;
ROSRunConfiguration *targetsActiveRunConfiguration() const;
Expand All @@ -67,7 +67,7 @@ class ROSGenericRunStep : public RunStep
virtual void setDebugContinueOnAttach(const bool &contOnAttach);

protected:
bool fromMap(const QVariantMap &map) override;
void fromMap(const Utils::Store &map) override;

virtual QMap<QString, QString> getAvailableTargets() { return QMap<QString, QString>(); }

Expand Down
2 changes: 1 addition & 1 deletion src/project_manager/ros_project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ void ROSProject::updateCppCodeModel()

}

Project::RestoreResult ROSProject::fromMap(const QVariantMap &map, QString *errorMessage)
Project::RestoreResult ROSProject::fromMap(const Utils::Store &map, QString *errorMessage)
{
RestoreResult result = Project::fromMap(map, errorMessage);
if (result != RestoreResult::Ok)
Expand Down
2 changes: 1 addition & 1 deletion src/project_manager/ros_project.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private slots:
void updateCppCodeModel();

protected:
Project::RestoreResult fromMap(const QVariantMap &map, QString *errorMessage) override;
Project::RestoreResult fromMap(const Utils::Store &map, QString *errorMessage) override;

private:
void asyncUpdate();
Expand Down
43 changes: 20 additions & 23 deletions src/project_manager/ros_run_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,12 @@ RunStep *RunStepFactory::create(RunStepList *parent, Utils::Id id)
return rs;
}

RunStep *RunStepFactory::restore(RunStepList *parent, const QVariantMap &map)
RunStep *RunStepFactory::restore(RunStepList *parent, const Utils::Store &map)
{
RunStep *rs = m_info.creator(parent);
if (!rs)
return nullptr;
if (!rs->fromMap(map)) {
QTC_CHECK(false);
delete rs;
return nullptr;
}
rs->fromMap(map);
return rs;
}

Expand All @@ -172,17 +168,16 @@ RunStep::RunStep(RunStepList *rsl, Utils::Id id) :
//
}

bool RunStep::fromMap(const QVariantMap &map)
void RunStep::fromMap(const Utils::Store &map)
{
m_enabled = map.value(runStepEnabledKey, true).toBool();
return ProjectConfiguration::fromMap(map);
ProjectConfiguration::fromMap(map);
}

QVariantMap RunStep::toMap() const
void RunStep::toMap(Utils::Store &map) const
{
QVariantMap map = ProjectConfiguration::toMap();
ProjectConfiguration::toMap(map);
map.insert(runStepEnabledKey, m_enabled);
return map;
}

ProjectExplorer::RunConfiguration *RunStep::runConfiguration() const
Expand Down Expand Up @@ -268,15 +263,18 @@ void RunStepList::clear()
m_steps.clear();
}

QVariantMap RunStepList::toMap() const
void RunStepList::toMap(Utils::Store &map) const
{
QVariantMap map(ProjectConfiguration::toMap());
ProjectConfiguration::toMap(map);
// Save run steps
map.insert(QString::fromLatin1(STEPS_COUNT_KEY), m_steps.count());
for (int i = 0; i < m_steps.count(); ++i)
map.insert(QString::fromLatin1(STEPS_PREFIX) + QString::number(i), m_steps.at(i)->toMap());
map.insert(STEPS_COUNT_KEY, m_steps.count());
for (int i = 0; i < m_steps.count(); ++i) {
const Utils::Key key_step = (QString(STEPS_PREFIX) + QString::number(i)).toUtf8();
Utils::Store map_step;
m_steps.at(i)->toMap(map_step);
map.insert(key_step, Utils::variantFromStore(map_step));
}

return map;
}

int RunStepList::count() const
Expand Down Expand Up @@ -305,18 +303,18 @@ bool RunStepList::enabled() const
return false;
}

bool RunStepList::fromMap(const QVariantMap &map)
void RunStepList::fromMap(const Utils::Store &map)
{
clear();

// We need the ID set before trying to restore the steps!
if (!ProjectConfiguration::fromMap(map))
return false;
ProjectConfiguration::fromMap(map);

const QList<RunStepFactory *> factories = RunStepFactory::allRunStepFactories();
int maxSteps = map.value(QString::fromLatin1(STEPS_COUNT_KEY), 0).toInt();
int maxSteps = map.value(STEPS_COUNT_KEY, 0).toInt();
for (int i = 0; i < maxSteps; ++i) {
QVariantMap rsData(map.value(QString::fromLatin1(STEPS_PREFIX) + QString::number(i)).toMap());
const Utils::Key key_step = (QString(STEPS_PREFIX) + QString::number(i)).toUtf8();
Utils::Store rsData = Utils::storeFromVariant(map.value(key_step).toMap());
if (rsData.isEmpty()) {
Core::MessageManager::writeSilently(tr("[ROS Warning] No step data found for step %1 (continuing).").arg(i));
continue;
Expand All @@ -337,7 +335,6 @@ bool RunStepList::fromMap(const QVariantMap &map)
}
QTC_ASSERT(handled, qDebug() << "No factory for run step" << stepId.toString() << "found.");
}
return true;
}

void RunStepList::runStep_enabledChanged(RunStep *step)
Expand Down
Loading

0 comments on commit 58a22a7

Please sign in to comment.