configuration: Use a builder to create widgets

This gets rid of some repeated code and sets us up to send more
information to the new widget.
This commit is contained in:
lat9nq
2023-06-21 01:42:42 -04:00
parent 62ffaa730f
commit ad645c29a4
18 changed files with 206 additions and 209 deletions

View File

@ -15,12 +15,12 @@
ConfigureGeneral::ConfigureGeneral(
const Core::System& system_,
std::shared_ptr<std::forward_list<ConfigurationShared::Tab*>> group_,
const ConfigurationShared::TranslationMap& translations_,
const ConfigurationShared::ComboboxTranslationMap& combobox_translations_, QWidget* parent)
: Tab(group_, parent), ui{std::make_unique<Ui::ConfigureGeneral>()}, system{system_},
translations{translations_}, combobox_translations{combobox_translations_} {
const ConfigurationShared::Builder& builder, QWidget* parent)
: Tab(group_, parent), ui{std::make_unique<Ui::ConfigureGeneral>()}, system{system_} {
ui->setupUi(this);
Setup(builder);
SetConfiguration();
connect(ui->button_reset_defaults, &QPushButton::clicked, this,
@ -33,17 +33,20 @@ ConfigureGeneral::ConfigureGeneral(
ConfigureGeneral::~ConfigureGeneral() = default;
void ConfigureGeneral::SetConfiguration() {
const bool runtime_lock = !system.IsPoweredOn();
void ConfigureGeneral::SetConfiguration() {}
void ConfigureGeneral::Setup(const ConfigurationShared::Builder& builder) {
QLayout& layout = *ui->general_widget->layout();
std::map<u32, QWidget*> hold{};
for (const auto setting :
UISettings::values.linkage.by_category[Settings::Category::UiGeneral]) {
auto* widget = new ConfigurationShared::Widget(setting, translations, combobox_translations,
this, runtime_lock, apply_funcs);
auto* widget = builder.BuildWidget(setting, apply_funcs);
if (widget == nullptr) {
continue;
}
if (!widget->Valid()) {
delete widget;
continue;