diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-08-30 07:14:30 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-08-30 07:14:30 -0300 |
commit | 69903903d213e45fe16f3b5a6acb52278eee9291 (patch) | |
tree | d6d67ff1771196962bc5e47da076ea0fd31654ca /qt-ui/diveplanner.cpp | |
parent | 6c56f0795923453f2502637d6f7ddda59190bc2d (diff) | |
download | subsurface-69903903d213e45fe16f3b5a6acb52278eee9291.tar.gz |
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>
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r-- | qt-ui/diveplanner.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 9fadd53c0..63b8229ad 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -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(); |