catch case that users tries to delete all items in the dialog list

This commit is contained in:
donovaly
2020-02-16 22:24:52 +01:00
committed by wmayer
parent 316a8840b4
commit b86d97b9bc
4 changed files with 28 additions and 0 deletions

View File

@@ -28,6 +28,7 @@
# include <QMessageBox>
# include <QAction>
# include <QListWidget>
# include <QMessageBox>
#endif
#include "ui_TaskDraftParameters.h"
@@ -243,6 +244,12 @@ void TaskDraftParameters::onRefDeleted(void)
// get the list of items to be deleted
QList<QListWidgetItem*> selectedList = ui->listWidgetReferences->selectedItems();
// if all items are selected, we must stop because one must be kept to avoid that the feature gets broken
if (selectedList.count() == ui->listWidgetReferences->model()->rowCount()) {
QMessageBox::warning(this, tr("Selection error"), tr("At least one item must be kept."));
return;
}
// delete the selection backwards to assure the list index keeps valid for the deletion
for (int i = selectedList.count() - 1; i > -1; i--) {
QListWidgetItem* item = selectedList.at(i);