map: call set_selection() core function to select dives

The map widget called the dive list to select dives. This is
inconsistent and complex. The dive list has to call down to
the core anyway. Therefore, change the code to call the common
core function.

This means that we have to transform integer ids into dive-pointers.
That is a bit sad, because the dives were just transformed into
indices. Let's address that in a future commit.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-04-25 20:54:12 +02:00 committed by Dirk Hohndel
parent eccbf01a22
commit 75ef8b68a1

View file

@ -6,11 +6,10 @@
#include "mapwidget.h"
#include "core/divesite.h"
#include "core/selection.h"
#include "map-widget/qmlmapwidgethelper.h"
#include "qt-models/maplocationmodel.h"
#include "qt-models/divelocationmodel.h"
#include "mainwindow.h"
#include "divelistview.h"
#include "commands/command.h"
static const QUrl urlMapWidget = QUrl(QStringLiteral("qrc:/qml/MapWidget.qml"));
@ -94,7 +93,15 @@ void MapWidget::selectionChanged()
void MapWidget::selectedDivesChanged(const QList<int> &list)
{
CHECK_IS_READY_RETURN_VOID();
MainWindow::instance()->diveList->selectDives(list);
// We get a list of dive indices, but the selection code wants a list of dives.
// Therefore, transform them here.
std::vector<dive *> selection;
selection.reserve(list.size());
for (int idx: list) {
if (dive *d = get_dive(idx))
selection.push_back(d);
}
setSelection(selection, current_dive);
}
void MapWidget::coordinatesChanged(struct dive_site *ds, const location_t &location)