22 #include <QAbstractItemModel>
23 #include <QApplication>
24 #include <QHBoxLayout>
25 #include <QItemSelectionModel>
26 #include <QMouseEvent>
27 #include <QPaintDevice>
30 #include <QStyleOptionSlider>
37 const double maximum_doublespin_value = std::numeric_limits<double>::max();
38 const double minimum_doublespin_value = std::numeric_limits<double>::lowest();
42 : m_smin(0), m_smax(100), m_rmin(0.0), m_rmax(0.0), m_range_factor(100.0)
48 m_range_factor = range_factor;
53 m_item_limits = item_limits;
60 dr = 1.0 * m_range_factor / 100.;
62 dr = std::abs(value) * m_range_factor / 100.;
67 if (m_item_limits.hasLowerLimit() && m_rmin < m_item_limits.lowerLimit())
68 m_rmin = m_item_limits.lowerLimit();
70 if (m_item_limits.hasUpperLimit() && m_rmax > m_item_limits.upperLimit())
71 m_rmax = m_item_limits.upperLimit();
73 double result = m_smin + (value - m_rmin) * (m_smax - m_smin) / (m_rmax - m_rmin);
74 return static_cast<int>(result);
79 return m_rmin + (slider - m_smin) * (m_rmax - m_rmin) / (m_smax - m_smin);
84 return (m_rmax - m_rmin) / (m_smax - m_smin);
88 : QItemDelegate(parent)
102 const QModelIndex& index)
const
106 if (!index.parent().isValid())
109 QVariant prop_value = index.model()->data(index, Qt::EditRole);
110 if (prop_value.isValid()) {
112 if (type == QVariant::Double) {
113 double value = prop_value.toDouble();
116 QStyleOptionViewItem myOption = option;
117 myOption.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter;
119 drawDisplay(painter, myOption, myOption.rect, text);
120 drawFocus(painter, myOption, myOption.rect);
125 QItemDelegate::paint(painter, option, index);
129 const QModelIndex& index)
const
135 if (index.parent().isValid() ==
false)
138 QVariant data = index.model()->data(index, Qt::EditRole);
147 double value = data.toDouble();
176 m_slider =
new QSlider(Qt::Horizontal);
177 m_slider->setFocusPolicy(Qt::StrongFocus);
178 m_slider->setTickPosition(QSlider::NoTicks);
208 return QItemDelegate::createEditor(parent, option, index);
214 disconnect(
m_slider, &QSlider::valueChanged,
this,
237 disconnect(
m_slider, &QSlider::valueChanged,
this,
251 QItemDelegate::setEditorData(editor, index);
256 const QModelIndex& index)
const
263 QItemDelegate::setModelData(editor, model, index);
Defines ModelPath namespace.
Defines classes for ParameterTreeItems.
Defines class ParameterTuningDelegate.
Defines class ParameterTuningModel.
Defines class ScientificSpinBox.
Defines namespace SessionItemUtils.
Defines class SessionModel.
static QModelIndex toSourceIndex(QModelIndex index)
The ParameterItem class represent a tuning value in a parameter tuning tree.
SessionItem * linkedItem()
Returns corresponding linked item in MultiLayerItem/IsntrumentItem.
void propagateValueToLink(double newValue)
Sets current value to the original PropertyItem of MultiLayerItem/InstrumentItem.
int value_to_slider(double value)
double slider_to_value(int slider)
void setItemLimits(const RealLimits &item_limits)
void setRangeFactor(double range_factor)
void setReadOnly(bool isReadOnly)
QHBoxLayout * m_contentLayout
void setEditorData(QWidget *editor, const QModelIndex &index) const
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
ParameterItem * m_currentItem
QWidget * m_contentWidget
void setSliderRangeFactor(double value)
void updateSlider(double value) const
ScientificSpinBox * m_valueBox
ParameterTuningDelegate(QObject *parent=0)
void editorValueChanged(double value)
void emitSignals(double value)
~ParameterTuningDelegate()
void sliderValueChanged(int position)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
void currentLinkChanged(SessionItem *item)
Limits for a real fit parameter.
bool hasUpperLimit() const
if has upper limit
double upperLimit() const
Returns upper limit.
double lowerLimit() const
Returns lower limit.
bool hasLowerLimit() const
if has lower limit
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)
RealLimits limits() const
int VariantType(const QVariant &variant)
Returns type of variant (additionally checks for user type).