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>
This commit is contained in:
Tomaz Canabrava 2013-08-30 15:06:26 -03:00
parent 2d0e877bb2
commit 5e722a93e4
4 changed files with 41 additions and 11 deletions

View file

@ -712,7 +712,6 @@ error_exit:
free(gaschanges); free(gaschanges);
} }
#if USE_GTK_UI
/* /*
* Get a value in tenths (so "10.2" == 102, "9" = 90) * 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; return 1;
} }
#if USE_GTK_UI
struct diveplan diveplan = {}; struct diveplan diveplan = {};
char *cache_data = NULL; char *cache_data = NULL;
struct dive *planned_dive = NULL; struct dive *planned_dive = NULL;

View file

@ -1,6 +1,11 @@
#ifndef PLANNER_H #ifndef PLANNER_H
#define 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 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_gas(const char *text, int *o2_p, int *he_p);
extern int validate_time(const char *text, int *sec_p, int *rel_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 char *disclaimer;
extern double plangflow, plangfhigh; extern double plangflow, plangfhigh;
#ifdef __cplusplus
}
#endif
#endif /* PLANNER_H */ #endif /* PLANNER_H */

View file

@ -5,7 +5,7 @@
#include "../dive.h" #include "../dive.h"
#include "../divelist.h" #include "../divelist.h"
#include "../planner.h"
#include <cmath> #include <cmath>
#include <QMouseEvent> #include <QMouseEvent>
@ -30,10 +30,20 @@
#define MIN_DEEPNESS 40 #define MIN_DEEPNESS 40
QStringListModel *airTypes(){ 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; 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(); static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0) 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) void DivePlannerGraphics::pointInserted(const QModelIndex& parent, int start , int end)
{ {
qDebug() << "Adicionou";
divedatapoint point = plannerModel->at(start); divedatapoint point = plannerModel->at(start);
DiveHandler *item = new DiveHandler (); DiveHandler *item = new DiveHandler ();
double xpos = timeLine->posAtValue(point.time / 60); double xpos = timeLine->posAtValue(point.time / 60);
@ -393,7 +402,8 @@ void DivePlannerGraphics::prepareSelectGas()
void DivePlannerGraphics::selectGas(const QModelIndex& index) void DivePlannerGraphics::selectGas(const QModelIndex& index)
{ {
QString gasSelected = gasListView->model()->data(index, Qt::DisplayRole).toString(); 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(); gasListView->hide();
} }
@ -423,7 +433,6 @@ void DivePlannerGraphics::createDecoStops()
dp = plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2); dp = plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2);
} }
#if DEBUG_PLAN #if DEBUG_PLAN
dump_plan(&diveplan); dump_plan(&diveplan);
#endif #endif
@ -456,13 +465,13 @@ void DivePlannerGraphics::createDecoStops()
int gasCount = gases.count(); int gasCount = gases.count();
for(int i = 0; i < gasCount; i++){ 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 p1 = (i == 0) ? QPointF(timeLine->posAtValue(0), depthLine->posAtValue(0)) : handles[i-1]->pos();
QPointF p2 = handles[i]->pos(); QPointF p2 = handles[i]->pos();
QLineF line(p1, p2); QLineF line(p1, p2);
QPointF pos = line.pointAt(0.5); QPointF pos = line.pointAt(0.5);
gases[i]->setPos(pos); 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 // (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 CCSETPOINT: return 0;
case DEPTH: return p.depth / 1000; case DEPTH: return p.depth / 1000;
case DURATION: return p.time / 60; case DURATION: return p.time / 60;
case GAS: return tr("Air"); case GAS: return strForAir(p);
} }
} }
if (role == Qt::DecorationRole){ if (role == Qt::DecorationRole){
@ -928,7 +937,15 @@ bool DivePlannerPointsModel::setData(const QModelIndex& index, const QVariant& v
case DEPTH: p.depth = value.toInt() * 1000; break; case DEPTH: p.depth = value.toInt() * 1000; break;
case DURATION: p.time = value.toInt() * 60; break; case DURATION: p.time = value.toInt() * 60; break;
case CCSETPOINT: /* what do I do here? */ 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); editStop(index.row(), p);
} }

View file

@ -262,6 +262,10 @@ void AirTypesDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::E
void AirTypesDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const 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) AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(airTypes(), parent)