aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/divelistview.cpp1
-rw-r--r--qt-ui/models.cpp104
2 files changed, 80 insertions, 25 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index a8b1eff05..676d7c463 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -8,4 +8,5 @@
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent)
{
+ setUniformRowHeights(true);
}
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 40307d022..e7f4b1f8b 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -8,6 +8,8 @@
#include "../dive.h"
#include "../divelist.h"
+#include <QtDebug>
+
extern struct tank_info tank_info[100];
CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent)
@@ -292,14 +294,16 @@ void TankInfoModel::update()
class DiveItem
{
public:
- explicit DiveItem(): number(0), dateTime(QString()), duration(0.0), depth(0.0), location(QString()) {parentItem = 0;}
- explicit DiveItem(int num, QString dt, float, float, QString loc, DiveItem *parent = 0);
+ explicit DiveItem(): number(0), dateTime(QString()), seconds(0), mm(0), location(QString()) { parentItem = 0; }
+ explicit DiveItem(int num, QString dt, int, int, QString loc, DiveItem *parent = 0);
~DiveItem() { qDeleteAll(childlist); }
int diveNumber() const { return number; }
const QString& diveDateTime() const { return dateTime; }
- float diveDuration() const { return duration; }
- float diveDepth() const { return depth; }
+ int diveDuration() const { return seconds; }
+ int diveDepth() const { return mm; }
+ QString displayDuration() const;
+ QString displayDepth() const;
const QString& diveLocation() const { return location; }
DiveItem *parent() const { return parentItem; }
const QList<DiveItem *>& children() const { return childlist; }
@@ -312,8 +316,8 @@ public:
private:
int number;
QString dateTime;
- float duration;
- float depth;
+ int seconds;
+ int mm;
QString location;
DiveItem *parentItem;
@@ -321,13 +325,45 @@ private:
};
-DiveItem::DiveItem(int num, QString dt, float dur, float dep, QString loc, DiveItem *p):
- number(num), dateTime(dt), duration(dur), depth(dep), location(loc), parentItem(p)
+DiveItem::DiveItem(int num, QString dt, int dur, int dep, QString loc, DiveItem *p):
+ number(num), dateTime(dt), seconds(dur), mm(dep), location(loc), parentItem(p)
{
if (parentItem)
parentItem->addChild(this);
}
+QString DiveItem::displayDepth() const
+{
+ const int scale = 1000;
+ QString fract, str;
+ if (get_units()->length == units::METERS) {
+ fract = QString::number((unsigned)(mm % scale) / 10);
+ str = QString("%1.%2").arg((unsigned)(mm / scale)).arg(fract, 2, QChar('0'));
+ }
+ if (get_units()->length == units::FEET) {
+ str = QString::number(mm_to_feet(mm),'f',2);
+ }
+ return str;
+}
+
+QString DiveItem::displayDuration() const
+{
+ int hrs, mins, secs;
+
+ secs = seconds % 60;
+ mins = seconds / 60;
+ hrs = mins / 60;
+ mins -= hrs * 60;
+
+ QString displayTime;
+ if (hrs)
+ displayTime = QString("%1:%2:").arg(hrs).arg(mins, 2, 10, QChar('0'));
+ else
+ displayTime = QString("%1:").arg(mins);
+ displayTime += QString("%1").arg(secs, 2, 10, QChar('0'));
+ return displayTime;
+}
+
DiveTripModel::DiveTripModel(QObject *parent) : QAbstractItemModel(parent)
{
rootItem = new DiveItem;
@@ -341,8 +377,8 @@ DiveTripModel::DiveTripModel(QObject *parent) : QAbstractItemModel(parent)
buffer = get_dive_date_string(&tm);
new DiveItem(d->number,
buffer,
- d->duration.seconds/60.0,
- d->maxdepth.mm/1000.0 ,
+ d->duration.seconds,
+ d->maxdepth.mm,
d->location,
rootItem);
free(buffer);
@@ -368,7 +404,17 @@ QVariant DiveTripModel::data(const QModelIndex &index, int role) const
DiveItem *item = static_cast<DiveItem*>(index.internalPointer());
QVariant retVal;
- if (role == Qt::DisplayRole){
+ if (role == Qt::TextAlignmentRole) {
+ switch (index.column()) {
+ case DURATION: /* fall through */
+ case DEPTH:
+ retVal = Qt::AlignRight;
+ break;
+ default:
+ retVal = Qt::AlignLeft;
+ }
+ }
+ if (role == Qt::DisplayRole) {
switch (index.column()) {
case NR:
retVal = item->diveNumber();
@@ -377,10 +423,12 @@ QVariant DiveTripModel::data(const QModelIndex &index, int role) const
retVal = item->diveDateTime();
break;
case DURATION:
- retVal = item->diveDuration();
+ retVal = item->displayDuration();
+ //retVal = item->diveDuration();
break;
case DEPTH:
- retVal = item->diveDepth();
+ retVal = item->displayDepth();
+ //retVal = item->diveDepth();
break;
case LOCATION:
retVal = item->diveLocation();
@@ -394,12 +442,11 @@ QVariant DiveTripModel::data(const QModelIndex &index, int role) const
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const
{
QVariant ret;
- if (orientation != Qt::Horizontal){
+ if (orientation != Qt::Horizontal)
return ret;
- }
if (role == Qt::DisplayRole) {
- switch(section){
+ switch(section) {
case NR:
ret = tr("#");
break;
@@ -407,19 +454,28 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int
ret = tr("Date");
break;
case RATING:
- ret = UTF8_BLACKSTAR;
+ ret = QString::fromUtf8(UTF8_BLACKSTAR);
break;
case DEPTH:
- ret = tr("ft");
+ if (get_units()->length == units::METERS)
+ ret = tr("m");
+ else
+ ret = tr("ft");
break;
case DURATION:
ret = tr("min");
break;
case TEMPERATURE:
- ret = UTF8_DEGREE "F";
+ if (get_units()->temperature == units::CELSIUS)
+ ret = QString("%1%2").arg(QString::fromUtf8(UTF8_DEGREE)).arg("C");
+ else
+ ret = QString("%1%2").arg(QString::fromUtf8(UTF8_DEGREE)).arg("F");
break;
case TOTALWEIGHT:
- ret = tr("lbs");
+ if (get_units()->weight == units::KG)
+ ret = tr("kg");
+ else
+ ret = tr("lbs");
break;
case SUIT:
ret = tr("Suit");
@@ -428,7 +484,7 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int
ret = tr("Cyl");
break;
case NITROX:
- ret = "O" UTF8_SUBSCRIPT_2 "%";
+ ret = QString("O%1%").arg(QString::fromUtf8(UTF8_SUBSCRIPT_2));
break;
case SAC:
ret = tr("SAC");
@@ -450,9 +506,8 @@ QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int
int DiveTripModel::rowCount(const QModelIndex &parent) const
{
/* only allow kids in column 0 */
- if (parent.isValid() && parent.column() > 0){
+ if (parent.isValid() && parent.column() > 0)
return 0;
- }
DiveItem *item = itemForIndex(parent);
return item ? item->children().count() : 0;
}
@@ -474,9 +529,8 @@ QModelIndex DiveTripModel::index(int row, int column, const QModelIndex &parent)
DiveItem *parentItem = itemForIndex(parent);
Q_ASSERT(parentItem);
- if (DiveItem *item = parentItem->children().at(row)){
+ if (DiveItem *item = parentItem->children().at(row))
return createIndex(row, column, item);
- }
return QModelIndex();
}