Commit 087d1e40 authored by LE BRETON Come's avatar LE BRETON Come

Set values and block signals.

parent c9600b11
......@@ -31,7 +31,7 @@ int main(int argc, char **argv)
QMainWindow *window = new QMainWindow;
dtk::d_real real_parameter = 0.;
dtk::d_real real_parameter = 5.;
real_parameter.setDocumentation("A real parameter.");
QObject::connect(&real_parameter, &dtk::d_real::valueChanged, [=] (QVariant v) {
......@@ -48,8 +48,11 @@ int main(int argc, char **argv)
available_strings.append("SecondString");
available_strings.append("ThirdString");
dtk::d_inliststring inliststring_parameter = available_strings;
dtk::d_inliststring inliststring_parameter("listofstrings", available_strings);
inliststring_parameter.setDocumentation("A inliststring parameter.");
inliststring_parameter.setValue(QString("SecondString"));
dtkWidgetsAbstractParameter *inliststring_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&inliststring_parameter, "dtkWidgetsParameterStringListComboBox");
QObject::connect(&inliststring_parameter, &dtk::d_inliststring::valueChanged, [=] (QVariant v) {
......@@ -57,11 +60,21 @@ int main(int argc, char **argv)
qInfo() << value;
});
dtk::d_bool bool_parameter = true;
dtkWidgetsAbstractParameter *bool_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&bool_parameter, "dtkWidgetsParameterBoolCheckBox");
QObject::connect(&bool_parameter, &dtk::d_bool::valueChanged, [=] (QVariant v) {
bool value = v.value<dtk::d_bool>().value();
qInfo() << value;
});
QVBoxLayout *central_layout = new QVBoxLayout;
central_layout->addWidget(first_real_parameter_widget);
central_layout->addWidget(second_real_parameter_widget);
central_layout->addWidget(new QSplitter);
central_layout->addWidget(inliststring_parameter_widget);
central_layout->addWidget(new QSplitter);
central_layout->addWidget(bool_parameter_widget);
QWidget *central_widget = new QWidget;
central_widget->setLayout(central_layout);
......
......@@ -54,9 +54,13 @@ bool dtkWidgetsParameterDoubleSpinBox::connect(dtkCoreAbstractParameter *p)
d->spin_box->setMaximum(p_real->max());
d->spin_box->setToolTip(p_real->documentation());
d->spin_box->setValue(p_real->value());
QObject::connect(p_real, &dtk::d_real::valueChanged, [=] (QVariant v) {
d->spin_box->blockSignals(true);
double value = v.value<dtk::d_real>().value();
d->spin_box->setValue(value);
d->spin_box->blockSignals(false);
});
QObject::connect(d->spin_box, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double v) {
......
......@@ -6,6 +6,7 @@
#include "dtkWidgetsSettings.h"
#include "dtkWidgetsParameterBoolCheckBox.h"
#include "dtkWidgetsParameterIntSpinBox.h"
#include "dtkWidgetsParameterStringListComboBox.h"
......@@ -45,6 +46,7 @@ namespace dtk {
// ///////////////////////////////////////////////////////////////////
// Initializes default plugins
// ///////////////////////////////////////////////////////////////////
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterBoolCheckBox", dtkWidgetsParameterBoolCheckBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterIntSpinBox", dtkWidgetsParameterIntSpinBoxCreator);
dtk::widgets::parameters::pluginFactory().record("dtkWidgetsParameterStringListComboBox", dtkWidgetsParameterStringListComboBoxCreator);
}
......
......@@ -52,6 +52,12 @@ bool dtkWidgetsParameterBoolCheckBox::connect(dtkCoreAbstractParameter *p)
d->check_box->setToolTip(p_bool->documentation());
if(p_bool->value()) {
d->check_box->setCheckState(Qt::Checked);
} else {
d->check_box->setCheckState(Qt::Unchecked);
}
QObject::connect(p_bool, &dtk::d_bool::valueChanged, [=] (QVariant v) {
bool value = v.value<dtk::d_bool>().value();
d->check_box->blockSignals(true);
......@@ -64,9 +70,7 @@ bool dtkWidgetsParameterBoolCheckBox::connect(dtkCoreAbstractParameter *p)
});
QObject::connect(d->check_box, &QCheckBox::stateChanged, [=] (int state) {
p_bool->block(true);
p_bool->setValue(state == Qt::Checked);
p_bool->block(false);
});
dtkWidgetsAbstractParameter::m_parameter = p;
......
......@@ -54,9 +54,13 @@ bool dtkWidgetsParameterIntSpinBox::connect(dtkCoreAbstractParameter *p)
d->spin_box->setMaximum(p_int->max());
d->spin_box->setToolTip(p_int->documentation());
d->spin_box->setValue(p_int->value());
QObject::connect(p_int, &dtk::d_int::valueChanged, [=] (QVariant v) {
int value = v.value<dtk::d_int>().value();
d->spin_box->blockSignals(true);
d->spin_box->setValue(value);
d->spin_box->blockSignals(false);
});
QObject::connect(d->spin_box, QOverload<int>::of(&QSpinBox::valueChanged), [=] (int v) {
......
......@@ -53,11 +53,18 @@ bool dtkWidgetsParameterStringListComboBox::connect(dtkCoreAbstractParameter *p)
d->combo_box->addItems(p_inliststring->values());
d->combo_box->setToolTip(p_inliststring->documentation());
int index = d->combo_box->findText(p_inliststring->value());
if ( index != -1 ) {
d->combo_box->setCurrentIndex(index);
}
QObject::connect(p_inliststring, &dtk::d_inliststring::valueChanged, [=] (QVariant v) {
QString value = v.value<dtk::d_inliststring>().value();
int index = d->combo_box->findText(value);
if ( index != -1 ) {
d->combo_box->blockSignals(true);
d->combo_box->setCurrentIndex(index);
d->combo_box->blockSignals(false);
}
});
......
......@@ -36,6 +36,18 @@ class dtkWidgetsParameterMenuBarGeneratorTestCasePrivate
dtkWidgetsParameterMenuBarGeneratorTestCase::dtkWidgetsParameterMenuBarGeneratorTestCase(void) : d(new dtkWidgetsParameterMenuBarGeneratorTestCasePrivate)
{
qRegisterMetaTypeStreamOperators<dtk::d_bool>("dtk::d_bool");
qRegisterMetaTypeStreamOperators<dtk::d_real>("dtk::d_real");
qRegisterMetaTypeStreamOperators<dtk::d_int>("dtk::d_int");
qRegisterMetaTypeStreamOperators<dtk::d_string>("dtk::d_string");
qRegisterMetaType<dtk::d_real *>();
qRegisterMetaType<dtk::d_bool *>();
qRegisterMetaType<dtk::d_int *>();
qRegisterMetaType<dtk::d_string *>();
dtk::widgets::setVerboseLoading(true);
dtk::widgets::initialize("");
}
......
......@@ -95,7 +95,7 @@ void dtkWidgetsParametersTestCase::testBasic(void)
available_strings.append("SecondString");
available_strings.append("ThirdString");
dtk::d_inliststring inliststring_parameter = available_strings;
dtk::d_inliststring inliststring_parameter("listofstrings", available_strings);
inliststring_parameter.setDocumentation("A inliststring parameter.");
dtkWidgetsAbstractParameter *inliststring_combo_box = dtk::widgets::parameters::pluginFactory().create(&inliststring_parameter, "dtkWidgetsParameterStringListComboBox");
......@@ -140,7 +140,7 @@ void dtkWidgetsParametersTestCase::testBasic(void)
available_strings.append("SecondString");
available_strings.append("ThirdString");
dtk::d_inliststring inliststring_parameter = available_strings;
dtk::d_inliststring inliststring_parameter("listofstrings", available_strings);
inliststring_parameter.setDocumentation("A inliststring parameter.");
dtkWidgetsAbstractParameter *inliststring_combo_box = dtk::widgets::parameters::pluginFactory().create("dtkWidgetsParameterStringListComboBox");
......
......@@ -2,12 +2,12 @@
"contents": [
{ "group": {"uid" : "Model parameters", "icon": "fa::cogs", "advanced": false,
"contents": [
{"parameter": {"uid": "hyp", "type": "dtk::d_int", "widget": "dtkWidgetsParameterSpinBox", "advanced": false}},
{"parameter": {"uid": "dif", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterCheckBox", "advanced": false}},
{"parameter": {"uid": "res", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterCheckBox", "advanced": false}},
{"parameter": {"uid": "prec", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterCheckBox", "advanced": false}},
{"parameter": {"uid": "inf", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterCheckBox", "advanced": false}},
{"parameter": {"uid": "wind", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterCheckBox", "advanced": false}}
{"parameter": {"uid": "hyp", "type": "dtk::d_int", "widget": "dtkWidgetsParameterIntSpinBox", "advanced": false}},
{"parameter": {"uid": "dif", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}},
{"parameter": {"uid": "res", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}},
{"parameter": {"uid": "prec", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}},
{"parameter": {"uid": "inf", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}},
{"parameter": {"uid": "wind", "type": "dtk::d_bool", "widget": "dtkWidgetsParameterBoolCheckBox", "advanced": false}}
]
} }
]
......
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