From 2021035cfcee08ec4c6f9d16683db8ce400bef30 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 26 Apr 2020 22:05:28 +0200 Subject: selection: replace selectedTrips() by singleSelectedTrip() function To check wether the tab widgets should show the trip view, they called the selectedTrips() function. The trip view was shown if that contained only one trip. However, the selectedTrips() function was very slow, because it has to query to core models. Change the function to singleSelectedTrip(), which returns a trip if there is exactly one trip selected. The function returns early if there is more than one trip selected. This makes the select-all case much faster. There are two cases which are still very slow: - List mode, because here all top-level items are queried. - Dive log with many only top-level items. Ultimately, we will have to cache the trip selection because querying the model is too slow. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/maintab.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'desktop-widgets/tab-widgets') 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(); -- cgit v1.2.3-70-g09d2