postpone deletion of task dialog as long as inside its accept() or reject() method

This commit is contained in:
wmayer 2016-08-06 14:07:58 +02:00
parent 6026608c20
commit e0c69c8afe

View File

@ -574,12 +574,18 @@ void TaskView::removeDialog(void)
TaskDialog* remove = NULL;
if (ActiveDialog) {
const std::vector<QWidget*> &cont = ActiveDialog->getDialogContent();
for(std::vector<QWidget*>::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<QWidget*> &cont = ActiveDialog->getDialogContent();
for(std::vector<QWidget*>::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<QWidget> fwp = fw;
while (fw && !fw->isWindow()) {
if (fw == this) {
QWidget *fw = QApplication::focusWidget();
if (!fw)
this->setFocus();
QPointer<QWidget> 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<TaskWatcher*>::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<TaskWatcher*>::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();
}