diff options
author | Anton Lundin <glance@acc.umu.se> | 2014-10-27 22:12:46 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-10-27 15:41:55 -0700 |
commit | ee7c86f206f5465df0f0ade08b13da3b8062e67f (patch) | |
tree | 05d6319263f40e2e48940fcd1e51d463b28f06c3 /qt-ui/configuredivecomputerdialog.cpp | |
parent | 0e3a9328bc10b59a4e4843819bad0b3a4d75c456 (diff) | |
download | subsurface-ee7c86f206f5465df0f0ade08b13da3b8062e67f.tar.gz |
Create a delegate for depth and gas components
This creates a delegate to simplify the handling of gas components and
the change depth.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/configuredivecomputerdialog.cpp')
-rw-r--r-- | qt-ui/configuredivecomputerdialog.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp index c2da24485..4b6649959 100644 --- a/qt-ui/configuredivecomputerdialog.cpp +++ b/qt-ui/configuredivecomputerdialog.cpp @@ -28,6 +28,42 @@ struct mydescriptor { unsigned int model; }; +GasSpinBoxItemDelegate::GasSpinBoxItemDelegate(QObject *parent, column_type type) : QStyledItemDelegate(parent), type(type) { } +GasSpinBoxItemDelegate::~GasSpinBoxItemDelegate() { } + +QWidget* GasSpinBoxItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + // Create the spinbox and give it it's settings + QSpinBox *sb = new QSpinBox(parent); + if (type == PERCENT) { + sb->setMinimum(0); + sb->setMaximum(100); + sb->setSuffix("%"); + } else if (type == DEPTH) { + sb->setMinimum(0); + sb->setMaximum(255); + sb->setSuffix("m"); + } + return sb; +} + +void GasSpinBoxItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + if(QSpinBox *sb = qobject_cast<QSpinBox *>(editor)) + sb->setValue(index.data(Qt::EditRole).toInt()); + else + QStyledItemDelegate::setEditorData(editor, index); +} + + +void GasSpinBoxItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + if(QSpinBox *sb = qobject_cast<QSpinBox *>(editor)) + model->setData(index, sb->value(), Qt::EditRole); + else + QStyledItemDelegate::setModelData(editor, model, index); +} + GasTypeComboBoxItemDelegate::GasTypeComboBoxItemDelegate(QObject *parent, computer_type type) : QStyledItemDelegate(parent), type(type) { } GasTypeComboBoxItemDelegate::~GasTypeComboBoxItemDelegate() { } @@ -89,10 +125,18 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : ui.DiveComputerList->setCurrentRow(0); on_DiveComputerList_currentRowChanged(0); + ui.ostc3GasTable->setItemDelegateForColumn(1, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT)); + ui.ostc3GasTable->setItemDelegateForColumn(2, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT)); ui.ostc3GasTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC3)); + ui.ostc3GasTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH)); ui.ostc3DilTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC3)); + ui.ostc3DilTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH)); + ui.ostcGasTable->setItemDelegateForColumn(1, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT)); + ui.ostcGasTable->setItemDelegateForColumn(2, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::PERCENT)); ui.ostcGasTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC)); + ui.ostcGasTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH)); ui.ostcDilTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC)); + ui.ostcDilTable->setItemDelegateForColumn(4, new GasSpinBoxItemDelegate(this, GasSpinBoxItemDelegate::DEPTH)); QSettings settings; settings.beginGroup("ConfigureDiveComputerDialog"); |