aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2021-08-15 19:55:17 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-08-18 19:09:59 -0700
commit9b669d91e0cf4e7f09e399704a2052705e165be0 (patch)
treef1185acc3e78c9c464d5b5b475b1f61db1ee9e51
parent454207cd80f1159e9596c236893eba786ff3b918 (diff)
downloadsubsurface-9b669d91e0cf4e7f09e399704a2052705e165be0.tar.gz
mobile: add ability to edit tags
We already showed the tags, but we didn't allow the user to edit them. This tries hard not to create inconsistent or illogical tags by trimming white space and being careful with how the tags are added. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--CHANGELOG.md1
-rw-r--r--mobile-widgets/qml/DiveDetails.qml2
-rw-r--r--mobile-widgets/qml/DiveDetailsEdit.qml17
-rw-r--r--mobile-widgets/qmlmanager.cpp22
-rw-r--r--mobile-widgets/qmlmanager.h2
5 files changed, 40 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e92da774..cc2e06a04 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,4 @@
+- mobile: add ability to edit tags
- replace dive computer management with a new implementation, this fixes rare cases where
Subsurface unnecessarily download already downloaded dives, but also means
that some older style dive computer can no longer have nicknames
diff --git a/mobile-widgets/qml/DiveDetails.qml b/mobile-widgets/qml/DiveDetails.qml
index 1215e86ad..c5edfb8b7 100644
--- a/mobile-widgets/qml/DiveDetails.qml
+++ b/mobile-widgets/qml/DiveDetails.qml
@@ -22,6 +22,7 @@ Kirigami.Page {
property alias divemasterIndex: detailsEdit.divemasterIndex
property alias divemasterText: detailsEdit.divemasterText
property alias divemasterModel: detailsEdit.divemasterModel
+ property alias tagText: detailsEdit.tagText
property alias depth: detailsEdit.depthText
property alias duration: detailsEdit.durationText
property alias location: detailsEdit.locationText
@@ -353,6 +354,7 @@ Kirigami.Page {
suitIndex = manager.suitList.indexOf(modelData.suit)
buddyText = modelData.buddy;
divemasterText = modelData.diveMaster
+ tagText = modelData.tags
notes = modelData.notes
if (modelData.singleWeight) {
// we have only one weight, go ahead, have fun and edit it
diff --git a/mobile-widgets/qml/DiveDetailsEdit.qml b/mobile-widgets/qml/DiveDetailsEdit.qml
index 6f5690bae..5c9b99b02 100644
--- a/mobile-widgets/qml/DiveDetailsEdit.qml
+++ b/mobile-widgets/qml/DiveDetailsEdit.qml
@@ -22,6 +22,7 @@ Item {
property alias buddyText: buddyBox.editText
property alias divemasterIndex: divemasterBox.currentIndex
property alias divemasterText: divemasterBox.editText
+ property alias tagText: txtTag.text
property alias cylinderIndex0: cylinderBox0.currentIndex
property alias cylinderIndex1: cylinderBox1.currentIndex
property alias cylinderIndex2: cylinderBox2.currentIndex
@@ -118,7 +119,7 @@ Item {
// apply the changes to the dive_table
manager.commitChanges(dive_id, detailsEdit.number, detailsEdit.dateText, locationBox.editText, detailsEdit.gpsText, detailsEdit.durationText,
detailsEdit.depthText, detailsEdit.airtempText, detailsEdit.watertempText,
- suitBox.editText, buddyBox.editText, divemasterBox.editText,
+ suitBox.editText, buddyBox.editText, divemasterBox.editText, detailsEdit.tagText,
detailsEdit.weightText, detailsEdit.notesText, startpressure,
endpressure, usedGas, usedCyl,
detailsEdit.rating,
@@ -331,7 +332,19 @@ Item {
manager.divemasterList : null
}
}
-
+ RowLayout {
+ width: Kirigami.Units.gridUnit * 20
+ TemplateLabelSmall {
+ Layout.preferredWidth: Kirigami.Units.gridUnit * 4
+ horizontalAlignment: Text.AlignRight
+ text: qsTr("Tags:")
+ }
+ SsrfTextField {
+ Layout.preferredWidth: Kirigami.Units.gridUnit * 16
+ id: txtTag
+ flickable: detailsEditFlickable
+ }
+ }
RowLayout {
width: Kirigami.Units.gridUnit * 16
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index e70b18027..4f8cdbd52 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -48,6 +48,7 @@
#include "core/settings/qPrefPartialPressureGas.h"
#include "core/settings/qPrefUnit.h"
#include "core/trip.h"
+#include "core/tag.h"
#include "backend-shared/exportfuncs.h"
#include "core/worldmap-save.h"
#include "core/uploadDiveLogsDE.h"
@@ -1078,7 +1079,7 @@ bool QMLManager::checkDepth(dive *d, QString depth)
// update the dive and return the notes field, stripped of the HTML junk
void QMLManager::commitChanges(QString diveId, QString number, QString date, QString location, QString gps, QString duration, QString depth,
- QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString weight, QString notes,
+ QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString tags, QString weight, QString notes,
QStringList startpressure, QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility, QString state)
{
struct dive *orig = get_dive_by_uniq_id(diveId.toInt());
@@ -1100,6 +1101,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt
QStringLiteral("suit :'%1'\n").arg(suit) <<
QStringLiteral("buddy :'%1'\n").arg(buddy) <<
QStringLiteral("diveMstr:'%1'\n").arg(diveMaster) <<
+ QStringLiteral("tags :'%1'\n").arg(tags) <<
QStringLiteral("weight :'%1'\n").arg(weight) <<
QStringLiteral("state :'%1'\n").arg(state);
}
@@ -1235,6 +1237,24 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt
free(d->divemaster);
d->divemaster = copy_qstring(diveMaster);
}
+ // normalize the tag list we have and the one we get from the UI
+ // try hard to deal with accidental white space issues
+ QStringList existingTagList = get_taglist_string(d->tag_list).split(",", QString::SkipEmptyParts);
+ QStringList newTagList = tags.split(",", QString::SkipEmptyParts);
+ QStringList newCleanTagList;
+ for (QString s: newTagList) {
+ if (!s.simplified().isEmpty())
+ newCleanTagList << s.simplified();
+ }
+ newCleanTagList.sort();
+ existingTagList.sort();
+ if (newCleanTagList.join(",") != existingTagList.join(",")) {
+ diveChanged = true;
+ taglist_free(d->tag_list);
+ d->tag_list = nullptr;
+ for (QString tag: newCleanTagList)
+ taglist_add_tag(&d->tag_list, qPrintable(tag));
+ }
if (d->rating != rating) {
diveChanged = true;
d->rating = rating;
diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h
index e403a6f46..cc2633676 100644
--- a/mobile-widgets/qmlmanager.h
+++ b/mobile-widgets/qmlmanager.h
@@ -184,7 +184,7 @@ public slots:
void commitChanges(QString diveId, QString number, QString date, QString location, QString gps,
QString duration, QString depth, QString airtemp,
QString watertemp, QString suit, QString buddy,
- QString diveMaster, QString weight, QString notes, QStringList startpressure,
+ QString diveMaster, QString tags, QString weight, QString notes, QStringList startpressure,
QStringList endpressure, QStringList gasmix, QStringList usedCylinder, int rating, int visibility, QString state);
void updateTripDetails(QString tripIdString, QString tripLocation, QString tripNotes);
void removeDiveFromTrip(int id);