diff options
-rw-r--r-- | core/string-format.cpp | 7 | ||||
-rw-r--r-- | core/string-format.h | 1 | ||||
-rw-r--r-- | core/subsurface-qt/diveobjecthelper.h | 2 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 57 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.h | 8 | ||||
-rw-r--r-- | qt-models/divetripmodel.cpp | 6 |
6 files changed, 42 insertions, 39 deletions
diff --git a/core/string-format.cpp b/core/string-format.cpp index 9de145b7a..5652a15bf 100644 --- a/core/string-format.cpp +++ b/core/string-format.cpp @@ -250,3 +250,10 @@ QString formatDiveTime(const dive *d) QDateTime localTime = timestampToDateTime(d->when); return localTime.time().toString(prefs.time_format); } + +QString formatDiveDateTime(const dive *d) +{ + QDateTime localTime = timestampToDateTime(d->when); + return QStringLiteral("%1 %2").arg(localTime.date().toString(prefs.date_format_short), + localTime.time().toString(prefs.time_format)); +} diff --git a/core/string-format.h b/core/string-format.h index 12f36bd11..54a40b890 100644 --- a/core/string-format.h +++ b/core/string-format.h @@ -24,5 +24,6 @@ QString formatDiveDuration(const dive *d); QString formatDiveGPS(const dive *d); QString formatDiveDate(const dive *d); QString formatDiveTime(const dive *d); +QString formatDiveDateTime(const dive *d); #endif diff --git a/core/subsurface-qt/diveobjecthelper.h b/core/subsurface-qt/diveobjecthelper.h index 30dee6bf7..8b328673f 100644 --- a/core/subsurface-qt/diveobjecthelper.h +++ b/core/subsurface-qt/diveobjecthelper.h @@ -96,6 +96,4 @@ public: QString waterType; }; -Q_DECLARE_METATYPE(DiveObjectHelper) - #endif diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 1b5c1ed17..8e88d91aa 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -38,6 +38,7 @@ #include "core/downloadfromdcthread.h" #include "core/subsurfacestartup.h" // for ignore_bt flag #include "core/subsurface-string.h" +#include "core/string-format.h" #include "core/pref.h" #include "core/selection.h" #include "core/ssrf.h" @@ -851,9 +852,9 @@ static void setupDivesite(DiveSiteChange &res, struct dive *d, struct dive_site res.changed = true; } -bool QMLManager::checkDate(const DiveObjectHelper &myDive, struct dive *d, QString date) +bool QMLManager::checkDate(struct dive *d, QString date) { - QString oldDate = myDive.date() + " " + myDive.time(); + QString oldDate = formatDiveDateTime(d); if (date != oldDate) { QDateTime newDate; // what a pain - Qt will not parse dates if the day of the week is incorrect @@ -956,12 +957,13 @@ parsed: return false; } -bool QMLManager::checkLocation(DiveSiteChange &res, const DiveObjectHelper &myDive, struct dive *d, QString location, QString gps) +bool QMLManager::checkLocation(DiveSiteChange &res, struct dive *d, QString location, QString gps) { struct dive_site *ds = get_dive_site_for_dive(d); bool changed = false; - qDebug() << "checkLocation" << location << "gps" << gps << "dive had" << myDive.location << "gps" << myDive.gas; - if (myDive.location != location) { + QString oldLocation = get_dive_location(d); + qDebug() << "checkLocation" << location << "gps" << gps << "dive had" << oldLocation << "gps" << formatDiveGPS(d); + if (oldLocation != location) { ds = get_dive_site_by_name(qPrintable(location), &dive_site_table); if (!ds && !location.isEmpty()) { res.createdDs.reset(alloc_dive_site_with_name(qPrintable(location))); @@ -974,7 +976,7 @@ bool QMLManager::checkLocation(DiveSiteChange &res, const DiveObjectHelper &myDi // now make sure that the GPS coordinates match - if the user changed the name but not // the GPS coordinates, this still does the right thing as the now new dive site will // have no coordinates, so the coordinates from the edit screen will get added - if (myDive.gps != gps) { + if (formatDiveGPS(d) != gps) { double lat, lon; if (parseGpsText(gps, &lat, &lon)) { qDebug() << "parsed GPS, using it"; @@ -999,9 +1001,9 @@ bool QMLManager::checkLocation(DiveSiteChange &res, const DiveObjectHelper &myDi return changed | res.changed; } -bool QMLManager::checkDuration(const DiveObjectHelper &myDive, struct dive *d, QString duration) +bool QMLManager::checkDuration(struct dive *d, QString duration) { - if (myDive.duration != duration) { + if (formatDiveDuration(d) != duration) { int h = 0, m = 0, s = 0; QRegExp r1(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2[\\s,:]*(\\d*)\\s*%3").arg(tr("h")).arg(tr("min")).arg(tr("sec")), Qt::CaseInsensitive); QRegExp r2(QStringLiteral("(\\d*)\\s*%1[\\s,:]*(\\d*)\\s*%2").arg(tr("h")).arg(tr("min")), Qt::CaseInsensitive); @@ -1038,9 +1040,9 @@ bool QMLManager::checkDuration(const DiveObjectHelper &myDive, struct dive *d, Q return false; } -bool QMLManager::checkDepth(const DiveObjectHelper &myDive, dive *d, QString depth) +bool QMLManager::checkDepth(dive *d, QString depth) { - if (myDive.depth != depth) { + if (get_depth_string(d->dc.maxdepth.mm, true, true) != depth) { int depthValue = parseLengthToMm(depth); // the QML code should stop negative depth, but massively huge depth can make // the profile extremely slow or even run out of memory and crash, so keep @@ -1072,7 +1074,6 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt Command::OwningDivePtr d_ptr(alloc_dive()); // Automatically delete dive if we exit early! dive *d = d_ptr.get(); copy_dive(orig, d); - DiveObjectHelper myDive(d); // notes comes back as rich text - let's convert this into plain text QTextDocument doc; @@ -1081,28 +1082,28 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt bool diveChanged = false; - diveChanged = checkDate(myDive, d, date); + diveChanged = checkDate(d, date); DiveSiteChange dsChange; - diveChanged |= checkLocation(dsChange, myDive, d, location, gps); + diveChanged |= checkLocation(dsChange, d, location, gps); - diveChanged |= checkDuration(myDive, d, duration); + diveChanged |= checkDuration(d, duration); - diveChanged |= checkDepth(myDive, d, depth); + diveChanged |= checkDepth(d, depth); - if (QString::number(myDive.number) != number) { + if (QString::number(d->number) != number) { diveChanged = true; d->number = number.toInt(); } - if (myDive.airTemp != airtemp) { + if (get_temperature_string(d->airtemp, true) != airtemp) { diveChanged = true; d->airtemp.mkelvin = parseTemperatureToMkelvin(airtemp); } - if (myDive.waterTemp != watertemp) { + if (get_temperature_string(d->watertemp, true) != watertemp) { diveChanged = true; d->watertemp.mkelvin = parseTemperatureToMkelvin(watertemp); } - if (myDive.sumWeight != weight) { + if (formatSumWeight(d) != weight) { diveChanged = true; // not sure what we'd do if there was more than one weight system // defined - for now just ignore that case @@ -1119,7 +1120,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt startpressure = QStringList(); if (endpressure == QStringList(QString())) endpressure = QStringList(); - if (myDive.startPressure != startpressure || myDive.endPressure != endpressure) { + if (formatStartPressure(d) != startpressure || formatEndPressure(d) != endpressure) { diveChanged = true; for ( int i = 0, j = 0 ; j < startpressure.length() && j < endpressure.length() ; i++ ) { if (state != "add" && !is_cylinder_used(d, i)) @@ -1135,7 +1136,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt } } // gasmix for first cylinder - if (myDive.firstGas != gasmix) { + if (formatFirstGas(d) != gasmix) { for ( int i = 0, j = 0 ; j < gasmix.length() ; i++ ) { if (state != "add" && !is_cylinder_used(d, i)) continue; @@ -1154,7 +1155,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt } } // info for first cylinder - if (myDive.getCylinder != usedCylinder) { + if (formatGetCylinder(d) != usedCylinder) { diveChanged = true; int size = 0, wp = 0, j = 0, k = 0; for (j = 0; k < usedCylinder.length(); j++) { @@ -1180,12 +1181,12 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt k++; } } - if (myDive.suit != suit) { + if (d->suit != suit) { diveChanged = true; free(d->suit); d->suit = copy_qstring(suit); } - if (myDive.buddy != buddy) { + if (d->buddy != buddy) { if (buddy.contains(",")){ buddy = buddy.replace(QRegExp("\\s*,\\s*"), ", "); } @@ -1193,7 +1194,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt free(d->buddy); d->buddy = copy_qstring(buddy); } - if (myDive.divemaster != diveMaster) { + if (d->divemaster != diveMaster) { if (diveMaster.contains(",")){ diveMaster = diveMaster.replace(QRegExp("\\s*,\\s*"), ", "); } @@ -1201,15 +1202,15 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt free(d->divemaster); d->divemaster = copy_qstring(diveMaster); } - if (myDive.rating != rating) { + if (d->rating != rating) { diveChanged = true; d->rating = rating; } - if (myDive.visibility != visibility) { + if (d->visibility != visibility) { diveChanged = true; d->visibility = visibility; } - if (myDive.notes != notes) { + if (formatNotes(d) != notes) { diveChanged = true; free(d->notes); d->notes = copy_qstring(notes); diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index 59cf37cab..cbb451d8a 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -261,10 +261,10 @@ private: QString m_notificationText; qreal m_lastDevicePixelRatio; QElapsedTimer timer; - bool checkDate(const DiveObjectHelper &myDive, struct dive *d, QString date); - bool checkLocation(DiveSiteChange &change, const DiveObjectHelper &myDive, struct dive *d, QString location, QString gps); - bool checkDuration(const DiveObjectHelper &myDive, struct dive *d, QString duration); - bool checkDepth(const DiveObjectHelper &myDive, struct dive *d, QString depth); + bool checkDate(struct dive *d, QString date); + bool checkLocation(DiveSiteChange &change, struct dive *d, QString location, QString gps); + bool checkDuration(struct dive *d, QString duration); + bool checkDepth(struct dive *d, QString depth); bool currentGitLocalOnly; bool localChanges; QString m_progressMessage; diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 6d9bd8de4..a0385822c 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -197,11 +197,7 @@ QVariant DiveTripModelBase::diveData(const struct dive *d, int column, int role) // We have to return a QString as trip-id, because that will be used as section // variable in the QtQuick list view. That has to be a string because it will try // to do locale-aware sorting. And amazingly this can't be changed. - case MobileListModel::DateTimeRole: { - QDateTime localTime = timestampToDateTime(d->when); - return QStringLiteral("%1 %2").arg(localTime.date().toString(prefs.date_format_short), - localTime.time().toString(prefs.time_format)); - } + case MobileListModel::DateTimeRole: return formatDiveDateTime(d); case MobileListModel::IdRole: return d->id; case MobileListModel::NumberRole: return d->number; case MobileListModel::LocationRole: return get_dive_location(d); |