aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-04-15 22:16:33 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-16 23:46:19 +1200
commit09c0d7a6f537d83068878c39f18f36f9dcb18d7f (patch)
treebd0a2ccb44b9e09424aa2ca7d58f4aa60eab3771 /desktop-widgets
parent5b270dd895a57942981a4bb9a3b0993d04f1049f (diff)
downloadsubsurface-09c0d7a6f537d83068878c39f18f36f9dcb18d7f.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/locationinformation.cpp9
1 files changed, 7 insertions, 2 deletions
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();
}
}