avoid changing scenegraph while traversing it

This commit is contained in:
wmayer 2017-01-13 22:01:47 +01:00
parent 09d80342d6
commit 8924cb194e
3 changed files with 77 additions and 3 deletions

View File

@ -112,4 +112,45 @@ void ActionFunction::hovered()
}
}
// ----------------------------------------------------------------------------
namespace Gui {
class TimerFunctionPrivate
{
public:
boost::function<void()> timeoutFunc;
bool autoDelete;
};
}
TimerFunction::TimerFunction(QObject* parent)
: QObject(parent), d_ptr(new TimerFunctionPrivate())
{
d_ptr->autoDelete = false;
}
TimerFunction::~TimerFunction()
{
}
void TimerFunction::setFunction(boost::function<void()> 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"

View File

@ -86,6 +86,29 @@ private:
Q_DECLARE_PRIVATE(ActionFunction)
};
class TimerFunctionPrivate;
class GuiExport TimerFunction : public QObject
{
Q_OBJECT
public:
/// Constructor
TimerFunction(QObject* = 0);
virtual ~TimerFunction();
void setFunction(boost::function<void()> func);
void setAutoDelete(bool);
private Q_SLOTS:
void timeout();
private:
QScopedPointer<TimerFunctionPrivate> d_ptr;
Q_DISABLE_COPY(TimerFunction)
Q_DECLARE_PRIVATE(TimerFunction)
};
} //namespace Gui

View File

@ -25,6 +25,7 @@
#ifndef _PreComp_
# include <QPixmap>
# include <QTimer>
# include <Inventor/SoPickedPoint.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoSwitch.h>
@ -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 <boost/bind.hpp>
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