summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/mainwindow.cpp3
-rw-r--r--qt-ui/models.cpp62
2 files changed, 35 insertions, 30 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 56b512a3a..deaab4715 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -37,7 +37,6 @@ MainWindow* mainWindow()
MainWindow::MainWindow() : ui(new Ui::MainWindow())
{
ui->setupUi(this);
- readSettings();
setWindowIcon(QIcon(":subsurface-icon"));
connect(ui->ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int)));
ui->globeMessage->hide();
@@ -45,6 +44,7 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow())
ui->globeMessage->setCloseButtonVisible(false);
ui->ProfileWidget->setFocusProxy(ui->ListWidget);
ui->ListWidget->reload();
+ readSettings();
ui->ListWidget->setFocus();
ui->globe->reload();
instance = this;
@@ -344,6 +344,7 @@ void MainWindow::readSettings()
ui->ListWidget->resizeColumnToContents(i);
}
ui->ListWidget->collapseAll();
+ ui->ListWidget->expand(ui->ListWidget->model()->index(0,0));
ui->ListWidget->scrollTo(ui->ListWidget->model()->index(0,0), QAbstractItemView::PositionAtCenter);
settings.endGroup();
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 04f7256e6..466dcd2f9 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -5,6 +5,7 @@
*
*/
#include "models.h"
+#include "../helpers.h"
#include <QCoreApplication>
#include <QDebug>
#include <QColor>
@@ -62,30 +63,42 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const
if (!index.isValid() || index.row() >= MAX_CYLINDERS)
return ret;
- cylinder_t& cyl = current->cylinder[index.row()];
+ cylinder_t *cyl = &current->cylinder[index.row()];
if (role == Qt::DisplayRole) {
switch(index.column()) {
case TYPE:
- ret = QString(cyl.type.description);
+ ret = QString(cyl->type.description);
break;
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;
case MAXPRESS:
- ret = cyl.type.workingpressure.mbar;
+ if (cyl->type.workingpressure.mbar)
+ ret = get_pressure_string(cyl->type.workingpressure, TRUE);
break;
case START:
- ret = cyl.start.mbar;
+ if (cyl->start.mbar)
+ ret = get_pressure_string(cyl->start, TRUE);
break;
case END:
- ret = cyl.end.mbar;
+ if (cyl->end.mbar)
+ ret = get_pressure_string(cyl->end, TRUE );
break;
case O2:
- ret = cyl.gasmix.o2.permille;
+ ret = QString("%1%").arg((cyl->gasmix.o2.permille + 5) / 10);
break;
case HE:
- ret = cyl.gasmix.he.permille;
+ ret = QString("%1%").arg((cyl->gasmix.he.permille + 5) / 10);
break;
}
}
@@ -136,10 +149,10 @@ void CylindersModel::setDive(dive* d)
if (current)
clear();
- int amount = 0;
+ int amount = MAX_CYLINDERS;
for(int i = 0; i < MAX_CYLINDERS; i++){
- cylinder_t& cylinder = d->cylinder[i];
- if (!cylinder.type.description){
+ cylinder_t *cylinder = &d->cylinder[i];
+ if (cylinder_none(cylinder)) {
amount = i;
break;
}
@@ -178,13 +191,7 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const
ret = QString(ws->description);
break;
case WEIGHT:
- if (get_units()->weight == units::KG) {
- 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)));
- }
+ ret = get_weight_string(ws->weight, TRUE);
break;
}
}
@@ -217,9 +224,8 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r
void WeightModel::add(weightsystem_t* weight)
{
- if (rows >= MAX_WEIGHTSYSTEMS) {
+ if (rows >= MAX_WEIGHTSYSTEMS)
return;
- }
int row = rows;
@@ -243,10 +249,10 @@ void WeightModel::setDive(dive* d)
if (current)
clear();
- int amount = 0;
- for(int i = 0; i < MAX_WEIGHTSYSTEMS; i++){
- weightsystem_t& weightsystem = d->weightsystem[i];
- if (!weightsystem.description){
+ int amount = MAX_WEIGHTSYSTEMS;
+ for(int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
+ weightsystem_t *weightsystem = &d->weightsystem[i];
+ if (weightsystem_none(weightsystem)) {
amount = i;
break;
}
@@ -528,13 +534,11 @@ QVariant DiveItem::data(int column, int role) const
break;
}
- if(role == STAR_ROLE){
+ if (role == STAR_ROLE)
retVal = dive->rating;
- }
- if(role == DIVE_ROLE){
+ if (role == DIVE_ROLE)
retVal = QVariant::fromValue<void*>(dive);
- }
return retVal;
}
@@ -663,7 +667,7 @@ Qt::ItemFlags DiveTripModel::flags(const QModelIndex& index) const
}
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation,
- int role) const
+ int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
return rootItem->data(section, role);