Commit f9b64c17 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas
Browse files

add reset method in dtkWidgetsParameter. Will restore the initial value

of the parameter
parent 0d4a95ee
Pipeline #255019 passed with stage
in 0 seconds
......@@ -97,11 +97,24 @@ int main(int argc, char **argv)
dtk::d_bool bool_parameter = true;
dtkWidgetsParameter *bool_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&bool_parameter, "dtkWidgetsParameterBoolCheckBox");
dtk::d_bool bool2_parameter = false;
dtkWidgetsParameter *reset_parameter_widget = dtk::widgets::parameters::pluginFactory().create(&bool2_parameter, "dtkWidgetsParameterBoolPushButton");
dynamic_cast<dtkWidgetsParameterBoolPushButton*>(reset_parameter_widget)->setOffText("Reset");
bool_parameter.connect([=] (QVariant v) {
bool value = v.value<dtk::d_bool>().value();
qInfo() << "bool_parameter =" << value;
});
bool2_parameter.connect([=] (QVariant v) {
bool value = v.value<dtk::d_bool>().value();
qInfo() << "bool2_parameter =" << value;
string_parameter_widget->reset();
inliststring_parameter_widget->reset();
longlong_parameter_widget->reset();
scientific_parameter_widget->reset();
longlong_parameter_widget->reset();
});
QVBoxLayout *central_layout = new QVBoxLayout;
QFrame *frame = new QFrame();
frame->setFrameStyle(QFrame::Box | QFrame::Raised);
......@@ -123,6 +136,7 @@ int main(int argc, char **argv)
central_layout->addWidget(string_parameter_widget);
central_layout->addWidget(new QSplitter);
central_layout->addWidget(bool_parameter_widget);
central_layout->addWidget(reset_parameter_widget);
QWidget *central_widget = new QWidget;
central_widget->setLayout(central_layout);
......
......@@ -13,6 +13,7 @@
// Code:
#include "dtkWidgetsParameter.h"
#include <dtkCore/dtkCoreParameter.h>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsAbstractParameter implementation
......@@ -33,6 +34,11 @@ void dtkWidgetsParameter::setReadOnly(bool)
};
void dtkWidgetsParameter::reset(void)
{
this->parameter()->shareValue(m_default);
}
void dtkWidgetsParameter::setAdvanced(bool adv)
{
m_advanced = adv;
......
......@@ -17,6 +17,7 @@
#include <dtkWidgetsExport>
#include <QtWidgets/QWidget>
#include <QVariant>
// ///////////////////////////////////////////////////////////////////
// dtkWidgetsParameter
......@@ -45,12 +46,16 @@ public:
void setAdvanced(bool);
bool advanced(void);
public:
virtual void reset(void);
signals:
void advancedChanged(bool);
protected:
bool m_readonly = false;
bool m_advanced = false;
QVariant m_default;
};
Q_DECLARE_METATYPE(dtkWidgetsParameter *);
......
......@@ -66,6 +66,7 @@ bool dtkWidgetsParameterBoolCheckBox::connect(dtkCoreParameter *p)
return false;
}
m_default = m_parameter->variant();
d->check_box->setToolTip(m_parameter->documentation());
if(m_parameter->value()) {
......
......@@ -84,6 +84,7 @@ bool dtkWidgetsParameterBoolPushButton::connect(dtkCoreParameter *p)
d->push_button->setToolTip(m_parameter->documentation());
d->running = m_parameter->value();
m_default = m_parameter->variant();
if(d->running) {
qWarning() << Q_FUNC_INFO << "It is not advised to set d_bool parameter to on before connecting";
......
......@@ -91,7 +91,7 @@ bool dtkWidgetsParameterBrowse::connect(dtkCoreParameter *p)
d->push_button->setText(text);
d->setToolTip( m_parameter->documentation(), m_parameter->path() );
m_default = m_parameter->variant();
m_parameter->connect([=] (QVariant v) {
d->push_button->blockSignals(true);
QString value = v.value<dtk::d_path>().baseName();
......
......@@ -102,6 +102,8 @@ bool dtkWidgetsParameterDoubleSlider::connect(dtkCoreParameter *p)
}
int decimals = m_parameter->decimals();
m_default = m_parameter->variant();
d->slider->setMinimum(0);
d->slider->setMaximum((int)d->nx);
d->min->setText(QString::number(m_parameter->min()));
......
......@@ -71,6 +71,8 @@ bool dtkWidgetsParameterDoubleSpinBox::connect(dtkCoreParameter *p)
return false;
}
m_default = m_parameter->variant();
d->spin_box->setMinimum(m_parameter->min());
d->spin_box->setMaximum(m_parameter->max());
d->spin_box->setToolTip(m_parameter->documentation());
......
......@@ -108,6 +108,8 @@ bool dtkWidgetsParameterIntSlider::connect(dtkCoreParameter *p)
return false;
}
m_default = m_parameter->variant();
d->setMinimum(m_parameter->min());
d->setMaximum(m_parameter->max());
d->min->setText(QString::number(m_parameter->min()));
......
......@@ -69,6 +69,8 @@ bool dtkWidgetsParameterIntSpinBox::connect(dtkCoreParameter *p)
return false;
}
m_default = m_parameter->variant();
d->spin_box->setMinimum(m_parameter->min());
d->spin_box->setMaximum(m_parameter->max());
d->spin_box->setToolTip(m_parameter->documentation());
......
......@@ -69,6 +69,8 @@ bool dtkWidgetsParameterLongLongSpinBox::connect(dtkCoreParameter *p)
return false;
}
m_default = m_parameter->variant();
d->spin_box->setMinimum(m_parameter->min());
d->spin_box->setMaximum(m_parameter->max());
d->spin_box->setToolTip(m_parameter->documentation());
......
......@@ -69,6 +69,8 @@ bool dtkWidgetsParameterScientificSpinBox::connect(dtkCoreParameter *p)
return false;
}
m_default = m_parameter->variant();
d->spin_box->setMinimum(m_parameter->min());
d->spin_box->setMaximum(m_parameter->max());
d->spin_box->setToolTip(m_parameter->documentation());
......
......@@ -59,6 +59,8 @@ bool dtkWidgetsParameterStringLineEdit::connect(dtkCoreParameter *p)
return false;
}
m_default = m_parameter->variant();
d->line_edit->setText(m_parameter->value());
d->line_edit->setToolTip(m_parameter->documentation());
......
......@@ -109,6 +109,8 @@ bool dtkWidgetsParameterStringListComboBox::connect(dtkCoreParameter *p)
d->combo_box->addItems(m_parameter->values());
d->combo_box->setToolTip(m_parameter->documentation());
m_default = m_parameter->variant();
int index = d->combo_box->findText(m_parameter->value());
if ( index != -1 ) {
d->combo_box->setCurrentIndex(index);
......
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