qt: hide machine types with no available machines

This commit is contained in:
Alexander Babikov
2022-02-14 03:18:56 +05:00
parent 04e37b8771
commit f24923b988

View File

@@ -74,12 +74,21 @@ SettingsMachine::SettingsMachine(QWidget *parent) :
int selectedMachineType = 0; int selectedMachineType = 0;
auto* machineTypesModel = ui->comboBoxMachineType->model(); auto* machineTypesModel = ui->comboBoxMachineType->model();
for (int i = 0; i < MACHINE_TYPE_MAX; ++i) { for (int i = 1; i < MACHINE_TYPE_MAX; ++i) {
Models::AddEntry(machineTypesModel, machine_types[i].name, machine_types[i].id); int j = 0;
if (machine_types[i].id == machine_get_type(machine)) { while (machine_get_internal_name_ex(j) != nullptr) {
selectedMachineType = i; if (machine_available(j) && (machine_get_type(j) == i)) {
int row = Models::AddEntry(machineTypesModel, machine_types[i].name, machine_types[i].id);
if (machine_types[i].id == machine_get_type(machine)) {
selectedMachineType = row;
}
break;
}
j++;
} }
} }
ui->comboBoxMachineType->setCurrentIndex(-1);
ui->comboBoxMachineType->setCurrentIndex(selectedMachineType); ui->comboBoxMachineType->setCurrentIndex(selectedMachineType);
} }
@@ -124,12 +133,16 @@ void SettingsMachine::save() {
} }
void SettingsMachine::on_comboBoxMachineType_currentIndexChanged(int index) { void SettingsMachine::on_comboBoxMachineType_currentIndexChanged(int index) {
if (index < 0) {
return;
}
auto* model = ui->comboBoxMachine->model(); auto* model = ui->comboBoxMachine->model();
int removeRows = model->rowCount(); int removeRows = model->rowCount();
int selectedMachineRow = 0; int selectedMachineRow = 0;
for (int i = 0; i < machine_count(); ++i) { for (int i = 0; i < machine_count(); ++i) {
if ((machine_get_type(i) == index) && machine_available(i)) { if ((machine_get_type(i) == ui->comboBoxMachineType->currentData().toInt()) && machine_available(i)) {
int row = Models::AddEntry(model, machines[i].name, i); int row = Models::AddEntry(model, machines[i].name, i);
if (i == machine) { if (i == machine) {
selectedMachineRow = row - removeRows; selectedMachineRow = row - removeRows;