Commit 5f4e2cf0 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas
Browse files

Merge branch '59-persistent-widgets' into 'develop'

Resolve "Persistent widgets"

Closes #59

See merge request !60
parents 17f0e8b9 3b637abd
Pipeline #137672 passed with stage
in 0 seconds
......@@ -21,7 +21,7 @@
"combo_box":{
"label": "Input",
"doc": "Select a choice in the combo box",
"value": "Choice 1",
"index": "1",
"type": "dtk::d_inliststring",
"values": [
"Choice 1",
......@@ -104,7 +104,7 @@
"combo_box_ro":{
"label": "Input (Read Only)",
"doc": "Select a choice in the combo box",
"value": "Choice 1",
"index": "1",
"type": "dtk::d_inliststring",
"values": [
"Choice 1",
......
......@@ -113,6 +113,7 @@
"widget": "dtkWidgetsParameterDoubleSpinBox",
"uid": "spin_double",
"advanced": false,
"persistent": true,
"widget_read_only": false
}
},
......@@ -120,6 +121,7 @@
"parameter": {
"widget": "dtkWidgetsParameterStringListComboBox",
"uid": "combo_box",
"persistent": true,
"advanced": false
}
},
......
......@@ -4,7 +4,7 @@ channels:
- conda-forge
dependencies:
- qt >=5.9.0
- dtk-core >=2.6.0
- dtk-core >=2.8.0
- dtk-fonts >=2.1.1
- dtk-log
- dtk-themes
......@@ -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,26 @@ 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");
if(settings.contains(parameter->uid())) {
parameter->setValue(settings.value(parameter->uid()));
}
settings.endGroup();
parameter->connect([=] (const QVariant& v) {
QSettings settings;
settings.beginGroup("parameters");
settings.setValue(parameter->uid(), parameter->variant());
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());
......
......@@ -48,7 +48,8 @@
"parameter": {
"uid": "vrOn/temporal_step",
"widget": "dtkWidgetsParameterDoubleSpinBox",
"advanced": false
"advanced": false,
"persistent":true
}
},
{
......@@ -62,7 +63,8 @@
"parameter": {
"uid": "vrOn/pixels_per_degree",
"widget": "dtkWidgetsParameterDoubleSpinBox",
"advanced": false
"advanced": false,
"persistent": true
}
},
{
......@@ -619,4 +621,4 @@
}
}
]
}
\ No newline at end of file
}
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