mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <dirk@hohndel.org>
This commit is contained in:
parent
c6140c6e21
commit
be418458db
4 changed files with 30 additions and 9 deletions
18
divelist.c
18
divelist.c
|
@ -25,7 +25,7 @@
|
|||
* void clear_trip_indexes(void)
|
||||
* void delete_single_dive(int idx)
|
||||
* void add_single_dive(int idx, struct dive *dive)
|
||||
* void merge_dive_index(int i, struct dive *a)
|
||||
* void merge_two_dives(struct dive *a, struct dive *b)
|
||||
* void select_dive(int idx)
|
||||
* void deselect_dive(int idx)
|
||||
* void mark_divelist_changed(int changed)
|
||||
|
@ -916,22 +916,24 @@ void add_single_dive(int idx, struct dive *dive)
|
|||
}
|
||||
}
|
||||
|
||||
void merge_dive_index(int i, struct dive *a)
|
||||
struct dive *merge_two_dives(struct dive *a, struct dive *b)
|
||||
{
|
||||
struct dive *b = get_dive(i+1);
|
||||
struct dive *res;
|
||||
int i,j;
|
||||
|
||||
if (!a || !b)
|
||||
return NULL;
|
||||
i = get_index_for_dive(a);
|
||||
j = get_index_for_dive(b);
|
||||
res = merge_dives(a, b, b->when - a->when, FALSE);
|
||||
if (!res)
|
||||
return;
|
||||
return NULL;
|
||||
|
||||
add_single_dive(i, res);
|
||||
delete_single_dive(i+1);
|
||||
delete_single_dive(i+1);
|
||||
#if USE_GTK_UI
|
||||
dive_list_update_dives();
|
||||
#endif
|
||||
delete_single_dive(j);
|
||||
mark_divelist_changed(TRUE);
|
||||
return res;
|
||||
}
|
||||
|
||||
void select_dive(int idx)
|
||||
|
|
|
@ -43,7 +43,7 @@ extern dive_trip_t *find_matching_trip(timestamp_t when);
|
|||
extern void remove_dive_from_trip(struct dive *dive);
|
||||
extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive);
|
||||
extern void autogroup_dives(void);
|
||||
extern void merge_dive_index(int i, struct dive *a);
|
||||
extern struct dive *merge_two_dives(struct dive *a, struct dive *b);
|
||||
extern void select_dive(int idx);
|
||||
extern void deselect_dive(int idx);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -42,6 +42,7 @@ public slots:
|
|||
void fixMessyQtModelBehaviour();
|
||||
void mergeTripAbove();
|
||||
void mergeTripBelow();
|
||||
void mergeDives();
|
||||
|
||||
signals:
|
||||
void currentDiveChanged(int divenr);
|
||||
|
|
Loading…
Add table
Reference in a new issue