Commit 1e6769d4 authored by Martin Heistermann's avatar Martin Heistermann
Browse files

propvis scripting: refactor for lifetimes and add vector prop stub.

parent 3d951077
#ifndef SCRIPTOBJECT_HH
#define SCRIPTOBJECT_HH
#include <QScriptValue>
class QScriptContext;
class QWidget;
QScriptValue createSettingsScriptObject(QScriptContext *ctx, QWidget *widget);
#endif // SCRIPTOBJECT_HH
#include "ScriptObject.hh"
#include "ScriptSettings.hh"
#include <QScriptContext>
#include <QScriptEngine>
#include <QWidget>
#include "Widgets/BooleanWidget.hh"
#include "Widgets/VectorWidget.hh"
#include "Widgets/DoubleWidget.hh"
#include "ScriptSettingsBoolean.hh"
#include "ScriptSettingsDouble.hh"
#include "ScriptSettingsVector.hh"
QScriptValue createSettingsScriptObject(
QScriptContext *ctx,
QWidget *widget)
ScriptSettings::ScriptSettings(QWidget *widget)
{
if (widget == nullptr)
return;
connect(widget, &QWidget::destroyed,
this, &QObject::deleteLater);
}
QScriptValue createSettingsScriptObject(QScriptContext *ctx, QWidget *widget)
{
QScriptEngine *engine = ctx->engine();
auto bw = dynamic_cast<BooleanWidget*>(widget);
if (bw) {return engine->newQObject(new ScriptSettingsBoolean(bw)); }
auto dw = dynamic_cast<DoubleWidget*>(widget);
if (dw) {return engine->newQObject(new ScriptSettingsDouble(dw)); }
auto dv = dynamic_cast<VectorWidget*>(widget);
if (dv) {return engine->newQObject(new ScriptSettingsVector(dv)); }
// not implemented:
return QScriptValue::SpecialValue::NullValue;
}
#ifndef SCRIPTSETTINGS_HH
#define SCRIPTSETTINGS_HH
#include <QObject>
#include <QScriptValue>
class QWidget;
class QScriptContext;
class ScriptSettings : public QObject
{
Q_OBJECT
public:
explicit ScriptSettings(QWidget *widget);
};
QScriptValue createSettingsScriptObject(
QScriptContext *ctx,
QWidget *widget);
#endif // SCRIPTSETTINGS_HH
......@@ -2,16 +2,19 @@
#include "ACG/Utils/ColorConversion.hh"
ScriptSettingsBoolean::ScriptSettingsBoolean()
: widget_(nullptr)
{}
: ScriptSettings(nullptr),
widget_(nullptr)
{
assert(false);
}
ScriptSettingsBoolean::ScriptSettingsBoolean(BooleanWidget *widget)
: widget_(widget)
: ScriptSettings(widget),
widget_(widget)
{}
ScriptSettingsBoolean::ScriptSettingsBoolean(const ScriptSettingsBoolean &other)
: QObject(),
widget_(other.widget_)
: ScriptSettingsBoolean(other.widget_)
{}
ScriptSettingsBoolean::~ScriptSettingsBoolean() {}
......
......@@ -2,12 +2,13 @@
#define SCRIPTSETTINGSBOOLEAN_HH
#include <QObject>
#include "ScriptSettings.hh"
#include "Widgets/BooleanWidget.hh"
#include "ACG/Math/VectorT.hh"
#include "OpenFlipper/common/DataTypes.hh"
class ScriptSettingsBoolean : public QObject {
class ScriptSettingsBoolean : public ScriptSettings {
Q_OBJECT
// We use Vector4 instead of a proper color type as those are not (yet)
// exposed to the scripting environment.
......
......@@ -2,16 +2,17 @@
#include "ACG/Utils/ColorConversion.hh"
ScriptSettingsDouble::ScriptSettingsDouble()
: widget_(nullptr)
{}
: ScriptSettings(nullptr),
widget_(nullptr)
{
assert(false);
}
ScriptSettingsDouble::ScriptSettingsDouble(
DoubleWidget *widget)
: widget_(widget)
{
connect(widget_, &QWidget::destroyed,
this, &QObject::deleteLater);
}
: ScriptSettings(widget),
widget_(widget)
{}
ScriptSettingsDouble::ScriptSettingsDouble(
const ScriptSettingsDouble &other)
......@@ -71,7 +72,6 @@ void ScriptSettingsDouble::setUseColorCoder(bool useColorCoder)
return widget_->doubleColorCoder->setChecked(useColorCoder);
}
void ScriptSettingsDouble::setUseFixedRange(bool useFixedRange)
{
return widget_->doubleFixedRange->setChecked(useFixedRange);
......
......@@ -2,17 +2,16 @@
#define SCRIPTSETTINGSDOUBLE_HH
#include <QObject>
#include "ScriptSettings.hh"
#include "Widgets/DoubleWidget.hh"
#include "ACG/Math/VectorT.hh"
#include "OpenFlipper/common/DataTypes.hh"
class ScriptSettingsDouble : public QObject {
class ScriptSettingsDouble : public ScriptSettings {
Q_OBJECT
// We use Vector4 instead of a proper color type as those are not (yet)
// exposed to the scripting environment.
Q_PROPERTY(bool useColorCoder READ useColorCoder WRITE setUseColorCoder)
Q_PROPERTY(Vector4 colorMin READ colorMin WRITE setColorMin)
Q_PROPERTY(Vector4 colorMax READ colorMax WRITE setColorMax)
......@@ -48,6 +47,7 @@ public slots:
void setRangeMax(double val);
void setMapOutsideRange(bool mapOutsideRange);
void setAbsolute(bool absolute);
private:
DoubleWidget *widget_;
};
......
#include "ScriptSettingsVector.hh"
ScriptSettingsVector::ScriptSettingsVector()
: ScriptSettings(nullptr),
widget_(nullptr)
{
assert(false);
}
ScriptSettingsVector::ScriptSettingsVector(
VectorWidget *widget)
: ScriptSettings(widget),
widget_(widget)
{}
ScriptSettingsVector::ScriptSettingsVector(
const ScriptSettingsVector &other)
: ScriptSettingsVector(other.widget_)
{}
ScriptSettingsVector::~ScriptSettingsVector()
{}
#ifndef SCRIPTSETTINGSVECTOR_HH
#define SCRIPTSETTINGSVECTOR_HH
#include <QObject>
#include "ScriptSettings.hh"
#include "Widgets/VectorWidget.hh"
#include "ACG/Math/VectorT.hh"
#include "OpenFlipper/common/DataTypes.hh"
class ScriptSettingsVector : public ScriptSettings
{
Q_OBJECT
//Q_PROPERTY(Vector4 colorTrue READ colorTrue WRITE setColorTrue )
public:
explicit ScriptSettingsVector();
explicit ScriptSettingsVector(VectorWidget *widget);
explicit ScriptSettingsVector(const ScriptSettingsVector &other);
virtual ~ScriptSettingsVector();
signals:
public slots:
private:
VectorWidget *widget_;
};
Q_DECLARE_METATYPE(ScriptSettingsVector)
#endif // SCRIPTSETTINGSVECTOR_HH
......@@ -48,7 +48,7 @@
\*===========================================================================*/
#include "SingleObjectPropertyModel.hh"
#include "ScriptObjects/ScriptObject.hh"
#include "ScriptObjects/ScriptSettings.hh"
SingleObjectPropertyModel::SingleObjectPropertyModel(QObject *parent)
: PropertyModel(parent),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment