Commit 3a8a1952 authored by LE BRETON Come's avatar LE BRETON Come
Browse files

Proposal for saving the parameter in the widget.

parent a7ddca48
Pipeline #137291 failed with stage
in 0 seconds
......@@ -212,9 +212,9 @@ dtkWidgetsMenuItem *dtkWidgetsMenu::addParameter(dtkWidgetsMenuItem *item)
return this->addItem(item);
}
dtkWidgetsMenuItem *dtkWidgetsMenu::addParameter(const QString& title, dtkCoreParameter *parameter, const QString& representation)
dtkWidgetsMenuItem *dtkWidgetsMenu::addParameter(const QString& title, dtkCoreParameter *parameter, const QString& representation, bool persistent)
{
dtkWidgetsMenuItem *item = new dtkWidgetsMenuItemParameter(title, parameter, representation);
dtkWidgetsMenuItem *item = new dtkWidgetsMenuItemParameter(title, parameter, representation, persistent);
auto it = this->addItem(item);
......
......@@ -63,7 +63,7 @@ public:
dtkWidgetsMenuItem *addSeparator(void);
dtkWidgetsMenuItem *addParameter(dtkWidgetsMenuItem *item);
dtkWidgetsMenuItem *addParameter(const QString&, dtkCoreParameter *, const QString& representation);
dtkWidgetsMenuItem *addParameter(const QString&, dtkCoreParameter *, const QString& representation, bool persistent = false);
void removeItem(dtkWidgetsMenuItem *item);
void removeMenu(dtkWidgetsMenu *menu);
......
......@@ -81,10 +81,10 @@ public:
// dtkWidgetsMenuItem implementation
// ///////////////////////////////////////////////////////////////////
dtkWidgetsMenuItemParameter::dtkWidgetsMenuItemParameter(const QString& title, dtkCoreParameter *parameter, const QString& representation) : dtkWidgetsMenuItem(0, title, 0), d(new dtkWidgetsMenuItemParameterPrivate)
dtkWidgetsMenuItemParameter::dtkWidgetsMenuItemParameter(const QString& title, dtkCoreParameter *parameter, const QString& representation, bool persistent) : dtkWidgetsMenuItem(0, title, 0), d(new dtkWidgetsMenuItemParameterPrivate)
{
d->parameter = parameter;
d->widget = ::dtk::widgets::parameters::pluginFactory().create(parameter, representation);
d->widget = ::dtk::widgets::parameters::pluginFactory().create(parameter, representation, persistent);
}
dtkWidgetsMenuItemParameter::~dtkWidgetsMenuItemParameter(void)
......
......@@ -63,7 +63,7 @@ class DTKWIDGETS_EXPORT dtkWidgetsMenuItemParameter : public dtkWidgetsMenuItem
Q_OBJECT
public:
explicit dtkWidgetsMenuItemParameter(const QString& title, dtkCoreParameter *parameter, const QString& representation);
explicit dtkWidgetsMenuItemParameter(const QString& title, dtkCoreParameter *parameter, const QString& representation, bool persistent = false);
~dtkWidgetsMenuItemParameter(void);
public:
......
......@@ -30,7 +30,7 @@ dtkWidgetsParameter *dtkWidgetsParameterFactory::create(const QString& key)
return widget;
}
dtkWidgetsParameter *dtkWidgetsParameterFactory::create(dtkCoreParameter *parameter, const QString& key)
dtkWidgetsParameter *dtkWidgetsParameterFactory::create(dtkCoreParameter *parameter, const QString& key, bool persistent)
{
if (!parameter) {
qWarning() << Q_FUNC_INFO << "The input parameter is null. Nothing is done. Return nullptr.";
......@@ -42,8 +42,23 @@ dtkWidgetsParameter *dtkWidgetsParameterFactory::create(dtkCoreParameter *parame
qWarning() << Q_FUNC_INFO << "The widget with key :" << key << "could not be instanciated by the factory.";
return nullptr;
}
if(!widget->connect(parameter)) {
qWarning() << Q_FUNC_INFO << "The parameter could not be connected to the widget.";
} else {
if(persistent) {
QSettings settings;
settings.beginGroup("parameters");
parameter->setValue(settings.value(parameter->uid()));
settings.endGroup();
parameter->connect([=] (const QVariant& v) {
QSettings settings;
settings.beginGroup("parameters");
parameter->setValue(v);
settings.endGroup();
});
}
}
return widget;
}
......
......@@ -43,7 +43,7 @@ class DTKWIDGETS_EXPORT dtkWidgetsParameterFactory : public dtkCorePluginFactory
{
public:
dtkWidgetsParameter *create(const QString& key);
dtkWidgetsParameter *create(dtkCoreParameter *parameter, const QString& key);
dtkWidgetsParameter *create(dtkCoreParameter *parameter, const QString& key, bool persistent = false);
};
// /////////////////////////////////////////////////////////////////
......
......@@ -97,7 +97,14 @@ void dtkWidgetsParameterMenuBarGeneratorPrivate::parseParameter(dtkWidgetsMenu *
}
dtkWidgetsMenuItem *parameter_item = menu->addParameter(parameter->label(), parameter, widget_string);
dtkWidgetsMenuItem *parameter_item = nullptr;
if(parameter_object.contains("persistent")) {
parameter_item = menu->addParameter(parameter->label(), parameter, widget_string, parameter_object["persistent"].toBool());
} else {
parameter_item = menu->addParameter(parameter->label(), parameter, widget_string);
}
if(parameter_item) {
if(parameter_object.contains("widget_read_only")) {
static_cast<dtkWidgetsMenuItemParameter *>(parameter_item)->widget()->setReadOnly(parameter_object["widget_read_only"].toBool());
......
Supports Markdown
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