mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-17 19:36:15 +00:00
Started the work of Editable Model for the Planner
This commit is the start of the Editable Model work for the planner, it creates a new delegate and shares the code for the model that creates the gas types, so we only need to change in one place to add new gases. The table is already edition-enabled, but the outcome is still undone, next commit - put all together. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
6c56f07959
commit
69903903d2
4 changed files with 47 additions and 4 deletions
|
@ -1,10 +1,12 @@
|
|||
#include "diveplanner.h"
|
||||
#include "graphicsview-common.h"
|
||||
#include "models.h"
|
||||
#include "modeldelegates.h"
|
||||
|
||||
#include "../dive.h"
|
||||
#include "../divelist.h"
|
||||
|
||||
|
||||
#include <cmath>
|
||||
#include <QMouseEvent>
|
||||
#include <QDebug>
|
||||
|
@ -27,6 +29,11 @@
|
|||
#define MAX_DEEPNESS 150
|
||||
#define MIN_DEEPNESS 40
|
||||
|
||||
QStringListModel *airTypes(){
|
||||
static QStringListModel *self = new QStringListModel(QStringList() << QObject::tr("AIR") << QObject::tr("EAN32") << QObject::tr("EAN36"));
|
||||
return self;
|
||||
}
|
||||
|
||||
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
||||
|
||||
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0)
|
||||
|
@ -135,10 +142,9 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
|||
#undef ADD_ACTION
|
||||
|
||||
// Prepare the stuff for the gas-choices.
|
||||
gasChoices = new QStringListModel(QStringList() << tr("AIR") << tr("EAN32") << tr("EAN36"));
|
||||
gasListView = new QListView();
|
||||
gasListView->setWindowFlags(Qt::Popup);
|
||||
gasListView->setModel(gasChoices);
|
||||
gasListView->setModel(airTypes());
|
||||
gasListView->hide();
|
||||
|
||||
connect(gasListView, SIGNAL(activated(QModelIndex)), this, SLOT(selectGas(QModelIndex)));
|
||||
|
@ -394,8 +400,6 @@ void DivePlannerGraphics::createDecoStops()
|
|||
{
|
||||
qDeleteAll(lines);
|
||||
lines.clear();
|
||||
//TODO: fix.
|
||||
//qSort(handles.begin(), handles.end(), handlerLessThenMinutes);
|
||||
|
||||
// This needs to be done in the following steps:
|
||||
// Get the user-input and calculate the dive info
|
||||
|
@ -807,6 +811,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge
|
|||
{
|
||||
ui->setupUi(this);
|
||||
ui->tablePoints->setModel(DivePlannerPointsModel::instance());
|
||||
ui->tablePoints->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
|
||||
connect(ui->startTime, SIGNAL(timeChanged(QTime)), this, SLOT(startTimeChanged(QTime)));
|
||||
connect(ui->ATMPressure, SIGNAL(textChanged(QString)), this, SLOT(atmPressureChanged(QString)));
|
||||
connect(ui->bottomSAC, SIGNAL(textChanged(QString)), this, SLOT(bottomSacChanged(QString)));
|
||||
|
@ -914,6 +919,11 @@ QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
bool DivePlannerPointsModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||
{
|
||||
return QAbstractItemModel::setData(index, value, role);
|
||||
}
|
||||
|
||||
QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal){
|
||||
|
@ -927,6 +937,11 @@ QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orienta
|
|||
return QVariant();
|
||||
}
|
||||
|
||||
Qt::ItemFlags DivePlannerPointsModel::flags(const QModelIndex& index) const
|
||||
{
|
||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
int DivePlannerPointsModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
return divepoints.count();
|
||||
|
|
|
@ -17,6 +17,9 @@ class QListView;
|
|||
class QStringListModel;
|
||||
class QModelIndex;
|
||||
|
||||
// Return a Model containing the air types.
|
||||
QStringListModel *airTypes();
|
||||
|
||||
class DivePlannerPointsModel : public QAbstractTableModel{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -26,6 +29,8 @@ public:
|
|||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
|
||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
||||
|
||||
/**
|
||||
* @return the row number.
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "../divelist.h"
|
||||
#include "starwidget.h"
|
||||
#include "models.h"
|
||||
#include "diveplanner.h"
|
||||
|
||||
#include <QtDebug>
|
||||
#include <QPainter>
|
||||
|
@ -14,6 +15,7 @@
|
|||
#include <QLineEdit>
|
||||
#include <QKeyEvent>
|
||||
#include <QAbstractItemView>
|
||||
#include <QStringListModel>
|
||||
|
||||
// Gets the index of the model in the currentRow and column.
|
||||
// currCombo is defined below.
|
||||
|
@ -253,3 +255,15 @@ QWidget* WSInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewIte
|
|||
currWeigth.weigth = ws->weight.grams;
|
||||
return editor;
|
||||
}
|
||||
|
||||
void AirTypesDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint)
|
||||
{
|
||||
}
|
||||
|
||||
void AirTypesDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
|
||||
{
|
||||
}
|
||||
|
||||
AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(airTypes(), parent)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -49,4 +49,13 @@ public slots:
|
|||
void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
};
|
||||
|
||||
class AirTypesDelegate : public ComboBoxDelegate{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AirTypesDelegate(QObject* parent = 0);
|
||||
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
|
||||
public slots:
|
||||
void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue