QCAD
Open Source 2D CAD
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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