19 #include <QAbstractItemModel>
20 #include <QApplication>
21 #include <QHBoxLayout>
22 #include <QItemSelectionModel>
23 #include <QMouseEvent>
24 #include <QPaintDevice>
27 #include <QStyleOptionSlider>
35 const double maximum_doublespin_value = std::numeric_limits<double>::max();
36 const double minimum_doublespin_value = std::numeric_limits<double>::lowest();
45 , m_range_factor(100.0)
51 m_range_factor = range_factor;
56 m_item_limits = item_limits;
63 dr = 1.0 * m_range_factor / 100.;
65 dr = std::abs(value) * m_range_factor / 100.;
69 if (m_item_limits.hasLowerLimit() && m_rmin < m_item_limits.lowerLimit())
70 m_rmin = m_item_limits.lowerLimit();
72 if (m_item_limits.hasUpperLimit() && m_rmax > m_item_limits.upperLimit())
73 m_rmax = m_item_limits.upperLimit();
75 double result = m_smin + (value - m_rmin) * (m_smax - m_smin) / (m_rmax - m_rmin);
76 return static_cast<int>(result);
81 return m_rmin + (slider - m_smin) * (m_rmax - m_rmin) / (m_smax - m_smin);
86 return (m_rmax - m_rmin) / (m_smax - m_smin);
90 : QItemDelegate(parent)
104 const QModelIndex& index)
const
107 if (!index.parent().isValid())
110 QVariant valueAsVariant = index.model()->data(index, Qt::EditRole);
111 if (valueAsVariant.isValid() && valueAsVariant.type() == QVariant::Double) {
112 double value = valueAsVariant.toDouble();
115 QStyleOptionViewItem myOption = option;
116 myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
118 drawDisplay(painter, myOption, myOption.rect, text);
119 drawFocus(painter, myOption, myOption.rect);
123 QItemDelegate::paint(painter, option, index);
127 const QModelIndex& index)
const
133 return QItemDelegate::createEditor(parent, option, index);
135 if (!index.parent().isValid())
138 QVariant data = index.model()->data(index, Qt::EditRole);
146 double value = data.toDouble();
158 if (limits.hasLowerLimit())
163 if (limits.hasUpperLimit())
173 m_slider =
new QSlider(Qt::Horizontal);
174 m_slider->setFocusPolicy(Qt::StrongFocus);
175 m_slider->setTickPosition(QSlider::NoTicks);
208 disconnect(
m_slider, &QSlider::valueChanged,
this,
231 disconnect(
m_slider, &QSlider::valueChanged,
this,
245 QItemDelegate::setEditorData(editor, index);
250 const QModelIndex& index)
const
255 QItemDelegate::setModelData(editor, model, index);
Defines classes for ParameterTreeItems.
Defines class ParameterTuningDelegate.
Defines class ParameterTuningModel.
Defines class ScientificSpinBox.
void propagateValueToLink(double newValue)
Sets current value to the original PropertyItem of MultiLayerItem/InstrumentItem.
int decimalsOfLink() const
RealLimits limitsOfLink() const
int value_to_slider(double value)
void setItemLimits(const RealLimits &item_limits)
void setRangeFactor(double range_factor)
double slider_to_value(int slider) const
void setReadOnly(bool isReadOnly)
QHBoxLayout * m_contentLayout
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
ParameterItem * m_currentItem
QWidget * m_contentWidget
void setSliderRangeFactor(double value)
void updateSlider(double value) const
ScientificSpinBox * m_valueBox
void editorValueChanged(double value)
void emitSignals(double value)
void sliderValueChanged(int position)
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
static ParameterItem * toParameterItem(const QModelIndex &index)
void setMaximum(double max)
void setMinimum(double min)
void setValue(double val)
void setSingleStep(double step)
static QString toString(double val, int decimal_points)
void valueChanged(double value)