Set to define last value when creating new delegate.
--HG-- branch : develop
This commit is contained in:
parent
145dd73113
commit
9839b6b331
|
@ -40,11 +40,18 @@
|
||||||
* @return editor to be used for editing the data item.
|
* @return editor to be used for editing the data item.
|
||||||
*/
|
*/
|
||||||
//cppcheck-suppress unusedFunction
|
//cppcheck-suppress unusedFunction
|
||||||
|
DoubleSpinBoxDelegate::DoubleSpinBoxDelegate(QObject *parent): QItemDelegate(parent), lastValue(-10001.0)
|
||||||
|
{
|
||||||
|
//Little hack. Help save value in const method.
|
||||||
|
connect(this, &DoubleSpinBoxDelegate::NewLastValue, this, &DoubleSpinBoxDelegate::SetLastValue);
|
||||||
|
}
|
||||||
|
|
||||||
QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
QWidget *DoubleSpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||||
const QModelIndex &index ) const
|
const QModelIndex &index ) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(option);
|
Q_UNUSED(option);
|
||||||
Q_UNUSED(index);
|
Q_UNUSED(index);
|
||||||
|
emit NewLastValue(-10001.0);//Here need reset value to default because we begin work with new item
|
||||||
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
||||||
editor->setMinimum(-10000.0);
|
editor->setMinimum(-10000.0);
|
||||||
editor->setMaximum(10000.0);
|
editor->setMaximum(10000.0);
|
||||||
|
@ -119,3 +126,9 @@ void DoubleSpinBoxDelegate::commitAndCloseEditor()
|
||||||
}
|
}
|
||||||
emit closeEditor(spinBox);
|
emit closeEditor(spinBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void DoubleSpinBoxDelegate::SetLastValue(const qreal &newLastValue)
|
||||||
|
{
|
||||||
|
lastValue = newLastValue;
|
||||||
|
}
|
||||||
|
|
|
@ -43,13 +43,21 @@ public:
|
||||||
* @brief DoubleSpinBoxDelegate constructor.
|
* @brief DoubleSpinBoxDelegate constructor.
|
||||||
* @param parent parent object.
|
* @param parent parent object.
|
||||||
*/
|
*/
|
||||||
DoubleSpinBoxDelegate(QObject *parent = nullptr): QItemDelegate(parent), lastValue(-10001.0){}
|
DoubleSpinBoxDelegate(QObject *parent = nullptr);
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
signals:
|
||||||
|
/**
|
||||||
|
* @brief NewLastValue help reset last value in const method (hack).
|
||||||
|
* @param text text.
|
||||||
|
*/
|
||||||
|
void NewLastValue(const qreal &newLastValue) const;
|
||||||
public slots:
|
public slots:
|
||||||
void commitAndCloseEditor();
|
void commitAndCloseEditor();
|
||||||
|
private slots:
|
||||||
|
void SetLastValue(const qreal &newLastValue);
|
||||||
private:
|
private:
|
||||||
/** @brief lastValue last saved value. */
|
/** @brief lastValue last saved value. */
|
||||||
qreal lastValue;
|
qreal lastValue;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user