//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/Model/Descriptor/SpanProperty.h
//! @brief     Defines class SpanProperty.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2022
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_SPANPROPERTY_H
#define BORNAGAIN_GUI_MODEL_DESCRIPTOR_SPANPROPERTY_H

#include "GUI/Model/Descriptor/DoubleProperty.h"
#include <memory>

//! Holds values which can be used to describe a EquiDivision.
//!
//! Use this as a member in your class to
//! * reduce dependency to axis items and axis classes
//! * simplify serialization
//! * easily have a UI supporting solution.
//!
//! This class is designed to work seamlessly with the serialization methods; just call it's
//! serialize for both reading and writing.
//! For UI integration just use SpanPropertyForm.
//!
//! Do not forget to call all two init functions from within the containing class's constructor!

class SpanProperty {
public:
    SpanProperty();

    DoubleProperty& width() { return m_width; }
    const DoubleProperty& width() const { return m_width; }
    void setWidth(double v) { m_width.setValue(v); }

    DoubleProperty& center() { return m_center; }
    const DoubleProperty& center() const { return m_center; }
    void setCenter(double v) { m_center.setValue(v); }

    void initWidth(const QString& label, const QString& tooltip, double value,
                   const RealLimits& limits, uint decimals = 3);
    void initCenter(const QString& label, const QString& tooltip, double value,
                    const RealLimits& limits, uint decimals = 3);

    uint nbins() const { return m_nbins; }
    void setNbins(uint v) { m_nbins = v; }

    void writeTo(QXmlStreamWriter* w) const;
    void readFrom(QXmlStreamReader* r);

private:
    uint m_nbins = 100;
    DoubleProperty m_width;
    DoubleProperty m_center;
};

#endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_SPANPROPERTY_H
