-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRScriptHandlerJs.h
116 lines (90 loc) · 3.16 KB
/
RScriptHandlerJs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* Copyright (c) 2021 by Andrew Mustun. All rights reserved.
*
* This file is part of the QCAD project.
*
* QCAD is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QCAD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QCAD.
*/
#ifndef RSCRIPTHANDLERJS_H
#define RSCRIPTHANDLERJS_H
#include "qcadjsapi_global.h"
#include <QString>
#include <QJSEngine>
#include <QQmlApplicationEngine>
#include <QMainWindow>
#include <QList>
#include <QObject>
#include <QDebug>
#include "RScriptHandler.h"
#include "RDocumentInterface.h"
#include "RGuiAction.h"
class RJSWrapperObj;
class RJSTools;
class RJSApi;
/**
* Script handler implementation for JS scripts, based on QJSEngine..
*
* \ingroup js
*/
class QCADJSAPI_EXPORT RScriptHandlerJs: public QObject, public RScriptHandler {
Q_OBJECT
public:
RScriptHandlerJs();
virtual ~RScriptHandlerJs();
static void deleteWrapper(RJSWrapperObj* wrapper);
virtual void init(bool main=false);
static RScriptHandler* factory();
static QList<QString> getSupportedFileExtensionsStatic();
QList<QString> getSupportedFileExtensions();
virtual void doScript(const QString& scriptFile,const QStringList& arguments = QStringList());
virtual QVariant eval(const QString& script, const QString& fileName = QString());
virtual QJSValue evalInternal(const QString& script, const QString& fileName = QString());
virtual QVariant evalGlobal(const QString& script, const QString& fileName = QString());
virtual RFileImporterAdapter* createFileImporter(const QString& className, RDocument& document);
virtual bool isRunning();
virtual void abort();
virtual bool hasUncaughtExceptions();
virtual void createActionDocumentLevel(const QString& scriptFile,
RGuiAction* guiAction, RDocumentInterface* documentInterface);
virtual void createActionApplicationLevel(const QString& scriptFile,
RGuiAction* guiAction);
void initGlobalVariables(const QString& scriptFile);
QJSEngine* getEngine() {
return engine;
}
RJSApi* getRJSApi() {
return rjsapi;
}
void trace() {
engine->evaluate("console.trace();");
}
QJSValue getSelf() {
return engine->evaluate("self");
}
void registerWrapper(RJSWrapperObj& obj);
public slots:
void unregisterWrapper(RJSWrapperObj& obj);
void slotDestroyed(QObject* obj);
private:
RJSApi* rjsapi;
//QJSEngine* engine;
static QQmlApplicationEngine* mainEngine;
QQmlApplicationEngine* engine;
RJSTools* tools;
// list of wrappers created for this script handler:
// deleted when script handler is deleted:
QSet<RJSWrapperObj*> wrappers;
};
Q_DECLARE_METATYPE(RScriptHandlerJs*)
#endif // RJSSCRIPTHANDLER_H