Developer Documentation

ScriptSettings.cc
1 #include "ScriptSettings.hh"
2
3 #include <QScriptContext>
4 #include <QScriptEngine>
5 #include <QWidget>
6
7 #include "Widgets/BooleanWidget.hh"
8 #include "Widgets/VectorWidget.hh"
9 #include "Widgets/DoubleWidget.hh"
10
11 #include "ScriptSettingsBoolean.hh"
12 #include "ScriptSettingsDouble.hh"
13 #include "ScriptSettingsVector.hh"
14
15
16 ScriptSettings::ScriptSettings(QWidget *widget)
17 {
18 if (widget) {
19 connect(widget, &QWidget::destroyed,
20 this, &QObject::deleteLater);
21 }
22 }
23
24 QScriptValue createSettingsScriptObject(QScriptContext *ctx, QWidget *widget)
25 {
26 QScriptEngine *engine = ctx->engine();
27 ScriptSettings *obj = nullptr;
28 if (auto w = dynamic_cast<BooleanWidget*>(widget)) {
29 obj = new ScriptSettingsBoolean(w);
30 }
31 else if (auto w = dynamic_cast<DoubleWidget*>(widget)) {
32 obj = new ScriptSettingsDouble(w);
33 }
34 else if (auto w = dynamic_cast<VectorWidget*>(widget)) {
35 obj = new ScriptSettingsVector(w);
36 }
37
38 if (!obj) { // no ScriptSettings class implemented for this widget
39 return QScriptValue::SpecialValue::NullValue;
40 }
41 return engine->newQObject(obj,
42 QScriptEngine::QtOwnership,
43 QScriptEngine::ExcludeSuperClassMethods
44 | QScriptEngine::ExcludeSuperClassProperties
45 | QScriptEngine::ExcludeChildObjects
46 );
47 }
ScriptSettingsVector
Definition: ScriptSettingsVector.hh:11
ScriptSettingsDouble
Definition: ScriptSettingsDouble.hh:11
ScriptSettingsBoolean
Definition: ScriptSettingsBoolean.hh:11
ScriptSettings
Definition: ScriptSettings.hh:10