scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Script.h
Go to the documentation of this file.
1 
13 
31 #ifndef SCRIPT_H
32 #define SCRIPT_H
33 
34 #include <QVariant>
35 #include <QString>
36 #include <QStringList>
37 #include <QObject>
38 #include <QStringList>
39 #include <QEvent>
40 
41 #include "customevents.h"
42 #include "ScriptingEnv.h"
43 
44 class ApplicationWindow;
45 
47 
52 class Script : public QObject
53 {
54  Q_OBJECT
55 
56  public:
57  Script(ScriptingEnv *env, const QString &code, QObject *context=0, const QString &name="<input>")
58  : QObject(context), Env(env), Code(code), Name(name), compiled(notCompiled)
59  { Env->incref(); Context = context; EmitErrors=true; }
60  ~Script() { Env->decref(); }
61 
63  const QString code() const { return Code; }
65  const QObject* context() const { return Context; }
67  const QString name() const { return Name; }
69  bool emitErrors() const { return EmitErrors; }
71  virtual void addCode(const QString &code) { Code.append(code); compiled = notCompiled; emit codeChanged(); }
73  virtual void setCode(const QString &code) { Code=code; compiled = notCompiled; emit codeChanged(); }
75  virtual void setContext(QObject *context) { Context = context; compiled = notCompiled; }
77  void setName(const QString &name) { Name = name; compiled = notCompiled; }
79  void setEmitErrors(bool yes) { EmitErrors = yes; }
80 
82  bool batchMode=false;
83 
84  public slots:
86  virtual bool compile(bool for_eval=true);
88  virtual QVariant eval();
90  virtual bool exec();
91 
92  // local variables
93  virtual bool setQObject(QObject*, const char*) { return false; }
94  virtual bool setInt(int, const char*) { return false; }
95  virtual bool setDouble(double, const char*) { return false; }
96 
97  signals:
99  void codeChanged();
101  void error(const QString & message, const QString & scriptName, int lineNumber);
103  void print(const QString & output);
104 
105  protected:
107  QString Code, Name;
108  QObject *Context;
111 
112  void emit_error(const QString & message, int lineNumber)
113  { if(EmitErrors) emit error(message, Name, lineNumber); }
114 };
115 
118 {
119  public:
121  static ScriptingEnv *newEnv(ApplicationWindow *parent);
123  static ScriptingEnv *newEnv(const std::string& name, ApplicationWindow *parent, bool batch=false);
125  static QStringList languages();
127  static int numLanguages();
128 
129 };
130 
132 class ScriptingChangeEvent : public QEvent
133 {
134  public:
136  ScriptingEnv *scriptingEnv() const { return env; }
137  Type type() const { return SCRIPTING_CHANGE_EVENT; }
138  private:
140 };
141 
143 
148 class scripted
149 {
150  public:
151  scripted(ScriptingEnv* env);
152  ~scripted();
154  protected:
156 };
157 
158 #endif
159 
Script::error
void error(const QString &message, const QString &scriptName, int lineNumber)
signal an error condition / exception
Script::setContext
virtual void setContext(QObject *context)
Set the context in which the code is to be executed.
Definition: Script.h:75
Script::Script
Script(ScriptingEnv *env, const QString &code, QObject *context=0, const QString &name="<input>")
Definition: Script.h:57
ScriptingChangeEvent::scriptingEnv
ScriptingEnv * scriptingEnv() const
Definition: Script.h:136
ScriptingEnv.h
scripted::scriptEnv
ScriptingEnv * scriptEnv
Definition: Script.h:155
ScriptingEnv::incref
void incref()
Increase the reference count. This should only be called by scripted and Script to avoid memory leaks...
Definition: ScriptingEnv.cpp:60
Script::compiled
enum Script::compileStatus compiled
ScriptingChangeEvent::env
ScriptingEnv * env
Definition: Script.h:139
Script::setDouble
virtual bool setDouble(double, const char *)
Definition: Script.h:95
ScriptingEnv::decref
void decref()
Decrease the reference count. This should only be called by scripted and Script to avoid segfaults.
Definition: ScriptingEnv.cpp:65
ScriptingLangManager::newEnv
static ScriptingEnv * newEnv(ApplicationWindow *parent)
Return an instance of the first implementation we can find.
Definition: Script.cpp:56
Script::compileStatus
compileStatus
Definition: Script.h:109
Script::Context
QObject * Context
Definition: Script.h:108
SCRIPTING_CHANGE_EVENT
#define SCRIPTING_CHANGE_EVENT
Definition: customevents.h:40
Script::code
const QString code() const
Return the code that will be executed when calling exec() or eval()
Definition: Script.h:63
scripted
Interface for maintaining a reference to the current ScriptingEnv.
Definition: Script.h:149
Script::setEmitErrors
void setEmitErrors(bool yes)
Set whether errors / exceptions are to be emitted or silently ignored.
Definition: Script.h:79
Script::batchMode
bool batchMode
true if running in batch - don't redirect stdio
Definition: Script.h:82
Script::compileErr
@ compileErr
Definition: Script.h:109
Script::emitErrors
bool emitErrors() const
Return whether errors / exceptions are to be emitted or silently ignored.
Definition: Script.h:69
scripted::scriptingChangeEvent
void scriptingChangeEvent(ScriptingChangeEvent *)
Definition: Script.cpp:119
customevents.h
Script::Env
ScriptingEnv * Env
Definition: Script.h:106
ScriptingEnv
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:53
ScriptingChangeEvent::ScriptingChangeEvent
ScriptingChangeEvent(ScriptingEnv *e)
Definition: Script.h:135
ApplicationWindow
SciDAVis's main window.
Definition: ApplicationWindow.h:122
Script
A chunk of scripting code. Abstract.
Definition: Script.h:53
Script::context
const QObject * context() const
Return the context in which the code is to be executed.
Definition: Script.h:65
ScriptingChangeEvent
notify an object that it should update its scripting environment (see class scripted)
Definition: Script.h:133
ScriptingLangManager::numLanguages
static int numLanguages()
Return the number of available implementations.
Script::emit_error
void emit_error(const QString &message, int lineNumber)
Definition: Script.h:112
scripted::scripted
scripted(ScriptingEnv *env)
Definition: Script.cpp:108
name
char * name()
Definition: exp_saturation.c:45
Script::codeChanged
void codeChanged()
This is emitted whenever the code to be executed by exec() and eval() is changed.
Script::isCompiled
@ isCompiled
Definition: Script.h:109
ScriptingLangManager
keeps a static list of available interpreters and instantiates them on demand
Definition: Script.h:118
scripted::~scripted
~scripted()
Definition: Script.cpp:114
Script::eval
virtual QVariant eval()
Evaluate the Code, returning QVariant() on an error / exception.
Definition: Script.cpp:96
Script::setCode
virtual void setCode(const QString &code)
Set the code that will be executed when calling exec() or eval()
Definition: Script.h:73
ScriptingLangManager::languages
static QStringList languages()
Return the names of available implementations.
Definition: Script.cpp:82
Script::print
void print(const QString &output)
output generated by the code
Script::Name
QString Name
Definition: Script.h:107
Script::setQObject
virtual bool setQObject(QObject *, const char *)
Definition: Script.h:93
Script::name
const QString name() const
Like QObject::name, but with unicode support.
Definition: Script.h:67
Script::EmitErrors
bool EmitErrors
Definition: Script.h:110
Script::setInt
virtual bool setInt(int, const char *)
Definition: Script.h:94
Script::addCode
virtual void addCode(const QString &code)
Append to the code that will be executed when calling exec() or eval()
Definition: Script.h:71
Script::~Script
~Script()
Definition: Script.h:60
Script::setName
void setName(const QString &name)
Like QObject::setName, but with unicode support.
Definition: Script.h:77
ScriptingChangeEvent::type
Type type() const
Definition: Script.h:137
Script::exec
virtual bool exec()
Execute the Code, returning false on an error / exception.
Definition: Script.cpp:102
Script::compile
virtual bool compile(bool for_eval=true)
Compile the Code. Return true if the implementation doesn't support compilation.
Definition: Script.cpp:90
Script::Code
QString Code
Definition: Script.h:107
Script::notCompiled
@ notCompiled
Definition: Script.h:109