ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
doublespinboxdelegate.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 #include <QDoubleSpinBox>
11 
12 namespace VtkUtils {
13 
15  : QStyledItemDelegate(parent) {}
16 
18  QWidget *parent,
19  const QStyleOptionViewItem & /* option */,
20  const QModelIndex & /* index */) const {
21  QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
22  editor->setSingleStep(0.1);
23  editor->setFrame(false);
24  editor->setDecimals(2);
25  editor->setMinimum(-INT_MAX);
26  editor->setMaximum(INT_MAX);
27 
28  return editor;
29 }
30 
32  const QModelIndex &index) const {
33  qreal value = index.model()->data(index, Qt::EditRole).toDouble();
34  QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox *>(editor);
35  spinBox->setValue(value);
36 }
37 
39  QAbstractItemModel *model,
40  const QModelIndex &index) const {
41  QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox *>(editor);
42  spinBox->interpretText();
43  qreal value = spinBox->value();
44 
45  model->setData(index, value, Qt::EditRole);
46 }
47 
49  QWidget *editor,
50  const QStyleOptionViewItem &option,
51  const QModelIndex & /* index */) const {
52  editor->setGeometry(option.rect);
53 }
54 
55 } // namespace VtkUtils
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const Q_DECL_OVERRIDE
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE
void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE