QtiPlot  0.9.8.2
ScriptingEnv.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : ScriptingEnv.h
3  Project : QtiPlot
4  --------------------------------------------------------------------
5  Copyright : (C) 2006 by Ion Vasilief, Knut Franke
6  Email (use @ for *) : ion_vasilief*yahoo.fr
7  Description : Scripting abstraction layer
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 #ifndef SCRIPTINGENV_H
30 #define SCRIPTINGENV_H
31 
32 #include <QVariant>
33 #include <QString>
34 #include <QStringList>
35 #include <QObject>
36 #include <QStringList>
37 #include <QEvent>
38 
39 #include "customevents.h"
40 
41 class ApplicationWindow;
42 class Script;
43 
45 
50 class ScriptingEnv : public QObject
51 {
52  Q_OBJECT
53 
54  public:
55  ScriptingEnv(ApplicationWindow *parent, const char *langName);
57  virtual bool initialize() { return true; };
59  bool initialized() const { return d_initialized; }
61  virtual bool isRunning() const { return false; }
62 
64  virtual Script *newScript(const QString&, QObject*, const QString&) { return 0; }
65 
67  virtual QString stackTraceString() { return QString::null; }
68 
70  virtual const QStringList mathFunctions() const { return QStringList(); }
72  virtual const QString mathFunctionDoc(const QString&) const { return QString::null; }
74  virtual const QStringList fileExtensions() const { return QStringList(); };
76  const QString fileFilter() const;
77 
79 
80  public slots:
81  // global variables
82  virtual bool setQObject(QObject*, const char*) { return false; }
83  virtual bool setInt(int, const char*) { return false; }
84  virtual bool setDouble(double, const char*) { return false; }
85 
87  virtual void clear() {}
89  virtual void stopExecution() {}
91  virtual void startExecution() {}
92 
94  void incref();
96  void decref();
97 
98  signals:
100  void error(const QString & message, const QString & scriptName, int lineNumber);
102  void print(const QString & output);
103 
104  protected:
109 
110  private:
113 };
114 
115 #endif
ApplicationWindow * application()
Definition: ScriptingEnv.h:78
void incref()
Increase the reference count. This should only be called by scripted and Script to avoid memory leaks...
Definition: ScriptingEnv.cpp:59
void error(const QString &message, const QString &scriptName, int lineNumber)
signal an error condition / exception
virtual void clear()
Clear the global environment. What exactly happens depends on the implementation. ...
Definition: ScriptingEnv.h:87
virtual const QStringList fileExtensions() const
Return a list of file extensions commonly used for this language.
Definition: ScriptingEnv.h:74
virtual bool setDouble(double, const char *)
Definition: ScriptingEnv.h:84
virtual const QStringList mathFunctions() const
Return a list of supported mathematical functions. These should be imported into the global namespace...
Definition: ScriptingEnv.h:70
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:50
virtual bool setInt(int, const char *)
Definition: ScriptingEnv.h:83
ApplicationWindow * d_parent
the context in which we are running
Definition: ScriptingEnv.h:108
virtual QString stackTraceString()
If an exception / error occured, return a nicely formated stack backtrace.
Definition: ScriptingEnv.h:67
virtual bool isRunning() const
whether asynchronuous execution is enabled (if supported by the implementation)
Definition: ScriptingEnv.h:61
const QString fileFilter() const
Construct a filter expression from fileExtension(), suitable for QFileDialog.
Definition: ScriptingEnv.cpp:50
int d_refcount
the reference counter
Definition: ScriptingEnv.h:112
A chunk of scripting code. Abstract.
Definition: Script.h:50
QtiPlot's main window.
Definition: ApplicationWindow.h:133
ScriptingEnv(ApplicationWindow *parent, const char *langName)
Definition: ScriptingEnv.cpp:43
bool d_initialized
whether the interpreter has been successfully initialized
Definition: ScriptingEnv.h:106
void decref()
Decrease the reference count. This should only be called by scripted and Script to avoid segfaults...
Definition: ScriptingEnv.cpp:64
void print(const QString &output)
output that is not handled by a Script
virtual Script * newScript(const QString &, QObject *, const QString &)
Instantiate the Script subclass matching the ScriptEnv subclass.
Definition: ScriptingEnv.h:64
virtual bool initialize()
Part of the initialization is deferred from the constructor until after the signals have been connect...
Definition: ScriptingEnv.h:57
virtual bool setQObject(QObject *, const char *)
Definition: ScriptingEnv.h:82
virtual const QString mathFunctionDoc(const QString &) const
Return a documentation string for the given mathematical function.
Definition: ScriptingEnv.h:72
virtual void startExecution()
If the implementation supports asynchronuos execution, activate it.
Definition: ScriptingEnv.h:91
bool initialized() const
initialization of the interpreter may fail; or there could be other errors setting up the environment...
Definition: ScriptingEnv.h:59
virtual void stopExecution()
If the implementation supports asynchronuos execution, deactivate it.
Definition: ScriptingEnv.h:89