Skip to content

Commit

Permalink
postpone deletion of task dialog as long as inside its accept() or re…
Browse files Browse the repository at this point in the history
…ject() method
  • Loading branch information
wwmayer committed Aug 6, 2016
1 parent 6026608 commit e0c69c8
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions src/Gui/TaskView/TaskView.cpp
Expand Up @@ -574,20 +574,26 @@ 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();

// put the watcher back in control
addTaskWatcher();

if(remove) {
if (remove) {
remove->emitDestructionSignal();
delete remove;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}

Expand Down

0 comments on commit e0c69c8

Please sign in to comment.