mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
DolphinQt: Refactor, add ConfigControl class
This reduces code duplication in the different ConfigControls. This is helpful for the next commit, which will modify the now deduplicated code.
This commit is contained in:
@ -5,85 +5,65 @@
|
||||
|
||||
#include <QSignalBlocker>
|
||||
|
||||
#include "Common/Config/Config.h"
|
||||
|
||||
#include "DolphinQt/Settings.h"
|
||||
|
||||
ConfigChoice::ConfigChoice(const QStringList& options, const Config::Info<int>& setting)
|
||||
: m_setting(setting)
|
||||
: ConfigControl(setting.GetLocation()), m_setting(setting)
|
||||
{
|
||||
addItems(options);
|
||||
setCurrentIndex(ReadValue(setting));
|
||||
|
||||
connect(this, &QComboBox::currentIndexChanged, this, &ConfigChoice::Update);
|
||||
setCurrentIndex(Config::Get(m_setting));
|
||||
|
||||
connect(&Settings::Instance(), &Settings::ConfigChanged, this, [this] {
|
||||
QFont bf = font();
|
||||
bf.setBold(Config::GetActiveLayerForConfig(m_setting) != Config::LayerType::Base);
|
||||
setFont(bf);
|
||||
|
||||
const QSignalBlocker blocker(this);
|
||||
setCurrentIndex(Config::Get(m_setting));
|
||||
});
|
||||
}
|
||||
|
||||
void ConfigChoice::Update(int choice)
|
||||
{
|
||||
Config::SetBaseOrCurrent(m_setting, choice);
|
||||
SaveValue(m_setting, choice);
|
||||
}
|
||||
|
||||
void ConfigChoice::OnConfigChanged()
|
||||
{
|
||||
setCurrentIndex(ReadValue(m_setting));
|
||||
}
|
||||
|
||||
ConfigStringChoice::ConfigStringChoice(const std::vector<std::string>& options,
|
||||
const Config::Info<std::string>& setting)
|
||||
: m_setting(setting), m_text_is_data(true)
|
||||
: ConfigControl(setting.GetLocation()), m_setting(setting), m_text_is_data(true)
|
||||
{
|
||||
for (const auto& op : options)
|
||||
addItem(QString::fromStdString(op));
|
||||
|
||||
Connect();
|
||||
Load();
|
||||
connect(this, &QComboBox::currentIndexChanged, this, &ConfigStringChoice::Update);
|
||||
}
|
||||
|
||||
ConfigStringChoice::ConfigStringChoice(const std::vector<std::pair<QString, QString>>& options,
|
||||
const Config::Info<std::string>& setting)
|
||||
: m_setting(setting), m_text_is_data(false)
|
||||
: ConfigControl(setting.GetLocation()), m_setting(setting), m_text_is_data(false)
|
||||
{
|
||||
for (const auto& [option_text, option_data] : options)
|
||||
addItem(option_text, option_data);
|
||||
|
||||
Connect();
|
||||
Load();
|
||||
}
|
||||
|
||||
void ConfigStringChoice::Connect()
|
||||
{
|
||||
const auto on_config_changed = [this]() {
|
||||
QFont bf = font();
|
||||
bf.setBold(Config::GetActiveLayerForConfig(m_setting) != Config::LayerType::Base);
|
||||
setFont(bf);
|
||||
|
||||
Load();
|
||||
};
|
||||
|
||||
connect(&Settings::Instance(), &Settings::ConfigChanged, this, on_config_changed);
|
||||
connect(this, &QComboBox::currentIndexChanged, this, &ConfigStringChoice::Update);
|
||||
Load();
|
||||
}
|
||||
|
||||
void ConfigStringChoice::Update(int index)
|
||||
{
|
||||
if (m_text_is_data)
|
||||
{
|
||||
Config::SetBaseOrCurrent(m_setting, itemText(index).toStdString());
|
||||
}
|
||||
SaveValue(m_setting, itemText(index).toStdString());
|
||||
else
|
||||
{
|
||||
Config::SetBaseOrCurrent(m_setting, itemData(index).toString().toStdString());
|
||||
}
|
||||
SaveValue(m_setting, itemData(index).toString().toStdString());
|
||||
}
|
||||
|
||||
void ConfigStringChoice::Load()
|
||||
{
|
||||
const QString setting_value = QString::fromStdString(Config::Get(m_setting));
|
||||
const QString setting_value = QString::fromStdString(ReadValue(m_setting));
|
||||
|
||||
const int index = m_text_is_data ? findText(setting_value) : findData(setting_value);
|
||||
const QSignalBlocker blocker(this);
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
|
||||
void ConfigStringChoice::OnConfigChanged()
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
Reference in New Issue
Block a user