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