mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
2d0e877bb2
commit
5e722a93e4
4 changed files with 41 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue