Skip to content
Snippets Groups Projects
Commit 8f4d375d authored by Matthias Puchner's avatar Matthias Puchner
Browse files

free BackgroundItems from SessionItem

parent 53ed3a6a
No related branches found
No related tags found
1 merge request!624Remove SessionItem from Instrument items
......@@ -16,65 +16,31 @@
#include "Core/Background/ConstantBackground.h"
#include "Core/Background/PoissonNoiseBackground.h"
#include "GUI/Model/Types/DoubleDescriptor.h"
BackgroundItem::BackgroundItem(const QString& model_type)
: SessionItem(model_type)
{
}
// Background none
/* ------------------------------------------------ */
NoBackgroundItem::NoBackgroundItem()
: BackgroundItem(M_TYPE)
{
}
std::unique_ptr<IBackground> NoBackgroundItem::createBackground() const
{
return {};
}
// Constant background
/* ------------------------------------------------ */
namespace {
const QString constant_background_value_tooltip = "Constant background value [counts/pixel]";
}
#include "GUI/Model/XML/Serializer.h"
ConstantBackgroundItem::ConstantBackgroundItem()
: BackgroundItem(M_TYPE)
{
addProperty(P_VALUE, 0.0)
->setLimits(RealLimits::nonnegative())
.setToolTip(constant_background_value_tooltip);
m_backgroundValue.init("Background value", "Constant background value", 0.0, "counts/pixel", 3,
RealLimits::nonnegative(), "value");
}
std::unique_ptr<IBackground> ConstantBackgroundItem::createBackground() const
{
return std::make_unique<ConstantBackground>(getItemValue(P_VALUE).toDouble());
return std::make_unique<ConstantBackground>(m_backgroundValue);
}
DoubleDescriptor ConstantBackgroundItem::backgroundValue() const
void ConstantBackgroundItem::serialize(Serializer& s)
{
return DoubleDescriptor(getItem(P_VALUE), "counts/pixel");
s.assertVersion(0);
s.rw(m_backgroundValue);
}
void ConstantBackgroundItem::setBackgroundValue(double value)
{
setItemValue(P_VALUE, value);
}
// Background consisting of Poisson noise
/* ------------------------------------------------ */
PoissonNoiseBackgroundItem::PoissonNoiseBackgroundItem()
: BackgroundItem(M_TYPE)
std::unique_ptr<IBackground> PoissonNoiseBackgroundItem::createBackground() const
{
return std::make_unique<PoissonNoiseBackground>();
}
std::unique_ptr<IBackground> PoissonNoiseBackgroundItem::createBackground() const
std::unique_ptr<IBackground> NoBackgroundItem::createBackground() const
{
return std::make_unique<PoissonNoiseBackground>();
return {};
}
......@@ -15,45 +15,36 @@
#ifndef BORNAGAIN_GUI_MODEL_ITEM_BACKGROUNDITEMS_H
#define BORNAGAIN_GUI_MODEL_ITEM_BACKGROUNDITEMS_H
#include "GUI/Model/BaseItem/SessionItem.h"
#include "GUI/Model/Types/DoubleProperty.h"
#include <memory>
class IBackground;
class DoubleDescriptor;
class Serializer;
class BA_CORE_API_ BackgroundItem : public SessionItem {
class BackgroundItem {
public:
explicit BackgroundItem(const QString& model_type);
virtual ~BackgroundItem() = default;
virtual std::unique_ptr<IBackground> createBackground() const = 0;
virtual void serialize(Serializer& s) {}
};
class NoBackgroundItem : public BackgroundItem {
public:
static constexpr auto M_TYPE{"NoBackground"};
NoBackgroundItem();
std::unique_ptr<IBackground> createBackground() const override;
};
class ConstantBackgroundItem : public BackgroundItem {
private:
static constexpr auto P_VALUE{"BackgroundValue"};
public:
static constexpr auto M_TYPE{"ConstantBackground"};
ConstantBackgroundItem();
std::unique_ptr<IBackground> createBackground() const override;
void serialize(Serializer& s) override;
DoubleDescriptor backgroundValue() const;
void setBackgroundValue(double value);
DOUBLE_PROPERTY(backgroundValue, BackgroundValue);
};
class PoissonNoiseBackgroundItem : public BackgroundItem {
public:
static constexpr auto M_TYPE{"PoissonNoiseBackground"};
PoissonNoiseBackgroundItem();
std::unique_ptr<IBackground> createBackground() const override;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment