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 void eval(const QString& script, const QString& fileName = QString()) = 0;
69 
73  virtual RFileImporterAdapter* createFileImporter(const QString& className, RDocument& document) = 0;
74 
79  virtual bool isRunning() = 0;
80 
81  virtual void abort() = 0;
82 
83  virtual bool hasUncaughtExceptions() = 0;
84 
85  static void triggerActionApplicationLevel(const QString& scriptFile,
86  RGuiAction* guiAction = NULL);
87 
91  virtual void
92  createActionDocumentLevel(const QString& scriptFile,
93  RGuiAction* guiAction,
94  RDocumentInterface* documentInterface = NULL) = 0;
95  virtual void createActionApplicationLevel(const QString& scriptFile,
96  RGuiAction* guiAction) = 0;
97 
104  template<class T>
105  void createActionDocumentLevelT(const QString& scriptFile,
106  RGuiAction* guiAction, RDocumentInterface* documentInterface) {
107  if (documentInterface == NULL) {
108  documentInterface = RMainWindow::getDocumentInterfaceStatic();
109  if (documentInterface == NULL) {
110  qWarning("RScriptHandler::createActionDocumentLevelT(): No document interface given or found.");
111  return;
112  }
113  }
114 
115  RScriptAction* a = new T(scriptFile, guiAction);
116  a->setDocumentInterface(documentInterface);
117  documentInterface->setCurrentAction(a);
118  }
119 
127  template<class T>
128  void createActionApplicationLevelT(const QString& scriptFile, RGuiAction* guiAction) {
129  T action(scriptFile, guiAction);
130  action.beginEvent();
131  action.finishEvent();
132  }
133 
134 protected:
135  static QString autostartScriptName;
136 };
137 
138 #endif