dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
dblspindelegate.cpp
Go to the documentation of this file.
1 
12 /*
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with this program; if not, see <http://www.gnu.org/licenses/>
25  */
26 
27 #include "dblspindelegate.h"
28 
33  : QItemDelegate(parent)
34 {
35  m_min = 0.0;
36  m_max = 1.0;
37  m_decimals = 2;
38  m_step = 0.01;
39 }
40 
41 QWidget *DoubleSpinDelegate::createEditor(QWidget *parent,
42  const QStyleOptionViewItem & /* option */,
43  const QModelIndex & /* index */) const
44 {
45  QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
46  editor->setMinimum(m_min);
47  editor->setMaximum(m_max);
48  editor->setDecimals(m_decimals);
49  editor->setSingleStep(m_step);
50 
51  connect(editor, SIGNAL(valueChanged(double)), this, SLOT(valueChanged()));
52 
53  return editor;
54 }
55 
56 void DoubleSpinDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
57 {
58  double value = index.model()->data(index, Qt::EditRole).toDouble();
59 
60  QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox *>(editor);
61  spinBox->setValue(value);
62 }
63 
64 void DoubleSpinDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
65  const QModelIndex &index) const
66 {
67  QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox *>(editor);
68  spinBox->interpretText();
69  double value = spinBox->value();
70 
71  model->setData(index, value, Qt::EditRole);
72 }
73 
74 void DoubleSpinDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
75  const QModelIndex & /* index */) const
76 {
77  editor->setGeometry(option.rect);
78 }
79 
80 void DoubleSpinDelegate::valueChanged()
81 {
82  emit ValueChanged();
83 }
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
void setEditorData(QWidget *editor, const QModelIndex &index) const
DoubleSpinDelegate(QObject *parent=nullptr)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const