Mobile/filtering: add count of filtered dives to search bar

The count in the trip headers is still that for the complete trip and therefore
misleading.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2018-10-17 06:28:53 -04:00
parent 65aa6bc43b
commit 90d321f0ff
3 changed files with 37 additions and 8 deletions

View file

@ -366,15 +366,38 @@ Kirigami.ScrollablePage {
Component { Component {
id: filterHeader id: filterHeader
Controls.TextField { RowLayout {
id: sitefilter anchors.left: parent.left
visible: (opacity > 0) && rootItem.filterToggle anchors.right: parent.right
text: "" visible: rootItem.filterToggle
placeholderText: "Dive site name" height: rootItem.filterToggle ? sitefilter.implicitHeight * 1.1 : 0
onTextChanged: { Rectangle {
rootItem.filterPattern = text width: Kirigami.Units.gridUnit / 4
diveModel.setFilter(text)
} }
onVisibleChanged: numShown.text = diveModel.shown()
Controls.TextField {
id: sitefilter
verticalAlignment: TextInput.AlignVCenter
text: ""
placeholderText: "Full text search"
onTextChanged: {
rootItem.filterPattern = text
diveModel.setFilter(text)
numShown.text = diveModel.shown()
}
}
Controls.Label {
id: numShown
verticalAlignment: Text.AlignVCenter
// when this is first rendered, the model is still empty, so
// instead of having a misleading 0 here, just don't show a count
// it gets set whenever visibility or the search text changes
text: ""
}
Rectangle {
width: Kirigami.Units.regularSpacing
}
} }
} }

View file

@ -20,6 +20,11 @@ void DiveListSortModel::resetFilter()
setFilterRegExp(""); setFilterRegExp("");
} }
int DiveListSortModel::shown()
{
return rowCount();
}
int DiveListSortModel::getDiveId(int idx) int DiveListSortModel::getDiveId(int idx)
{ {
DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel()); DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());

View file

@ -19,6 +19,7 @@ public slots:
int getIdxForId(int id); int getIdxForId(int id);
void setFilter(QString f); void setFilter(QString f);
void resetFilter(); void resetFilter();
int shown();
}; };
class DiveListModel : public QAbstractListModel class DiveListModel : public QAbstractListModel