Commit 3886eb82 authored by LE BRETON Come's avatar LE BRETON Come

Reduces to a single dynamic cast.

parent 2c18733d
......@@ -39,7 +39,7 @@ int main(int argc, char **argv)
qDebug() << value;
});
dtkWidgetsParameter *real_parameter_widget = dtk::widgets::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBoxPlugin");
dtkWidgetsAbstractParameter *real_parameter_widget = dtk::widgets::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBoxPlugin");
window->setCentralWidget(real_parameter_widget);
......
......@@ -26,7 +26,7 @@ public:
// ///////////////////////////////////////////////////////////////////
dtkWidgetsParameterDoubleSpinBox::dtkWidgetsParameterDoubleSpinBox(QWidget* parent) : dtkWidgetsParameterDouble(parent), d(new dtkWidgetsParameterDoubleSpinBoxPrivate)
dtkWidgetsParameterDoubleSpinBox::dtkWidgetsParameterDoubleSpinBox(QWidget* parent) : dtkWidgetsParameter<dtk::d_real>(parent), d(new dtkWidgetsParameterDoubleSpinBoxPrivate)
{
d->spin_box = new QDoubleSpinBox;
......@@ -41,26 +41,19 @@ dtkWidgetsParameterDoubleSpinBox::~dtkWidgetsParameterDoubleSpinBox(void)
delete d;
}
void dtkWidgetsParameterDoubleSpinBox::connect(dtkCoreAbstractParameter *parameter)
void dtkWidgetsParameterDoubleSpinBox::connect(dtk::d_real *parameter)
{
dtk::d_real *double_parameter = dynamic_cast<dtk::d_real *>(parameter);
d->spin_box->setMinimum(parameter->min());
d->spin_box->setMaximum(parameter->max());
d->spin_box->setToolTip(parameter->documentation());
if(!double_parameter) {
qWarning() << "Could not connect the parameter to the widget, the parameter is not of type dtk::d_real";
return;
}
d->spin_box->setMinimum(double_parameter->min());
d->spin_box->setMaximum(double_parameter->max());
d->spin_box->setToolTip(double_parameter->documentation());
QObject::connect(double_parameter, &dtk::d_real::valueChanged, [=] (QVariant v) {
QObject::connect(parameter, &dtk::d_real::valueChanged, [=] (QVariant v) {
double value = v.value<dtk::d_real>().value();
d->spin_box->setValue(value);
});
QObject::connect(d->spin_box, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double v) {
double_parameter->setValue(v);
parameter->setValue(v);
});
}
......
......@@ -17,7 +17,7 @@
#include <QtWidgets>
#include <dtkWidgets/dtkWidgetsParameter>
class dtkWidgetsParameterDoubleSpinBox : public dtkWidgetsParameterDouble
class dtkWidgetsParameterDoubleSpinBox : public dtkWidgetsParameter<dtk::d_real>
{
Q_OBJECT
......@@ -26,7 +26,7 @@ public:
virtual ~dtkWidgetsParameterDoubleSpinBox(void);
public:
virtual void connect(dtkCoreAbstractParameter *);
virtual void connect(dtk::d_real *);
private:
class dtkWidgetsParameterDoubleSpinBoxPrivate *d;
......@@ -34,7 +34,7 @@ private:
// ///////////////////////////////////////////////////////////////////
inline dtkWidgetsParameter *dtkWidgetsParameterDoubleSpinBoxCreator(void)
inline dtkWidgetsAbstractParameter *dtkWidgetsParameterDoubleSpinBoxCreator(void)
{
return new dtkWidgetsParameterDoubleSpinBox();
}
......
......@@ -18,10 +18,10 @@
#include <dtkWidgets/dtkWidgetsParameter>
class dtkWidgetsParameterDoubleSpinBoxPlugin : public dtkWidgetsParameterPlugin
class dtkWidgetsParameterDoubleSpinBoxPlugin : public dtkWidgetsAbstractParameterPlugin
{
Q_OBJECT
Q_INTERFACES(dtkWidgetsParameterPlugin);
Q_INTERFACES(dtkWidgetsAbstractParameterPlugin);
Q_PLUGIN_METADATA(IID "fr.inria.dtkWidgetsParameterDoubleSpinBoxPlugin" FILE "dtkWidgetsParameterDoubleSpinBoxPlugin.json")
public:
......
{
"name" : "dtkWidgetsParameterDoubleSpinBoxPlugin",
"concept" : "dtkWidgetsParameter",
"concept" : "dtkWidgetsAbstractParameter",
"version" : "0.0.1",
"dependencies" : []
}
......@@ -22,31 +22,29 @@
#include <dtkCore/dtkCoreParameter>
class DTKWIDGETS_EXPORT dtkWidgetsParameter : public QWidget {
class DTKWIDGETS_EXPORT dtkWidgetsAbstractParameter : public QWidget {
public:
dtkWidgetsParameter(QWidget *parent) : QWidget(parent) {};
virtual ~dtkWidgetsParameter() = default;
public:
virtual void connect(dtkCoreAbstractParameter *) = 0;
};
class DTKWIDGETS_EXPORT dtkWidgetsParameterInt : public dtkWidgetsParameter
{
dtkWidgetsAbstractParameter(QWidget *parent) : QWidget(parent) {};
virtual ~dtkWidgetsAbstractParameter() = default;
/* public: */
/* virtual void connect(dtkCoreAbstractParameter *) = 0; */
};
class DTKWIDGETS_EXPORT dtkWidgetsParameterDouble : public dtkWidgetsParameter
template <typename T>
class DTKWIDGETS_EXPORT dtkWidgetsParameter : public dtkWidgetsAbstractParameter
{
public:
dtkWidgetsParameterDouble(QWidget *parent) : dtkWidgetsParameter(parent) {};
dtkWidgetsParameter(QWidget *parent) : dtkWidgetsAbstractParameter(parent) {};
virtual void connect(T *) = 0;
};
DTK_DECLARE_OBJECT(dtkWidgetsParameter*);
DTK_DECLARE_PLUGIN(dtkWidgetsParameter, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_FACTORY(dtkWidgetsParameter, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_MANAGER(dtkWidgetsParameter, DTKWIDGETS_EXPORT);
DTK_DECLARE_OBJECT(dtkWidgetsAbstractParameter*);
DTK_DECLARE_PLUGIN(dtkWidgetsAbstractParameter, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_FACTORY(dtkWidgetsAbstractParameter, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_MANAGER(dtkWidgetsAbstractParameter, DTKWIDGETS_EXPORT);
// /////////////////////////////////////////////////////////////////
// Register to dtkDiscretegeometry layer
......@@ -54,7 +52,7 @@ DTK_DECLARE_PLUGIN_MANAGER(dtkWidgetsParameter, DTKWIDGETS_EXPORT);
namespace dtk {
namespace widgets {
DTK_DECLARE_CONCEPT(dtkWidgetsParameter, DTKWIDGETS_EXPORT, parameter);
DTK_DECLARE_CONCEPT(dtkWidgetsAbstractParameter, DTKWIDGETS_EXPORT, parameter);
}
}
......
......@@ -9,7 +9,7 @@ namespace dtk
namespace _private
{
dtkWidgetsParameterFactory factory;
dtkWidgetsParameterPluginManager manager;
dtkWidgetsAbstractParameterPluginManager manager;
}
dtkWidgetsParameterFactory& pluginFactory()
......@@ -17,7 +17,7 @@ namespace dtk
return _private::factory;
}
dtkWidgetsParameterPluginManager& pluginManager()
dtkWidgetsAbstractParameterPluginManager& pluginManager()
{
return _private::manager;
}
......
......@@ -4,17 +4,16 @@
#include "dtkWidgetsParameter.h"
class DTKWIDGETS_EXPORT dtkWidgetsParameterFactory : public dtkWidgetsParameterPluginFactory {
class DTKWIDGETS_EXPORT dtkWidgetsParameterFactory : public dtkWidgetsAbstractParameterPluginFactory {
public:
dtkWidgetsParameter *create(dtkCoreAbstractParameter *parameter, const QString& key) {
qDebug() << Q_FUNC_INFO;
dtkWidgetsParameter *widget = dtkWidgetsParameterPluginFactory::create(key);
qDebug() << "widget" << widget;
dtkWidgetsParameterDouble *double_widget = dynamic_cast<dtkWidgetsParameterDouble *>(widget);
template <typename T>
dtkWidgetsAbstractParameter *create(dtkCoreParameter<T> *parameter, const QString& key) {
dtkWidgetsAbstractParameter *widget = dtkWidgetsAbstractParameterPluginFactory::create(key);
if(double_widget) {
double_widget->connect(parameter);
return double_widget;
dtkWidgetsParameter<dtkCoreParameter<T>> *t_widget = dynamic_cast<dtkWidgetsParameter<dtkCoreParameter<T>> *>(widget);
if(t_widget) {
t_widget->connect(parameter);
return t_widget;
}
return nullptr;
......@@ -26,6 +25,6 @@ namespace dtk
namespace widgets
{
DTKWIDGETS_EXPORT dtkWidgetsParameterFactory& pluginFactory();
DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager& pluginManager();
DTKWIDGETS_EXPORT dtkWidgetsAbstractParameterPluginManager& pluginManager();
}
}
......@@ -64,7 +64,7 @@ void dtkWidgetsParameterTestCase::testBasic(void)
{
dtk::d_real real_parameter;
dtkWidgetsParameter *spin_box = dtk::widgets::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBoxPlugin");
dtkWidgetsAbstractParameter *spin_box = dtk::widgets::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBoxPlugin");
qDebug() << "spin_box" << spin_box;
......
Markdown is supported
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