BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularDataPropertyWidget Class Reference

Description

Widget to edit properties of a SpecularDataItem or a Data1DViewItem.

Definition at line 35 of file SpecularDataPropertyWidget.h.

Inheritance diagram for SpecularDataPropertyWidget:
[legend]
Collaboration diagram for SpecularDataPropertyWidget:
[legend]

Public Member Functions

 SpecularDataPropertyWidget (QWidget *parent=nullptr)
 
const JobItemjobItem () const
 
void setItem (Data1DViewItem *item)
 
void setItem (SpecularDataItem *item)
 

Private Member Functions

QWidget * createCheckBox (const QString &title, function< bool()> getter, function< void(bool)> setter)
 
QWidget * createCheckBox (const QString &title, SessionItem *item)
 
QWidget * createComboBox (SelectionDescriptor< QString > d)
 
QWidget * createDoubleSpinbox (DoubleDescriptor d)
 
QWidget * createTextEdit (SessionItem *item)
 
void setCurrentItem (SessionItem *item)
 
void updateUIValues ()
 

Private Attributes

SessionItemm_item
 
QFormLayout * m_mainLayout
 
QWidget * m_parent
 
QList< function< void()> > m_updaters
 

Constructor & Destructor Documentation

◆ SpecularDataPropertyWidget()

SpecularDataPropertyWidget::SpecularDataPropertyWidget ( QWidget *  parent = nullptr)
explicit

Definition at line 31 of file SpecularDataPropertyWidget.cpp.

32  : QWidget(parent)
33  , m_parent(parent)
34  , m_item(nullptr)
35 {
36  setWindowTitle("Properties");
37  setAttribute(Qt::WA_StyledBackground, true);
38  setProperty("stylable", true); // for stylesheet addressing
39 
40  m_mainLayout = new QFormLayout(this);
41  m_mainLayout->setContentsMargins(8, 20, 8, 8);
42  m_mainLayout->setSpacing(5);
43 }

References m_mainLayout.

Member Function Documentation

◆ createCheckBox() [1/2]

QWidget * SpecularDataPropertyWidget::createCheckBox ( const QString &  title,
function< bool()>  getter,
function< void(bool)>  setter 
)
private

Definition at line 159 of file SpecularDataPropertyWidget.cpp.

161 {
162  auto* checkBox = new QCheckBox(title, this);
163  connect(checkBox, &QCheckBox::stateChanged, [=]() { setter(checkBox->isChecked()); });
164 
165  m_updaters << [=]() {
166  QSignalBlocker b(checkBox);
167  checkBox->setChecked(getter());
168  };
169 
170  return checkBox;
171 }
QList< function< void()> > m_updaters

References m_updaters.

◆ createCheckBox() [2/2]

QWidget * SpecularDataPropertyWidget::createCheckBox ( const QString &  title,
SessionItem item 
)
private

Definition at line 153 of file SpecularDataPropertyWidget.cpp.

154 {
155  return createCheckBox(
156  title, [=]() { return item->value().toBool(); }, [=](bool b) { item->setValue(b); });
157 }
QVariant value() const
Get value.
bool setValue(QVariant value)
Set value, ensure that variant types match.
QWidget * createCheckBox(const QString &title, SessionItem *item)

References SessionItem::setValue(), and SessionItem::value().

Referenced by setCurrentItem().

Here is the call graph for this function:

◆ createComboBox()

QWidget * SpecularDataPropertyWidget::createComboBox ( SelectionDescriptor< QString >  d)
private

Definition at line 173 of file SpecularDataPropertyWidget.cpp.

174 {
175  auto* combo = new QComboBox(this);
176  combo->addItems(d.options);
177  combo->setMaxCount(d.options.size());
178 
179  connect(combo, qOverload<int>(&QComboBox::currentIndexChanged),
180  [=](int newIndex) { d.setCurrentIndex(newIndex); });
181 
182  m_updaters << [=]() {
183  QSignalBlocker b(combo);
184  combo->setCurrentIndex(d.currentIndex());
185  };
186 
187  return combo;
188 }
int currentIndex() const override
Get currently selected option.
QStringList options
List of options, usually presented as combo entries.
void setCurrentIndex(int newIndex) const override
Set currently selected option.

References SelectionDescriptor< T >::currentIndex(), m_updaters, SelectionDescriptor< T >::options, and SelectionDescriptor< T >::setCurrentIndex().

Referenced by setCurrentItem().

Here is the call graph for this function:

◆ createDoubleSpinbox()

QWidget * SpecularDataPropertyWidget::createDoubleSpinbox ( DoubleDescriptor  d)
private

Definition at line 132 of file SpecularDataPropertyWidget.cpp.

133 {
134  auto* spinBox = new DoubleSpinBox(this, d);
135  QObject::connect(spinBox, &DoubleSpinBox::baseValueChanged,
136  [=](double newValue) { d.set(newValue); });
137 
138  m_updaters << [=]() { spinBox->updateValue(); };
139 
140  return spinBox;
141 }
function< void(double)> set
function to set the value
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.

References DoubleSpinBox::baseValueChanged(), m_updaters, and DoubleDescriptor::set.

Referenced by setCurrentItem().

◆ createTextEdit()

QWidget * SpecularDataPropertyWidget::createTextEdit ( SessionItem item)
private

Definition at line 143 of file SpecularDataPropertyWidget.cpp.

144 {
145  auto* edit = new QLineEdit(this);
146  connect(edit, &QLineEdit::textEdited, [=](const QString& t) { item->setValue(t); });
147 
148  m_updaters << [=]() { edit->setText(item->value().toString()); };
149 
150  return edit;
151 }

References m_updaters, SessionItem::setValue(), and SessionItem::value().

Referenced by setCurrentItem().

Here is the call graph for this function:

◆ jobItem()

const JobItem * SpecularDataPropertyWidget::jobItem ( ) const

Definition at line 55 of file SpecularDataPropertyWidget.cpp.

56 {
57  SessionItemWidget* sessionItemWidget = dynamic_cast<SessionItemWidget*>(m_parent);
58  if (!sessionItemWidget)
59  return nullptr;
60 
61  return dynamic_cast<JobItem*>(sessionItemWidget->currentItem());
62 }
The SessionItemWidget class is a base for all widgets representing the content of SessionItem....
SessionItem * currentItem()

References SessionItemWidget::currentItem(), and m_parent.

Referenced by setCurrentItem().

Here is the call graph for this function:

◆ setCurrentItem()

void SpecularDataPropertyWidget::setCurrentItem ( SessionItem item)
private

Definition at line 64 of file SpecularDataPropertyWidget.cpp.

65 {
66  if (m_item)
67  m_item->mapper()->unsubscribe(this);
68 
70  m_updaters.clear();
71  m_item = item;
72  if (!m_item)
73  return;
74 
75  BasicAxisItem* xAxisItem = nullptr;
76  AmplitudeAxisItem* yAxisItem = nullptr;
77  SelectionDescriptor<QString> axesUnitsDescriptor;
78 
79  if (auto* p = dynamic_cast<SpecularDataItem*>(m_item)) {
80  axesUnitsDescriptor = p->axesUnits();
81  xAxisItem = p->xAxisItem();
82  yAxisItem = p->yAxisItem();
83  } else if (auto* p = dynamic_cast<Data1DViewItem*>(m_item)) {
84  axesUnitsDescriptor = p->axesUnitsDescriptor();
85  xAxisItem = p->xAxisItem();
86  yAxisItem = p->yAxisItem();
87  } else
88  return;
89 
90  m_mainLayout->addRow("Axes units:", createComboBox(axesUnitsDescriptor));
91 
92  // -- x-axis
93  auto* xGroup = new QGroupBox("X axis", this);
94  auto* xFormLayout = new QFormLayout(xGroup);
95  xFormLayout->setContentsMargins(0, 0, 0, 0);
96  xFormLayout->setSpacing(5);
97 
98  xFormLayout->addRow("Min:", createDoubleSpinbox(xAxisItem->min()));
99  xFormLayout->addRow("Max:", createDoubleSpinbox(xAxisItem->max()));
100  xFormLayout->addRow("Title:", createTextEdit(xAxisItem->titleItem()));
101 
102  m_mainLayout->addRow(xGroup);
103 
104  // -- y-axis
105  auto* yGroup = new QGroupBox("Y axis", this);
106  auto* yFormLayout = new QFormLayout(yGroup);
107  yFormLayout->setContentsMargins(0, 0, 0, 0);
108  yFormLayout->setSpacing(5);
109 
110  yFormLayout->addRow("Min:", createDoubleSpinbox(yAxisItem->min()));
111  yFormLayout->addRow("Max:", createDoubleSpinbox(yAxisItem->max()));
112  yFormLayout->addRow("Title:", createTextEdit(yAxisItem->titleItem()));
113  yFormLayout->addRow(createCheckBox("log10", yAxisItem->logScaleItem()));
114 
115  m_mainLayout->addRow(yGroup);
116 
117  updateUIValues();
118 
119  // react on external changes (e.g. zooming in customplot shall update the axis values)
121  [=](SessionItem*, const QString&) { updateUIValues(); }, this);
122 
123  // update coordinates on axes units change
125  [this](SessionItem* item, const QString& name) {
126  if(jobItem())
127  DataItem::updateAxesUnits(item, name, jobItem()->instrumentItem());
128  },
129  this);
130 }
SessionItem * logScaleItem() const
Definition: AxesItems.cpp:188
DoubleDescriptor min(const QString &unit=QString()) const
Definition: AxesItems.cpp:41
SessionItem * titleItem() const
Definition: AxesItems.cpp:90
DoubleDescriptor max(const QString &unit=QString()) const
Definition: AxesItems.cpp:58
View model for 1D DataItem. Can represent several items at once. In current implementation the first ...
static void updateAxesUnits(SessionItem *item, const QString &name, InstrumentItem *instrumentItem)
Definition: DataItem.cpp:118
void unsubscribe(const void *caller)
Cancels all subscriptions of given caller.
Definition: ModelMapper.cpp:78
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:39
void setOnChildPropertyChange(std::function< void(SessionItem *, QString)> f, const void *caller=nullptr)
Calls back on child property change, report childItem and property name.
Definition: ModelMapper.cpp:53
Describes a selection (various possibilities and the current one).
Base class for a GUI data item.
Definition: SessionItem.h:204
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
QWidget * createTextEdit(SessionItem *item)
QWidget * createComboBox(SelectionDescriptor< QString > d)
QWidget * createDoubleSpinbox(DoubleDescriptor d)
QString const & name(EShape k)
Definition: particles.cpp:20
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:68

References GUI::Util::Layout::clearLayout(), createCheckBox(), createComboBox(), createDoubleSpinbox(), createTextEdit(), jobItem(), AmplitudeAxisItem::logScaleItem(), m_item, m_mainLayout, m_updaters, SessionItem::mapper(), BasicAxisItem::max(), BasicAxisItem::min(), GUI::RealSpace::Particles::name(), ModelMapper::setOnChildPropertyChange(), ModelMapper::setOnPropertyChange(), BasicAxisItem::titleItem(), ModelMapper::unsubscribe(), DataItem::updateAxesUnits(), and updateUIValues().

Referenced by setItem().

Here is the call graph for this function:

◆ setItem() [1/2]

void SpecularDataPropertyWidget::setItem ( Data1DViewItem item)

Definition at line 50 of file SpecularDataPropertyWidget.cpp.

51 {
52  setCurrentItem(item);
53 }
void setCurrentItem(SessionItem *item)

References setCurrentItem().

Here is the call graph for this function:

◆ setItem() [2/2]

void SpecularDataPropertyWidget::setItem ( SpecularDataItem item)

Definition at line 45 of file SpecularDataPropertyWidget.cpp.

46 {
47  setCurrentItem(item);
48 }

References setCurrentItem().

Referenced by SpecularDataWidget::setItem(), and FitComparisonWidget1D::subscribeToItem().

Here is the call graph for this function:

◆ updateUIValues()

void SpecularDataPropertyWidget::updateUIValues ( )
private

Definition at line 190 of file SpecularDataPropertyWidget.cpp.

191 {
192  for (const auto& updater : m_updaters)
193  updater();
194 }

References m_updaters.

Referenced by setCurrentItem().

Member Data Documentation

◆ m_item

SessionItem* SpecularDataPropertyWidget::m_item
private

Definition at line 57 of file SpecularDataPropertyWidget.h.

Referenced by setCurrentItem().

◆ m_mainLayout

QFormLayout* SpecularDataPropertyWidget::m_mainLayout
private

Definition at line 58 of file SpecularDataPropertyWidget.h.

Referenced by SpecularDataPropertyWidget(), and setCurrentItem().

◆ m_parent

QWidget* SpecularDataPropertyWidget::m_parent
private

Definition at line 56 of file SpecularDataPropertyWidget.h.

Referenced by jobItem().

◆ m_updaters

QList<function<void()> > SpecularDataPropertyWidget::m_updaters
private

The documentation for this class was generated from the following files: