summaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r--qt-ui/models.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index b981793fb..4debafd9a 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -1010,6 +1010,7 @@ static int nitrox_sort_value(struct dive *dive)
QVariant DiveItem::data(int column, int role) const
{
QVariant retVal;
+ struct dive *dive = getDiveById(diveId);
switch (role) {
case Qt::TextAlignmentRole:
@@ -1025,6 +1026,7 @@ QVariant DiveItem::data(int column, int role) const
}
break;
case DiveTripModel::SORT_ROLE:
+ Q_ASSERT(dive != NULL);
switch (column) {
case NR: retVal = (qulonglong) dive->when; break;
case DATE: retVal = (qulonglong) dive->when; break;
@@ -1043,6 +1045,7 @@ QVariant DiveItem::data(int column, int role) const
}
break;
case Qt::DisplayRole:
+ Q_ASSERT(dive != NULL);
switch (column) {
case NR: retVal = dive->number; break;
case DATE: retVal = displayDate(); break;
@@ -1061,13 +1064,15 @@ QVariant DiveItem::data(int column, int role) const
break;
}
- if (role == DiveTripModel::STAR_ROLE)
+ if (role == DiveTripModel::STAR_ROLE) {
+ Q_ASSERT(dive != NULL);
retVal = dive->rating;
-
- if (role == DiveTripModel::DIVE_ROLE)
+ }
+ if (role == DiveTripModel::DIVE_ROLE) {
retVal = QVariant::fromValue<void*>(dive);
-
+ }
if(role == DiveTripModel::DIVE_IDX){
+ Q_ASSERT(dive != NULL);
retVal = get_divenr(dive);
}
return retVal;
@@ -1098,21 +1103,26 @@ bool DiveItem::setData(const QModelIndex& index, const QVariant& value, int role
if (d->number == v)
return false;
}
-
- dive->number = value.toInt();
+ d = getDiveById(diveId);
+ Q_ASSERT(d != NULL);
+ d->number = value.toInt();
mark_divelist_changed(TRUE);
return true;
}
QString DiveItem::displayDate() const
{
+ struct dive *dive = getDiveById(diveId);
+ Q_ASSERT(dive != NULL);
return get_dive_date_string(dive->when);
}
QString DiveItem::displayDepth() const
{
- const int scale = 1000;
QString fract, str;
+ const int scale = 1000;
+ struct dive *dive = getDiveById(diveId);
+ Q_ASSERT(dive != NULL);
if (get_units()->length == units::METERS) {
fract = QString::number((unsigned)(dive->maxdepth.mm % scale) / 100);
str = QString("%1.%2").arg((unsigned)(dive->maxdepth.mm / scale)).arg(fract, 1, QChar('0'));
@@ -1126,6 +1136,8 @@ QString DiveItem::displayDepth() const
QString DiveItem::displayDuration() const
{
int hrs, mins, secs;
+ struct dive *dive = getDiveById(diveId);
+ Q_ASSERT(dive != NULL);
secs = dive->duration.seconds % 60;
mins = dive->duration.seconds / 60;
hrs = mins / 60;
@@ -1143,6 +1155,8 @@ QString DiveItem::displayDuration() const
QString DiveItem::displayTemperature() const
{
QString str;
+ struct dive *dive = getDiveById(diveId);
+ Q_ASSERT(dive != NULL);
if (!dive->watertemp.mkelvin)
return str;
if (get_units()->temperature == units::CELSIUS)
@@ -1155,6 +1169,8 @@ QString DiveItem::displayTemperature() const
QString DiveItem::displaySac() const
{
QString str;
+ struct dive *dive = getDiveById(diveId);
+ Q_ASSERT(dive != NULL);
if (get_units()->volume == units::LITER)
str = QString::number(dive->sac / 1000.0, 'f', 1).append(tr(" l/min"));
else
@@ -1170,6 +1186,8 @@ QString DiveItem::displayWeight() const
int DiveItem::weight() const
{
+ struct dive *dive = getDiveById(diveId);
+ Q_ASSERT(dive != 0);
weight_t tw = { total_weight(dive) };
return tw.grams;
}
@@ -1237,7 +1255,7 @@ void DiveTripModel::setupModelData()
dive_trip_t* trip = dive->divetrip;
DiveItem* diveItem = new DiveItem();
- diveItem->dive = dive;
+ diveItem->diveId = dive->id;
if (!trip || currentLayout == LIST) {
diveItem->parent = rootItem;
@@ -1644,7 +1662,7 @@ ProfilePrintModel::ProfilePrintModel(QObject *parent)
void ProfilePrintModel::setDive(struct dive *divePtr)
{
- dive = divePtr;
+ diveId = divePtr->id;
// reset();
}
@@ -1665,8 +1683,10 @@ QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
switch (role) {
case Qt::DisplayRole: {
+ struct dive *dive = getDiveById(diveId);
+ Q_ASSERT(dive != NULL);
struct DiveItem di;
- di.dive = dive;
+ di.diveId = diveId;
const QString unknown = tr("unknown");