QML UI: clean up notes field after edit

We don't want any of the rich text markup to sneak into our fields.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-01-07 22:30:58 -08:00
parent a0d3480bbe
commit 624e44e73d
3 changed files with 13 additions and 8 deletions

View file

@ -80,9 +80,9 @@ MobileComponents.Page {
iconName: "document-save" iconName: "document-save"
onTriggered: { onTriggered: {
// apply the changes to the dive_table // apply the changes to the dive_table
manager.commitChanges(dive_id, detailsEdit.dateText, detailsEdit.locationText, detailsEdit.gpsText, detailsEdit.durationText, notes = manager.commitChanges(dive_id, detailsEdit.dateText, detailsEdit.locationText, detailsEdit.gpsText, detailsEdit.durationText,
detailsEdit.depthText, detailsEdit.airtempText, detailsEdit.watertempText, detailsEdit.suitText, detailsEdit.depthText, detailsEdit.airtempText, detailsEdit.watertempText, detailsEdit.suitText,
detailsEdit.buddyText, detailsEdit.divemasterText, detailsEdit.notesText) detailsEdit.buddyText, detailsEdit.divemasterText, detailsEdit.notesText)
// apply the changes to the dive detail view // apply the changes to the dive detail view
date = detailsEdit.dateText date = detailsEdit.dateText
location = detailsEdit.locationText location = detailsEdit.locationText
@ -93,7 +93,6 @@ MobileComponents.Page {
suit = detailsEdit.suitText suit = detailsEdit.suitText
buddy = detailsEdit.buddyText buddy = detailsEdit.buddyText
divemaster = detailsEdit.divemasterText divemaster = detailsEdit.divemasterText
notes = detailsEdit.notesText
// back to view state and close the drawer // back to view state and close the drawer
diveDetailsWindow.state = "view" diveDetailsWindow.state = "view"
contextDrawer.close() contextDrawer.close()

View file

@ -5,6 +5,7 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QAuthenticator> #include <QAuthenticator>
#include <QDesktopServices> #include <QDesktopServices>
#include <QTextDocument>
#include "qt-models/divelistmodel.h" #include "qt-models/divelistmodel.h"
#include "divelist.h" #include "divelist.h"
@ -309,15 +310,19 @@ void QMLManager::loadDivesWithValidCredentials()
setLoadFromCloud(true); setLoadFromCloud(true);
} }
void QMLManager::commitChanges(QString diveId, QString date, QString location, QString gps, QString duration, QString depth, // update the dive and return the notes field, stripped of the HTML junk
QString QMLManager::commitChanges(QString diveId, QString date, QString location, QString gps, QString duration, QString depth,
QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString notes) QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString notes)
{ {
struct dive *d = get_dive_by_uniq_id(diveId.toInt()); struct dive *d = get_dive_by_uniq_id(diveId.toInt());
qDebug() << diveId.toInt() << (d != 0 ? d->number : -1); // notes comes back as rich text - let's convert this into plain text
QTextDocument doc;
doc.setHtml(notes);
notes = doc.toPlainText();
if (!d) { if (!d) {
qDebug() << "don't touch this... no dive"; qDebug() << "don't touch this... no dive";
return; return notes;
} }
bool diveChanged = false; bool diveChanged = false;
bool needResort = false; bool needResort = false;
@ -455,6 +460,7 @@ void QMLManager::commitChanges(QString diveId, QString date, QString location, Q
} }
mark_divelist_changed(true); mark_divelist_changed(true);
} }
return notes;
} }
void QMLManager::saveChanges() void QMLManager::saveChanges()

View file

@ -71,7 +71,7 @@ public slots:
void loadDivesWithValidCredentials(); void loadDivesWithValidCredentials();
void loadDiveProgress(int percent); void loadDiveProgress(int percent);
void provideAuth(QNetworkReply *reply, QAuthenticator *auth); void provideAuth(QNetworkReply *reply, QAuthenticator *auth);
void commitChanges(QString diveId, QString date, QString location, QString gps, QString duration, QString depth, QString commitChanges(QString diveId, QString date, QString location, QString gps, QString duration, QString depth,
QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString notes); QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString notes);
void saveChanges(); void saveChanges();
QString addDive(); QString addDive();