-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qt: move code from emu_settings to config_adapter
- Loading branch information
Showing
8 changed files
with
248 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#pragma once | ||
|
||
#include <QStringList> | ||
|
||
#include "config_adapter.h" | ||
|
||
#include "Emu/system_config.h" | ||
|
||
// Helper methods to interact with YAML and the config settings. | ||
namespace cfg_adapter | ||
{ | ||
static cfg::_base& get_cfg(cfg::_base& root, const std::string& name) | ||
{ | ||
if (root.get_type() == cfg::type::node) | ||
{ | ||
for (const auto& pair : static_cast<cfg::node&>(root).get_nodes()) | ||
{ | ||
if (pair.first == name) | ||
{ | ||
return *pair.second; | ||
} | ||
} | ||
} | ||
|
||
fmt::throw_exception("Node not found: %s", name); | ||
} | ||
|
||
static cfg::_base& get_cfg(cfg::_base& root, cfg_location::const_iterator begin, cfg_location::const_iterator end) | ||
{ | ||
return begin == end ? root : get_cfg(get_cfg(root, *begin), begin + 1, end); | ||
} | ||
|
||
YAML::Node get_node(const YAML::Node& node, cfg_location::const_iterator begin, cfg_location::const_iterator end) | ||
{ | ||
return begin == end ? node : get_node(node[*begin], begin + 1, end); // TODO | ||
} | ||
|
||
YAML::Node get_node(const YAML::Node& node, cfg_location loc) | ||
{ | ||
return get_node(node, loc.cbegin(), loc.cend()); | ||
} | ||
|
||
QStringList get_options(cfg_location location) | ||
{ | ||
QStringList values; | ||
auto begin = location.cbegin(); | ||
auto end = location.cend(); | ||
for (const auto& v : cfg_adapter::get_cfg(g_cfg, begin, end).to_list()) | ||
{ | ||
values.append(QString::fromStdString(v)); | ||
} | ||
return values; | ||
} | ||
|
||
static bool get_is_dynamic(cfg_location location) | ||
{ | ||
auto begin = location.cbegin(); | ||
auto end = location.cend(); | ||
return cfg_adapter::get_cfg(g_cfg, begin, end).get_is_dynamic(); | ||
} | ||
|
||
bool get_is_dynamic(emu_settings_type type) | ||
{ | ||
const cfg_location loc = settings_location[type]; | ||
return get_is_dynamic(loc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <QStringList> | ||
|
||
#include "emu_settings_type.h" | ||
#include "yaml-cpp/yaml.h" | ||
|
||
// Helper methods to interact with YAML and the config settings. | ||
namespace cfg_adapter | ||
{ | ||
YAML::Node get_node(const YAML::Node& node, cfg_location::const_iterator begin, cfg_location::const_iterator end); | ||
|
||
/** Syntactic sugar to get a setting at a given config location. */ | ||
YAML::Node get_node(const YAML::Node& node, cfg_location loc); | ||
|
||
/** Returns possible options for values for some particular setting.*/ | ||
QStringList get_options(cfg_location location); | ||
|
||
/** Returns dynamic property for some particular setting.*/ | ||
bool get_is_dynamic(emu_settings_type type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.