BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
AxesItems.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Device/AxesItems.cpp
6 //! @brief Implements various axis items
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "Base/Axis/FixedBinAxis.h"
18 
19 const int max_detector_pixels = 65536;
20 
22  : BasicAxisItem(M_TYPE)
23 {
24 }
25 
27 {
28  return getItemValue(P_NBINS).toInt();
29 }
30 
31 void BasicAxisItem::setBinCount(size_t value)
32 {
33  setItemValue(P_NBINS, (int)value);
34 }
35 
37 {
38  return getItem(P_NBINS);
39 }
40 
41 DoubleDescriptor BasicAxisItem::min(const QString& unit) const
42 {
44  d.label = "Min";
45  return d;
46 }
47 
48 void BasicAxisItem::setLowerBound(double value)
49 {
51 }
52 
54 {
55  return getItem(P_MIN_DEG);
56 }
57 
58 DoubleDescriptor BasicAxisItem::max(const QString& unit) const
59 {
61  d.label = "Max";
62  return d;
63 }
64 
65 void BasicAxisItem::setUpperBound(double value)
66 {
68 }
69 
71 {
72  return getItem(P_MAX_DEG);
73 }
74 
76 {
77  return name == P_MIN_DEG || name == P_MAX_DEG;
78 }
79 
80 QString BasicAxisItem::title() const
81 {
82  return getItemValue(P_TITLE).toString();
83 }
84 
85 void BasicAxisItem::setTitle(const QString& title)
86 {
88 }
89 
91 {
92  return getItem(P_TITLE);
93 }
94 
96 {
97  return name == P_TITLE;
98 }
99 
101 {
102  return getItemValue(P_TITLE_IS_VISIBLE).toBool();
103 }
104 
106 {
107  return name == P_TITLE_IS_VISIBLE;
108 }
109 
110 std::unique_ptr<IAxis> BasicAxisItem::createAxis(double scale) const
111 {
112  return std::make_unique<FixedBinAxis>(title().toStdString(), binCount(), min() * scale,
113  max() * scale);
114 }
115 
117 {
118  return getItem(P_IS_VISIBLE);
119 }
120 
122 {
123  return visibilityItem()->value().toBool();
124 }
125 
127 {
129 }
130 
132 {
133  return name == P_IS_VISIBLE;
134 }
135 
137 
138 BasicAxisItem::BasicAxisItem(const QString& type)
139  : SessionItem(type)
140 {
141  addProperty(P_IS_VISIBLE, true);
142  addProperty(P_NBINS, 100)->setLimits(RealLimits::limited(1, max_detector_pixels));
143  addProperty(P_MIN_DEG, 0.0)->setDecimals(3).setLimits(RealLimits::limitless());
144  addProperty(P_MAX_DEG, -1.0)->setDecimals(3).setLimits(RealLimits::limitless());
145  addProperty(P_TITLE, QString());
147 }
148 
150 {
151  s.assertVersion(0);
152  Serialize::rwSessionItem<bool>(s, "visible", getItem(P_IS_VISIBLE));
153  Serialize::rwSessionItem<int>(s, "nbins", getItem(P_NBINS));
154  Serialize::rwSessionItem<double>(s, "min", getItem(P_MIN_DEG));
155  Serialize::rwSessionItem<double>(s, "max", getItem(P_MAX_DEG));
156  Serialize::rwSessionItem<QString>(s, "title", getItem(P_TITLE));
157  Serialize::rwSessionItem<bool>(s, "titleVisible", getItem(P_TITLE_IS_VISIBLE));
158 }
159 
160 // ---------------------------------------------------------------------------------------------- //
161 
163  : BasicAxisItem(M_TYPE)
164 {
165  addProperty(P_LOCK_MIN_MAX, false);
166  addProperty(P_IS_LOGSCALE, true);
167  visibilityItem();
168 }
169 
171 {
172  s.assertVersion(0);
173  Serialize::rwBaseClass<BasicAxisItem>(s, "base", this);
174  Serialize::rwSessionItem<bool>(s, "lockMinMax", getItem(P_LOCK_MIN_MAX));
175  Serialize::rwSessionItem<bool>(s, "log", getItem(P_IS_LOGSCALE));
176 }
177 
179 {
180  return getItemValue(P_IS_LOGSCALE).toBool();
181 }
182 
184 {
186 }
187 
189 {
190  return getItem(P_IS_LOGSCALE);
191 }
192 
194 {
195  return name == P_IS_LOGSCALE;
196 }
197 
199 {
200  return getItemValue(P_LOCK_MIN_MAX).toBool();
201 }
202 
204 {
205  setItemValue(P_LOCK_MIN_MAX, locked);
206 }
const int max_detector_pixels
Definition: AxesItems.cpp:19
Defines various axis items.
Defines class Streamer.
static bool isLogScalePropertyName(const QString &name)
Definition: AxesItems.cpp:193
static constexpr auto P_LOCK_MIN_MAX
Definition: AxesItems.h:78
static constexpr auto P_IS_LOGSCALE
Definition: AxesItems.h:77
bool isLogScale() const
Definition: AxesItems.cpp:178
void serialize(Streamer &s) override
Definition: AxesItems.cpp:170
SessionItem * logScaleItem() const
Definition: AxesItems.cpp:188
bool isLocked() const
Definition: AxesItems.cpp:198
void setLogScale(bool value)
Definition: AxesItems.cpp:183
void setLocked(bool locked)
Definition: AxesItems.cpp:203
SessionItem * maxItem() const
Definition: AxesItems.cpp:70
bool isTitleVisible() const
Definition: AxesItems.cpp:100
SessionItem * binsItem() const
Definition: AxesItems.cpp:36
void setVisibilityValue(bool b)
Definition: AxesItems.cpp:126
DoubleDescriptor min(const QString &unit=QString()) const
Definition: AxesItems.cpp:41
static bool isVisibilityPropertyName(const QString &name)
Definition: AxesItems.cpp:131
static constexpr auto P_NBINS
Definition: AxesItems.h:28
static bool isBoundsPropertiesName(const QString &name)
either lower bound or upper bound property name
Definition: AxesItems.cpp:75
SessionItem * visibilityItem() const
Definition: AxesItems.cpp:116
bool visibilityValue() const
Definition: AxesItems.cpp:121
SessionItem * minItem() const
Definition: AxesItems.cpp:53
QString title() const
Definition: AxesItems.cpp:80
int binCount() const
Definition: AxesItems.cpp:26
void setBinCount(size_t value)
Definition: AxesItems.cpp:31
virtual void serialize(Streamer &s)
Definition: AxesItems.cpp:149
~BasicAxisItem() override
static constexpr auto P_IS_VISIBLE
Definition: AxesItems.h:27
static constexpr auto P_TITLE
Definition: AxesItems.h:31
SessionItem * titleItem() const
Definition: AxesItems.cpp:90
static constexpr auto P_MAX_DEG
Definition: AxesItems.h:30
void setLowerBound(double value)
Definition: AxesItems.cpp:48
static constexpr auto P_TITLE_IS_VISIBLE
Definition: AxesItems.h:32
void setUpperBound(double value)
Definition: AxesItems.cpp:65
static bool isTitlePropertyName(const QString &name)
Definition: AxesItems.cpp:95
static constexpr auto P_MIN_DEG
Definition: AxesItems.h:29
virtual std::unique_ptr< IAxis > createAxis(double scale) const
Definition: AxesItems.cpp:110
DoubleDescriptor max(const QString &unit=QString()) const
Definition: AxesItems.cpp:58
static bool isTitleVisiblePropertyName(const QString &name)
Definition: AxesItems.cpp:105
void setTitle(const QString &title)
Definition: AxesItems.cpp:85
Describes properties of a double value which are necessary to allow GUI representation,...
QString label
A label text (short, no trailing colon)
Base class for a GUI data item.
Definition: SessionItem.h:204
SessionItem * addProperty(const QString &name, const QVariant &variant)
Add new property item and register new tag. name is the tag name and the display name....
SessionItem & setDecimals(int n)
QVariant value() const
Get value.
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
void setItemValue(const QString &tag, const QVariant &variant) const
Directly set value of item under given tag.
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
SessionItem & setLimits(const RealLimits &value)
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26
QString const & name(EShape k)
Definition: particles.cpp:20