Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 2c18733d authored by LE BRETON Come's avatar LE BRETON Come

Nicer user api. But two dynamic casts.

parent 5e08573a
......@@ -17,6 +17,7 @@
#include <dtkCore/dtkCoreParameter>
#include <dtkWidgets/dtkWidgetsParameter>
#include <dtkWidgets/dtkWidgetsParameterFactory>
// ///////////////////////////////////////////////////////////////////
//
......@@ -38,8 +39,7 @@ int main(int argc, char **argv)
qDebug() << value;
});
dtkWidgetsParameterDouble *real_parameter_widget = dtk::widgets::parameterDouble::pluginFactory().create("dtkWidgetsParameterDoubleSpinBoxPlugin");
real_parameter_widget->connect(&real_parameter);
dtkWidgetsParameter *real_parameter_widget = dtk::widgets::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBoxPlugin");
window->setCentralWidget(real_parameter_widget);
......
......@@ -41,19 +41,26 @@ dtkWidgetsParameterDoubleSpinBox::~dtkWidgetsParameterDoubleSpinBox(void)
delete d;
}
void dtkWidgetsParameterDoubleSpinBox::connect(dtk::d_real *parameter)
void dtkWidgetsParameterDoubleSpinBox::connect(dtkCoreAbstractParameter *parameter)
{
d->spin_box->setMinimum(parameter->min());
d->spin_box->setMaximum(parameter->max());
d->spin_box->setToolTip(parameter->documentation());
dtk::d_real *double_parameter = dynamic_cast<dtk::d_real *>(parameter);
QObject::connect(parameter, &dtk::d_real::valueChanged, [=] (QVariant v) {
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) {
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) {
parameter->setValue(v);
double_parameter->setValue(v);
});
}
......
......@@ -26,7 +26,7 @@ public:
virtual ~dtkWidgetsParameterDoubleSpinBox(void);
public:
virtual void connect(dtk::d_real *);
virtual void connect(dtkCoreAbstractParameter *);
private:
class dtkWidgetsParameterDoubleSpinBoxPrivate *d;
......@@ -34,9 +34,8 @@ private:
// ///////////////////////////////////////////////////////////////////
inline dtkWidgetsParameterDouble *dtkWidgetsParameterDoubleSpinBoxCreator(void)
inline dtkWidgetsParameter *dtkWidgetsParameterDoubleSpinBoxCreator(void)
{
qDebug() << Q_FUNC_INFO;
return new dtkWidgetsParameterDoubleSpinBox();
}
//
......
......@@ -15,7 +15,7 @@
#include "dtkWidgetsParameterDoubleSpinBoxPlugin.h"
#include "dtkWidgetsParameterDoubleSpinBox.h"
#include <dtkCoreWidgets/dtkCoreWidgets>
#include <dtkWidgets/dtkWidgetsParameterFactory>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameterDoubleSpinBoxPlugin
......@@ -24,7 +24,7 @@
void dtkWidgetsParameterDoubleSpinBoxPlugin::initialize(void)
{
qDebug() << Q_FUNC_INFO;
dtk::widgets::parameterDouble::pluginFactory().record("dtkWidgetsParameterDoubleSpinBoxPlugin", dtkWidgetsParameterDoubleSpinBoxCreator);
dtk::widgets::pluginFactory().record("dtkWidgetsParameterDoubleSpinBoxPlugin", dtkWidgetsParameterDoubleSpinBoxCreator);
}
void dtkWidgetsParameterDoubleSpinBoxPlugin::uninitialize(void)
......
......@@ -18,10 +18,10 @@
#include <dtkWidgets/dtkWidgetsParameter>
class dtkWidgetsParameterDoubleSpinBoxPlugin : public dtkWidgetsParameterDoublePlugin
class dtkWidgetsParameterDoubleSpinBoxPlugin : public dtkWidgetsParameterPlugin
{
Q_OBJECT
Q_INTERFACES(dtkWidgetsParameterDoublePlugin);
Q_INTERFACES(dtkWidgetsParameterPlugin);
Q_PLUGIN_METADATA(IID "fr.inria.dtkWidgetsParameterDoubleSpinBoxPlugin" FILE "dtkWidgetsParameterDoubleSpinBoxPlugin.json")
public:
......
{
"name" : "dtkWidgetsParameterDoubleSpinBoxPlugin",
"concept" : "dtkWidgetsParameterDouble",
"concept" : "dtkWidgetsParameter",
"version" : "0.0.1",
"dependencies" : []
}
......@@ -60,6 +60,8 @@ set(${PROJECT_NAME}_HEADERS
dtkWidgetsOverlayRope.h
dtkWidgetsParameter
dtkWidgetsParameter.h
dtkWidgetsParameterFactory
dtkWidgetsParameterFactory.h
dtkWidgetsSettings
dtkWidgetsSettings.h
dtkWidgetsStylesheetParser
......@@ -88,6 +90,7 @@ set(${PROJECT_NAME}_SOURCES
dtkWidgetsOverlayPaneSlider.cpp
dtkWidgetsOverlayRope.cpp
dtkWidgetsParameter.cpp
dtkWidgetsParameterFactory.cpp
dtkWidgetsSettings.cpp
dtkWidgetsStylesheetParser.cpp
dtkWidgetsWidget.cpp)
......
#include "dtkWidgetsParameter.h"
#include "dtkWidgets.h"
namespace dtk {
namespace widgets {
DTK_DEFINE_CONCEPT(dtkWidgetsParameterDouble, parameterDouble, dtk::widgets);
}
}
......@@ -22,28 +22,31 @@
#include <dtkCore/dtkCoreParameter>
class DTKWIDGETS_EXPORT dtkWidgetsParameterInt : public QWidget
{
class DTKWIDGETS_EXPORT dtkWidgetsParameter : public QWidget {
public:
virtual void connect(dtk::d_int *) = 0;
dtkWidgetsParameter(QWidget *parent) : QWidget(parent) {};
virtual ~dtkWidgetsParameter() = default;
public:
virtual void connect(dtkCoreAbstractParameter *) = 0;
};
class DTKWIDGETS_EXPORT dtkWidgetsParameterDouble : public QWidget
class DTKWIDGETS_EXPORT dtkWidgetsParameterInt : public dtkWidgetsParameter
{
public:
dtkWidgetsParameterDouble(QWidget *parent) : QWidget(parent) {};
};
class DTKWIDGETS_EXPORT dtkWidgetsParameterDouble : public dtkWidgetsParameter
{
public:
virtual void connect(dtk::d_real *) = 0;
dtkWidgetsParameterDouble(QWidget *parent) : dtkWidgetsParameter(parent) {};
};
DTK_DECLARE_OBJECT(dtkWidgetsParameterDouble*);
DTK_DECLARE_PLUGIN(dtkWidgetsParameterDouble, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_FACTORY(dtkWidgetsParameterDouble, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_MANAGER(dtkWidgetsParameterDouble, DTKWIDGETS_EXPORT);
DTK_DECLARE_OBJECT(dtkWidgetsParameter*);
DTK_DECLARE_PLUGIN(dtkWidgetsParameter, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_FACTORY(dtkWidgetsParameter, DTKWIDGETS_EXPORT);
DTK_DECLARE_PLUGIN_MANAGER(dtkWidgetsParameter, DTKWIDGETS_EXPORT);
// /////////////////////////////////////////////////////////////////
// Register to dtkDiscretegeometry layer
......@@ -51,7 +54,7 @@ DTK_DECLARE_PLUGIN_MANAGER(dtkWidgetsParameterDouble, DTKWIDGETS_EXPORT);
namespace dtk {
namespace widgets {
DTK_DECLARE_CONCEPT(dtkWidgetsParameterDouble, DTKWIDGETS_EXPORT, parameterDouble);
DTK_DECLARE_CONCEPT(dtkWidgetsParameter, DTKWIDGETS_EXPORT, parameter);
}
}
......
#include "dtkWidgetsParameterFactory.h"
\ No newline at end of file
#include "dtkWidgetsParameterFactory.h"
#include "dtkWidgets.h"
namespace dtk
{
namespace widgets
{
namespace _private
{
dtkWidgetsParameterFactory factory;
dtkWidgetsParameterPluginManager manager;
}
dtkWidgetsParameterFactory& pluginFactory()
{
return _private::factory;
}
dtkWidgetsParameterPluginManager& pluginManager()
{
return _private::manager;
}
namespace _private
{
dtkCorePluginManagerRecorder mrecorder(&dtk::widgets::manager(), &pluginManager(), "dtkWidgetsParameter");
dtkCorePluginFactoryRecorder frecorder(&dtk::widgets::manager(), &pluginFactory(), "dtkWidgetsParameter");
}
}
}
#pragma once
#include<dtkWidgetsExport.h>
#include "dtkWidgetsParameter.h"
class DTKWIDGETS_EXPORT dtkWidgetsParameterFactory : public dtkWidgetsParameterPluginFactory {
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);
if(double_widget) {
double_widget->connect(parameter);
return double_widget;
}
return nullptr;
}
};
namespace dtk
{
namespace widgets
{
DTKWIDGETS_EXPORT dtkWidgetsParameterFactory& pluginFactory();
DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager& pluginManager();
}
}
......@@ -21,6 +21,7 @@
#include <dtkWidgets/dtkWidgets>
#include <dtkWidgets/dtkWidgetsParameter>
#include <dtkWidgets/dtkWidgetsParameterFactory>
// ///////////////////////////////////////////////////////////////////
//
......@@ -63,7 +64,7 @@ void dtkWidgetsParameterTestCase::testBasic(void)
{
dtk::d_real real_parameter;
dtkWidgetsParameterDouble *spin_box = dtk::widgets::parameterDouble::pluginFactory().create("dtkWidgetsSpinBoxPlugin");
dtkWidgetsParameter *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