Dive sites: select each dive site only once

After selecting dives, the selected dive sites are collected.
This was done using the selectionModel()->selection().indexes(),
which is wrong, because it gives one index per row *and* column.
Accordingly, every dive site was added numerous times to the
array of dive sites to be selected. Change this to
selectionModel()->selectedRows(), which gives one entry per row.

Moreover, if multiple dives with the same site were selected,
this site was also added to the array multiple times. Therefore,
check the array before adding sites.

Note that all this should not change the user experience in
any way, it is only a code-hygiene thing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-02-03 11:51:25 +01:00 committed by Dirk Hohndel
parent 65df9ca7b0
commit 670a5bd55a

View file

@ -555,10 +555,10 @@ void DiveListView::selectionChangeDone()
// by the selected dives.
if (!DiveFilter::instance()->diveSiteMode()) {
QVector<dive_site *> selectedSites;
for (QModelIndex index: selectionModel()->selection().indexes()) {
for (QModelIndex index: selectionModel()->selectedRows()) {
const QAbstractItemModel *model = index.model();
struct dive *dive = model->data(index, DiveTripModelBase::DIVE_ROLE).value<struct dive *>();
if (dive && dive->dive_site)
if (dive && dive->dive_site && !selectedSites.contains(dive->dive_site))
selectedSites.push_back(dive->dive_site);
}
MapWidget::instance()->setSelected(selectedSites);