settings_dialog: get rid of string duplication

use enum to dictate button id
This commit is contained in:
Megamouse 2017-07-16 23:34:34 +02:00 committed by Ivan
parent 7426eb285f
commit ae8f858c56
2 changed files with 47 additions and 55 deletions

View File

@ -112,23 +112,32 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> xSettings, const
ui->ppu_fast->setToolTip(json_cpu_ppu["fast"].toString()); ui->ppu_fast->setToolTip(json_cpu_ppu["fast"].toString());
ui->ppu_llvm->setToolTip(json_cpu_ppu["LLVM"].toString()); ui->ppu_llvm->setToolTip(json_cpu_ppu["LLVM"].toString());
QButtonGroup *ppuBG = new QButtonGroup(this);
ppuBG->addButton(ui->ppu_precise, (int)ppu_decoder_type::precise);
ppuBG->addButton(ui->ppu_fast, (int)ppu_decoder_type::fast);
ppuBG->addButton(ui->ppu_llvm, (int)ppu_decoder_type::llvm);
{ // PPU Stuff { // PPU Stuff
QString selectedPPU = qstr(xemu_settings->GetSetting(emu_settings::PPUDecoder)); QString selectedPPU = qstr(xemu_settings->GetSetting(emu_settings::PPUDecoder));
for (const auto& button : ui->ppuBG->buttons()) QStringList ppu_list = xemu_settings->GetSettingOptions(emu_settings::PPUDecoder);
for (int i = 0; i < ppu_list.count(); i++)
{ {
QString current = button->text(); ppuBG->button(i)->setText(ppu_list[i]);
button->setCheckable(true);
if (current == selectedPPU) if (ppu_list[i] == selectedPPU)
{ {
button->setChecked(true); ppuBG->button(i)->setChecked(true);
} }
#ifndef LLVM_AVAILABLE #ifndef LLVM_AVAILABLE
if (current == "Recompiler (LLVM)") if (ppu_list[i].toLower().contains("llvm"))
{ {
button->setEnabled(false); ppuBG->button(i)->setEnabled(false);
} }
#endif #endif
connect(button, &QAbstractButton::pressed, [=]() {xemu_settings->SetSetting(emu_settings::PPUDecoder, sstr(current)); });
connect(ppuBG->button(i), &QAbstractButton::pressed, [=]() {xemu_settings->SetSetting(emu_settings::PPUDecoder, sstr(ppu_list[i])); });
} }
} }
@ -138,21 +147,26 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> xSettings, const
ui->spu_asmjit->setToolTip(json_cpu_spu["ASMJIT"].toString()); ui->spu_asmjit->setToolTip(json_cpu_spu["ASMJIT"].toString());
ui->spu_llvm->setToolTip(json_cpu_spu["LLVM"].toString()); ui->spu_llvm->setToolTip(json_cpu_spu["LLVM"].toString());
QButtonGroup *spuBG = new QButtonGroup(this);
spuBG->addButton(ui->spu_precise, (int)spu_decoder_type::precise);
spuBG->addButton(ui->spu_fast, (int)spu_decoder_type::fast);
spuBG->addButton(ui->spu_asmjit, (int)spu_decoder_type::asmjit);
spuBG->addButton(ui->spu_llvm, (int)spu_decoder_type::llvm);
{ // Spu stuff { // Spu stuff
QString selectedSPU = qstr(xemu_settings->GetSetting(emu_settings::SPUDecoder)); QString selectedSPU = qstr(xemu_settings->GetSetting(emu_settings::SPUDecoder));
for (const auto& button : ui->spuBG->buttons()) QStringList spu_list = xemu_settings->GetSettingOptions(emu_settings::SPUDecoder);
for (int i = 0; i < spu_list.count(); i++)
{ {
QString current = button->text(); spuBG->button(i)->setText(spu_list[i]);
if (current == "Recompiler (LLVM)")
if (spu_list[i] == selectedSPU)
{ {
button->setEnabled(false); spuBG->button(i)->setChecked(true);
} }
button->setCheckable(true);
if (current == selectedSPU) connect(spuBG->button(i), &QAbstractButton::pressed, [=]() {xemu_settings->SetSetting(emu_settings::SPUDecoder, sstr(spu_list[i])); });
{
button->setChecked(true);
}
connect(button, &QAbstractButton::pressed, [=]() {xemu_settings->SetSetting(emu_settings::SPUDecoder, sstr(current)); });
} }
} }
@ -164,22 +178,25 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> xSettings, const
// creating this in ui file keeps scrambling the order... // creating this in ui file keeps scrambling the order...
QButtonGroup *libModeBG = new QButtonGroup(this); QButtonGroup *libModeBG = new QButtonGroup(this);
libModeBG->addButton(ui->lib_auto, 0); libModeBG->addButton(ui->lib_auto, (int)lib_loading_type::automatic);
libModeBG->addButton(ui->lib_manu, 1); libModeBG->addButton(ui->lib_manu, (int)lib_loading_type::manual);
libModeBG->addButton(ui->lib_both, 2); libModeBG->addButton(ui->lib_both, (int)lib_loading_type::both);
libModeBG->addButton(ui->lib_lv2, 3); libModeBG->addButton(ui->lib_lv2, (int)lib_loading_type::liblv2only);
{// Handle lib loading options {// Handle lib loading options
QString selectedLib = qstr(xemu_settings->GetSetting(emu_settings::LibLoadOptions)); QString selectedLib = qstr(xemu_settings->GetSetting(emu_settings::LibLoadOptions));
for (const auto& button : libModeBG->buttons()) QStringList libmode_list = xemu_settings->GetSettingOptions(emu_settings::LibLoadOptions);
for (int i = 0; i < libmode_list.count(); i++)
{ {
QString current = button->text(); libModeBG->button(i)->setText(libmode_list[i]);
button->setCheckable(true);
if (current == selectedLib) if (libmode_list[i] == selectedLib)
{ {
button->setChecked(true); libModeBG->button(i)->setChecked(true);
} }
connect(button, &QAbstractButton::pressed, [=]() {xemu_settings->SetSetting(emu_settings::LibLoadOptions, sstr(current)); });
connect(libModeBG->button(i), &QAbstractButton::pressed, [=]() {xemu_settings->SetSetting(emu_settings::LibLoadOptions, sstr(libmode_list[i])); });
} }
} }
@ -228,7 +245,7 @@ settings_dialog::settings_dialog(std::shared_ptr<gui_settings> xSettings, const
auto l_OnLibButtonClicked = [=](int ind) auto l_OnLibButtonClicked = [=](int ind)
{ {
if (ind == 1 || ind == 2) if (ind == (int)lib_loading_type::manual || ind == (int)lib_loading_type::both)
{ {
ui->searchBox->setEnabled(true); ui->searchBox->setEnabled(true);
ui->lleList->setEnabled(true); ui->lleList->setEnabled(true);

View File

@ -58,9 +58,6 @@
<property name="text"> <property name="text">
<string>Interpreter (precise)</string> <string>Interpreter (precise)</string>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">ppuBG</string>
</attribute>
</widget> </widget>
</item> </item>
<item> <item>
@ -68,9 +65,6 @@
<property name="text"> <property name="text">
<string>Interpreter (fast)</string> <string>Interpreter (fast)</string>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">ppuBG</string>
</attribute>
</widget> </widget>
</item> </item>
<item> <item>
@ -78,9 +72,6 @@
<property name="text"> <property name="text">
<string>Recompiler (LLVM)</string> <string>Recompiler (LLVM)</string>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">ppuBG</string>
</attribute>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -97,9 +88,6 @@
<property name="text"> <property name="text">
<string>Interpreter (precise)</string> <string>Interpreter (precise)</string>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">spuBG</string>
</attribute>
</widget> </widget>
</item> </item>
<item> <item>
@ -107,9 +95,6 @@
<property name="text"> <property name="text">
<string>Interpreter (fast)</string> <string>Interpreter (fast)</string>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">spuBG</string>
</attribute>
</widget> </widget>
</item> </item>
<item> <item>
@ -117,9 +102,6 @@
<property name="text"> <property name="text">
<string>Recompiler (ASMJIT)</string> <string>Recompiler (ASMJIT)</string>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">spuBG</string>
</attribute>
</widget> </widget>
</item> </item>
<item> <item>
@ -130,9 +112,6 @@
<property name="text"> <property name="text">
<string>Recompiler (LLVM)</string> <string>Recompiler (LLVM)</string>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">spuBG</string>
</attribute>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -232,7 +211,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Load automatic and manual libraries</string> <string>Load automatic and manual selection</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -1383,8 +1362,4 @@
<include location="../resources.qrc"/> <include location="../resources.qrc"/>
</resources> </resources>
<connections/> <connections/>
<buttongroups>
<buttongroup name="ppuBG"/>
<buttongroup name="spuBG"/>
</buttongroups>
</ui> </ui>