Commit 396493ee authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas
Browse files

Merge branch 'release/2.26.0'

parents 6df67367 e0ab5641
Pipeline #256245 passed with stage
in 0 seconds
# ChangeLog
## version 2.26.0 - 2021-06-04
- add methods to import/export in menu
- add reset method in dtkWidgetsParameter
- add tooltips for layout buttons
- add the possibility of overriding textOn and textOff for dtkWidgetsParameterBoolPushButton
## version 2.25.1 - 2021-04-02
- fix emission of inserted signal of dtkWidgetsController
## version 2.25.0 - 2021-02-01
......
......@@ -24,8 +24,8 @@ project(dtkWidgets)
## ###################################################################
set(${PROJECT_NAME}_VERSION_MAJOR 2)
set(${PROJECT_NAME}_VERSION_MINOR 25)
set(${PROJECT_NAME}_VERSION_PATCH 1)
set(${PROJECT_NAME}_VERSION_MINOR 26)
set(${PROJECT_NAME}_VERSION_PATCH 0)
set(${PROJECT_NAME}_VERSION
${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH})
......
......@@ -43,14 +43,6 @@
"widget_read_only": true
}
},
{
"parameter": {
"widget": "dtkWidgetsParameterBoolPushButton",
"uid": "push_button_ro",
"advanced": false,
"widget_read_only": true
}
},
{
"parameter": {
"widget": "dtkWidgetsParameterFileBrowse",
......@@ -153,6 +145,8 @@
"widget": "dtkWidgetsParameterBoolPushButton",
"uid": "push_button",
"advanced": false,
"textOn": "Nobody expects the spanish inquisition!",
"textOff": "Hit me",
"widget_read_only": false
}
},
......
......@@ -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);
......
......@@ -400,6 +400,11 @@ dtkWidgetsLayoutItem::dtkWidgetsLayoutItem(dtkWidgetsLayoutItem *parent) : QFram
d->horzt->setEnabled(false);
d->maxmz->setEnabled(false);
d->close->setToolTip("Minimize");
d->vertc->setToolTip("Split vertically");
d->horzt->setToolTip("Split horizontally");
d->maxmz->setToolTip("Maximize");
this->setFocusPolicy(Qt::ClickFocus);
}
......
......@@ -243,6 +243,40 @@ dtkWidgetsMenuItem *dtkWidgetsMenu::addParameter(const QString& title, dtkCorePa
return it;
}
void dtkWidgetsMenu::exportParameters(QJsonObject &json, bool recursive) const
{
for (auto o: d->object_hash) {
dtkWidgetsMenuItemParameter *item = dynamic_cast<dtkWidgetsMenuItemParameter*>(o);
if (item){
json.insert(item->parameter()->uid(), QJsonObject::fromVariantHash(item->parameter()->toVariantHash()));
}
}
if (recursive) {
for (auto menu: d->menu_list) {
menu->exportParameters(json, true);
}
}
}
// Import parameter value from json to embedded parameters in menu and submenus
void dtkWidgetsMenu::importParameters(const QJsonObject &json, bool recursive) const
{
for (auto o: d->object_hash) {
dtkWidgetsMenuItemParameter *item = dynamic_cast<dtkWidgetsMenuItemParameter*>(o);
if (item){
if (json.contains(item->parameter()->uid())) {
QVariant v = json[item->parameter()->uid()].toVariant();
item->parameter()->shareValue(v);
}
}
}
if (recursive) {
for (auto menu: d->menu_list) {
menu->importParameters(json, true);
}
}
}
void dtkWidgetsMenu::removeItem(dtkWidgetsMenuItem *item)
{
if (!(item && d->object_hash.contains(item->title())))
......
......@@ -65,6 +65,9 @@ public:
dtkWidgetsMenuItem *addParameter(dtkWidgetsMenuItem *item);
dtkWidgetsMenuItem *addParameter(const QString&, dtkCoreParameter *, const QString& representation, bool persistent = false);
void exportParameters(QJsonObject &json, bool recursive = true) const;
void importParameters(const QJsonObject& json, bool recursive = true) const;
void removeItem(dtkWidgetsMenuItem *item);
void removeMenu(dtkWidgetsMenu *menu);
......
......@@ -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()) {
......
......@@ -26,6 +26,8 @@ public:
QPushButton *push_button = nullptr;
bool running = false;
QString on_text = "Running ...";
QString off_text = "Run";
};
// ///////////////////////////////////////////////////////////////////
......@@ -47,6 +49,17 @@ dtkWidgetsParameterBoolPushButton::~dtkWidgetsParameterBoolPushButton(void)
delete d;
}
void dtkWidgetsParameterBoolPushButton::setOnText(const QString & text)
{
d->on_text = text;
}
void dtkWidgetsParameterBoolPushButton::setOffText(const QString & text)
{
d->off_text = text;
d->push_button->setText(d->off_text);
}
void dtkWidgetsParameterBoolPushButton::setReadOnly(bool val)
{
this->dtkWidgetsParameter::m_readonly = val;
......@@ -71,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";
......@@ -79,10 +93,10 @@ bool dtkWidgetsParameterBoolPushButton::connect(dtkCoreParameter *p)
auto setAppearance = [this] (bool state) {
if (state) {
this->d->push_button->setStyleSheet("background-color: red");
this->d->push_button->setText("Running...");
this->d->push_button->setText(d->on_text);
} else {
this->d->push_button->setStyleSheet("");
this->d->push_button->setText("Run");
this->d->push_button->setText(d->off_text);
}
};
......
......@@ -31,6 +31,8 @@ public:
public:
bool connect(dtkCoreParameter *) override;
void setReadOnly(bool) override;
void setOnText(const QString&);
void setOffText(const QString&);
private:
using dtkWidgetsParameterBase<dtk::d_bool>::m_parameter;
......
......@@ -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());
......
......@@ -14,6 +14,7 @@
#include "dtkWidgetsParameterMenuBarGenerator.h"
#include "dtkWidgetsParameterBoolPushButton.h"
#include "dtkWidgetsParameterFactory.h"
#include "dtkWidgetsParameter.h"
#include "dtkWidgetsMenu.h"
......@@ -107,6 +108,15 @@ void dtkWidgetsParameterMenuBarGeneratorPrivate::parseParameter(dtkWidgetsMenu *
if(parameter_object.contains("widget_read_only")) {
param_widget->setReadOnly(parameter_object["widget_read_only"].toBool());
}
auto bool_widget = dynamic_cast<dtkWidgetsParameterBoolPushButton*>(param_widget);
if (bool_widget) {
if (parameter_object.contains("textOn")) {
bool_widget->setOnText(parameter_object["textOn"].toString());
}
if (parameter_object.contains("textOff")) {
bool_widget->setOffText(parameter_object["textOff"].toString());
}
}
parameters_widgets[parameter_uid] = param_widget;
}
}
......
......@@ -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());
......
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