From 8924cb194ed7d9c7ce87eabcaf0d72c06b1fd9f1 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 13 Jan 2017 22:01:47 +0100 Subject: [PATCH] avoid changing scenegraph while traversing it --- src/Gui/ActionFunction.cpp | 41 ++++++++++++++++++++++++++++++++++++++ src/Gui/ActionFunction.h | 23 +++++++++++++++++++++ src/Gui/ViewProvider.cpp | 16 ++++++++++++--- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/Gui/ActionFunction.cpp b/src/Gui/ActionFunction.cpp index 7f83f98a2708..56e66122657e 100644 --- a/src/Gui/ActionFunction.cpp +++ b/src/Gui/ActionFunction.cpp @@ -112,4 +112,45 @@ void ActionFunction::hovered() } } +// ---------------------------------------------------------------------------- + +namespace Gui { +class TimerFunctionPrivate +{ +public: + boost::function timeoutFunc; + bool autoDelete; +}; +} + +TimerFunction::TimerFunction(QObject* parent) + : QObject(parent), d_ptr(new TimerFunctionPrivate()) +{ + d_ptr->autoDelete = false; +} + +TimerFunction::~TimerFunction() +{ +} + +void TimerFunction::setFunction(boost::function func) +{ + Q_D(TimerFunction); + d->timeoutFunc = func; +} + +void TimerFunction::setAutoDelete(bool on) +{ + Q_D(TimerFunction); + d->autoDelete = on; +} + +void TimerFunction::timeout() +{ + Q_D(TimerFunction); + d->timeoutFunc(); + if (d->autoDelete) + deleteLater(); +} + #include "moc_ActionFunction.cpp" diff --git a/src/Gui/ActionFunction.h b/src/Gui/ActionFunction.h index 04484b5bd514..8fa367d1fd9f 100644 --- a/src/Gui/ActionFunction.h +++ b/src/Gui/ActionFunction.h @@ -86,6 +86,29 @@ private Q_SLOTS: Q_DECLARE_PRIVATE(ActionFunction) }; +class TimerFunctionPrivate; + +class GuiExport TimerFunction : public QObject +{ + Q_OBJECT + +public: + /// Constructor + TimerFunction(QObject* = 0); + virtual ~TimerFunction(); + + void setFunction(boost::function func); + void setAutoDelete(bool); + +private Q_SLOTS: + void timeout(); + +private: + QScopedPointer d_ptr; + Q_DISABLE_COPY(TimerFunction) + Q_DECLARE_PRIVATE(TimerFunction) +}; + } //namespace Gui diff --git a/src/Gui/ViewProvider.cpp b/src/Gui/ViewProvider.cpp index e65b95d4811b..7e89d675c882 100644 --- a/src/Gui/ViewProvider.cpp +++ b/src/Gui/ViewProvider.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ # include +# include # include # include # include @@ -44,6 +45,7 @@ #include "ViewProvider.h" #include "Application.h" +#include "ActionFunction.h" #include "Document.h" #include "ViewProviderPy.h" #include "BitmapFactory.h" @@ -52,6 +54,8 @@ #include "SoFCDB.h" #include "ViewProviderExtension.h" +#include + using namespace std; using namespace Gui; @@ -171,10 +175,16 @@ void ViewProvider::eventCallback(void * ud, SoEventCallback * node) const SbBool press = ke->getState() == SoButtonEvent::DOWN ? true : false; switch (ke->getKey()) { case SoKeyboardEvent::ESCAPE: - if (self->keyPressed (press, ke->getKey())) + if (self->keyPressed (press, ke->getKey())) { node->setHandled(); - else - Gui::Application::Instance->activeDocument()->resetEdit(); + } + else { + Gui::TimerFunction* func = new Gui::TimerFunction(); + func->setAutoDelete(true); + Gui::Document* doc = Gui::Application::Instance->activeDocument(); + func->setFunction(boost::bind(&Document::resetEdit, doc)); + QTimer::singleShot(0, func, SLOT(timeout())); + } break; default: // call the virtual method