UI: Optimize several Settings pages to reduce the amount of iterations and repeated calls to functions where multiple there are multiple instances of the same device type, should further speed up te opening of the Settings dialog.

This commit is contained in:
OBattler
2025-03-30 03:40:08 +02:00
parent 90464f7914
commit 19e01b8ddf
5 changed files with 184 additions and 127 deletions

View File

@@ -140,51 +140,60 @@ SettingsNetwork::onCurrentMachineChanged(int machineId)
int c = 0; int c = 0;
int selectedRow = 0; int selectedRow = 0;
for (int i = 0; i < NET_CARD_MAX; ++i) { // Network Card
auto *cbox = findChild<QComboBox *>(QString("comboBoxNIC%1").arg(i + 1)); QComboBox * cbox_[NET_CARD_MAX] = { 0 };
auto *model = cbox->model(); QAbstractItemModel *models[NET_CARD_MAX] = { 0 };
auto removeRows = model->rowCount(); int removeRows_[NET_CARD_MAX] = { 0 };
int selectedRows[NET_CARD_MAX] = { 0 };
int m_has_net = machine_has_flags(machineId, MACHINE_NIC);
for (uint8_t i = 0; i < NET_CARD_MAX; ++i) {
cbox_[i] = findChild<QComboBox *>(QString("comboBoxNIC%1").arg(i + 1));
models[i] = cbox_[i]->model();
removeRows_[i] = models[i]->rowCount();
}
c = 0; c = 0;
selectedRow = 0;
while (true) { while (true) {
/* Skip "internal" if machine doesn't have it or this is not the primary card. */ const QString name = DeviceConfig::DeviceName(network_card_getdevice(c),
if ((c == 1) && ((i > 0) || (machine_has_flags(machineId, MACHINE_NIC) == 0))) { network_card_get_internal_name(c), 1);
c++;
continue;
}
auto name = DeviceConfig::DeviceName(network_card_getdevice(c), network_card_get_internal_name(c), 1); if (name.isEmpty())
if (name.isEmpty()) {
break; break;
if (network_card_available(c)) {
if (device_is_valid(network_card_getdevice(c), machineId)) {
for (uint8_t i = 0; i < NET_CARD_MAX; ++i) {
if ((c != 1) || ((i == 0) && m_has_net)) {
int row = Models::AddEntry(models[i], name, c);
if (c == net_cards_conf[i].device_num)
selectedRows[i] = row - removeRows_[i];
}
}
}
} }
if (network_card_available(c) && device_is_valid(network_card_getdevice(c), machineId)) {
int row = Models::AddEntry(model, name, c);
if (c == net_cards_conf[i].device_num) {
selectedRow = row - removeRows;
}
}
c++; c++;
} }
model->removeRows(0, removeRows); for (uint8_t i = 0; i < NET_CARD_MAX; ++i) {
cbox->setEnabled(model->rowCount() > 0); models[i]->removeRows(0, removeRows_[i]);
cbox->setCurrentIndex(-1); cbox_[i]->setEnabled(models[i]->rowCount() > 1);
cbox->setCurrentIndex(selectedRow); cbox_[i]->setCurrentIndex(-1);
cbox_[i]->setCurrentIndex(selectedRows[i]);
cbox = findChild<QComboBox *>(QString("comboBoxNet%1").arg(i + 1)); auto cbox = findChild<QComboBox *>(QString("comboBoxNet%1").arg(i + 1));
model = cbox->model(); auto model = cbox->model();
removeRows = model->rowCount(); auto removeRows = model->rowCount();
Models::AddEntry(model, tr("Null Driver"), NET_TYPE_NONE); Models::AddEntry(model, tr("Null Driver"), NET_TYPE_NONE);
Models::AddEntry(model, "SLiRP", NET_TYPE_SLIRP); Models::AddEntry(model, "SLiRP", NET_TYPE_SLIRP);
if (network_ndev > 1) { if (network_ndev > 1)
Models::AddEntry(model, "PCap", NET_TYPE_PCAP); Models::AddEntry(model, "PCap", NET_TYPE_PCAP);
}
if (network_devmap.has_vde) { if (network_devmap.has_vde)
Models::AddEntry(model, "VDE", NET_TYPE_VDE); Models::AddEntry(model, "VDE", NET_TYPE_VDE);
}
model->removeRows(0, removeRows); model->removeRows(0, removeRows);
cbox->setCurrentIndex(cbox->findData(net_cards_conf[i].net_type)); cbox->setCurrentIndex(cbox->findData(net_cards_conf[i].net_type));
@@ -205,6 +214,7 @@ SettingsNetwork::onCurrentMachineChanged(int machineId)
model->removeRows(0, removeRows); model->removeRows(0, removeRows);
cbox->setCurrentIndex(selectedRow); cbox->setCurrentIndex(selectedRow);
} }
if (net_cards_conf[i].net_type == NET_TYPE_VDE) { if (net_cards_conf[i].net_type == NET_TYPE_VDE) {
QString currentVdeSocket = net_cards_conf[i].host_dev_name; QString currentVdeSocket = net_cards_conf[i].host_dev_name;
auto editline = findChild<QLineEdit *>(QString("socketVDENIC%1").arg(i+1)); auto editline = findChild<QLineEdit *>(QString("socketVDENIC%1").arg(i+1));

View File

@@ -83,31 +83,45 @@ SettingsOtherPeripherals::onCurrentMachineChanged(int machineId)
ui->comboBoxRTC->setCurrentIndex(selectedRow); ui->comboBoxRTC->setCurrentIndex(selectedRow);
ui->pushButtonConfigureRTC->setEnabled((isartc_type != 0) && isartc_has_config(isartc_type) && machineHasIsa); ui->pushButtonConfigureRTC->setEnabled((isartc_type != 0) && isartc_has_config(isartc_type) && machineHasIsa);
for (int c = 0; c < ISAMEM_MAX; c++) { // ISA Memory Expansion Card
auto *cbox = findChild<QComboBox *>(QString("comboBoxCard%1").arg(c + 1)); QComboBox * cbox[ISAMEM_MAX] = { 0 };
model = cbox->model(); QAbstractItemModel *models[ISAMEM_MAX] = { 0 };
int removeRows_[ISAMEM_MAX] = { 0 };
int selectedRows[ISAMEM_MAX] = { 0 };
for (uint8_t c = 0; c < ISAMEM_MAX; ++c) {
cbox[c] = findChild<QComboBox *>(QString("comboBoxCard%1").arg(c + 1));
models[c] = cbox[c]->model();
removeRows_[c] = models[c]->rowCount();
}
d = 0; d = 0;
selectedRow = 0;
while (true) { while (true) {
QString name = DeviceConfig::DeviceName(isamem_get_device(d), isamem_get_internal_name(d), 0); const QString name = DeviceConfig::DeviceName(isamem_get_device(d),
if (name.isEmpty()) { isamem_get_internal_name(d), 0);
if (name.isEmpty())
break; break;
if (device_is_valid(isamem_get_device(d), machineId)) {
for (uint8_t c = 0; c < ISAMEM_MAX; ++c) {
int row = Models::AddEntry(models[c], name, d);
if (d == isamem_type[c])
selectedRows[c] = row - removeRows_[c];
}
} }
if (!device_is_valid(isamem_get_device(d), machineId)) { d++;
break;
} }
int row = Models::AddEntry(model, name, d); for (uint8_t c = 0; c < ISAMEM_MAX; ++c) {
if (d == isamem_type[c]) { models[c]->removeRows(0, removeRows_[c]);
selectedRow = row; cbox[c]->setEnabled(models[c]->rowCount() > 1);
} cbox[c]->setCurrentIndex(-1);
++d; cbox[c]->setCurrentIndex(selectedRows[c]);
} findChild<QPushButton *>(QString("pushButtonConfigureCard%1").arg(c + 1))->setEnabled((isamem_type[c] != 0) &&
cbox->setCurrentIndex(-1); isamem_has_config(isamem_type[c]) && machineHasIsa);
cbox->setCurrentIndex(selectedRow);
cbox->setEnabled(machineHasIsa);
findChild<QPushButton *>(QString("pushButtonConfigureCard%1").arg(c + 1))->setEnabled((isamem_type[c] != 0) && isamem_has_config(isamem_type[c]) && machineHasIsa);
} }
} }

View File

@@ -73,34 +73,49 @@ SettingsPorts::onCurrentMachineChanged(int machineId)
{ {
this->machineId = machineId; this->machineId = machineId;
for (int i = 0; i < PARALLEL_MAX; i++) {
auto *cbox = findChild<QComboBox *>(QString("comboBoxLpt%1").arg(i + 1));
auto *model = cbox->model();
const auto removeRows = model->rowCount();
int c = 0; int c = 0;
int selectedRow = 0;
while (true) { // LPT Device
const char *lptName = lpt_device_get_name(c); QComboBox * cbox[PARALLEL_MAX] = { 0 };
if (lptName == nullptr) { QAbstractItemModel *models[PARALLEL_MAX] = { 0 };
break; int removeRows_[PARALLEL_MAX] = { 0 };
int selectedRows[PARALLEL_MAX] = { 0 };
for (uint8_t i = 0; i < PARALLEL_MAX; ++i) {
cbox[i] = findChild<QComboBox *>(QString("comboBoxLpt%1").arg(i + 1));
models[i] = cbox[i]->model();
removeRows_[i] = models[i]->rowCount();
} }
int row = Models::AddEntry(model, tr(lptName), c); while (true) {
if (c == lpt_ports[i].device) { const char *lptName = lpt_device_get_name(c);
selectedRow = row - removeRows;
if (lptName == nullptr)
break;
const QString name = tr(lptName);
for (uint8_t i = 0; i < PARALLEL_MAX; ++i) {
int row = Models::AddEntry(models[i], name, c);
if (c == lpt_ports[i].device)
selectedRows[i] = row - removeRows_[i];
} }
c++; c++;
} }
model->removeRows(0, removeRows);
cbox->setEnabled(model->rowCount() > 0); for (uint8_t i = 0; i < PARALLEL_MAX; ++i) {
cbox->setCurrentIndex(-1); models[i]->removeRows(0, removeRows_[i]);
cbox->setCurrentIndex(selectedRow); cbox[i]->setEnabled(models[i]->rowCount() > 1);
cbox[i]->setCurrentIndex(-1);
cbox[i]->setCurrentIndex(selectedRows[i]);
auto *checkBox = findChild<QCheckBox *>(QString("checkBoxParallel%1").arg(i + 1)); auto *checkBox = findChild<QCheckBox *>(QString("checkBoxParallel%1").arg(i + 1));
if (checkBox != NULL) if (checkBox != NULL)
checkBox->setChecked(lpt_ports[i].enabled > 0); checkBox->setChecked(lpt_ports[i].enabled > 0);
if (cbox != NULL) if (cbox[i] != NULL)
cbox->setEnabled(lpt_ports[i].enabled > 0); cbox[i]->setEnabled(lpt_ports[i].enabled > 0);
} }
for (int i = 0; i < SERIAL_MAX; i++) { for (int i = 0; i < SERIAL_MAX; i++) {

View File

@@ -77,31 +77,35 @@ SettingsSound::onCurrentMachineChanged(const int machineId)
int selectedRow; int selectedRow;
// Sound Card // Sound Card
QComboBox * cbox[SOUND_CARD_MAX] = { 0 };
QAbstractItemModel *models[SOUND_CARD_MAX] = { 0 };
int removeRows_[SOUND_CARD_MAX] = { 0 };
int selectedRows[SOUND_CARD_MAX] = { 0 };
int m_has_snd = machine_has_flags(machineId, MACHINE_SOUND);
for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) { for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) {
QComboBox *cbox = findChild<QComboBox *>(QString("comboBoxSoundCard%1").arg(i + 1)); cbox[i] = findChild<QComboBox *>(QString("comboBoxSoundCard%1").arg(i + 1));
models[i] = cbox[i]->model();
removeRows_[i] = models[i]->rowCount();
}
c = 0; c = 0;
auto model = cbox->model();
auto removeRows = model->rowCount();
selectedRow = 0;
while (true) { while (true) {
/* Skip "internal" if machine doesn't have it or this is not the primary card. */ const QString name = DeviceConfig::DeviceName(sound_card_getdevice(c),
if ((c == 1) && ((i > 0) || (machine_has_flags(machineId, MACHINE_SOUND) == 0))) { sound_card_get_internal_name(c), 1);
c++;
continue;
}
const QString name = DeviceConfig::DeviceName(sound_card_getdevice(c), sound_card_get_internal_name(c), 1); if (name.isEmpty())
if (name.isEmpty()) {
break; break;
}
if (sound_card_available(c)) { if (sound_card_available(c)) {
const device_t *sound_dev = sound_card_getdevice(c); if (device_is_valid(sound_card_getdevice(c), machineId)) {
if (device_is_valid(sound_dev, machineId)) { for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) {
int row = Models::AddEntry(model, name, c); if ((c != 1) || ((i == 0) && m_has_snd)) {
if (c == sound_card_current[i]) { int row = Models::AddEntry(models[i], name, c);
selectedRow = row - removeRows;
if (c == sound_card_current[i])
selectedRows[i] = row - removeRows_[i];
}
} }
} }
} }
@@ -109,10 +113,11 @@ SettingsSound::onCurrentMachineChanged(const int machineId)
c++; c++;
} }
model->removeRows(0, removeRows); for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) {
cbox->setEnabled(model->rowCount() > 0); models[i]->removeRows(0, removeRows_[i]);
cbox->setCurrentIndex(-1); cbox[i]->setEnabled(models[i]->rowCount() > 1);
cbox->setCurrentIndex(selectedRow); cbox[i]->setCurrentIndex(-1);
cbox[i]->setCurrentIndex(selectedRows[i]);
} }
// Midi Out // Midi Out

View File

@@ -171,35 +171,48 @@ SettingsStorageControllers::onCurrentMachineChanged(int machineId)
ui->comboBoxCDInterface->setCurrentIndex(-1); ui->comboBoxCDInterface->setCurrentIndex(-1);
ui->comboBoxCDInterface->setCurrentIndex(selectedRow); ui->comboBoxCDInterface->setCurrentIndex(selectedRow);
for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) { // SCSI Card
QComboBox *cbox = findChild<QComboBox *>(QString("comboBoxSCSI%1").arg(i + 1)); QComboBox * cbox[SCSI_CARD_MAX] = { 0 };
c = 0; QAbstractItemModel *models[SCSI_CARD_MAX] = { 0 };
model = cbox->model(); int removeRows_[SCSI_CARD_MAX] = { 0 };
removeRows = model->rowCount(); int selectedRows[SCSI_CARD_MAX] = { 0 };
selectedRow = 0; int m_has_scsi = machine_has_flags(machineId, MACHINE_SCSI);
while (true) { for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) {
QString name = DeviceConfig::DeviceName(scsi_card_getdevice(c), scsi_card_get_internal_name(c), 1); cbox[i] = findChild<QComboBox *>(QString("comboBoxSCSI%1").arg(i + 1));
if (name.isEmpty()) { models[i] = cbox[i]->model();
break; removeRows_[i] = models[i]->rowCount();
} }
c = 0;
while (true) {
const QString name = DeviceConfig::DeviceName(scsi_card_getdevice(c),
scsi_card_get_internal_name(c), 1);
if (name.isEmpty())
break;
if (scsi_card_available(c)) { if (scsi_card_available(c)) {
const device_t *scsi_dev = scsi_card_getdevice(c); if (device_is_valid(scsi_card_getdevice(c), machineId)) {
if (device_is_valid(scsi_dev, machineId)) { for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) {
int row = Models::AddEntry(model, name, c); if ((c != 1) || ((i == 0) && m_has_scsi)) {
if (c == scsi_card_current[i]) { int row = Models::AddEntry(models[i], name, c);
selectedRow = row - removeRows;
if (c == scsi_card_current[i])
selectedRows[i] = row - removeRows_[i];
} }
} }
} }
}
c++; c++;
} }
model->removeRows(0, removeRows); for (uint8_t i = 0; i < SCSI_CARD_MAX; ++i) {
cbox->setEnabled(model->rowCount() > 0); models[i]->removeRows(0, removeRows_[i]);
cbox->setCurrentIndex(-1); cbox[i]->setEnabled(models[i]->rowCount() > 1);
cbox->setCurrentIndex(selectedRow); cbox[i]->setCurrentIndex(-1);
cbox[i]->setCurrentIndex(selectedRows[i]);
} }
int is_at = IS_AT(machineId); int is_at = IS_AT(machineId);