Commit 6f257098 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

refactor settings saving in the base class

parent cff52fb0
......@@ -36,5 +36,13 @@ void dtkVisualizationDecorator::draw(void)
}
}
void dtkVisualizationDecorator::saveSettings(const QString & name, const QVariant& value)
{
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_" + name, value);
settings.endGroup();
}
//
// dtkVisualizationDecorator.cpp ends here
......@@ -40,6 +40,7 @@ public:
protected:
void draw(void);
void saveSettings(const QString &, const QVariant&);
public:
virtual bool isDecorating(void) = 0;
......
......@@ -54,6 +54,9 @@ public:
public:
QList<QWidget *> inspectors;
public:
bool default_visibility = false;
public:
QCheckBox *show_actor_cb = nullptr;
QPushButton *color_button = nullptr;
......@@ -70,9 +73,15 @@ public:
// dtkVisualizationDecoratorDelaunay2D implementation
// ///////////////////////////////////////////////////////////////////
dtkVisualizationDecoratorDelaunay2D::dtkVisualizationDecoratorDelaunay2D(void): d(new dtkVisualizationDecoratorDelaunay2DPrivate())
dtkVisualizationDecoratorDelaunay2D::dtkVisualizationDecoratorDelaunay2D(const QString& name): d(new dtkVisualizationDecoratorDelaunay2DPrivate())
{
this->setObjectName("Delaunay 2D");
this->setObjectName(name);
QSettings settings;
settings.beginGroup("canvas");
d->default_visibility = settings.value(name+"_visibility", true).toBool();
bool show_scalar_bar = settings.value(name+"_show_scalarbar", false).toBool();
settings.endGroup();
d->data = vtkSmartPointer<vtkPolyData>::New();
......@@ -86,7 +95,7 @@ dtkVisualizationDecoratorDelaunay2D::dtkVisualizationDecoratorDelaunay2D(void):
d->actor = vtkSmartPointer<vtkActor>::New();
d->actor->SetMapper(d->mapper);
d->actor->SetVisibility(false);
d->actor->SetVisibility(d->default_visibility);
d->actor->GetProperty()->SetPointSize(30);
d->actor->GetProperty()->SetColor(0.5,0.5,0.5);
......@@ -104,7 +113,7 @@ dtkVisualizationDecoratorDelaunay2D::dtkVisualizationDecoratorDelaunay2D(void):
d->opacity_spinbox->setValue(1.);
d->show_actor_cb->setObjectName("Display");
d->show_actor_cb->setChecked(false);
d->show_actor_cb->setChecked(d->default_visibility);
//////////
// Inspectors connections
......@@ -119,11 +128,9 @@ dtkVisualizationDecoratorDelaunay2D::dtkVisualizationDecoratorDelaunay2D(void):
connect(d->opacity_spinbox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &dtkVisualizationDecoratorDelaunay2D::setOpacity);
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
if (state == Qt::Checked) {
this->show();
} else {
this->hide();
}
this->saveSettings("visibility",state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
d->inspectors << d->color_button << d->opacity_spinbox << d->show_actor_cb;
......@@ -202,26 +209,13 @@ void dtkVisualizationDecoratorDelaunay2D::unsetCanvas(void)
d->view = nullptr;
}
void dtkVisualizationDecoratorDelaunay2D::show(void)
{
d->actor->SetVisibility(true);
d->show_actor_cb->blockSignals(true);
d->show_actor_cb->setCheckState(Qt::Checked);
d->show_actor_cb->blockSignals(false);
this->draw();
}
void dtkVisualizationDecoratorDelaunay2D::hide(void)
void dtkVisualizationDecoratorDelaunay2D::setVisibility(bool visible)
{
d->actor->SetVisibility(false);
d->actor->SetVisibility(visible);
d->show_actor_cb->blockSignals(true);
d->show_actor_cb->setCheckState(Qt::Unchecked);
d->show_actor_cb->setCheckState(visible ? Qt::Checked : Qt::Unchecked);
d->show_actor_cb->blockSignals(false);
this->draw();
}
void dtkVisualizationDecoratorDelaunay2D::setColor(const QColor& color)
......@@ -234,7 +228,7 @@ void dtkVisualizationDecoratorDelaunay2D::setColor(const QColor& color)
void dtkVisualizationDecoratorDelaunay2D::setOpacity(const double& alpha)
{
d->actor->GetProperty()->SetOpacity(alpha);
d->opacity_spinbox->blockSignals(true);
d->opacity_spinbox->setValue(alpha);
d->opacity_spinbox->blockSignals(false);
......
......@@ -23,7 +23,7 @@ class DTKVISUALIZATION_EXPORT dtkVisualizationDecoratorDelaunay2D : public dtkVi
Q_OBJECT
public:
dtkVisualizationDecoratorDelaunay2D(void);
dtkVisualizationDecoratorDelaunay2D(const QString & name = QString("Delaunay 2D"));
~dtkVisualizationDecoratorDelaunay2D(void);
public:
......@@ -39,8 +39,7 @@ public:
QList<QWidget *> inspectors(void) const override;
public:
void show(void);
void hide(void);
void setVisibility(bool);
public:
virtual void setColor(const QColor&);
......
......@@ -82,11 +82,7 @@ dtkVisualizationDecoratorScalarColorMap::dtkVisualizationDecoratorScalarColorMap
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_visibility",state == Qt::Checked);
settings.endGroup();
this->saveSettings("visibility", state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
......
......@@ -90,7 +90,6 @@ dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(con
settings.beginGroup("canvas");
d->default_glyph_size = settings.value(name+"_glyph_size", 1.0).toDouble();
d->default_glyph_shape = settings.value(name+"_glyph_shape", "Sphere").toString();
settings.endGroup();
d->source_arrow = vtkSmartPointer<vtkArrowSource>::New();
......@@ -153,22 +152,14 @@ dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(con
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_visibility",state == Qt::Checked);
settings.endGroup();
this->saveSettings("visibility",state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
connect(d->glyphs_size_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double value) {
this->blockSignals(true);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_glyph_size", value);
settings.endGroup();
this->saveSettings("glyph_size", value);
this->setCurrentGlyphsSize(value);
this->blockSignals(false);
this->draw();
......@@ -183,10 +174,7 @@ dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(con
connect(d->glyphs_source_cb, &QComboBox::currentTextChanged, [=] (const QString& source) {
this->blockSignals(true);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_glyph_shape", source);
settings.endGroup();
this->saveSettings("glyph_shape", source);
this->setCurrentGlyphsSource(source);
this->blockSignals(false);
this->draw();
......
......@@ -96,10 +96,7 @@ dtkVisualizationDecoratorScalarIsolines::dtkVisualizationDecoratorScalarIsolines
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_visibility",state == Qt::Checked);
settings.endGroup();
this->saveSettings("visibility",state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
......
......@@ -131,10 +131,7 @@ dtkVisualizationDecoratorVectorStreamlines::dtkVisualizationDecoratorVectorStrea
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_visibility",state == Qt::Checked);
settings.endGroup();
this->saveSettings("visibility",state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
......
......@@ -228,7 +228,6 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(const QStri
{
this->setObjectName(name);
QSettings settings;
settings.beginGroup("canvas");
d->default_visibility = settings.value(name+"_visibility", true).toBool();
......@@ -247,12 +246,7 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(const QStri
connect(d->fields_box, &QComboBox::currentTextChanged, [=] (const QString& field_name) {
d->fields_box->blockSignals(true);
this->setCurrentFieldName(field_name);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_field_name", field_name);
settings.endGroup();
this->saveSettings("field_name", field_name);
d->fields_box->blockSignals(false);
this->touch();
});
......@@ -284,22 +278,14 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(const QStri
d->color_transfer_functions[d->current_field_name] = d->colormap_editor->name();
d->colormap_editor->blockSignals(true);
this->setColorMap(val);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_colormap", d->colormap_editor->name());
settings.endGroup();
this->saveSettings("colormap", d->colormap_editor->name());
d->colormap_editor->blockSignals(false);
this->draw();
});
connect(d->show_scalar_bar, &QCheckBox::stateChanged, [=] (int state) {
d->scalar_bar->SetVisibility(state == Qt::Checked);
QSettings settings;
settings.beginGroup("canvas");
settings.setValue(this->objectName()+"_show_scalarbar", state == Qt::Checked);
settings.endGroup();
this->saveSettings("show_scalarbar", state == Qt::Checked);
this->draw();
});
}
......
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