BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ParameterTuningDelegate.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Fit/ParameterTuningDelegate.h
6 //! @brief Defines class ParameterTuningDelegate
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 
15 #ifndef BORNAGAIN_GUI_VIEW_FIT_PARAMETERTUNINGDELEGATE_H
16 #define BORNAGAIN_GUI_VIEW_FIT_PARAMETERTUNINGDELEGATE_H
17 
18 #include "Fit/Param/RealLimits.h"
19 #include <QItemDelegate>
20 #include <memory>
21 
22 class QDoubleSpinBox;
23 class QHBoxLayout;
24 class ParameterItem;
25 class ScientificSpinBox;
26 class SessionItem;
27 
28 class ParameterTuningDelegate : public QItemDelegate {
29  Q_OBJECT
30 
31 public:
32  class TuningData {
33  public:
34  TuningData();
35  void setRangeFactor(double range_factor);
36  void setItemLimits(const RealLimits& item_limits);
37  int value_to_slider(double value);
38  double slider_to_value(int slider) const;
39  double step() const;
40  int m_smin;
41  int m_smax;
42  double m_rmin;
43  double m_rmax;
45  RealLimits m_item_limits;
46  };
47 
48  ParameterTuningDelegate(QObject* parent = nullptr);
50 
51  QSize sizeHint(const QStyleOptionViewItem& option,
52  const QModelIndex& /* index */) const override
53  {
54  return QSize(option.rect.width(), 25);
55  }
56 
57  void paint(QPainter* painter, const QStyleOptionViewItem& option,
58  const QModelIndex& index) const override;
59  QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
60  const QModelIndex& index) const override;
61  void setEditorData(QWidget* editor, const QModelIndex& index) const override;
62  void setModelData(QWidget* editor, QAbstractItemModel* model,
63  const QModelIndex& index) const override;
64  void setSliderRangeFactor(double value);
65 
66  void setValueColumn(int valueColumn) { m_valueColumn = valueColumn; }
67 
68  void setReadOnly(bool isReadOnly);
69 
70 signals:
72 
73 private slots:
74  void sliderValueChanged(int position);
75  void editorValueChanged(double value);
76 
77 private:
78  void updateSlider(double value) const;
79  void emitSignals(double value);
80 
82  mutable QSlider* m_slider;
84  mutable QWidget* m_contentWidget;
85  mutable QHBoxLayout* m_contentLayout;
89 };
90 
91 #endif // BORNAGAIN_GUI_VIEW_FIT_PARAMETERTUNINGDELEGATE_H
The ParameterItem class represent a tuning value in a parameter tuning tree.
void setItemLimits(const RealLimits &item_limits)
void setReadOnly(bool isReadOnly)
void setValueColumn(int valueColumn)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
~ParameterTuningDelegate() override
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const override
void setSliderRangeFactor(double value)
void updateSlider(double value) const
ScientificSpinBox * m_valueBox
ParameterTuningDelegate(QObject *parent=nullptr)
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
void currentLinkChanged(ParameterItem *item)
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Base class for a GUI data item.
Definition: SessionItem.h:204