mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Mobile/filtering: first attempt to filter on dive site
[Dirk Hohndel: this is the starting point of my following commits, I decided to leave it in place to give Jan credit for the work he did on figuring out some of the plumbing needed to get things to work] Signed-off-by: Jan Mulder <jlmulder@xs4all.nl> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f1bb2c8478
commit
0bc0b6bfe8
4 changed files with 52 additions and 1 deletions
|
@ -336,6 +336,7 @@ Kirigami.ScrollablePage {
|
||||||
prefs.credentialStatus === CloudStatus.CS_NOCLOUD) {
|
prefs.credentialStatus === CloudStatus.CS_NOCLOUD) {
|
||||||
page.actions.main = page.downloadFromDCAction
|
page.actions.main = page.downloadFromDCAction
|
||||||
page.actions.right = page.addDiveAction
|
page.actions.right = page.addDiveAction
|
||||||
|
page.actions.left = page.filterToggleAction
|
||||||
page.title = qsTr("Dive list")
|
page.title = qsTr("Dive list")
|
||||||
if (diveListView.count === 0)
|
if (diveListView.count === 0)
|
||||||
showPassiveNotification(qsTr("Please tap the '+' button to add a dive (or download dives from a supported dive computer)"), 3000)
|
showPassiveNotification(qsTr("Please tap the '+' button to add a dive (or download dives from a supported dive computer)"), 3000)
|
||||||
|
@ -363,6 +364,20 @@ Kirigami.ScrollablePage {
|
||||||
visible: diveListView.visible && diveListView.count === 0
|
visible: diveListView.visible && diveListView.count === 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: filterHeader
|
||||||
|
Controls.TextField {
|
||||||
|
id: sitefilter
|
||||||
|
visible: (opacity > 0) && rootItem.filterToggle
|
||||||
|
text: ""
|
||||||
|
placeholderText: "Dive site name"
|
||||||
|
onTextChanged: {
|
||||||
|
rootItem.filterPattern = text
|
||||||
|
diveModel.setFilter(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: diveListView
|
id: diveListView
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
@ -371,6 +386,7 @@ Kirigami.ScrollablePage {
|
||||||
model: diveModel
|
model: diveModel
|
||||||
currentIndex: -1
|
currentIndex: -1
|
||||||
delegate: diveDelegate
|
delegate: diveDelegate
|
||||||
|
header: filterHeader
|
||||||
boundsBehavior: Flickable.DragOverBounds
|
boundsBehavior: Flickable.DragOverBounds
|
||||||
maximumFlickVelocity: parent.height * 5
|
maximumFlickVelocity: parent.height * 5
|
||||||
bottomMargin: Kirigami.Units.iconSizes.medium + Kirigami.Units.gridUnit
|
bottomMargin: Kirigami.Units.iconSizes.medium + Kirigami.Units.gridUnit
|
||||||
|
@ -420,6 +436,22 @@ Kirigami.ScrollablePage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property QtObject filterToggleAction: Kirigami.Action {
|
||||||
|
icon {
|
||||||
|
name: ":icons/ic_filter_list"
|
||||||
|
}
|
||||||
|
text: qsTr("Filter dives")
|
||||||
|
onTriggered: {
|
||||||
|
rootItem.filterToggle = !rootItem.filterToggle
|
||||||
|
if (rootItem.filterToggle) {
|
||||||
|
diveModel.setFilter(rootItem.filterPattern)
|
||||||
|
} else {
|
||||||
|
diveModel.resetFilter()
|
||||||
|
rootItem.filterPattern = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onBackRequested: {
|
onBackRequested: {
|
||||||
if (startPage.visible && diveListView.count > 0 &&
|
if (startPage.visible && diveListView.count > 0 &&
|
||||||
prefs.credentialStatus !== CloudStatus.CS_INCORRECT_USER_PASSWD) {
|
prefs.credentialStatus !== CloudStatus.CS_INCORRECT_USER_PASSWD) {
|
||||||
|
|
|
@ -32,6 +32,9 @@ Kirigami.ApplicationWindow {
|
||||||
property alias pluggedInDeviceName: manager.pluggedInDeviceName
|
property alias pluggedInDeviceName: manager.pluggedInDeviceName
|
||||||
property alias showPin: prefs.showPin
|
property alias showPin: prefs.showPin
|
||||||
property alias defaultCylinderIndex: settingsWindow.defaultCylinderIndex
|
property alias defaultCylinderIndex: settingsWindow.defaultCylinderIndex
|
||||||
|
property bool filterToggle: false
|
||||||
|
property string filterPattern: ""
|
||||||
|
|
||||||
onNotificationTextChanged: {
|
onNotificationTextChanged: {
|
||||||
if (notificationText != "") {
|
if (notificationText != "") {
|
||||||
// there's a risk that we have a >5 second gap in update events;
|
// there's a risk that we have a >5 second gap in update events;
|
||||||
|
|
|
@ -8,6 +8,17 @@ DiveListSortModel::DiveListSortModel(QObject *parent) : QSortFilterProxyModel(pa
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DiveListSortModel::setFilter(QString f)
|
||||||
|
{
|
||||||
|
setFilterRole(DiveListModel::DiveSiteRole);
|
||||||
|
setFilterRegExp(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiveListSortModel::resetFilter()
|
||||||
|
{
|
||||||
|
setFilterRegExp("");
|
||||||
|
}
|
||||||
|
|
||||||
int DiveListSortModel::getDiveId(int idx)
|
int DiveListSortModel::getDiveId(int idx)
|
||||||
{
|
{
|
||||||
DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());
|
DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());
|
||||||
|
@ -151,6 +162,7 @@ QVariant DiveListModel::data(const QModelIndex &index, int role) const
|
||||||
switch(role) {
|
switch(role) {
|
||||||
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
|
case DiveRole: return QVariant::fromValue<QObject*>(curr_dive);
|
||||||
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
|
case DiveDateRole: return (qlonglong)curr_dive->timestamp();
|
||||||
|
case DiveSiteRole: return curr_dive->location();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
|
@ -161,6 +173,7 @@ QHash<int, QByteArray> DiveListModel::roleNames() const
|
||||||
QHash<int, QByteArray> roles;
|
QHash<int, QByteArray> roles;
|
||||||
roles[DiveRole] = "dive";
|
roles[DiveRole] = "dive";
|
||||||
roles[DiveDateRole] = "date";
|
roles[DiveDateRole] = "date";
|
||||||
|
roles[DiveSiteRole] = "site";
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
int getDiveId(int idx);
|
int getDiveId(int idx);
|
||||||
int getIdxForId(int id);
|
int getIdxForId(int id);
|
||||||
|
void setFilter(QString f);
|
||||||
|
void resetFilter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class DiveListModel : public QAbstractListModel
|
class DiveListModel : public QAbstractListModel
|
||||||
|
@ -26,7 +28,8 @@ public:
|
||||||
|
|
||||||
enum DiveListRoles {
|
enum DiveListRoles {
|
||||||
DiveRole = Qt::UserRole + 1,
|
DiveRole = Qt::UserRole + 1,
|
||||||
DiveDateRole
|
DiveDateRole,
|
||||||
|
DiveSiteRole
|
||||||
};
|
};
|
||||||
|
|
||||||
static DiveListModel *instance();
|
static DiveListModel *instance();
|
||||||
|
|
Loading…
Add table
Reference in a new issue