Commit 827611ff authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

- add virtual restoreSettings method;

 - add hide/show helper function in base classe.
 - call restoreSettings when changing objectName
parent 8816ca81
......@@ -44,5 +44,21 @@ void dtkVisualizationDecorator::saveSettings(const QString & name, const QVarian
settings.endGroup();
}
void dtkVisualizationDecorator::show(void)
{
this->setVisibility(true);
}
void dtkVisualizationDecorator::hide(void)
{
this->setVisibility(false);
}
void dtkVisualizationDecorator::setObjectName(const QString & name)
{
QObject::setObjectName(name);
this->restoreSettings();
}
//
// dtkVisualizationDecorator.cpp ends here
......@@ -37,12 +37,20 @@ public:
public:
virtual void touch(void) = 0;
void setObjectName(const QString &);
public:
void show(void);
void hide(void);
protected:
void draw(void);
void saveSettings(const QString &, const QVariant&);
public:
virtual void setVisibility(bool visible) = 0;
virtual void restoreSettings(void) {};
virtual bool isDecorating(void) = 0;
virtual void setData(const QVariant&) = 0;
......
......@@ -164,6 +164,13 @@ bool dtkVisualizationDecoratorInfo::isDecorating(void)
return d->dataset;
}
void dtkVisualizationDecoratorInfo::setVisibility(bool visible)
{
for (QWidget * w: d->inspectors) {
w->setVisible(visible);
}
}
void dtkVisualizationDecoratorInfo::setData(const QVariant& data)
{
d->dataset = data.value<vtkDataSet *>();
......
......@@ -31,6 +31,9 @@ public:
void setInformation(const QString& key, const QString& value, const QString& tooltip = QString());
void setInformation(const QString& key, QWidget *value);
public:
void setVisibility(bool) override;
public:
bool isDecorating(void) override;
......
......@@ -127,11 +127,8 @@ dtkVisualizationDecoratorPoints::dtkVisualizationDecoratorPoints(void): d(new dt
connect(d->size_spinbox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &dtkVisualizationDecoratorPoints::setSize);
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
if (state == Qt::Checked) {
this->show();
} else {
this->hide();
}
this->setVisibility(state == Qt::Checked);
this->draw();
});
d->inspectors << d->color_button << d->opacity_spinbox << d->size_spinbox << d->show_actor_cb;
......@@ -186,12 +183,7 @@ void dtkVisualizationDecoratorPoints::setData(const QVariant& data)
d->filter->Modified();
d->mapper->Modified();
if(this->canvas()) {
this->canvas()->renderer()->AddActor(d->actor);
if (this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
}
}
this->draw();
}
void dtkVisualizationDecoratorPoints::setCanvas(dtkVisualizationCanvas *canvas)
......@@ -221,42 +213,21 @@ void dtkVisualizationDecoratorPoints::unsetCanvas(void)
d->view = nullptr;
}
void dtkVisualizationDecoratorPoints::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);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
}
void dtkVisualizationDecoratorPoints::hide(void)
void dtkVisualizationDecoratorPoints::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);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
}
void dtkVisualizationDecoratorPoints::setColor(const QColor& color)
{
d->actor->GetProperty()->SetColor(color.red(), color.green(), color.blue());
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
this->draw();
}
void dtkVisualizationDecoratorPoints::setOpacity(const double& alpha)
......@@ -267,10 +238,7 @@ void dtkVisualizationDecoratorPoints::setOpacity(const double& alpha)
d->opacity_spinbox->setValue(alpha);
d->opacity_spinbox->blockSignals(false);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
this->draw();
}
void dtkVisualizationDecoratorPoints::setSize(const double& size)
......@@ -281,10 +249,7 @@ void dtkVisualizationDecoratorPoints::setSize(const double& size)
d->size_spinbox->setValue(size);
d->size_spinbox->blockSignals(false);
if (this->canvas() && this->canvas()->interactor()) {
this->canvas()->interactor()->Render();
this->canvas()->renderer()->GetRenderWindow()->Render();
}
this->draw();
}
QVariant dtkVisualizationDecoratorPoints::data(void) const
......
......@@ -41,8 +41,7 @@ public:
void touch(void) override;
public:
void show(void);
void hide(void);
void setVisibility(bool) override;
public:
virtual void setColor(const QColor&);
......
......@@ -85,12 +85,7 @@ public:
dtkVisualizationDecoratorScalarGlyphs::dtkVisualizationDecoratorScalarGlyphs(const QString& name): dtkVisualizationDecoratorWithClut(name), d(new dtkVisualizationDecoratorScalarGlyphsPrivate())
{
QSettings settings;
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();
this->restoreSettings();
d->source_arrow = vtkSmartPointer<vtkArrowSource>::New();
d->source_cube = vtkSmartPointer<vtkCubeSource>::New();
......@@ -205,6 +200,19 @@ dtkVisualizationDecoratorScalarGlyphs::~dtkVisualizationDecoratorScalarGlyphs(vo
d = nullptr;
}
void dtkVisualizationDecoratorScalarGlyphs::restoreSettings(void)
{
QString name = this->objectName();
if (name.isEmpty())
return;
QSettings settings;
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();
}
void dtkVisualizationDecoratorScalarGlyphs::setData(const QVariant& data)
{
vtkDataSet *dataset = data.value<vtkDataSet *>();
......
......@@ -37,6 +37,7 @@ protected:
public:
void setVisibility(bool) override;
void restoreSettings(void) override;
public:
void setCurrentGlyphsSize(double);
......
......@@ -128,6 +128,10 @@ QVariant dtkVisualizationDecoratorSnapshot::data(void) const
return QVariant();
}
void dtkVisualizationDecoratorSnapshot::setVisibility(bool)
{
}
dtkVisualizationCanvas *dtkVisualizationDecoratorSnapshot::canvas(void) const
{
return d->view;
......
......@@ -42,8 +42,7 @@ public:
void unsetCanvas(void) override;
public:
void show(void);
void hide(void);
void setVisibility(bool) override;
signals:
void updated(void);
......
......@@ -227,18 +227,7 @@ void dtkVisualizationDecoratorWithClutPrivate::sortEligibleFields(void)
dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(const QString& name): dtkVisualizationDecorator(), d(new dtkVisualizationDecoratorWithClutPrivate)
{
this->setObjectName(name);
QSettings settings;
settings.beginGroup("canvas");
d->default_visibility = settings.value(name+"_visibility", true).toBool();
d->default_field_name = settings.value(name+"_field_name").toString();
d->default_color_map = settings.value(name+"_colormap", "inferno").toString();
bool show_scalar_bar = settings.value(name+"_show_scalarbar", false).toBool();
settings.endGroup();
d->colormap_editor->setValue(d->default_color_map);
d->scalar_bar->SetVisibility(show_scalar_bar);
this->restoreSettings();
//////////
// Inspectors connections
......@@ -290,6 +279,24 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(const QStri
});
}
void dtkVisualizationDecoratorWithClut::restoreSettings(void)
{
QString name = this->objectName();
if (name.isEmpty())
return;
QSettings settings;
settings.beginGroup("canvas");
d->default_visibility = settings.value(name+"_visibility", true).toBool();
d->default_field_name = settings.value(name+"_field_name").toString();
d->default_color_map = settings.value(name+"_colormap", "inferno").toString();
d->default_show_scalar_bar = settings.value(name+"_show_scalarbar", false).toBool();
settings.endGroup();
d->colormap_editor->setValue(d->default_color_map);
d->scalar_bar->SetVisibility(d->default_show_scalar_bar);
}
void dtkVisualizationDecoratorWithClut::touch(void)
{
if (d->current_field_name.isEmpty() || !d->dataset) {
......
......@@ -52,6 +52,7 @@ public:
public:
virtual void setVisibility(bool visible);
void restoreSettings(void) override;
protected:
virtual void setCurrentRange(double, double);
......
......@@ -77,6 +77,7 @@ public:
QString default_field_name;
QString default_color_map;
bool default_visibility = true;
bool default_show_scalar_bar = false;
public:
vtkSmartPointer<vtkColorTransferFunction> color_function;
......
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