QCAD
Open Source 2D CAD
RScriptHandler.h
Go to the documentation of this file.
1 
20 #ifndef RSCRIPTHANDLER_H
21 #define RSCRIPTHANDLER_H
22 
23 #include "core_global.h"
24 
25 #include <QList>
26 #include <QMetaType>
27 #include <QString>
28 
29 #include "RNonCopyable.h"
30 #include "RDocumentInterface.h"
31 #include "RAction.h"
32 #include "RGuiAction.h"
33 #include "RScriptAction.h"
34 #include "RMainWindow.h"
35 
36 class RFileImporterAdapter;
37 
38 
45 
46 public:
47 
49 
50  virtual ~RScriptHandler() { }
51 
56  virtual QList<QString> getSupportedFileExtensions() = 0;
57 
58  virtual void init(const QString& autostartFile = QString::null, const QStringList& arguments = QStringList());
59 
63  virtual void doScript(const QString& scriptFile, const QStringList& arguments = QStringList()) = 0;
64 
68  virtual QVariant eval(const QString& script, const QString& fileName = QString()) = 0;
69 
73  virtual QVariant evalGlobal(const QString& script, const QString& fileName = QString()) = 0;
74 
78  virtual RFileImporterAdapter* createFileImporter(const QString& className, RDocument& document) = 0;
79 
84  virtual bool isRunning() = 0;
85 
86  virtual void abort() = 0;
87 
88  virtual bool hasUncaughtExceptions() = 0;
89 
90  static void triggerActionApplicationLevel(const QString& scriptFile,
91  RGuiAction* guiAction = NULL);
92 
96  virtual void
97  createActionDocumentLevel(const QString& scriptFile,
98  RGuiAction* guiAction,
99  RDocumentInterface* documentInterface = NULL) = 0;
100  virtual void createActionApplicationLevel(const QString& scriptFile,
101  RGuiAction* guiAction) = 0;
102 
109  template<class T>
110  void createActionDocumentLevelT(const QString& scriptFile,
111  RGuiAction* guiAction, RDocumentInterface* documentInterface) {
112  if (documentInterface == NULL) {
113  documentInterface = RMainWindow::getDocumentInterfaceStatic();
114  if (documentInterface == NULL) {
115  qWarning("RScriptHandler::createActionDocumentLevelT(): No document interface given or found.");
116  return;
117  }
118  }
119 
120  RScriptAction* a = new T(scriptFile, guiAction);
121  a->setDocumentInterface(documentInterface);
122  documentInterface->setCurrentAction(a);
123  }
124 
132  template<class T>
133  void createActionApplicationLevelT(const QString& scriptFile, RGuiAction* guiAction) {
134  T action(scriptFile, guiAction);
135  action.beginEvent();
136  action.finishEvent();
137  }
138 
139 protected:
140  static QString autostartScriptName;
141 };
142 
143 #endif
virtual ~RScriptHandler()
Definition: RScriptHandler.h:50
static RDocumentInterface * getDocumentInterfaceStatic()
Definition: RMainWindow.cpp:142
#define QCADCORE_EXPORT
Definition: core_global.h:10
void createActionApplicationLevelT(const QString &scriptFile, RGuiAction *guiAction)
Creates a new application level action by instantiating class T.
Definition: RScriptHandler.h:133
void setDocumentInterface(RDocumentInterface *di)
Definition: RAction.h:112
RScriptHandler()
Definition: RScriptHandler.h:48
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:63
void setCurrentAction(RAction *action)
Sets the current action.
Definition: RDocumentInterface.cpp:280
static QString autostartScriptName
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RScriptHandler.h:140
Abstract base class for GUI action classes.
Definition: RGuiAction.h:60
void createActionDocumentLevelT(const QString &scriptFile, RGuiAction *guiAction, RDocumentInterface *documentInterface)
Creates a new document level action by instantiating class T and attaching the action to the document...
Definition: RScriptHandler.h:110
Abstract base class for all script handlers.
Definition: RScriptHandler.h:44
Interface for interaction between a graphics document and a user.
Definition: RDocumentInterface.h:82
void init(void basePath)
Definition: AddBlockInit.js:2
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RScriptAction.h:35