...
 
include (plugin)
openflipper_plugin (DIRS config parser scene types types/objectId INSTALLDATA Icons VsiMetadata)
openflipper_plugin (DIRS config parser scene types types/objectId INSTALLDATA Icons VsiMetadata
DEPS Qt5Script)
......@@ -59,7 +59,8 @@
#include <QApplication>
#include <QClipboard>
#include <QScriptEngine>
//#include <QScriptEngine>
#include <QDomDocument>
......@@ -210,9 +211,12 @@ void BaseWidget::executeCode ()
if (errors.isEmpty ())
{
ctx_->scriptEngine ()->pushContext ();
ctx_->scriptEngine ()->evaluate (code);
ctx_->scriptEngine ()->popContext ();
// @NOTE jwedowski: empty stub to prevent runtime crashes during migration
//ctx_->scriptEngine ()->pushContext ();
//ctx_->scriptEngine ()->evaluate (code);
//ctx_->scriptEngine ()->popContext ();
// @script-ugprade
emit executeScript(code);
return;
}
......
......@@ -87,6 +87,7 @@ class BaseWidget : public QMainWindow
signals:
void codeToScriptEditor (QString _code);
void executeScript(QString script);
public slots:
......
......@@ -81,8 +81,7 @@ namespace VSI {
//=============================================================================
/// Constructor
Context::Context (QScriptEngine *_engine) :
scriptEngine_ (_engine)
Context::Context ()
{
// add start element
Element *e = new Element (this, "start");
......
......@@ -58,7 +58,8 @@
#include "element.hh"
//== FORWARDDECLARATIONS ======================================================
class QScriptEngine;
//class QScriptEngine;
// @script-upgrade
//== NAMESPACES ===============================================================
namespace VSI {
......@@ -77,7 +78,7 @@ class Context {
public:
/// Constructor
explicit Context (QScriptEngine *_engine);
Context ();
/// Destructor
~Context ();
......@@ -110,7 +111,8 @@ class Context {
bool canConvert (QString _type1, QString _type2);
/// Return script engine pointer
QScriptEngine *scriptEngine () { return scriptEngine_; };
/// @script-upgrade
//QScriptEngine *scriptEngine () { return scriptEngine_; };
/// Converts the given string to bool
static bool strToBool (QString _str);
......@@ -142,7 +144,6 @@ class Context {
QList <Type *> types_;
QScriptEngine *scriptEngine_;
};
//=============================================================================
......
......@@ -56,7 +56,6 @@
//== INCLUDES =================================================================
#include <QAction>
#include <QScriptEngine>
#include <QMessageBox>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
......@@ -100,7 +99,7 @@ void VsiPlugin::pluginsInitialized ()
QMenu *scriptingMenu;
emit emit getMenubarMenu(tr("&Scripting"), scriptingMenu, true );
emit getMenubarMenu(tr("&Scripting"), scriptingMenu, true );
QAction* showEditor = scriptingMenu->addAction ("Visual script editor");
showEditor->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"vsi_vsiEditor.png") );
......@@ -123,6 +122,8 @@ void VsiPlugin::showScriptEditor()
baseWidget_ = VSI::BaseWidget::createBaseWidget (context_);
connect (baseWidget_, SIGNAL (codeToScriptEditor (QString)),
this, SLOT (showInScriptEditor(QString)));
connect(baseWidget_, SIGNAL(executeScript (QString)),
this, SLOT(dispatchScript(QString)));
}
baseWidget_->show ();
......@@ -134,11 +135,9 @@ void VsiPlugin::initContext()
if (context_)
return;
QScriptEngine *engine;
emit getScriptingEngine (engine);
// empty context
context_ = new VSI::Context (engine);
context_ = new VSI::Context ();
// parse all metadata xml files
QDir dir = OpenFlipper::Options::dataDir ();
......@@ -172,6 +171,8 @@ void VsiPlugin::initContext()
//------------------------------------------------------------------------------
/// Gererates a dialog for the given element inputs
///
/* @script-upgrade
QScriptValue VsiPlugin::askForInputs(QString _element, QString _inputs)
{
initContext ();
......@@ -211,6 +212,12 @@ QScriptValue VsiPlugin::askForInputs(QString _element, QString _inputs)
script += "};";
// @script-upgrade
emit executeScript(script);
ScriptExecutionResult res;
emit getLastScriptExecutionResult(res);
context_->scriptEngine ()->pushContext ();
QScriptValue rv = context_->scriptEngine ()->evaluate (script);
context_->scriptEngine ()->globalObject ().setProperty ("inputs", rv);
......@@ -219,6 +226,13 @@ QScriptValue VsiPlugin::askForInputs(QString _element, QString _inputs)
return rv;
}
*/
// @script-upgrade
void VsiPlugin::dispatchScript(QString _script)
{
emit executeScript(_script);
std::cout << _script.toStdString() << std::endl;
}
//------------------------------------------------------------------------------
......
......@@ -53,7 +53,6 @@
#define VSIPLUGIN_HH
#include <QObject>
#include <QScriptValue>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
......@@ -87,7 +86,8 @@ class VsiPlugin : public QObject, BaseInterface, MenuInterface, ScriptInterface,
void getMenubarMenu (QString _name, QMenu *& _menu, bool _create);
// ScriptInterface
void getScriptingEngine (QScriptEngine*& _engine);
void executeScript(QString script);
void getLastScriptExecutionResult(ScriptExecutionResult& result);
// RPC Interface
void pluginExists (QString _pluginName, bool& _exists) ;
......@@ -110,7 +110,9 @@ class VsiPlugin : public QObject, BaseInterface, MenuInterface, ScriptInterface,
public slots:
/// Scripting function, that allows to ask the user for inputs during script execution
QScriptValue askForInputs (QString _element, QString _inputs);
//QScriptValue askForInputs (QString _element, QString _inputs);
// @script-upgrade executes a string as a script
void dispatchScript(QString _script);
/// Scripting function, that displays a message box
void messageBox (QString _message);
......