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,34 +73,49 @@ SettingsPorts::onCurrentMachineChanged(int 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 selectedRow = 0;
while (true) {
const char *lptName = lpt_device_get_name(c);
if (lptName == nullptr) {
break;
}
int c = 0;
int row = Models::AddEntry(model, tr(lptName), c);
if (c == lpt_ports[i].device) {
selectedRow = row - removeRows;
}
c++;
// LPT Device
QComboBox * cbox[PARALLEL_MAX] = { 0 };
QAbstractItemModel *models[PARALLEL_MAX] = { 0 };
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();
}
while (true) {
const char *lptName = lpt_device_get_name(c);
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];
}
model->removeRows(0, removeRows);
cbox->setEnabled(model->rowCount() > 0);
cbox->setCurrentIndex(-1);
cbox->setCurrentIndex(selectedRow);
c++;
}
for (uint8_t i = 0; i < PARALLEL_MAX; ++i) {
models[i]->removeRows(0, removeRows_[i]);
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));
if (checkBox != NULL)
checkBox->setChecked(lpt_ports[i].enabled > 0);
if (cbox != NULL)
cbox->setEnabled(lpt_ports[i].enabled > 0);
if (cbox[i] != NULL)
cbox[i]->setEnabled(lpt_ports[i].enabled > 0);
}
for (int i = 0; i < SERIAL_MAX; i++) {