summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/divetripmodel.cpp33
-rw-r--r--qt-models/divetripmodel.h2
-rw-r--r--qt-models/mobilelistmodel.cpp2
-rw-r--r--qt-models/mobilelistmodel.h2
4 files changed, 36 insertions, 3 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index 7c6655ba8..1281ed84c 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -964,10 +964,19 @@ QVariant DiveTripModelTree::data(const QModelIndex &index, int role) const
const Item &item = items[index.row()];
return std::find(item.dives.begin(), item.dives.end(), current_dive) != item.dives.end();
}
- if (entry.trip)
+ if (entry.trip) {
return tripData(entry.trip, index.column(), role);
- else
+ } else if (entry.dive) {
+#if defined(SUBSURFACE_MOBILE)
+ if (role == MobileListModel::TripAbove)
+ return tripInDirection(entry.dive, +1);
+ if (role == MobileListModel::TripBelow)
+ return tripInDirection(entry.dive, -1);
+#endif
return diveData(entry.dive, index.column(), role);
+ } else {
+ return QVariant();
+ }
}
// After a trip changed, the top level might need to be reordered.
@@ -1136,6 +1145,26 @@ static QVector<dive *> visibleDives(const QVector<dive *> &dives)
return res;
}
+#ifdef SUBSURFACE_MOBILE
+int DiveTripModelTree::tripInDirection(const struct dive *d, int direction) const
+{
+ for (int i = 0; i < (int)items.size(); ++i) {
+ if (items[i].d_or_t.dive == d || (items[i].d_or_t.trip && findDiveInTrip(i, d) != -1)) {
+ // now walk in the direction given to find a trip
+ int offset = direction;
+ while (i + offset >= 0 && i + offset < (int)items.size()) {
+ if (items[i + offset].d_or_t.trip && (!d->divetrip || items[i + offset].d_or_t.trip->id != d->divetrip->id))
+ // we found a trip (and if the dive is already in a trip, we make sure this is a different trip)
+ return items[i + offset].d_or_t.trip->id;
+ offset += direction;
+ }
+ break;
+ }
+ }
+ return -1;
+}
+#endif
+
void DiveTripModelTree::divesAdded(dive_trip *trip, bool newTrip, const QVector<dive *> &divesIn)
{
QVector <dive *> dives = visibleDives(divesIn);
diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h
index c5def254a..49fc3ce69 100644
--- a/qt-models/divetripmodel.h
+++ b/qt-models/divetripmodel.h
@@ -77,7 +77,6 @@ public:
// Used for sorting. This is a bit of a layering violation, as sorting should be performed
// by the higher-up QSortFilterProxyModel, but it makes things so much easier!
virtual bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const = 0;
-
signals:
// The propagation of selection changes is complex.
// The control flow of dive-selection goes:
@@ -120,6 +119,7 @@ public slots:
public:
DiveTripModelTree(QObject *parent = nullptr);
+ int tripInDirection(const struct dive *d, int direction) const;
private:
int rowCount(const QModelIndex &parent) const override;
void clearData() override;
diff --git a/qt-models/mobilelistmodel.cpp b/qt-models/mobilelistmodel.cpp
index 75753b12a..cbb6871b6 100644
--- a/qt-models/mobilelistmodel.cpp
+++ b/qt-models/mobilelistmodel.cpp
@@ -47,6 +47,8 @@ QHash<int, QByteArray> MobileListModelBase::roleNames() const
roles[FirstGasRole] = "firstGas";
roles[SelectedRole] = "selected";
roles[DiveInTripRole] = "diveInTrip";
+ roles[TripAbove] = "tripAbove";
+ roles[TripBelow] = "tripBelow";
return roles;
}
diff --git a/qt-models/mobilelistmodel.h b/qt-models/mobilelistmodel.h
index 572a3b146..d00f26c62 100644
--- a/qt-models/mobilelistmodel.h
+++ b/qt-models/mobilelistmodel.h
@@ -55,6 +55,8 @@ public:
FirstGasRole,
SelectedRole,
DiveInTripRole,
+ TripAbove,
+ TripBelow,
};
QHash<int, QByteArray> roleNames() const override;
protected: