Skip to content
Snippets Groups Projects
Commit 12a6e852 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

preserve central value of distribution

parent a81e347d
No related branches found
No related tags found
1 merge request!2750Initialize beam with reasonable default values
......@@ -38,6 +38,7 @@ public:
virtual DoubleProperty& center() = 0;
virtual const DoubleProperty& center() const = 0;
virtual void setCenter(double v) = 0;
//! Serialization of contents.
//!
......@@ -63,6 +64,7 @@ public:
DoubleProperty& center() override { return mean(); }
const DoubleProperty& center() const override { return mean(); }
void setCenter(double v) override { m_mean.setDVal(v); }
void writeTo(QXmlStreamWriter* w) const override;
void readFrom(QXmlStreamReader* r) override;
......@@ -88,6 +90,7 @@ public:
DoubleProperty& center() override { return m_center; }
const DoubleProperty& center() const override { return m_center; }
void setCenter(double v) override { m_center.setDVal(v); }
DoubleProperty& halfwidth() { return m_halfwidth; }
const DoubleProperty& halfwidth() const { return m_halfwidth; }
......@@ -149,6 +152,7 @@ public:
DoubleProperty& center() override { return median(); }
const DoubleProperty& center() const override { return median(); }
void setCenter(double v) override { m_median.setDVal(v); }
DoubleProperty& scaleParameter() { return m_scale_parameter; }
const DoubleProperty& scaleParameter() const { return m_scale_parameter; }
......
......@@ -33,13 +33,17 @@ DistributionSelector::DistributionSelector(std::optional<MeanConfig> mean_config
m_form_layout = new QFormLayout(this);
m_form_layout->setContentsMargins(0, 0, 0, 0);
m_distribution_combo = GUI::Util::createComboBoxFromPolyPtr(
item->distributionSelection(),
[this](int) {
m_distribution_combo = GUI::Util::createGeneralComboBoxFromPolyPtr(
m_item->distributionSelection(),
[this](int index) {
double old_center = m_item->distributionItem()->center().dVal();
m_item->distributionSelection().setCertainIndex(index);
m_item->distributionItem()->setCenter(old_center);
createDistributionWidgets();
emit distributionChanged();
},
true);
m_distribution_combo->setEnabled(allow_distr);
m_form_layout->addRow("Distribution:", m_distribution_combo);
......
......@@ -43,12 +43,9 @@ QComboBox* createComboBox(std::function<ComboProperty()> comboFunction,
//! Furthermore, the combo box can prohibit accidental changes by the mouse wheel. Otherwise it
//! would be dangerous if the combo is on a scrollable form - unintended and unnoticed changes would
//! take place when just scrolling through the form.
//!
//! Changes in the combobox will be notified to the PolyItem already. The additional (and
//! optional) slot can be used to be notified about an already executed change.
template <typename B, typename C>
QComboBox* createComboBoxFromPolyPtr(PolyPtr<B, C>& d, std::function<void(int)> slot,
bool inScrollArea)
QComboBox* createGeneralComboBoxFromPolyPtr(PolyPtr<B, C>& d, std::function<void(int)> full_slot,
bool inScrollArea)
{
auto* combo = new QComboBox;
combo->addItems(d.menuEntries());
......@@ -59,15 +56,30 @@ QComboBox* createComboBoxFromPolyPtr(PolyPtr<B, C>& d, std::function<void(int)>
if (inScrollArea)
WheelEventEater::install(combo);
QObject::connect(combo, &QComboBox::currentIndexChanged, [&d, slot](int index) {
d.setCertainIndex(index);
if (slot)
slot(index);
QObject::connect(combo, &QComboBox::currentIndexChanged, [full_slot](int index) {
if (full_slot)
full_slot(index);
});
return combo;
}
//! Create a combo box with the information found in a selection property.
//!
//! Changes in the combobox will be notified to the PolyItem already. The additional (and
//! optional) slot can be used to be notified about an already executed change.
template <typename B, typename C>
QComboBox* createComboBoxFromPolyPtr(PolyPtr<B, C>& d, std::function<void(int)> optional_slot,
bool inScrollArea)
{
return createGeneralComboBoxFromPolyPtr(
d,
[&d, optional_slot](int index) {
d.setCertainIndex(index);
if (optional_slot)
optional_slot(index);
},
inScrollArea);
}
} // namespace GUI::Util
#endif // BORNAGAIN_GUI_VIEW_NUMERIC_COMBOUTIL_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment