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

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