Commit 3eb46a36 authored by LE BRETON Come's avatar LE BRETON Come

Provides convenience function to recover the parameter conencted to

the widget.
parent bde10ea4
......@@ -63,6 +63,8 @@ bool dtkWidgetsParameterDoubleSpinBox::connect(dtkCoreAbstractParameter *p)
p_real->setValue(v);
});
dtkWidgetsAbstractParameter::m_parameter = p;
return true;
}
......
......@@ -27,7 +27,16 @@ public:
dtkWidgetsAbstractParameter(QWidget *parent) : QWidget(parent) {};
virtual ~dtkWidgetsAbstractParameter() = default;
public:
virtual bool connect(dtkCoreAbstractParameter *) = 0;
public:
dtkCoreAbstractParameter *parameter(void) {
return this->m_parameter;
}
protected:
dtkCoreAbstractParameter *m_parameter = nullptr;
};
template <typename T>
......
......@@ -13,6 +13,18 @@ class DTKWIDGETS_EXPORT dtkWidgetsParameterPluginManager : public dtkCorePluginM
class DTKWIDGETS_EXPORT dtkWidgetsParameterFactory : public dtkCorePluginFactory<dtkWidgetsAbstractParameter> {
public:
dtkWidgetsAbstractParameter *create(const QString& key) {
dtkWidgetsAbstractParameter *widget = dtkCorePluginFactory<dtkWidgetsAbstractParameter>::create(key);
if(!widget) {
qWarning() << "The widget with key :" << key << "could not be instanciated by the factory.";
return nullptr;
}
return widget;
}
dtkWidgetsAbstractParameter *create(dtkCoreAbstractParameter *parameter, const QString& key) {
dtkWidgetsAbstractParameter *widget = dtkCorePluginFactory<dtkWidgetsAbstractParameter>::create(key);
......
......@@ -63,6 +63,8 @@ bool dtkWidgetsParameterIntSpinBox::connect(dtkCoreAbstractParameter *p)
p_int->setValue(v);
});
dtkWidgetsAbstractParameter::m_parameter = p;
return true;
}
......
......@@ -62,29 +62,64 @@ void dtkWidgetsParametersTestCase::init(void)
void dtkWidgetsParametersTestCase::testBasic(void)
{
//////////////////// dtkWidgetsParameterDoubleSpinBox ////////////////////
{
//////////////////// dtkWidgetsParameterDoubleSpinBox ////////////////////
dtk::d_real real_parameter = 0.;
dtk::d_real real_parameter = 0.;
dtkWidgetsAbstractParameter *spin_box = dtk::widgets::parameters::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBox");
dtkWidgetsAbstractParameter *real_spin_box = dtk::widgets::parameters::pluginFactory().create(&real_parameter, "dtkWidgetsParameterDoubleSpinBox");
Q_ASSERT(spin_box);
QVERIFY(real_spin_box);
QVERIFY(real_spin_box->parameter() == &real_parameter);
//////////////////// dtkWidgetsParameterIntSpinBox ////////////////////
//////////////////// dtkWidgetsParameterIntSpinBox ////////////////////
dtk::d_int int_parameter = 0.;
dtk::d_int int_parameter = 0.;
dtkWidgetsAbstractParameter *int_spin_box = dtk::widgets::parameters::pluginFactory().create(&int_parameter, "dtkWidgetsParameterIntSpinBox");
dtkWidgetsAbstractParameter *int_spin_box = dtk::widgets::parameters::pluginFactory().create(&int_parameter, "dtkWidgetsParameterIntSpinBox");
Q_ASSERT(spin_box);
QVERIFY(int_spin_box);
QVERIFY(int_spin_box->parameter() == &int_parameter);
dtk::d_real wrong_type_parameter = 0.;
dtk::d_real wrong_type_parameter = 0.;
dtkWidgetsAbstractParameter *wrong_type_parameter_spin_box = dtk::widgets::parameters::pluginFactory().create(&wrong_type_parameter, "dtkWidgetsParameterIntSpinBox");
dtkWidgetsAbstractParameter *wrong_type_parameter_spin_box = dtk::widgets::parameters::pluginFactory().create(&wrong_type_parameter, "dtkWidgetsParameterIntSpinBox");
Q_ASSERT(wrong_type_parameter_spin_box == nullptr);
QVERIFY(wrong_type_parameter_spin_box);
QVERIFY(wrong_type_parameter_spin_box->parameter() == nullptr);
}
{
//////////////////// dtkWidgetsParameterDoubleSpinBox ////////////////////
dtk::d_real real_parameter = 0.;
dtkWidgetsAbstractParameter *spin_box = dtk::widgets::parameters::pluginFactory().create("dtkWidgetsParameterDoubleSpinBox");
QVERIFY(spin_box);
QVERIFY(spin_box->connect(&real_parameter));
QVERIFY(spin_box->parameter());
//////////////////// dtkWidgetsParameterIntSpinBox ////////////////////
dtk::d_int int_parameter = 0.;
dtkWidgetsAbstractParameter *int_spin_box = dtk::widgets::parameters::pluginFactory().create("dtkWidgetsParameterIntSpinBox");
QVERIFY(int_spin_box);
QVERIFY(int_spin_box->connect(&int_parameter));
QVERIFY(int_spin_box->parameter());
dtk::d_real wrong_type_parameter = 0.;
dtkWidgetsAbstractParameter *wrong_type_parameter_spin_box = dtk::widgets::parameters::pluginFactory().create("dtkWidgetsParameterIntSpinBox");
QVERIFY(wrong_type_parameter_spin_box);
QVERIFY(!wrong_type_parameter_spin_box->connect(&wrong_type_parameter));
QVERIFY(wrong_type_parameter_spin_box->parameter() == nullptr);
}
//////////////////// ////////////////////
}
void dtkWidgetsParametersTestCase::cleanup(void)
......
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