diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-11-17 15:36:57 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-17 15:36:57 -0800 |
commit | a2d6bd5c1df74734ec43a58cda120587ef28a0bd (patch) | |
tree | 155919ea5249ad7b30eed9e5d03d32acb926c8a8 /qt-ui/divelistview.cpp | |
parent | 7a6ff7a53cc23c2129fb5f4d4046acf71404b087 (diff) | |
download | subsurface-a2d6bd5c1df74734ec43a58cda120587ef28a0bd.tar.gz |
Add "add dive(s) to trip above" feature
This honors the sort order of the dive list when figuring which trip is
"above". It works both on a single dive or all selected dives.
This also fixes a couple other cases where the dive list selection and
trip display could get messed up.
Fixes #287
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r-- | qt-ui/divelistview.cpp | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index b0045b765..95f85d604 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -464,8 +464,11 @@ void DiveListView::removeFromTrip() if (d->selected) remove_dive_from_trip(d); } - mark_divelist_changed(TRUE); + rememberSelection(); reload(currentLayout, false); + fixMessyQtModelBehaviour(); + restoreSelection(); + mark_divelist_changed(TRUE); } void DiveListView::newTripAbove() @@ -482,9 +485,55 @@ void DiveListView::newTripAbove() add_dive_to_trip(d, trip); } trip->expanded = 1; + reload(currentLayout, false); + fixMessyQtModelBehaviour(); + mark_divelist_changed(TRUE); + restoreSelection(); +} + +void DiveListView::addToTripAbove() +{ + int idx, delta = (currentOrder == Qt::AscendingOrder) ? -1 : +1; + dive_trip_t *trip = NULL; + struct dive *pd; + struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>(); + if (!d) // shouldn't happen as we only are setting up this action if this is a dive + return; + rememberSelection(); + 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 + } + } + } + // now find the trip "above" in the dive list + if ((pd = get_dive(get_divenr(d) + delta)) != NULL) { + trip = pd->divetrip; + } + if (!pd || !trip) + // previous dive wasn't in a trip, so something is wrong + return; + add_dive_to_trip(d, trip); + if (d->selected) { // there are possibly other selected dives that we should add + for_each_dive(idx, d) { + if (d->selected) + add_dive_to_trip(d, trip); + } + } + trip->expanded = 1; mark_divelist_changed(TRUE); reload(currentLayout, false); restoreSelection(); + fixMessyQtModelBehaviour(); } void DiveListView::deleteDive() @@ -518,6 +567,7 @@ void DiveListView::deleteDive() selectDive(lastDiveNr); rememberSelection(); } + fixMessyQtModelBehaviour(); } void DiveListView::testSlot() @@ -550,6 +600,7 @@ 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 immideately above"), this, SLOT(addToTripAbove())); } if (trip) { popup.addAction(tr("merge trip with trip above"), this, SLOT(mergeTripAbove())); |