Speed up the multi dive selection

Dirk's code in commit a3d300ca91 ("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 <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-05-24 21:03:18 -07:00 committed by Dirk Hohndel
parent a3d300ca91
commit 81c84d02ed
2 changed files with 9 additions and 3 deletions

View file

@ -28,7 +28,8 @@
#include <iostream> #include <iostream>
#include "../qthelper.h" #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)); setItemDelegate(new DiveListDelegate(this));
setUniformRowHeights(true); setUniformRowHeights(true);
@ -241,6 +242,7 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
if (!newDiveSelection.count()) if (!newDiveSelection.count())
return; return;
dontEmitDiveChangedSignal = true;
// select the dives, highest index first - this way the oldest of the dives // select the dives, highest index first - this way the oldest of the dives
// becomes the selected_dive that we scroll to // becomes the selected_dive that we scroll to
QList<int> sortedSelection = newDiveSelection; QList<int> sortedSelection = newDiveSelection;
@ -254,6 +256,9 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
scrollTo(idx.parent()); scrollTo(idx.parent());
scrollTo(idx); scrollTo(idx);
// now that everything is up to date, update the widgets
Q_EMIT currentDiveChanged(selected_dive);
dontEmitDiveChangedSignal = false;
return; return;
} }
@ -454,8 +459,8 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected); QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection))); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection)));
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex))); connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex)));
// now that everything is up to date, update the widgets if(!dontEmitDiveChangedSignal)
Q_EMIT currentDiveChanged(selected_dive); Q_EMIT currentDiveChanged(selected_dive);
} }
static bool can_merge(const struct dive *a, const struct dive *b) static bool can_merge(const struct dive *a, const struct dive *b)

View file

@ -64,6 +64,7 @@ private:
DiveTripModel::Layout currentLayout; DiveTripModel::Layout currentLayout;
QLineEdit searchBox; QLineEdit searchBox;
QModelIndex contextMenuIndex; QModelIndex contextMenuIndex;
bool dontEmitDiveChangedSignal;
/* if dive_trip_t is null, there's no problem. */ /* if dive_trip_t is null, there's no problem. */
QMultiHash<dive_trip_t *, int> selectedDives; QMultiHash<dive_trip_t *, int> selectedDives;