diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-12-02 17:15:40 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-12-02 11:40:39 -0800 |
commit | 7481746d91212dff97233245c77db78f54e25f24 (patch) | |
tree | 9bd03f8e10ab5dd0ea3a0b5fca584d9046592d8e /qt-ui | |
parent | 768cab66ccdf4e2619b7c143638e85dce43592e1 (diff) | |
download | subsurface-7481746d91212dff97233245c77db78f54e25f24.tar.gz |
Huge speedup when selecting Dives from the Globe View.
The old code ( slow++ ) ignored that each new dive-selection
we recreated all information on the profile window, so this
version ( a lot more verbose, I know. ) will ignore all dives
that are being selected and will only send the 'dive was selected'
information in the last line of the algorithm, instead of calling
it for each dive on the list of 'to be selected' dives.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/divelistview.cpp | 64 | ||||
-rw-r--r-- | qt-ui/divelistview.h | 1 | ||||
-rw-r--r-- | qt-ui/globe.cpp | 4 |
3 files changed, 68 insertions, 1 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 378c8ba83..af2ff12b8 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -210,6 +210,70 @@ void DiveListView::selectDive(int i, bool scrollto, bool toggle) if (scrollto) scrollTo(idx, PositionAtCenter); } + +void DiveListView::selectDives(const QList< int >& newDiveSelection) +{ + if(!newDiveSelection.count()) + return; + + disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), + this, SLOT(selectionChanged(QItemSelection,QItemSelection))); + disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), + this, SLOT(currentChanged(QModelIndex,QModelIndex))); + + setAnimated(false); + collapseAll(); + QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model()); + QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::Select | QItemSelectionModel::Rows; + + QItemSelection newDeselected = selectionModel()->selection(); + QModelIndexList diveList; + QModelIndexList tripList; + + int firstSelectedDive = -1; + /* context for temp. variables. */{ + int i = 0; + struct dive *dive; + for_each_dive(i, dive){ + dive->selected = newDiveSelection.contains(i) == true; + if(firstSelectedDive == -1 && dive->selected ){ + firstSelectedDive = i; + } + } + } + select_dive(firstSelectedDive); + Q_FOREACH(int i, newDiveSelection){ + diveList.append(m->match(m->index(0,0), DiveTripModel::DIVE_IDX, + i, 2, Qt::MatchRecursive).first()); + } + + Q_FOREACH(const QModelIndex& idx, diveList){ + selectionModel()->select(idx, flags); + if(idx.parent().isValid()){ + if(tripList.contains(idx.parent())) + continue; + tripList.append(idx.parent()); + } + } + + Q_FOREACH(const QModelIndex& idx, tripList){ + if(!isExpanded(idx)){ + expand(idx); + } + } + setAnimated(true); + + 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))); + + Q_EMIT currentDiveChanged(selected_dive); + const QModelIndex& idx = m->match(m->index(0,0), DiveTripModel::DIVE_IDX,selected_dive, 2, Qt::MatchRecursive).first(); + scrollTo(idx); +} + void DiveListView::showSearchEdit() { searchBox->show(); diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index aae89a40f..da7660e88 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -26,6 +26,7 @@ public: bool eventFilter(QObject* , QEvent* ); void unselectDives(); void selectDive(int dive_table_idx, bool scrollto = false, bool toggle = false); + void selectDives(const QList<int>& newDiveSelection); void rememberSelection(); void restoreSelection(); void contextMenuEvent(QContextMenuEvent *event); diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index c149bda74..c39723dc3 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -135,6 +135,7 @@ void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) bool clear = !(QApplication::keyboardModifiers() && Qt::ControlModifier); bool toggle = !clear; bool first = true; + QList<int> selectedDiveIds; for_each_dive(idx, dive) { long lat_diff, lon_diff; if (!dive_has_gps_location(dive)) @@ -152,9 +153,10 @@ void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit) mainWindow()->dive_list()->unselectDives(); clear = false; } - mainWindow()->dive_list()->selectDive(idx, first, toggle); + selectedDiveIds.push_back(idx); first = false; } + mainWindow()->dive_list()->selectDives(selectedDiveIds); } void GlobeGPS::repopulateLabels() |