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

@@ -26,6 +26,7 @@
#ifndef _PreComp_
# include <QAction>
# include <QListWidget>
# include <QMessageBox>
#endif
#include "ui_TaskChamferParameters.h"
@@ -169,6 +170,12 @@ void TaskChamferParameters::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);

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);

View File

@@ -27,6 +27,7 @@
# include <QAction>
# include <QKeyEvent>
# include <QListWidget>
# include <QMessageBox>
#endif
#include "ui_TaskFilletParameters.h"
@@ -169,6 +170,12 @@ void TaskFilletParameters::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);

View File

@@ -26,6 +26,7 @@
#ifndef _PreComp_
# include <QAction>
# include <QListWidget>
# include <QMessageBox>
#endif
#include "ui_TaskThicknessParameters.h"
@@ -191,6 +192,12 @@ void TaskThicknessParameters::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);