From be418458dbf4299ef289b2790ac36e3efa3b5261 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 23 Sep 2013 21:57:28 -0700 Subject: Add "merge selected dives" to dive list popup menu This is fairly straight forward. What I dislike is the check for the magic number of "14 indeces". I'm sure there's a better way to tell if more than one dive is selected... Signed-off-by: Dirk Hohndel --- qt-ui/divelistview.cpp | 18 ++++++++++++++++++ qt-ui/divelistview.h | 1 + 2 files changed, 19 insertions(+) (limited to 'qt-ui') diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 639e988fd..a1436bf2d 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -290,6 +290,22 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS Q_EMIT currentDiveChanged(selected_dive); } +void DiveListView::mergeDives() +{ + int i; + struct dive *dive, *maindive = NULL; + + for_each_dive(i, dive) { + if (dive->selected) { + if (!maindive) + maindive = dive; + else + maindive = merge_two_dives(maindive, dive); + } + } + mainWindow()->refreshDisplay(); +} + void DiveListView::merge_trip(const QModelIndex &a, int offset) { int i = a.row() + offset; @@ -384,6 +400,8 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event) } if (d) popup.addAction(tr("delete dive"), this, SLOT(deleteDive())); + if (selectionModel()->selection().indexes().count() > 14) + popup.addAction(tr("merge selected dives"), this, SLOT(mergeDives())); // "collapse all" really closes all trips, // "collapse" keeps the trip with the selected dive open QAction * actionTaken = popup.exec(event->globalPos()); diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index 1faa3613a..1287349f4 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -42,6 +42,7 @@ public slots: void fixMessyQtModelBehaviour(); void mergeTripAbove(); void mergeTripBelow(); + void mergeDives(); signals: void currentDiveChanged(int divenr); -- cgit v1.2.3-70-g09d2