From 09c0d7a6f537d83068878c39f18f36f9dcb18d7f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 15 Apr 2019 22:16:33 +0200 Subject: Desktop: enable sorting in dive site selection widget The dive site selection widget implements a lessThan() function, but that was never called. Apparently in a QListView one has to start sorting by hand? Do just that. In any case, the lessThan function was erroneous as it would happily sort away the first two special entries. Fix it with a special case for these to. Finally use case insensitive string comparison. Signed-off-by: Berthold Stoeger --- desktop-widgets/locationinformation.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index a4ec0baac..dfceb8cd1 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -262,6 +262,7 @@ void DiveLocationFilterProxyModel::setFilter(const QString &filterIn) { filter = filterIn; invalidate(); + sort(LocationInformationModel::NAME); } bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex&) const @@ -275,7 +276,10 @@ bool DiveLocationFilterProxyModel::filterAcceptsRow(int source_row, const QModel bool DiveLocationFilterProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { - return source_left.data().toString() < source_right.data().toString(); + // The first two entries are special - we never want to change their order + if (source_left.row() <= 1 || source_right.row() <= 1) + return source_left.row() < source_right.row(); + return source_left.data().toString().compare(source_right.data().toString(), Qt::CaseInsensitive) < 0; } DiveLocationModel::DiveLocationModel(QObject *) @@ -367,7 +371,7 @@ DiveLocationLineEdit::DiveLocationLineEdit(QWidget *parent) : QLineEdit(parent), connect(view, &DiveLocationListView::currentIndexChanged, this, &DiveLocationLineEdit::currentChanged); } -bool DiveLocationLineEdit::eventFilter(QObject*, QEvent *e) +bool DiveLocationLineEdit::eventFilter(QObject *, QEvent *e) { if (e->type() == QEvent::KeyPress) { QKeyEvent *keyEv = (QKeyEvent *)e; @@ -553,6 +557,7 @@ void DiveLocationLineEdit::showPopup() if (!view->isVisible()) { setTemporaryDiveSiteName(text()); proxy->invalidate(); + proxy->sort(LocationInformationModel::NAME); view->show(); } } -- cgit v1.2.3-70-g09d2