From 95409691b7cbe65590660f9f36eb6d9be3f38812 Mon Sep 17 00:00:00 2001 From: Tobias Knopff <t.knopff@fz-juelich.de> Date: Wed, 26 May 2021 12:54:47 +0200 Subject: [PATCH] Make ConstantBackgroundItem::P_VALUE private --- GUI/Models/BackgroundItems.cpp | 7 ++++++- GUI/Models/BackgroundItems.h | 4 +++- GUI/Models/TransformFromDomain.cpp | 7 ++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/GUI/Models/BackgroundItems.cpp b/GUI/Models/BackgroundItems.cpp index 5925b6c7227..a5ae25b91a5 100644 --- a/GUI/Models/BackgroundItems.cpp +++ b/GUI/Models/BackgroundItems.cpp @@ -35,7 +35,7 @@ namespace { const QString constant_background_value_tooltip = "Constant background value [counts/pixel]"; } -const QString ConstantBackgroundItem::P_VALUE = QString::fromStdString("BackgroundValue"); +const QString ConstantBackgroundItem::P_VALUE = "BackgroundValue"; ConstantBackgroundItem::ConstantBackgroundItem() : BackgroundItem("ConstantBackground") { @@ -49,6 +49,11 @@ std::unique_ptr<IBackground> ConstantBackgroundItem::createBackground() const return std::make_unique<ConstantBackground>(getItemValue(P_VALUE).toDouble()); } +void ConstantBackgroundItem::setBackgroundValue(double value) +{ + setItemValue(P_VALUE, value); +} + // Background consisting of Poisson noise /* ------------------------------------------------ */ diff --git a/GUI/Models/BackgroundItems.h b/GUI/Models/BackgroundItems.h index 85c0056a986..96b3f83b756 100644 --- a/GUI/Models/BackgroundItems.h +++ b/GUI/Models/BackgroundItems.h @@ -33,11 +33,13 @@ public: }; class BA_CORE_API_ ConstantBackgroundItem : public BackgroundItem { -public: +private: static const QString P_VALUE; +public: ConstantBackgroundItem(); std::unique_ptr<IBackground> createBackground() const; + void setBackgroundValue(double value); }; class BA_CORE_API_ PoissonNoiseBackgroundItem : public BackgroundItem { diff --git a/GUI/Models/TransformFromDomain.cpp b/GUI/Models/TransformFromDomain.cpp index 14ecf8eb04a..02f3ea4abc0 100644 --- a/GUI/Models/TransformFromDomain.cpp +++ b/GUI/Models/TransformFromDomain.cpp @@ -558,10 +558,11 @@ void TransformFromDomain::setBackground(InstrumentItem* instrument_item, { auto p_bg = simulation.background(); if (auto p_constant_bg = dynamic_cast<const ConstantBackground*>(p_bg)) { - auto constant_bg_item = - instrument_item->setGroupProperty(InstrumentItem::P_BACKGROUND, "ConstantBackground"); + ConstantBackgroundItem* constant_bg_item = + dynamic_cast<ConstantBackgroundItem*> + (instrument_item->setGroupProperty(InstrumentItem::P_BACKGROUND, "ConstantBackground")); double value = p_constant_bg->backgroundValue(); - constant_bg_item->setItemValue(ConstantBackgroundItem::P_VALUE, value); + constant_bg_item->setBackgroundValue(value); } else if (dynamic_cast<const PoissonNoiseBackground*>(p_bg)) { instrument_item->setGroupProperty(InstrumentItem::P_BACKGROUND, "PoissonNoiseBackground"); } -- GitLab