summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/divelistview.cpp22
-rw-r--r--desktop-widgets/divelistview.h2
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp3
3 files changed, 15 insertions, 12 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index 3e26ca125..f95afee25 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -265,8 +265,7 @@ void DiveListView::tripChanged(dive_trip *trip, TripField)
{
// First check if the trip is already selected (and only
// this trip, as only then is it displayed). Is so, then do nothing.
- QList<dive_trip *> selected = selectedTrips();
- if (selected.size() == 1 && selected[0] == trip)
+ if (singleSelectedTrip() == trip)
return;
unselectDives();
@@ -309,16 +308,21 @@ void DiveListView::unselectDives()
}
}
-QList<dive_trip_t *> DiveListView::selectedTrips()
+// This function returns a trip if there is one selected trip or NULL.
+// Returning all selected trips turned out to be too slow.
+dive_trip_t *DiveListView::singleSelectedTrip()
{
- QList<dive_trip_t *> ret;
- Q_FOREACH (const QModelIndex &index, selectionModel()->selectedRows()) {
- dive_trip_t *trip = index.data(DiveTripModelBase::TRIP_ROLE).value<dive_trip *>();
- if (!trip)
+ dive_trip_t *res = nullptr;
+ for (const QModelIndex &index: selectionModel()->selectedRows()) {
+ if (index.parent().isValid())
continue;
- ret.push_back(trip);
+ if (dive_trip_t *trip = index.data(DiveTripModelBase::TRIP_ROLE).value<dive_trip *>()) {
+ if (res)
+ return nullptr; // More than one
+ res = trip;
+ }
}
- return ret;
+ return res;
}
bool DiveListView::eventFilter(QObject *, QEvent *event)
diff --git a/desktop-widgets/divelistview.h b/desktop-widgets/divelistview.h
index 502d0905e..2e15b9064 100644
--- a/desktop-widgets/divelistview.h
+++ b/desktop-widgets/divelistview.h
@@ -25,7 +25,7 @@ public:
~DiveListView();
void setSortOrder(int i, Qt::SortOrder order); // Call to set sort order
void reload(); // Call to reload model data
- QList<dive_trip *> selectedTrips();
+ dive_trip *singleSelectedTrip();
static QString lastUsedImageDir();
static void updateLastUsedImageDir(const QString &s);
void loadImages();
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 7fde2e1b6..ab8b5fbf3 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -365,8 +365,7 @@ void MainTab::updateDiveInfo()
// 2) the filter is reset, potentially erasing the current trip under our feet.
// TODO: Don't hard code tab location!
bool onDiveSiteTab = ui.tabWidget->currentIndex() == 6;
- if (MainWindow::instance() && MainWindow::instance()->diveList->selectedTrips().count() == 1) {
- currentTrip = MainWindow::instance()->diveList->selectedTrips().front();
+ if (dive_trip *currentTrip = MainWindow::instance()->diveList->singleSelectedTrip()) {
// Remember the tab selected for last dive but only if we're not on the dive site tab
if (lastSelectedDive && !onDiveSiteTab)
lastTabSelectedDive = ui.tabWidget->currentIndex();