Desktop: Add mergeing into the selected dive site.

When editing a dive site in the 'Dive sites' view, add a context menu
entry to allow mergeing of the displayed dive site into the dive site
seleted in the 'Near dive sites' list.
This merge has the opposite direction of the existing 'Merge into
current site' function, which can simplify the workflow when maintaining
a large number of dive sites, as the facilities to sort dive sites in
the 'Dive sites' view does not have a way to sort by location or
proximity.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2023-04-22 00:18:32 +12:00 committed by bstoeger
parent 84d9d0abe7
commit 2aa13ea9d7
4 changed files with 25 additions and 0 deletions

View file

@ -64,6 +64,9 @@ bool LocationInformationWidget::eventFilter(QObject *, QEvent *ev)
QContextMenuEvent *ctx = (QContextMenuEvent *)ev;
QMenu contextMenu;
contextMenu.addAction(tr("Merge into current site"), this, &LocationInformationWidget::mergeSelectedDiveSites);
const QModelIndexList selection = ui.diveSiteListView->selectionModel()->selectedIndexes();
if (selection.count() == 1)
contextMenu.addAction(tr("Merge current site into this site"), this, &LocationInformationWidget::mergeIntoSelectedDiveSite);
contextMenu.exec(ctx->globalPos());
return true;
}
@ -91,6 +94,24 @@ void LocationInformationWidget::mergeSelectedDiveSites()
Command::mergeDiveSites(diveSite, selected_dive_sites);
}
void LocationInformationWidget::mergeIntoSelectedDiveSite()
{
if (!diveSite)
return;
const QModelIndexList selection = ui.diveSiteListView->selectionModel()->selectedIndexes();
if (selection.count() != 1)
return;
dive_site *selected_dive_site = selection[0].data(LocationInformationModel::DIVESITE_ROLE).value<dive_site *>();
if (!selected_dive_site)
return;
QVector<dive_site *> dive_sites;
dive_sites.push_back(diveSite);
Command::mergeDiveSites(selected_dive_site, dive_sites);
}
// If we can't parse the coordinates, inform the user with a visual clue
void LocationInformationWidget::coordinatesSetWarning(bool warn)
{