mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Connect cylinders entered in planner with the gases available
Now the gases for which we have cylinders are offered in the gas selection list and correctly recognized and added for the plan. Still tons of work to be done to make this work the way it is designed, but we are getting closer. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
9ead871d64
commit
0a8892379d
3 changed files with 42 additions and 14 deletions
|
@ -32,19 +32,25 @@
|
||||||
|
|
||||||
#define M_OR_FT(_m,_f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) : ((_f) * 304.8))
|
#define M_OR_FT(_m,_f) ((prefs.units.length == units::METERS) ? ((_m) * 1000) : ((_f) * 304.8))
|
||||||
|
|
||||||
QStringListModel *airTypes() {
|
QStringListModel *gasSelectionModel() {
|
||||||
static QStringListModel *self = new QStringListModel(QStringList()
|
static QStringListModel *self = new QStringListModel(QStringList()
|
||||||
<< QObject::tr("AIR")
|
<< QObject::tr("AIR"));
|
||||||
<< QObject::tr("EAN32")
|
self->setStringList(DivePlannerPointsModel::instance()->getGasList());
|
||||||
<< QObject::tr("EAN36"));
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString strForAir(const divedatapoint& p) {
|
QString gasToStr(const int o2Permille, const int hePermille) {
|
||||||
return is_air(p.o2, p.he) ? QObject::tr("AIR")
|
uint o2 = (o2Permille + 5) / 10, he = (hePermille + 5) / 10;
|
||||||
: p.o2 == 320 ? QObject::tr("EAN32")
|
QString result = is_air(o2Permille, hePermille) ? QObject::tr("AIR")
|
||||||
: p.o2 == 360 ? QObject::tr("EAN36")
|
: he == 0 ? QString("EAN%1").arg(o2, 2, 10, QChar('0'))
|
||||||
: QObject::tr("Choose Gas");
|
: QString("%1/%2").arg(o2).arg(he);
|
||||||
|
qDebug() << o2 << he << result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString dpGasToStr(const divedatapoint& p)
|
||||||
|
{
|
||||||
|
return gasToStr(p.o2, p.he);
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor getColor(const color_indice_t i)
|
QColor getColor(const color_indice_t i)
|
||||||
|
@ -170,7 +176,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
// Prepare the stuff for the gas-choices.
|
// Prepare the stuff for the gas-choices.
|
||||||
gasListView = new QListView();
|
gasListView = new QListView();
|
||||||
gasListView->setWindowFlags(Qt::Popup);
|
gasListView->setWindowFlags(Qt::Popup);
|
||||||
gasListView->setModel(airTypes());
|
gasListView->setModel(gasSelectionModel());
|
||||||
gasListView->hide();
|
gasListView->hide();
|
||||||
gasListView->installEventFilter(this);
|
gasListView->installEventFilter(this);
|
||||||
|
|
||||||
|
@ -446,11 +452,31 @@ void DivePlannerPointsModel::loadFromDive(dive* d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList& DivePlannerPointsModel::getGasList()
|
||||||
|
{
|
||||||
|
static QStringList list;
|
||||||
|
list.clear();
|
||||||
|
if (!stagingDive) {
|
||||||
|
list.push_back(tr("AIR"));
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
||||||
|
cylinder_t *cyl = &stagingDive->cylinder[i];
|
||||||
|
if (cylinder_nodata(cyl))
|
||||||
|
break;
|
||||||
|
list.push_back(gasToStr(cyl->gasmix.o2.permille, cyl->gasmix.he.permille));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug() << list;
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
void DivePlannerGraphics::prepareSelectGas()
|
void DivePlannerGraphics::prepareSelectGas()
|
||||||
{
|
{
|
||||||
|
QStringListModel *model = qobject_cast<QStringListModel*>(gasListView->model());
|
||||||
currentGasChoice = static_cast<Button*>(sender());
|
currentGasChoice = static_cast<Button*>(sender());
|
||||||
QPoint c = QCursor::pos();
|
QPoint c = QCursor::pos();
|
||||||
gasListView->setGeometry(c.x(), c.y(), 150, 100);
|
gasListView->setGeometry(c.x(), c.y(), 150, 100);
|
||||||
|
model->setStringList(DivePlannerPointsModel::instance()->getGasList());
|
||||||
gasListView->show();
|
gasListView->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,6 +485,7 @@ void DivePlannerGraphics::selectGas(const QModelIndex& index)
|
||||||
QString gasSelected = gasListView->model()->data(index, Qt::DisplayRole).toString();
|
QString gasSelected = gasListView->model()->data(index, Qt::DisplayRole).toString();
|
||||||
int idx = gases.indexOf(currentGasChoice);
|
int idx = gases.indexOf(currentGasChoice);
|
||||||
plannerModel->setData(plannerModel->index(idx, DivePlannerPointsModel::GAS), gasSelected);
|
plannerModel->setData(plannerModel->index(idx, DivePlannerPointsModel::GAS), gasSelected);
|
||||||
|
qDebug() << "gas selected:" << gasSelected;
|
||||||
gasListView->hide();
|
gasListView->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +520,7 @@ void DivePlannerGraphics::drawProfile()
|
||||||
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);
|
||||||
gases[i]->setText(strForAir(plannerModel->at(i-1)));
|
gases[i]->setText(dpGasToStr(plannerModel->at(i-1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// (re-) create the profile with different colors for segments that were
|
// (re-) create the profile with different colors for segments that were
|
||||||
|
@ -980,7 +1007,7 @@ QVariant DivePlannerPointsModel::data(const QModelIndex& index, int role) const
|
||||||
case GAS:
|
case GAS:
|
||||||
if (index.row() > 0) {
|
if (index.row() > 0) {
|
||||||
p = divepoints.at(index.row() - 1);
|
p = divepoints.at(index.row() - 1);
|
||||||
return strForAir(p);
|
return dpGasToStr(p);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class QStringListModel;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
|
|
||||||
// Return a Model containing the air types.
|
// Return a Model containing the air types.
|
||||||
QStringListModel *airTypes();
|
QStringListModel *gasSelectionModel();
|
||||||
|
|
||||||
class DivePlannerPointsModel : public QAbstractTableModel{
|
class DivePlannerPointsModel : public QAbstractTableModel{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -41,6 +41,7 @@ public:
|
||||||
divedatapoint at(int row);
|
divedatapoint at(int row);
|
||||||
int size();
|
int size();
|
||||||
struct diveplan getDiveplan();
|
struct diveplan getDiveplan();
|
||||||
|
QStringList &getGasList();
|
||||||
public slots:
|
public slots:
|
||||||
int addStop(int meters = 0, int minutes = 0, int o2 = 0, int he = 0, int ccpoint = 0 );
|
int addStop(int meters = 0, int minutes = 0, int o2 = 0, int he = 0, int ccpoint = 0 );
|
||||||
void addCylinder_clicked();
|
void addCylinder_clicked();
|
||||||
|
|
|
@ -307,7 +307,7 @@ void AirTypesDelegate::setModelData(QWidget* editor, QAbstractItemModel* model,
|
||||||
model->setData(index, QVariant(combo->currentText()));
|
model->setData(index, QVariant(combo->currentText()));
|
||||||
}
|
}
|
||||||
|
|
||||||
AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(airTypes(), parent)
|
AirTypesDelegate::AirTypesDelegate(QObject* parent) : ComboBoxDelegate(gasSelectionModel(), parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue