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
+7 -3
View File
@@ -580,14 +580,16 @@ 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 (!ed->isEmpty()) {
if ((int)ed->chn == inputIdx) if ((int)ed->chn == inputIdx)
model->removeInput(i); 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();
updateItemModels(); updateItemModels();
@@ -596,16 +598,18 @@ 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 (!ed->isEmpty()) {
if ((int)ed->chn == inputIdx) if ((int)ed->chn == inputIdx)
model->removeInput(i); model->removeInput(i);
else if ((int)ed->chn > inputIdx) else if ((int)ed->chn > inputIdx)
ed->chn--; ed->chn--;
} }
}
for (int i = inputIdx; i < inputsCount; i++) { for (int i = inputIdx; i < inputsCount; i++) {
strncpy(model->inputNames[i], model->inputNames[i + 1], sizeof(model->inputNames[i]) - 1); strncpy(model->inputNames[i], model->inputNames[i + 1], sizeof(model->inputNames[i]) - 1);