Set to define last value when creating new delegate.

--HG--
branch : develop
This commit is contained in:
dismine 2014-10-08 13:44:42 +03:00
parent 145dd73113
commit 9839b6b331
2 changed files with 22 additions and 1 deletions

View file

@ -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;
}

View file

@ -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;