aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--divelist.c38
-rw-r--r--divelist.h5
-rw-r--r--qt-ui/divelistview.cpp24
3 files changed, 52 insertions, 15 deletions
diff --git a/divelist.c b/divelist.c
index 1daf0f5ac..a3207b02c 100644
--- a/divelist.c
+++ b/divelist.c
@@ -578,6 +578,44 @@ void find_new_trip_start_time(dive_trip_t *trip)
trip->when = when;
}
+/* check if we have a trip right before / after this dive */
+bool is_trip_before_after(struct dive *dive, bool before)
+{
+ int idx = get_idx_by_uniq_id(dive->id);
+ if (before) {
+ if (idx > 0 && get_dive(idx - 1)->divetrip)
+ return true;
+ } else {
+ if (idx < dive_table.nr - 1 && get_dive(idx + 1)->divetrip)
+ return true;
+ }
+ return false;
+}
+
+struct dive *first_selected_dive()
+{
+ int idx;
+ struct dive *d;
+
+ for_each_dive (idx, d) {
+ if (d->selected)
+ return d;
+ }
+ return NULL;
+}
+
+struct dive *last_selected_dive()
+{
+ int idx;
+ struct dive *d, *ret = NULL;
+
+ for_each_dive (idx, d) {
+ if (d->selected)
+ ret = d;
+ }
+ return ret;
+}
+
void remove_dive_from_trip(struct dive *dive, short was_autogen)
{
struct dive *next, **pprev;
diff --git a/divelist.h b/divelist.h
index ade4ce9a6..57f62fa11 100644
--- a/divelist.h
+++ b/divelist.h
@@ -30,7 +30,10 @@ extern struct dive *merge_two_dives(struct dive *a, struct dive *b);
extern bool consecutive_selected();
extern void select_dive(int idx);
extern void deselect_dive(int idx);
-void find_new_trip_start_time(dive_trip_t *trip);
+extern void find_new_trip_start_time(dive_trip_t *trip);
+extern struct dive *first_selected_dive();
+extern struct dive *last_selected_dive();
+extern bool is_trip_before_after(struct dive *dive, bool before);
#ifdef DEBUG_TRIP
extern void dump_selection(void);
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index ebad73b09..49877dc71 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -634,18 +634,10 @@ void DiveListView::addToTrip(bool below)
if (d->selected) { // we are right-clicking on one of possibly many selected dive(s)
// find the top selected dive, depending on the list order
- if (delta == 1) {
- for_each_dive (idx, d) {
- if (d->selected)
- pd = d;
- }
- d = pd; // this way we have the chronologically last
- } else {
- for_each_dive (idx, d) {
- if (d->selected)
- break; // now that's the chronologically first
- }
- }
+ if (delta == 1)
+ d = last_selected_dive();
+ else
+ d = first_selected_dive();
}
// now find the trip "above" in the dive list
if ((pd = get_dive(get_divenr(d) + delta)) != NULL) {
@@ -757,8 +749,12 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
if (d) {
popup.addAction(tr("remove dive(s) from trip"), this, SLOT(removeFromTrip()));
popup.addAction(tr("create new trip above"), this, SLOT(newTripAbove()));
- popup.addAction(tr("add dive(s) to trip immediately above"), this, SLOT(addToTripAbove()));
- popup.addAction(tr("add dive(s) to trip immediately below"), this, SLOT(addToTripBelow()));
+ if (!d->divetrip) {
+ if (is_trip_before_after(d, (currentOrder == Qt::AscendingOrder)))
+ popup.addAction(tr("add dive(s) to trip immediately above"), this, SLOT(addToTripAbove()));
+ if (is_trip_before_after(d, (currentOrder == Qt::DescendingOrder)))
+ popup.addAction(tr("add dive(s) to trip immediately below"), this, SLOT(addToTripBelow()));
+ }
}
if (trip) {
popup.addAction(tr("merge trip with trip above"), this, SLOT(mergeTripAbove()));