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>
This commit is contained in:
Berthold Stoeger 2019-04-15 22:16:33 +02:00 committed by Dirk Hohndel
parent 5b270dd895
commit 09c0d7a6f5

View file

@ -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();
}
}