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

@@ -73,46 +73,51 @@ SettingsSound::onCurrentMachineChanged(const int machineId)
{
this->machineId = machineId;
int c;
int selectedRow;
int c;
int selectedRow;
// 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) {
QComboBox *cbox = findChild<QComboBox *>(QString("comboBoxSoundCard%1").arg(i + 1));
c = 0;
auto model = cbox->model();
auto removeRows = model->rowCount();
selectedRow = 0;
cbox[i] = findChild<QComboBox *>(QString("comboBoxSoundCard%1").arg(i + 1));
models[i] = cbox[i]->model();
removeRows_[i] = models[i]->rowCount();
}
while (true) {
/* Skip "internal" if machine doesn't have it or this is not the primary card. */
if ((c == 1) && ((i > 0) || (machine_has_flags(machineId, MACHINE_SOUND) == 0))) {
c++;
continue;
}
c = 0;
while (true) {
const QString name = DeviceConfig::DeviceName(sound_card_getdevice(c),
sound_card_get_internal_name(c), 1);
const QString name = DeviceConfig::DeviceName(sound_card_getdevice(c), sound_card_get_internal_name(c), 1);
if (name.isEmpty()) {
break;
}
if (name.isEmpty())
break;
if (sound_card_available(c)) {
const device_t *sound_dev = sound_card_getdevice(c);
if (device_is_valid(sound_dev, machineId)) {
int row = Models::AddEntry(model, name, c);
if (c == sound_card_current[i]) {
selectedRow = row - removeRows;
if (sound_card_available(c)) {
if (device_is_valid(sound_card_getdevice(c), machineId)) {
for (uint8_t i = 0; i < SOUND_CARD_MAX; ++i) {
if ((c != 1) || ((i == 0) && m_has_snd)) {
int row = Models::AddEntry(models[i], name, c);
if (c == sound_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 < SOUND_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]);
}
// Midi Out