Correctly format the values shown for cylinders and weights

Make use of all the nice helpers that we have...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-05-21 12:03:05 -07:00
parent 19586081ed
commit 3009930aee

View file

@ -5,6 +5,7 @@
* *
*/ */
#include "models.h" #include "models.h"
#include "../helpers.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include <QColor> #include <QColor>
@ -62,30 +63,42 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
if (!index.isValid() || index.row() >= MAX_CYLINDERS) if (!index.isValid() || index.row() >= MAX_CYLINDERS)
return ret; return ret;
cylinder_t& cyl = current->cylinder[index.row()]; cylinder_t *cyl = &current->cylinder[index.row()];
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
switch(index.column()) { switch(index.column()) {
case TYPE: case TYPE:
ret = QString(cyl.type.description); ret = QString(cyl->type.description);
break; break;
case SIZE: case SIZE:
ret = cyl.type.size.mliter; // we can't use get_volume_string because the idiotic imperial tank
// sizes take working pressure into account...
if (cyl->type.size.mliter) {
if (prefs.units.volume == prefs.units.CUFT) {
int cuft = ml_to_cuft(gas_volume(cyl, cyl->type.workingpressure));
ret = QString("%1cuft").arg(cuft);
} else {
ret = QString("%1l").arg(cyl->type.size.mliter / 1000.0, 0, 'f', 1);
}
}
break; break;
case MAXPRESS: case MAXPRESS:
ret = cyl.type.workingpressure.mbar; if (cyl->type.workingpressure.mbar)
ret = get_pressure_string(cyl->type.workingpressure, TRUE);
break; break;
case START: case START:
ret = cyl.start.mbar; if (cyl->start.mbar)
ret = get_pressure_string(cyl->start, TRUE);
break; break;
case END: case END:
ret = cyl.end.mbar; if (cyl->end.mbar)
ret = get_pressure_string(cyl->end, TRUE );
break; break;
case O2: case O2:
ret = cyl.gasmix.o2.permille; ret = QString("%1%").arg((cyl->gasmix.o2.permille + 5) / 10);
break; break;
case HE: case HE:
ret = cyl.gasmix.he.permille; ret = QString("%1%").arg((cyl->gasmix.he.permille + 5) / 10);
break; break;
} }
} }
@ -178,13 +191,7 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const
ret = QString(ws->description); ret = QString(ws->description);
break; break;
case WEIGHT: case WEIGHT:
if (get_units()->weight == units::KG) { ret = get_weight_string(ws->weight, TRUE);
int gr = ws->weight.grams % 1000;
int kg = ws->weight.grams / 1000;
ret = QString("%1.%2").arg(kg).arg((unsigned) gr / 100);
} else {
ret = QString("%1").arg((unsigned)(grams_to_lbs(ws->weight.grams)));
}
break; break;
} }
} }