mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
0e3a9328bc
commit
ee7c86f206
2 changed files with 64 additions and 0 deletions
|
@ -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");
|
||||
|
|
|
@ -8,6 +8,26 @@
|
|||
#include "configuredivecomputer.h"
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class GasSpinBoxItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum column_type {
|
||||
PERCENT,
|
||||
DEPTH,
|
||||
};
|
||||
|
||||
GasSpinBoxItemDelegate(QObject *parent = 0, column_type type = PERCENT);
|
||||
~GasSpinBoxItemDelegate();
|
||||
|
||||
virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||
private:
|
||||
column_type type;
|
||||
};
|
||||
|
||||
class GasTypeComboBoxItemDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Reference in a new issue