diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-08-30 15:06:26 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-08-30 15:06:26 -0300 |
commit | 5e722a93e46ec1217bffd2bbcb1279cfd96dc2ed (patch) | |
tree | 13e21ee755155104cf5755ece2f3406fbfbb6f9a /qt-ui | |
parent | 2d0e877bb281733c94ac7f6d614914d7820c3af1 (diff) | |
download | subsurface-5e722a93e46ec1217bffd2bbcb1279cfd96dc2ed.tar.gz |
Gas choices working, both directions ( Planner and Table )
The gas choice now works and correctly ( I hope ) calculates
the gas choosen to show on the planner. User can choose the
gas from the list on the visual planner, and also on the table.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/diveplanner.cpp | 37 | ||||
-rw-r--r-- | qt-ui/modeldelegates.cpp | 4 |
2 files changed, 31 insertions, 10 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 8629791bd..bd83cf4ef 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -5,7 +5,7 @@ #include "../dive.h" #include "../divelist.h" - +#include "../planner.h" #include <cmath> #include <QMouseEvent> @@ -30,10 +30,20 @@ #define MIN_DEEPNESS 40 QStringListModel *airTypes(){ - static QStringListModel *self = new QStringListModel(QStringList() << QObject::tr("AIR") << QObject::tr("EAN32") << QObject::tr("EAN36")); + static QStringListModel *self = new QStringListModel(QStringList() + << QObject::tr("AIR") + << QObject::tr("EAN32") + << QObject::tr("EAN36")); return self; } +QString strForAir(const divedatapoint& p){ + return p.o2 == 209 ? QObject::tr("AIR") + : p.o2 == 320 ? QObject::tr("EAN32") + : p.o2 == 360 ? QObject::tr("EAN36") + : QObject::tr("Choose Gas"); +} + static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance(); DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0) @@ -156,7 +166,6 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) void DivePlannerGraphics::pointInserted(const QModelIndex& parent, int start , int end) { - qDebug() << "Adicionou"; divedatapoint point = plannerModel->at(start); DiveHandler *item = new DiveHandler (); double xpos = timeLine->posAtValue(point.time / 60); @@ -393,7 +402,8 @@ void DivePlannerGraphics::prepareSelectGas() void DivePlannerGraphics::selectGas(const QModelIndex& index) { QString gasSelected = gasListView->model()->data(index, Qt::DisplayRole).toString(); - currentGasChoice->setText(gasSelected); + int idx = gases.indexOf(currentGasChoice); + plannerModel->setData(plannerModel->index(idx, DivePlannerPointsModel::GAS), gasSelected); gasListView->hide(); } @@ -423,7 +433,6 @@ void DivePlannerGraphics::createDecoStops() dp = plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2); } - #if DEBUG_PLAN dump_plan(&diveplan); #endif @@ -456,13 +465,13 @@ void DivePlannerGraphics::createDecoStops() int gasCount = gases.count(); for(int i = 0; i < gasCount; i++){ + divedatapoint p = plannerModel->at(i); QPointF p1 = (i == 0) ? QPointF(timeLine->posAtValue(0), depthLine->posAtValue(0)) : handles[i-1]->pos(); QPointF p2 = handles[i]->pos(); - QLineF line(p1, p2); QPointF pos = line.pointAt(0.5); gases[i]->setPos(pos); - qDebug() << "Adding a gas at" << pos; + gases[i]->setText( strForAir(p) ); } // (re-) create the profile with different colors for segments that were @@ -909,7 +918,7 @@ QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const case CCSETPOINT: return 0; case DEPTH: return p.depth / 1000; case DURATION: return p.time / 60; - case GAS: return tr("Air"); + case GAS: return strForAir(p); } } if (role == Qt::DecorationRole){ @@ -928,11 +937,19 @@ bool DivePlannerPointsModel::setData(const QModelIndex& index, const QVariant& v case DEPTH: p.depth = value.toInt() * 1000; break; case DURATION: p.time = value.toInt() * 60; break; case CCSETPOINT: /* what do I do here? */ - case GAS: break; /* what do I do here? */ + case GAS: { + int o2 = 0; + int he = 0; + QByteArray gasv = value.toByteArray(); + if (validate_gas(gasv.data(), &o2, &he)) { + p.o2 = o2; + p.he = he; + }break; + } } editStop(index.row(), p); } - return QAbstractItemModel::setData(index, value, role); + return QAbstractItemModel::setData(index, value, role); } QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 31267810c..9bc633191 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -262,6 +262,10 @@ void AirTypesDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::E void AirTypesDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { + if (!index.isValid()) + return; + QComboBox *combo = qobject_cast<QComboBox*>(editor); + model->setData(index, QVariant(combo->currentText())); } AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(airTypes(), parent) |