summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-30 15:06:26 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-08-30 15:06:26 -0300
commit5e722a93e46ec1217bffd2bbcb1279cfd96dc2ed (patch)
tree13e21ee755155104cf5755ece2f3406fbfbb6f9a
parent2d0e877bb281733c94ac7f6d614914d7820c3af1 (diff)
downloadsubsurface-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>
-rw-r--r--planner.c2
-rw-r--r--planner.h9
-rw-r--r--qt-ui/diveplanner.cpp37
-rw-r--r--qt-ui/modeldelegates.cpp4
4 files changed, 41 insertions, 11 deletions
diff --git a/planner.c b/planner.c
index 56fc0ac46..7c77555ac 100644
--- a/planner.c
+++ b/planner.c
@@ -712,7 +712,6 @@ error_exit:
free(gaschanges);
}
-#if USE_GTK_UI
/*
* Get a value in tenths (so "10.2" == 102, "9" = 90)
*
@@ -980,6 +979,7 @@ int validate_volume(const char *text, int *sac)
return 1;
}
+#if USE_GTK_UI
struct diveplan diveplan = {};
char *cache_data = NULL;
struct dive *planned_dive = NULL;
diff --git a/planner.h b/planner.h
index 4de3c4669..d97a21fa7 100644
--- a/planner.h
+++ b/planner.h
@@ -1,6 +1,11 @@
#ifndef PLANNER_H
#define PLANNER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
extern void plan(struct diveplan *diveplan, char **cache_datap, struct dive **divep, char **error_string_p);
extern int validate_gas(const char *text, int *o2_p, int *he_p);
extern int validate_time(const char *text, int *sec_p, int *rel_p);
@@ -19,4 +24,8 @@ extern char *cache_data;
extern char *disclaimer;
extern double plangflow, plangfhigh;
+
+#ifdef __cplusplus
+}
+#endif
#endif /* PLANNER_H */
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)