From 07c9da30de732c9dddb065d2fd0db1b523d04fba Mon Sep 17 00:00:00 2001 From: "Joakim L. Gilje" Date: Mon, 6 Dec 2021 10:29:53 +0100 Subject: [PATCH] configuration fixes * moved CONFIG_MIDI and CONFIG_MIDI_IN to own blocks when constructing comboboxes in deviceconfig * use Models::AddEntry in deviceconfig * sub-handling of CONFIG_HEX16 and CONFIG_HEX20 in CONFIG_SELECTION block when constructing, and use corresponding config_setter * make sure SCSI controller- and ISAMEM-deviceconfig calls up deviceconfig with an instance number * midi input and midi output was mixed when constructing soundsettings when loading prev. settings --- src/qt/qt_deviceconfig.cpp | 120 ++++++++++++++--------- src/qt/qt_deviceconfig.hpp | 2 +- src/qt/qt_settingsotherperipherals.cpp | 8 +- src/qt/qt_settingsotherperipherals.hpp | 18 ---- src/qt/qt_settingssound.cpp | 4 +- src/qt/qt_settingsstoragecontrollers.cpp | 8 +- src/qt/qt_settingsstoragecontrollers.hpp | 30 ------ 7 files changed, 82 insertions(+), 108 deletions(-) diff --git a/src/qt/qt_deviceconfig.cpp b/src/qt/qt_deviceconfig.cpp index a99e1ab26..0cfe14a73 100644 --- a/src/qt/qt_deviceconfig.cpp +++ b/src/qt/qt_deviceconfig.cpp @@ -15,6 +15,7 @@ extern "C" { } #include "qt_filefield.hpp" +#include "qt_models_common.hpp" DeviceConfig::DeviceConfig(QWidget *parent) : QDialog(parent), @@ -28,12 +29,12 @@ DeviceConfig::~DeviceConfig() delete ui; } -void DeviceConfig::ConfigureDevice(const _device_* device) { +void DeviceConfig::ConfigureDevice(const _device_* device, int instance) { DeviceConfig dc; dc.setWindowTitle(QString("%1 Device Configuration").arg(device->name)); device_context_t device_context; - device_set_context(&device_context, device, 0); + device_set_context(&device_context, device, instance); const auto* config = device->config; while (config->type != -1) { @@ -47,9 +48,47 @@ void DeviceConfig::ConfigureDevice(const _device_* device) { dc.ui->formLayout->addRow(config->description, cbox); break; } - case CONFIG_SELECTION: case CONFIG_MIDI: + { + auto* cbox = new QComboBox(); + cbox->setObjectName(config->name); + auto* model = cbox->model(); + int currentIndex = -1; + int selected = config_get_int(device_context.name, const_cast(config->name), config->default_int); + for (int i = 0; i < plat_midi_get_num_devs(); i++) { + char midiName[512] = { 0 }; + plat_midi_get_dev_name(i, midiName); + + Models::AddEntry(model, midiName, i); + if (selected == i) { + currentIndex = i; + } + } + dc.ui->formLayout->addRow(config->description, cbox); + cbox->setCurrentIndex(currentIndex); + break; + } case CONFIG_MIDI_IN: + { + auto* cbox = new QComboBox(); + cbox->setObjectName(config->name); + auto* model = cbox->model(); + int currentIndex = -1; + int selected = config_get_int(device_context.name, const_cast(config->name), config->default_int); + for (int i = 0; i < plat_midi_in_get_num_devs(); i++) { + char midiName[512] = { 0 }; + plat_midi_in_get_dev_name(i, midiName); + + Models::AddEntry(model, midiName, i); + if (selected == i) { + currentIndex = i; + } + } + dc.ui->formLayout->addRow(config->description, cbox); + cbox->setCurrentIndex(currentIndex); + break; + } + case CONFIG_SELECTION: case CONFIG_HEX16: case CONFIG_HEX20: { @@ -57,50 +96,23 @@ void DeviceConfig::ConfigureDevice(const _device_* device) { cbox->setObjectName(config->name); auto* model = cbox->model(); int currentIndex = -1; - int selected = config_get_int(device_context.name, const_cast(config->name), config->default_int); + int selected; + switch (config->type) { + case CONFIG_SELECTION: + selected = config_get_int(device_context.name, const_cast(config->name), config->default_int); + break; + case CONFIG_HEX16: + selected = config_get_hex16(device_context.name, const_cast(config->name), config->default_int); + break; + case CONFIG_HEX20: + selected = config_get_hex20(device_context.name, const_cast(config->name), config->default_int); + break; + } - if (config->type == CONFIG_MIDI) { - for (int i = 0; i < plat_midi_get_num_devs(); i++) { - char midiName[512] = { 0 }; - plat_midi_get_dev_name(i, midiName); - - int rows = model->rowCount(); - model->insertRow(rows); - auto idx = model->index(rows, 0); - - model->setData(idx, midiName, Qt::DisplayRole); - model->setData(idx, i, Qt::UserRole); - if (selected == i) { - currentIndex = idx.row(); - } - } - } else if (config->type == CONFIG_MIDI_IN) { - for (int i = 0; i < plat_midi_in_get_num_devs(); i++) { - char midiName[512] = { 0 }; - plat_midi_in_get_dev_name(i, midiName); - - int rows = model->rowCount(); - model->insertRow(rows); - auto idx = model->index(rows, 0); - - model->setData(idx, midiName, Qt::DisplayRole); - model->setData(idx, i, Qt::UserRole); - if (selected == i) { - currentIndex = idx.row(); - } - } - } else { - for (auto* sel = config->selection; (sel->description != nullptr) && (strlen(sel->description) > 0); ++sel) { - int rows = model->rowCount(); - model->insertRow(rows); - auto idx = model->index(rows, 0); - - model->setData(idx, sel->description, Qt::DisplayRole); - model->setData(idx, sel->value, Qt::UserRole); - - if (selected == sel->value) { - currentIndex = idx.row(); - } + for (auto* sel = config->selection; (sel->description != nullptr) && (strlen(sel->description) > 0); ++sel) { + int row = Models::AddEntry(model, sel->description, sel->value); + if (selected == sel->value) { + currentIndex = row; } } dc.ui->formLayout->addRow(config->description, cbox); @@ -145,16 +157,26 @@ void DeviceConfig::ConfigureDevice(const _device_* device) { config_set_int(device_context.name, const_cast(config->name), cbox->isChecked() ? 1 : 0); break; } - case CONFIG_SELECTION: case CONFIG_MIDI: case CONFIG_MIDI_IN: - case CONFIG_HEX16: - case CONFIG_HEX20: + case CONFIG_SELECTION: { auto* cbox = dc.findChild(config->name); config_set_int(device_context.name, const_cast(config->name), cbox->currentData().toInt()); break; } + case CONFIG_HEX16: + { + auto* cbox = dc.findChild(config->name); + config_set_hex16(device_context.name, const_cast(config->name), cbox->currentData().toInt()); + break; + } + case CONFIG_HEX20: + { + auto* cbox = dc.findChild(config->name); + config_set_hex20(device_context.name, const_cast(config->name), cbox->currentData().toInt()); + break; + } case CONFIG_FNAME: { auto* fbox = dc.findChild(config->name); diff --git a/src/qt/qt_deviceconfig.hpp b/src/qt/qt_deviceconfig.hpp index 3090c96a7..8062c1851 100644 --- a/src/qt/qt_deviceconfig.hpp +++ b/src/qt/qt_deviceconfig.hpp @@ -19,7 +19,7 @@ public: explicit DeviceConfig(QWidget *parent = nullptr); ~DeviceConfig(); - static void ConfigureDevice(const _device_* device); + static void ConfigureDevice(const _device_* device, int instance = 0); static QString DeviceName(const _device_* device, const char* internalName, int bus); private: Ui::DeviceConfig *ui; diff --git a/src/qt/qt_settingsotherperipherals.cpp b/src/qt/qt_settingsotherperipherals.cpp index e52c3ead1..729ebe62e 100644 --- a/src/qt/qt_settingsotherperipherals.cpp +++ b/src/qt/qt_settingsotherperipherals.cpp @@ -96,7 +96,7 @@ void SettingsOtherPeripherals::on_comboBoxCard1_currentIndexChanged(int index) { } void SettingsOtherPeripherals::on_pushButtonConfigureCard1_clicked() { - DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard1->currentData().toInt())); + DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard1->currentData().toInt()), 1); } void SettingsOtherPeripherals::on_comboBoxCard2_currentIndexChanged(int index) { @@ -107,7 +107,7 @@ void SettingsOtherPeripherals::on_comboBoxCard2_currentIndexChanged(int index) { } void SettingsOtherPeripherals::on_pushButtonConfigureCard2_clicked() { - DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard2->currentData().toInt())); + DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard2->currentData().toInt()), 2); } void SettingsOtherPeripherals::on_comboBoxCard3_currentIndexChanged(int index) { @@ -118,7 +118,7 @@ void SettingsOtherPeripherals::on_comboBoxCard3_currentIndexChanged(int index) { } void SettingsOtherPeripherals::on_pushButtonConfigureCard3_clicked() { - DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard3->currentData().toInt())); + DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard3->currentData().toInt()), 3); } void SettingsOtherPeripherals::on_comboBoxCard4_currentIndexChanged(int index) { @@ -129,5 +129,5 @@ void SettingsOtherPeripherals::on_comboBoxCard4_currentIndexChanged(int index) { } void SettingsOtherPeripherals::on_pushButtonConfigureCard4_clicked() { - DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard4->currentData().toInt())); + DeviceConfig::ConfigureDevice(isamem_get_device(ui->comboBoxCard4->currentData().toInt()), 4); } diff --git a/src/qt/qt_settingsotherperipherals.hpp b/src/qt/qt_settingsotherperipherals.hpp index 605b629ba..e32704f1b 100644 --- a/src/qt/qt_settingsotherperipherals.hpp +++ b/src/qt/qt_settingsotherperipherals.hpp @@ -18,32 +18,14 @@ public: void save(); private slots: void on_pushButtonConfigureCard4_clicked(); - -private slots: void on_comboBoxCard4_currentIndexChanged(int index); - -private slots: void on_pushButtonConfigureCard3_clicked(); - -private slots: void on_comboBoxCard3_currentIndexChanged(int index); - -private slots: void on_pushButtonConfigureCard2_clicked(); - -private slots: void on_comboBoxCard2_currentIndexChanged(int index); - -private slots: void on_pushButtonConfigureCard1_clicked(); - -private slots: void on_comboBoxCard1_currentIndexChanged(int index); - -private slots: void on_pushButtonConfigureRTC_clicked(); - -private slots: void on_comboBoxRTC_currentIndexChanged(int index); private: diff --git a/src/qt/qt_settingssound.cpp b/src/qt/qt_settingssound.cpp index 7dd3fc51a..8e686f870 100644 --- a/src/qt/qt_settingssound.cpp +++ b/src/qt/qt_settingssound.cpp @@ -87,7 +87,7 @@ void SettingsSound::onCurrentMachineChanged(int machineId) { if (midi_device_available(c)) { int row = Models::AddEntry(model, name, c); - if (c == midi_input_device_current) { + if (c == midi_device_current) { selectedRow = row - removeRows; } } @@ -110,7 +110,7 @@ void SettingsSound::onCurrentMachineChanged(int machineId) { if (midi_in_device_available(c)) { int row = Models::AddEntry(model, name, c); - if (c == midi_device_current) { + if (c == midi_input_device_current) { selectedRow = row - removeRows; } } diff --git a/src/qt/qt_settingsstoragecontrollers.cpp b/src/qt/qt_settingsstoragecontrollers.cpp index 64bb0e488..fb5dd47cc 100644 --- a/src/qt/qt_settingsstoragecontrollers.cpp +++ b/src/qt/qt_settingsstoragecontrollers.cpp @@ -217,17 +217,17 @@ void SettingsStorageControllers::on_comboBoxSCSI4_currentIndexChanged(int index) void SettingsStorageControllers::on_pushButtonSCSI1_clicked() { - DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI1->currentData().toInt())); + DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI1->currentData().toInt()), 1); } void SettingsStorageControllers::on_pushButtonSCSI2_clicked() { - DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI2->currentData().toInt())); + DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI2->currentData().toInt()), 2); } void SettingsStorageControllers::on_pushButtonSCSI3_clicked() { - DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI3->currentData().toInt())); + DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI3->currentData().toInt()), 3); } void SettingsStorageControllers::on_pushButtonSCSI4_clicked() { - DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI4->currentData().toInt())); + DeviceConfig::ConfigureDevice(scsi_card_getdevice(ui->comboBoxSCSI4->currentData().toInt()), 4); } diff --git a/src/qt/qt_settingsstoragecontrollers.hpp b/src/qt/qt_settingsstoragecontrollers.hpp index de2e36646..e4596b567 100644 --- a/src/qt/qt_settingsstoragecontrollers.hpp +++ b/src/qt/qt_settingsstoragecontrollers.hpp @@ -22,50 +22,20 @@ public slots: private slots: void on_pushButtonSCSI4_clicked(); - -private slots: void on_pushButtonSCSI3_clicked(); - -private slots: void on_pushButtonSCSI2_clicked(); - -private slots: void on_pushButtonSCSI1_clicked(); - -private slots: void on_comboBoxSCSI4_currentIndexChanged(int index); - -private slots: void on_comboBoxSCSI3_currentIndexChanged(int index); - -private slots: void on_comboBoxSCSI2_currentIndexChanged(int index); - -private slots: void on_comboBoxSCSI1_currentIndexChanged(int index); - -private slots: void on_pushButtonQuaternaryIDE_clicked(); - -private slots: void on_pushButtonTertiaryIDE_clicked(); - -private slots: void on_pushButtonFD_clicked(); - -private slots: void on_pushButtonHD_clicked(); - -private slots: void on_checkBoxQuaternaryIDE_stateChanged(int arg1); - -private slots: void on_checkBoxTertiaryIDE_stateChanged(int arg1); - -private slots: void on_comboBoxFD_currentIndexChanged(int index); - -private slots: void on_comboBoxHD_currentIndexChanged(int index); private: