From 81c84d02edfa2d91153c8d52e16aa2db442c5264 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sat, 24 May 2014 21:03:18 -0700 Subject: Speed up the multi dive selection Dirk's code in commit a3d300ca919d ("Correctly implement multi dive selection") had a major flaw - it kept redrawing the selected dives one after another. Not what we need. So this fixes this up so that it doesn't take more than a sec to select all the dives that are on the same part of the click on the globe. I've achieved this by creating a boolean ' dontEmitDiveChanged and sending the signal only if this flag is false. The reason that we can't simply remove the emit from the selectionChanged is because the selectionChanged is what we have when we click on the diveList, if we removed this from there, nothing will happen upon selection. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/divelistview.cpp | 11 ++++++++--- qt-ui/divelistview.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index e505cfd0d..92e8dd506 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -28,7 +28,8 @@ #include #include "../qthelper.h" -DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false), sortColumn(0), currentOrder(Qt::DescendingOrder), searchBox(this) +DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false), sortColumn(0) + , currentOrder(Qt::DescendingOrder), searchBox(this), dontEmitDiveChangedSignal(false) { setItemDelegate(new DiveListDelegate(this)); setUniformRowHeights(true); @@ -241,6 +242,7 @@ void DiveListView::selectDives(const QList &newDiveSelection) if (!newDiveSelection.count()) return; + dontEmitDiveChangedSignal = true; // select the dives, highest index first - this way the oldest of the dives // becomes the selected_dive that we scroll to QList sortedSelection = newDiveSelection; @@ -254,6 +256,9 @@ void DiveListView::selectDives(const QList &newDiveSelection) scrollTo(idx.parent()); scrollTo(idx); + // now that everything is up to date, update the widgets + Q_EMIT currentDiveChanged(selected_dive); + dontEmitDiveChangedSignal = false; return; } @@ -454,8 +459,8 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS QTreeView::selectionChanged(selectionModel()->selection(), newDeselected); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection))); connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex))); - // now that everything is up to date, update the widgets - Q_EMIT currentDiveChanged(selected_dive); + if(!dontEmitDiveChangedSignal) + Q_EMIT currentDiveChanged(selected_dive); } static bool can_merge(const struct dive *a, const struct dive *b) diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index 7d577bcbf..23ca1cc42 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -64,6 +64,7 @@ private: DiveTripModel::Layout currentLayout; QLineEdit searchBox; QModelIndex contextMenuIndex; + bool dontEmitDiveChangedSignal; /* if dive_trip_t is null, there's no problem. */ QMultiHash selectedDives; -- cgit v1.2.3-70-g09d2