summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2012-03-02 21:16:12 +0100
committerArno <am@disconnect.de>2012-03-02 21:16:12 +0100
commitc81a54da19d0d81cb57e3f104ce4d7502faeb869 (patch)
treef203e928074b3eec567759b6c7222a6cefd4a6cd
parent8b0aca608140c72fb7d60f7b821f78a86848a70a (diff)
downloadSheMov-c81a54da19d0d81cb57e3f104ce4d7502faeb869.tar.gz
SheMov-c81a54da19d0d81cb57e3f104ce4d7502faeb869.tar.bz2
SheMov-c81a54da19d0d81cb57e3f104ce4d7502faeb869.zip
Add error checking to MappingTreeWidget::deleteChild()
Return an error if delete fails. Failure should only happen if there are still references to other tables.
-rw-r--r--mappingtreewidget.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp
index ba175ba..01582e5 100644
--- a/mappingtreewidget.cpp
+++ b/mappingtreewidget.cpp
@@ -72,7 +72,7 @@ MappingTreeWidget::MappingTreeWidget(QWidget *parent) : QWidget(parent){
mAddChildA = new QAction(tr("Add..."), this);
connect(mAddChildA, SIGNAL(triggered()), this, SLOT(addChild()));
mTree->addAction(mAddChildA);
- mDeleteChildA = new QAction(tr("Delete"), this);
+ mDeleteChildA = new QAction(tr("Delete..."), this);
connect(mDeleteChildA, SIGNAL(triggered()), this, SLOT(deleteChild()));
mTree->addAction(mDeleteChildA);
mEditChildA = new QAction(tr("Edit..."), this);
@@ -141,17 +141,20 @@ void MappingTreeWidget::addType(){
void MappingTreeWidget::deleteChild(){
QModelIndex sel = selected();
- if(!sel.isValid()){
- QMessageBox::critical(this, tr("Error"), tr("No item selected!"));
- return;
- }
QModelIndex real = mProxy->mapToSource(sel);
if(mModel->rowCount(real) > 0){
QString msg = QString(tr("Cannot delete item %1, because it has %2 children!")).arg(real.data().toString()).arg(QString::number(mModel->rowCount(real)));
QMessageBox::critical(this, tr("Error"), msg);
return;
}
- mModel->deleteChild(real);
+ QString question = QString(tr("Really delete %1?")).arg(real.data(MappingTreeModel::NameRole).toString());
+ int retval = QMessageBox::question(this, tr("Question"), question, QMessageBox::Yes | QMessageBox::No);
+ if(retval == QMessageBox::Yes){
+ if(!mModel->deleteChild(real)){
+ QString msg = QString(tr("Failed to delete %1. Most likely there are still items mapped.")).arg(real.data().toString());
+ QMessageBox::critical(this, tr("Error"), msg);
+ }
+ }
}
void MappingTreeWidget::deleteType(){