File: AmplitudeAxisItem.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (84 lines) | stat: -rw-r--r-- 2,687 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/Model/Axis/AmplitudeAxisItem.cpp
//! @brief     Implements class AmplitudeAxisItem.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "GUI/Model/Axis/AmplitudeAxisItem.h"
#include "GUI/Model/Util/UtilXML.h"

namespace {
namespace Tag {

const QString IsVisible("IsVisible");
const QString Nbins("Nbins");
const QString MinDeg("MinDeg");
const QString MaxDeg("MaxDeg");
const QString BaseData("BaseData");
const QString LockMinMax("LockMinMax");
const QString LogRangeOrders("LogRangeOrders");

} // namespace Tag
} // namespace


AmplitudeAxisItem::AmplitudeAxisItem()
    : BasicAxisItem()
    , m_lock_min_max(false)
    , m_visible(true)
{
    m_log_scale = true; // override base class
    m_log_range_orders.init("Log range", "", "Dynamic range to display values", 8, 3, true, 0.01,
                            RealLimits::nonnegative(), "logR");
}

void AmplitudeAxisItem::writeTo(QXmlStreamWriter* w) const
{
    XML::writeBaseElement<BasicAxisItem>(w, XML::Tag::BaseData, this);
    XML::writeTaggedValue(w, Tag::LockMinMax, m_lock_min_max);
    m_log_range_orders.writeTo2(w, Tag::LogRangeOrders);
    XML::writeTaggedValue(w, Tag::IsVisible, m_visible);
}

void AmplitudeAxisItem::readFrom(QXmlStreamReader* r)
{
    while (r->readNextStartElement()) {
        QString tag = r->name().toString();
        if (tag == Tag::BaseData)
            XML::readBaseElement<BasicAxisItem>(r, tag, this);
        else if (tag == Tag::LockMinMax)
            m_lock_min_max = XML::readTaggedBool(r, tag);
        else if (tag == Tag::LogRangeOrders)
            m_log_range_orders.readFrom2(r, tag);
        else if (tag == Tag::IsVisible)
            m_visible = XML::readTaggedBool(r, tag);
        else
            r->skipCurrentElement();
    }
}

void AmplitudeAxisItem::setLogRangeOrders(double v)
{
    m_log_range_orders.setAndNotify(v);
    setMin(max().dVal() / std::pow(10, m_log_range_orders.dVal()));
}

void AmplitudeAxisItem::adjustLogRangeOrders()
{
    if (min().dVal() > 0 && max().dVal() > 0)
        m_log_range_orders.setAndNotify(std::log10(max().dVal() / min().dVal()));
}

void AmplitudeAxisItem::setVisible(bool b)
{
    m_visible = b;
    emit axisVisibilityChanged();
}