From 9839b6b331f2077d44d1ae2d4c6f8df8bd3664a2 Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 8 Oct 2014 13:44:42 +0300 Subject: [PATCH] Set to define last value when creating new delegate. --HG-- branch : develop --- src/app/widgets/doubledelegate.cpp | 13 +++++++++++++ src/app/widgets/doubledelegate.h | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/app/widgets/doubledelegate.cpp b/src/app/widgets/doubledelegate.cpp index 0411b07d9..981ad3d0d 100644 --- a/src/app/widgets/doubledelegate.cpp +++ b/src/app/widgets/doubledelegate.cpp @@ -40,11 +40,18 @@ * @return editor to be used for editing the data item. */ //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, const QModelIndex &index ) const { Q_UNUSED(option); 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); editor->setMinimum(-10000.0); editor->setMaximum(10000.0); @@ -119,3 +126,9 @@ void DoubleSpinBoxDelegate::commitAndCloseEditor() } emit closeEditor(spinBox); } + +//--------------------------------------------------------------------------------------------------------------------- +void DoubleSpinBoxDelegate::SetLastValue(const qreal &newLastValue) +{ + lastValue = newLastValue; +} diff --git a/src/app/widgets/doubledelegate.h b/src/app/widgets/doubledelegate.h index 61ca17124..68557de9d 100644 --- a/src/app/widgets/doubledelegate.h +++ b/src/app/widgets/doubledelegate.h @@ -43,13 +43,21 @@ public: * @brief DoubleSpinBoxDelegate constructor. * @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; void setEditorData(QWidget *editor, 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; +signals: + /** + * @brief NewLastValue help reset last value in const method (hack). + * @param text text. + */ + void NewLastValue(const qreal &newLastValue) const; public slots: void commitAndCloseEditor(); +private slots: + void SetLastValue(const qreal &newLastValue); private: /** @brief lastValue last saved value. */ qreal lastValue;