Dirk, please add your SOB, I'v added mine because I also fixed stuff, but it mostly your code.
On Sat, May 24, 2014 at 10:32 PM, Tomaz Canabrava <[email protected]> wrote: > On Sat, May 24, 2014 at 10:09 PM, Dirk Hohndel <[email protected]> wrote: >> On Sat, May 24, 2014 at 10:02:44PM -0300, Tomaz Canabrava wrote: >>> the disconnect && reconnect at the bottom does that. >>> if you remove my code completely and just keep the connects and >>> disconnects there things works? >> >> No they don't. They disconnect our logic that keeps the selection >> consistent. What I need to stop doing is the >> Q_EMIT currentDiveChanged(selected_dive); >> at the end of selectionChanged() and instead do it at the end of >> selectDives(). That way we avoid all the unneccessary redraws. >> >> /D >> >>> On Sat, May 24, 2014 at 9:59 PM, Dirk Hohndel <[email protected]> wrote: >>> > On May 24, 2014 5:48:47 PM Tomaz Canabrava <[email protected]> wrote: >>> > >>> >> >>> >> Each selectDive call will trigger a replot of the dive in the profile, >>> >> so if you click on a point that has like 10 dives, it will plot those >>> >> 10 dives. that's why I disconnected the selectionModel and reconnected >>> >> afterwards, to make it only show the last selected dive on the >>> >> profile. >>> > >>> > >>> > OK, that at least explains it. But this is too broken for words. I'll >>> > instead figure out a way to not trigger a redraw. > > Hm... that could work. > testing here. > >>> > /D >>> > >>> > >>> >
From 9ae9d779b623eff16d6783c36c61b10e1947f614 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Sat, 24 May 2014 23:06:43 -0300 Subject: [PATCH] Reworked the massively stupid old way to keep selection in sync This is mostly dirk's code that he asked for help so, please: insert your commit message here. :) Tomaz's part: make sure it doesn't takes more than a sec to select all the dives that are on the same part of the click on the globe. I'v 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 <[email protected]> --- qt-ui/divelistview.cpp | 63 ++++++++++++++------------------------------------ qt-ui/divelistview.h | 1 + 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 49877dc..bd34d47 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -28,7 +28,8 @@ #include <iostream> #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); @@ -236,54 +237,24 @@ 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))); + dontEmitDiveChangedSignal = true; + // select the dives, highest index first - this way the oldest of the dives + // becomes the selected_dive that we scroll to + QList<int> sortedSelection = newDiveSelection; + qSort(sortedSelection.begin(), sortedSelection.end()); + while (!sortedSelection.isEmpty()) + selectDive(sortedSelection.takeLast()); - setAnimated(false); - collapseAll(); QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model()); - QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::Select | QItemSelectionModel::Rows; - - QItemSelection newDeselected = selectionModel()->selection(); - QModelIndexList diveList; - - //TODO: This should be called find_first_selected_dive and be ported to C code. - 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; - break; - } - } - } - 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() && !isExpanded(idx.parent())) { - expand(idx.parent()); - } - } - 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); QModelIndex idx = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive).first(); if (idx.parent().isValid()) - scrollTo(idx.parent()); + scrollTo(idx.parent()); scrollTo(idx); + + // now that everything is up to date, update the widgets + Q_EMIT currentDiveChanged(selected_dive); + dontEmitDiveChangedSignal = false; + return; } void DiveListView::showSearchEdit() @@ -496,8 +467,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 7d577bc..23ca1cc 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<dive_trip_t *, int> selectedDives; -- 1.9.3
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
