diff --git a/src/Gui/TaskView/TaskView.cpp b/src/Gui/TaskView/TaskView.cpp index fabb2f0f9..64c71a376 100644 --- a/src/Gui/TaskView/TaskView.cpp +++ b/src/Gui/TaskView/TaskView.cpp @@ -574,12 +574,18 @@ void TaskView::removeDialog(void) TaskDialog* remove = NULL; if (ActiveDialog) { - const std::vector &cont = ActiveDialog->getDialogContent(); - for(std::vector::const_iterator it=cont.begin();it!=cont.end();++it){ - taskPanel->removeWidget(*it); + // See 'accept' and 'reject' + if (ActiveDialog->property("taskview_accept_or_reject").isNull()) { + const std::vector &cont = ActiveDialog->getDialogContent(); + for(std::vector::const_iterator it=cont.begin();it!=cont.end();++it){ + taskPanel->removeWidget(*it); + } + remove = ActiveDialog; + ActiveDialog = 0; + } + else { + ActiveDialog->setProperty("taskview_remove_dialog", true); } - remove = ActiveDialog; - ActiveDialog = 0; } taskPanel->removeStretch(); @@ -587,7 +593,7 @@ void TaskView::removeDialog(void) // put the watcher back in control addTaskWatcher(); - if(remove) { + if (remove) { remove->emitDestructionSignal(); delete remove; } @@ -600,17 +606,17 @@ void TaskView::updateWatcher(void) // deleted because otherwise Qt may forward the focus via focusNextPrevChild() // to the mdi area which may switch to another mdi view which is not an // acceptable behaviour. - QWidget *fw = QApplication::focusWidget(); - if (!fw) - this->setFocus(); - QPointer fwp = fw; - while (fw && !fw->isWindow()) { - if (fw == this) { + QWidget *fw = QApplication::focusWidget(); + if (!fw) + this->setFocus(); + QPointer fwp = fw; + while (fw && !fw->isWindow()) { + if (fw == this) { this->setFocus(); - break; - } - fw = fw->parentWidget(); - } + break; + } + fw = fw->parentWidget(); + } // add all widgets for all watcher to the task view for (std::vector::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it) { @@ -675,16 +681,16 @@ void TaskView::removeTaskWatcher(void) // deleted because otherwise Qt may forward the focus via focusNextPrevChild() // to the mdi area which may switch to another mdi view which is not an // acceptable behaviour. - QWidget *fw = QApplication::focusWidget(); - if (!fw) - this->setFocus(); - while (fw && !fw->isWindow()) { - if (fw == this) { + QWidget *fw = QApplication::focusWidget(); + if (!fw) + this->setFocus(); + while (fw && !fw->isWindow()) { + if (fw == this) { this->setFocus(); - break; - } - fw = fw->parentWidget(); - } + break; + } + fw = fw->parentWidget(); + } // remove all widgets for (std::vector::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it) { @@ -700,13 +706,23 @@ void TaskView::removeTaskWatcher(void) void TaskView::accept() { - if (ActiveDialog->accept()) + // Make sure that if 'accept' calls 'closeDialog' the deletion is postponed until + // the dialog leaves the 'accept' method + ActiveDialog->setProperty("taskview_accept_or_reject", true); + bool success = ActiveDialog->accept(); + ActiveDialog->setProperty("taskview_accept_or_reject", QVariant()); + if (success || ActiveDialog->property("taskview_remove_dialog").isValid()) removeDialog(); } void TaskView::reject() { - if (ActiveDialog->reject()) + // Make sure that if 'reject' calls 'closeDialog' the deletion is postponed until + // the dialog leaves the 'reject' method + ActiveDialog->setProperty("taskview_accept_or_reject", true); + bool success = ActiveDialog->reject(); + ActiveDialog->setProperty("taskview_accept_or_reject", QVariant()); + if (success || ActiveDialog->property("taskview_remove_dialog").isValid()) removeDialog(); }