Merge pull request #8357 from opentx/elecpower/cpn-inp-del-fix-8354

Companion fix delete input corruption
This commit is contained in:
Bertrand Songis
2021-04-05 10:57:19 +02:00
committed by GitHub
+13 -9
View File
@@ -580,13 +580,15 @@ bool InputsPanel::cmInputMoveUpAllowed() const
void InputsPanel::cmInputClear() void InputsPanel::cmInputClear()
{ {
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear all lines for the selected Inputs. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Clear all lines for the selected Input. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
return; return;
for (int i = CPN_MAX_EXPOS - 1; i >= 0; i--) { for (int i = CPN_MAX_EXPOS - 1; i >= 0; i--) {
ExpoData *ed = &model->expoData[i]; ExpoData *ed = &model->expoData[i];
if ((int)ed->chn == inputIdx) if (!ed->isEmpty()) {
model->removeInput(i); if ((int)ed->chn == inputIdx)
model->removeInput(i);
}
} }
model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_CLEAR, inputIdx); model->updateAllReferences(ModelData::REF_UPD_TYPE_INPUT, ModelData::REF_UPD_ACT_CLEAR, inputIdx);
update(); update();
@@ -596,15 +598,17 @@ void InputsPanel::cmInputClear()
void InputsPanel::cmInputDelete() void InputsPanel::cmInputDelete()
{ {
if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Delete all lines for the selected Inputs. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) if (QMessageBox::question(this, CPN_STR_APP_NAME, tr("Delete all lines for the selected Input. Are you sure?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
return; return;
for (int i = 0; i < CPN_MAX_EXPOS; i++) { for (int i = CPN_MAX_EXPOS - 1; i >= 0; i--) {
ExpoData *ed = &model->expoData[i]; ExpoData *ed = &model->expoData[i];
if ((int)ed->chn == inputIdx) if (!ed->isEmpty()) {
model->removeInput(i); if ((int)ed->chn == inputIdx)
else if ((int)ed->chn > inputIdx) model->removeInput(i);
ed->chn--; else if ((int)ed->chn > inputIdx)
ed->chn--;
}
} }
for (int i = inputIdx; i < inputsCount; i++) { for (int i = inputIdx; i < inputsCount; i++) {