mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Planner: Add combo box for dive mode selection
I am not really sure what I am doing here but I copied code from the gas selection. Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
parent
969dfee9ec
commit
b8c94cad69
6 changed files with 71 additions and 0 deletions
|
@ -114,6 +114,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg
|
|||
ui.tableWidget->setModel(plannerModel);
|
||||
plannerModel->setRecalc(true);
|
||||
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
|
||||
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DIVEMODE, new DiveTypesDelegate(this));
|
||||
ui.cylinderTableWidget->setTitle(tr("Available gases"));
|
||||
ui.cylinderTableWidget->setBtnToolTip(tr("Add cylinder"));
|
||||
ui.cylinderTableWidget->setModel(CylindersModel::instance());
|
||||
|
|
|
@ -407,6 +407,24 @@ AirTypesDelegate::AirTypesDelegate(QObject *parent) : ComboBoxDelegate(GasSelect
|
|||
{
|
||||
}
|
||||
|
||||
void DiveTypesDelegate::revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint)
|
||||
{
|
||||
Q_UNUSED(widget)
|
||||
Q_UNUSED(hint)
|
||||
}
|
||||
|
||||
void DiveTypesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return;
|
||||
QComboBox *combo = qobject_cast<QComboBox *>(editor);
|
||||
model->setData(index, QVariant(combo->currentIndex()));
|
||||
}
|
||||
|
||||
DiveTypesDelegate::DiveTypesDelegate(QObject *parent) : ComboBoxDelegate(DiveTypeSelectionModel::instance(), parent, false)
|
||||
{
|
||||
}
|
||||
|
||||
SpinBoxDelegate::SpinBoxDelegate(int min, int max, int step, QObject *parent):
|
||||
QStyledItemDelegate(parent),
|
||||
min(min),
|
||||
|
|
|
@ -92,6 +92,16 @@ slots:
|
|||
void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
};
|
||||
|
||||
class DiveTypesDelegate : public ComboBoxDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DiveTypesDelegate(QObject *parent = 0);
|
||||
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||
public
|
||||
slots:
|
||||
void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
};
|
||||
|
||||
class SpinBoxDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
@ -55,6 +55,7 @@ void DivePlannerPointsModel::createSimpleDive()
|
|||
}
|
||||
updateMaxDepth();
|
||||
GasSelectionModel::instance()->repopulate();
|
||||
DiveTypeSelectionModel::instance()->repopulate();
|
||||
}
|
||||
|
||||
void DivePlannerPointsModel::setupStartTime()
|
||||
|
|
|
@ -67,6 +67,36 @@ QVariant GasSelectionModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
return QStringListModel::data(index, role);
|
||||
}
|
||||
// Dive Type Model for the divetype combo box
|
||||
|
||||
Qt::ItemFlags DiveTypeSelectionModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
DiveTypeSelectionModel *DiveTypeSelectionModel::instance()
|
||||
{
|
||||
static DiveTypeSelectionModel self;
|
||||
return &self;
|
||||
}
|
||||
|
||||
void DiveTypeSelectionModel::repopulate()
|
||||
{
|
||||
QStringList modes = QStringList();
|
||||
for (int i = 0; i < FREEDIVE; i++)
|
||||
modes.append(QString(divemode_text[i]));
|
||||
setStringList(modes);
|
||||
}
|
||||
|
||||
QVariant DiveTypeSelectionModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::FontRole) {
|
||||
return defaultModelFont();
|
||||
}
|
||||
return QStringListModel::data(index, role);
|
||||
}
|
||||
|
||||
|
||||
// Language Model, The Model to populate the list of possible Languages.
|
||||
|
||||
|
|
|
@ -33,6 +33,17 @@ slots:
|
|||
void repopulate();
|
||||
};
|
||||
|
||||
class DiveTypeSelectionModel : public QStringListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static DiveTypeSelectionModel *instance();
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
virtual QVariant data(const QModelIndex &index, int role) const;
|
||||
public
|
||||
slots:
|
||||
void repopulate();
|
||||
};
|
||||
|
||||
|
||||
class LanguageModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Add table
Reference in a new issue