Showing the changes to libraries/script-engine/src/UndoStackScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -0,0 +1,46 @@ | ||
| 1 | +// | |
| 2 | +// UndoStackScriptingInterface.cpp | |
| 3 | +// libraries/script-engine/src | |
| 4 | +// | |
| 5 | +// Created by Ryan Huffman on 10/22/14. | |
| 6 | +// Copyright 2014 High Fidelity, Inc. | |
| 7 | +// | |
| 8 | +// Distributed under the Apache License, Version 2.0. | |
| 9 | +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | |
| 10 | +// | |
| 11 | + | |
| 12 | +#include <QDebug> | |
| 13 | +#include <QScriptValueList> | |
| 14 | +#include <QScriptEngine> | |
| 15 | + | |
| 16 | +#include "UndoStackScriptingInterface.h" | |
| 17 | + | |
| 18 | +UndoStackScriptingInterface::UndoStackScriptingInterface(QUndoStack* undoStack) : _undoStack(undoStack) { | |
| 19 | +} | |
| 20 | + | |
| 21 | +void UndoStackScriptingInterface::pushCommand(QScriptValue undoFunction, QScriptValue undoData, | |
| 22 | + QScriptValue redoFunction, QScriptValue redoData) { | |
| 23 | + ScriptUndoCommand* undoCommand = new ScriptUndoCommand(undoFunction, undoData, redoFunction, redoData); | |
| 24 | + qDebug() << "Pushing command"; | |
| 25 | + _undoStack->push(undoCommand); | |
| 26 | +} | |
| 27 | + | |
| 28 | +ScriptUndoCommand::ScriptUndoCommand(QScriptValue undoFunction, QScriptValue undoData, | |
| 29 | + QScriptValue redoFunction, QScriptValue redoData) : | |
| 30 | + _undoFunction(undoFunction), | |
| 31 | + _undoData(undoData), | |
| 32 | + _redoFunction(redoFunction), | |
| 33 | + _redoData(redoData) { | |
| 34 | +} | |
| 35 | + | |
| 36 | +void ScriptUndoCommand::undo() { | |
| 37 | + QScriptValueList args; | |
| 38 | + args << _undoData; | |
| 39 | + _undoFunction.call(QScriptValue(), args); | |
| 40 | +} | |
| 41 | + | |
| 42 | +void ScriptUndoCommand::redo() { | |
| 43 | + QScriptValueList args; | |
| 44 | + args << _redoData; | |
| 45 | + _redoFunction.call(QScriptValue(), args); | |
| 46 | +} | |