request for comment

Tomaz Canabrava tcanabrava at kde.org
Sat May 24 17:48:42 PDT 2014


On Sat, May 24, 2014 at 7:05 PM, Dirk Hohndel <dirk at hohndel.org> wrote:
>
> I'm trying to figure out why the entirely broken code is SelectDives is
> there. Here's how I would implement this - with the added advantage that
> my code actually appears to work and to do what it appears the function is
> intended to do...
>
> The existing dive messes up our selection correlation, it always unselects
> all other dives (which it is not supposed to do if you look at the only
> caller of this code in globe.cpp) and is all in all ugly as hell.
>
> Comments? Tomaz? You wrote that...
>
> /D
>
>
> diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
> index 77a51343b7ce..97fa966c013d 100644
> --- a/qt-ui/divelistview.cpp
> +++ b/qt-ui/divelistview.cpp
> @@ -241,6 +241,21 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
>         if (!newDiveSelection.count())
>                 return;
>
> +       // 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());
> +
> +       QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model());
> +       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);
> +
> +       return;
> +#if 0
>         disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
>                    this, SLOT(selectionChanged(QItemSelection, QItemSelection)));
>         disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)),
> @@ -289,6 +304,7 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
>         if (idx.parent().isValid())
>                 scrollTo(idx.parent());
>         scrollTo(idx);
> +#endif
>  }
>
>  void DiveListView::showSearchEdit()

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.


More information about the subsurface mailing list