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

Description

Widget to edit properties of an IntensityDataItem.

Definition at line 33 of file IntensityDataPropertyWidget.h.

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

Public Member Functions

 IntensityDataPropertyWidget (QWidget *parent=nullptr)
 
 ~IntensityDataPropertyWidget ()
 
const JobItemjobItem () const
 
void setItem (IntensityDataItem *mainItem, IntensityDataItem *realItem=nullptr)
 

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 updateUIValues ()
 

Private Attributes

IntensityDataItemm_item
 
QFormLayout * m_mainLayout
 
QList< function< void()> > m_updaters
 
QWidget * parent
 

Constructor & Destructor Documentation

◆ IntensityDataPropertyWidget()

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

Definition at line 30 of file IntensityDataPropertyWidget.cpp.

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

References m_mainLayout.

◆ ~IntensityDataPropertyWidget()

IntensityDataPropertyWidget::~IntensityDataPropertyWidget ( )

Definition at line 44 of file IntensityDataPropertyWidget.cpp.

45 {
46  if (m_item)
47  m_item->mapper()->unsubscribe(this);
48 }
void unsubscribe(const void *caller)
Cancels all subscriptions of given caller.
Definition: ModelMapper.cpp:78
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.

References m_item, SessionItem::mapper(), and ModelMapper::unsubscribe().

Here is the call graph for this function:

Member Function Documentation

◆ createCheckBox() [1/2]

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

Definition at line 167 of file IntensityDataPropertyWidget.cpp.

169 {
170  auto* checkBox = new QCheckBox(title, this);
171  connect(checkBox, &QCheckBox::stateChanged, [=]() { setter(checkBox->isChecked()); });
172 
173  m_updaters << [=]() {
174  QSignalBlocker b(checkBox);
175  checkBox->setChecked(getter());
176  };
177 
178  return checkBox;
179 }
QList< function< void()> > m_updaters

References m_updaters.

◆ createCheckBox() [2/2]

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

Definition at line 161 of file IntensityDataPropertyWidget.cpp.

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

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

Referenced by setItem().

Here is the call graph for this function:

◆ createComboBox()

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

Definition at line 181 of file IntensityDataPropertyWidget.cpp.

182 {
183  auto* combo = new QComboBox(this);
184  combo->addItems(d.options);
185  combo->setMaxCount(d.options.size());
186 
187  connect(combo, qOverload<int>(&QComboBox::currentIndexChanged),
188  [=](int newIndex) { d.setCurrentIndex(newIndex); });
189 
190  m_updaters << [=]() {
191  QSignalBlocker b(combo);
192  combo->setCurrentIndex(d.currentIndex());
193  };
194 
195  return combo;
196 }
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 setItem().

Here is the call graph for this function:

◆ createDoubleSpinbox()

QWidget * IntensityDataPropertyWidget::createDoubleSpinbox ( DoubleDescriptor  d)
private

Definition at line 139 of file IntensityDataPropertyWidget.cpp.

140 {
141  auto* spinBox = new DoubleSpinBox(this, d);
142  spinBox->setToolTip(d.tooltip);
143  QObject::connect(spinBox, &DoubleSpinBox::baseValueChanged,
144  [=](double newValue) { d.set(newValue); });
145 
146  m_updaters << [=]() { spinBox->updateValue(); };
147 
148  return spinBox;
149 }
function< void(double)> set
function to set the value
QString tooltip
Tooltip text.
SpinBox for DoubleDescriptors, supporting units.
Definition: DoubleSpinBox.h:22
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.

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

Referenced by setItem().

◆ createTextEdit()

QWidget * IntensityDataPropertyWidget::createTextEdit ( SessionItem item)
private

Definition at line 151 of file IntensityDataPropertyWidget.cpp.

152 {
153  auto* edit = new QLineEdit(this);
154  connect(edit, &QLineEdit::textEdited, [=](const QString& t) { item->setValue(t); });
155 
156  m_updaters << [=]() { edit->setText(item->value().toString()); };
157 
158  return edit;
159 }

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

Referenced by setItem().

Here is the call graph for this function:

◆ jobItem()

const JobItem * IntensityDataPropertyWidget::jobItem ( ) const

Definition at line 130 of file IntensityDataPropertyWidget.cpp.

131 {
132  SessionItemWidget* sessionItemWidget = dynamic_cast<SessionItemWidget*>(parent);
133  if (!sessionItemWidget)
134  return nullptr;
135 
136  return dynamic_cast<JobItem*>(sessionItemWidget->currentItem());
137 }
The SessionItemWidget class is a base for all widgets representing the content of SessionItem....
SessionItem * currentItem()

References SessionItemWidget::currentItem(), and parent.

Referenced by setItem().

Here is the call graph for this function:

◆ setItem()

void IntensityDataPropertyWidget::setItem ( IntensityDataItem mainItem,
IntensityDataItem realItem = nullptr 
)

Definition at line 50 of file IntensityDataPropertyWidget.cpp.

51 {
52  if (m_item)
53  m_item->mapper()->unsubscribe(this);
54 
56  m_updaters.clear();
57  m_item = mainItem;
58 
59  if (!m_item)
60  return;
61 
62  m_mainLayout->addRow("Axes units:", createComboBox(m_item->axesUnits()));
63  m_mainLayout->addRow("Color scheme:", createComboBox(m_item->gradient()));
64 
66  "Interpolate", [=]() { return m_item->isInterpolated(); },
67  [=](bool b) { m_item->setInterpolated(b); }));
68 
69  // -- x-axis
70  auto* xGroup = new QGroupBox("X axis", this);
71  auto* xFormLayout = new QFormLayout(xGroup);
72  xFormLayout->setContentsMargins(0, 0, 0, 0);
73  xFormLayout->setSpacing(5);
74 
75  xFormLayout->addRow("Min:", createDoubleSpinbox(m_item->xAxisItem()->min()));
76  xFormLayout->addRow("Max:", createDoubleSpinbox(m_item->xAxisItem()->max()));
77  xFormLayout->addRow("Title:", createTextEdit(m_item->xAxisItem()->titleItem()));
78 
79  m_mainLayout->addRow(xGroup);
80 
81  // -- y-axis
82  auto* yGroup = new QGroupBox("Y axis", this);
83  auto* yFormLayout = new QFormLayout(yGroup);
84  yFormLayout->setContentsMargins(0, 0, 0, 0);
85  yFormLayout->setSpacing(5);
86 
87  yFormLayout->addRow("Min:", createDoubleSpinbox(m_item->yAxisItem()->min()));
88  yFormLayout->addRow("Max:", createDoubleSpinbox(m_item->yAxisItem()->max()));
89  yFormLayout->addRow("Title:", createTextEdit(m_item->yAxisItem()->titleItem()));
90 
91  m_mainLayout->addRow(yGroup);
92 
93  // -- color-axis
94  auto* zGroup = new QGroupBox("Color legend", this);
95  auto* zFormLayout = new QFormLayout(zGroup);
96  zFormLayout->setContentsMargins(0, 0, 0, 0);
97  zFormLayout->setSpacing(5);
98 
99  zFormLayout->addRow("Min:", createDoubleSpinbox(m_item->zAxisItem()->min()));
100  zFormLayout->addRow("Max:", createDoubleSpinbox(m_item->zAxisItem()->max()));
101  zFormLayout->addRow(createCheckBox("log10", m_item->zAxisItem()->logScaleItem()));
102  zFormLayout->addRow(createCheckBox("Visible", m_item->zAxisItem()->visibilityItem()));
103 
104  m_mainLayout->addRow(zGroup);
105 
106  updateUIValues();
107 
108  // react on external changes (e.g. zooming in customplot shall update the axis values)
110  [=](SessionItem*, const QString&) { updateUIValues(); }, this);
111 
112  // update coordinates on axes units change
114  [this](SessionItem* item, const QString& name) {
115  if(jobItem())
116  DataItem::updateAxesUnits(item, name, jobItem()->instrumentItem());
117  },
118  this);
119  if (realItem)
120  realItem->mapper()->setOnPropertyChange(
121  [this](SessionItem* item, const QString& name) {
122  if(jobItem())
123  DataItem::updateAxesUnits(item, name, jobItem()->instrumentItem());
124  },
125  this);
126 
127  m_item->mapper()->setOnItemDestroy([this](SessionItem*) { m_item = nullptr; }, this);
128 }
SessionItem * logScaleItem() const
Definition: AxesItems.cpp:188
DoubleDescriptor min(const QString &unit=QString()) const
Definition: AxesItems.cpp:41
SessionItem * visibilityItem() const
Definition: AxesItems.cpp:116
SessionItem * titleItem() const
Definition: AxesItems.cpp:90
DoubleDescriptor max(const QString &unit=QString()) const
Definition: AxesItems.cpp:58
static void updateAxesUnits(SessionItem *item, const QString &name, InstrumentItem *instrumentItem)
Definition: DataItem.cpp:118
SelectionDescriptor< QString > axesUnits() const
Definition: DataItem.cpp:108
const AmplitudeAxisItem * zAxisItem() const
SelectionDescriptor< QString > gradient() const
const BasicAxisItem * yAxisItem() const
void setInterpolated(bool interp)
const BasicAxisItem * xAxisItem() const
bool isInterpolated() const
QWidget * createTextEdit(SessionItem *item)
QWidget * createDoubleSpinbox(DoubleDescriptor d)
QWidget * createComboBox(SelectionDescriptor< QString > d)
void setOnItemDestroy(std::function< void(SessionItem *)> f, const void *caller=nullptr)
Definition: ModelMapper.cpp:67
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
Base class for a GUI data item.
Definition: SessionItem.h:204
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 DataItem::axesUnits(), GUI::Util::Layout::clearLayout(), createCheckBox(), createComboBox(), createDoubleSpinbox(), createTextEdit(), IntensityDataItem::gradient(), IntensityDataItem::isInterpolated(), jobItem(), AmplitudeAxisItem::logScaleItem(), m_item, m_mainLayout, m_updaters, SessionItem::mapper(), BasicAxisItem::max(), BasicAxisItem::min(), GUI::RealSpace::Particles::name(), IntensityDataItem::setInterpolated(), ModelMapper::setOnChildPropertyChange(), ModelMapper::setOnItemDestroy(), ModelMapper::setOnPropertyChange(), BasicAxisItem::titleItem(), ModelMapper::unsubscribe(), DataItem::updateAxesUnits(), updateUIValues(), BasicAxisItem::visibilityItem(), IntensityDataItem::xAxisItem(), IntensityDataItem::yAxisItem(), and IntensityDataItem::zAxisItem().

Referenced by IntensityDataWidget::onFFTAction(), MaskEditorPropertyPanel::resetContext(), ProjectionsEditor::resetContext(), ProjectionsEditor::setContext(), IntensityDataWidget::setItem(), MaskEditorPropertyPanel::setMaskContext(), MaskEditorPropertyPanel::setPanelHidden(), and FitComparisonWidget::subscribeToItem().

Here is the call graph for this function:

◆ updateUIValues()

void IntensityDataPropertyWidget::updateUIValues ( )
private

Definition at line 198 of file IntensityDataPropertyWidget.cpp.

199 {
200  for (const auto& updater : m_updaters)
201  updater();
202 }

References m_updaters.

Referenced by setItem().

Member Data Documentation

◆ m_item

IntensityDataItem* IntensityDataPropertyWidget::m_item
private

Definition at line 54 of file IntensityDataPropertyWidget.h.

Referenced by ~IntensityDataPropertyWidget(), and setItem().

◆ m_mainLayout

QFormLayout* IntensityDataPropertyWidget::m_mainLayout
private

Definition at line 55 of file IntensityDataPropertyWidget.h.

Referenced by IntensityDataPropertyWidget(), and setItem().

◆ m_updaters

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

◆ parent

QWidget* IntensityDataPropertyWidget::parent
private

Definition at line 53 of file IntensityDataPropertyWidget.h.

Referenced by jobItem().


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