1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Reduces boilerplate and key repetition.

This commit is contained in:
Thomas Harte 2020-06-26 00:39:30 -04:00
parent 293ab25634
commit 21c41ed4cb

View File

@ -726,88 +726,69 @@ void MainWindow::launchTarget(std::unique_ptr<Analyser::Static::Target> &&target
// than indices. This has historically been true on the Mac, as I tend to add additional
// options but the existing text is rarely affected.
#define AllSettings() \
/* Machine selection. */ \
Tabs(machineSelectionTabs, "machineSelection"); \
\
/* Apple II. */ \
ComboBox(appleIIModelComboBox, "appleII.model"); \
ComboBox(appleIIDiskControllerComboBox, "appleII.diskController"); \
\
/* Amstrad CPC. */ \
ComboBox(amstradCPCModelComboBox, "amstradcpc.model"); \
\
/* Atari ST: nothing */ \
\
/* Electron. */ \
CheckBox(electronDFSCheckBox, "electron.hasDFS"); \
CheckBox(electronADFSCheckBox, "electron.hasADFS"); \
\
/* Macintosh. */ \
ComboBox(macintoshModelComboBox, "macintosh.model"); \
\
/* MSX. */ \
ComboBox(msxRegionComboBox, "msx.region"); \
CheckBox(msxDiskDriveCheckBox, "msx.hasDiskDrive"); \
\
/* Oric. */ \
ComboBox(oricModelComboBox, "msx.model"); \
ComboBox(oricDiskInterfaceComboBox, "msx.diskInterface"); \
\
/* Vic-20 */ \
ComboBox(vic20RegionComboBox, "vic20.region"); \
ComboBox(vic20MemorySizeComboBox, "vic20.memorySize"); \
CheckBox(vic20C1540CheckBox, "vic20.has1540"); \
\
/* ZX80. */ \
ComboBox(zx80MemorySizeComboBox, "zx80.memorySize"); \
CheckBox(zx80UseZX81ROMCheckBox, "zx80.usesZX81ROM"); \
\
/* ZX81. */ \
ComboBox(zx81MemorySizeComboBox, "zx81.memorySize");
void MainWindow::storeSelections() {
Settings settings;
#define Tabs(name, key) settings.setValue(key, ui->name->currentIndex())
#define CheckBox(name, key) settings.setValue(key, ui->name->isChecked())
#define ComboBox(name, key) settings.setValue(key, ui->name->currentText())
// Machine selection.
settings.setValue("machineSelection", ui->machineSelectionTabs->currentIndex());
AllSettings();
// Apple II.
settings.setValue("appleII.model", ui->appleIIModelComboBox->currentText());
settings.setValue("appleII.diskController", ui->appleIIDiskControllerComboBox->currentText());
// Amstrad CPC.
settings.setValue("amstradcpc.model", ui->amstradCPCModelComboBox->currentText());
// Atari ST: nothing.
// Electron.
settings.setValue("electron.hasDFS", ui->electronDFSCheckBox->isChecked());
settings.setValue("electron.hasADFS", ui->electronADFSCheckBox->isChecked());
// Macintosh.
settings.setValue("macintosh.model", ui->macintoshModelComboBox->currentText());
// MSX.
settings.setValue("msx.region", ui->msxRegionComboBox->currentText());
settings.setValue("msx.hasDiskDrive", ui->msxDiskDriveCheckBox->isChecked());
// Oric.
settings.setValue("msx.model", ui->oricModelComboBox->currentText());
settings.setValue("msx.diskInterface", ui->oricDiskInterfaceComboBox->currentText());
// Vic-20.
settings.setValue("vic20.region", ui->vic20RegionComboBox->currentText());
settings.setValue("vic20.memorySize", ui->vic20MemorySizeComboBox->currentText());
settings.setValue("vic20.has1540", ui->vic20C1540CheckBox->isChecked());
// ZX80.
settings.setValue("zx80.memorySize", ui->zx80MemorySizeComboBox->currentText());
settings.setValue("zx80.usesZX81ROM", ui->zx80UseZX81ROMCheckBox->isChecked());
// ZX81.
settings.setValue("zx81.memorySize", ui->zx81MemorySizeComboBox->currentText());
#undef Tabs
#undef CheckBox
#undef ComboBox
}
void MainWindow::restoreSelections() {
Settings settings;
// Machine selection.
ui->machineSelectionTabs->setCurrentIndex(settings.value("machineSelection").toInt());
#define Tabs(name, key) ui->name->setCurrentIndex(settings.value(key).toInt())
#define CheckBox(name, key) ui->name->setCheckState(settings.value(key).toBool() ? Qt::Checked : Qt::Unchecked)
#define ComboBox(name, key) ui->name->setCurrentText(settings.value(key).toString())
// Apple II.
ui->appleIIModelComboBox->setCurrentText(settings.value("appleII.model").toString());
ui->appleIIDiskControllerComboBox->setCurrentText(settings.value("appleII.diskController").toString());
AllSettings();
// Amstrad CPC.
ui->amstradCPCModelComboBox->setCurrentText(settings.value("amstradcpc.model").toString());
// Atari ST: nothing.
// Electron.
ui->electronDFSCheckBox->setCheckState(settings.value("electron.hasDFS").toBool() ? Qt::Checked : Qt::Unchecked);
ui->electronADFSCheckBox->setCheckState(settings.value("electron.hasADFS").toBool() ? Qt::Checked : Qt::Unchecked);
// Macintosh.
ui->macintoshModelComboBox->setCurrentText(settings.value("macintosh.model").toString());
// MSX.
ui->msxRegionComboBox->setCurrentText(settings.value("msx.region").toString());
ui->msxDiskDriveCheckBox->setCheckState(settings.value("msx.hasDiskDrive").toBool() ? Qt::Checked : Qt::Unchecked);
// Oric.
ui->oricModelComboBox->setCurrentText(settings.value("msx.model").toString());
ui->oricDiskInterfaceComboBox->setCurrentText(settings.value("msx.diskInterface").toString());
// Vic-20.
ui->vic20RegionComboBox->setCurrentText(settings.value("vic20.region").toString());
ui->vic20MemorySizeComboBox->setCurrentText(settings.value("vic20.memorySize").toString());
ui->vic20C1540CheckBox->setCheckState(settings.value("vic20.has1540").toBool() ? Qt::Checked : Qt::Unchecked);
// ZX80.
ui->zx80MemorySizeComboBox->setCurrentText(settings.value("zx80.memorySize").toString());
ui->zx80UseZX81ROMCheckBox->setCheckState(settings.value("zx80.usesZX81ROM").toBool() ? Qt::Checked : Qt::Unchecked);
// ZX81.
ui->zx81MemorySizeComboBox->setCurrentText(settings.value("zx81.memorySize").toString());
#undef Tabs
#undef CheckBox
#undef ComboBox
}