Skip to content

Commit

Permalink
avoid changing scenegraph while traversing it
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 13, 2017
1 parent 09d8034 commit 8924cb1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
41 changes: 41 additions & 0 deletions src/Gui/ActionFunction.cpp
Expand Up @@ -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"
23 changes: 23 additions & 0 deletions src/Gui/ActionFunction.h
Expand Up @@ -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<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


Expand Down
16 changes: 13 additions & 3 deletions src/Gui/ViewProvider.cpp
Expand Up @@ -25,6 +25,7 @@

#ifndef _PreComp_
# include <QPixmap>
# include <QTimer>
# include <Inventor/SoPickedPoint.h>
# include <Inventor/nodes/SoSeparator.h>
# include <Inventor/nodes/SoSwitch.h>
Expand All @@ -44,6 +45,7 @@

#include "ViewProvider.h"
#include "Application.h"
#include "ActionFunction.h"
#include "Document.h"
#include "ViewProviderPy.h"
#include "BitmapFactory.h"
Expand All @@ -52,6 +54,8 @@
#include "SoFCDB.h"
#include "ViewProviderExtension.h"

#include <boost/bind.hpp>

using namespace std;
using namespace Gui;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8924cb1

Please sign in to comment.