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.
|
||||
*/
|
||||
//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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user