Qt6: deal with changes from QStringRef to QStringView
QStringRef is gone in Qt6 and mostly replaced by QStringView. The one major difference is that direct comparisons with string literals are no longer possible. Thanks to Thiago Macieira for helping me avoid more conditional compilation here. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
14362c2f55
commit
04b26d31c8
@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "core/parse-gpx.h"
|
||||
#include "core/subsurface-time.h"
|
||||
#include "core/qthelper.h"
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
@ -43,7 +44,7 @@ int getCoordsFromGPXFile(struct dive_coords *coords, QString fileName)
|
||||
while (!gpxReader.atEnd()) {
|
||||
gpxReader.readNext();
|
||||
if (gpxReader.isStartElement()) {
|
||||
if (gpxReader.name() == "trkpt") {
|
||||
if (nameCmp(gpxReader, "trkpt") == 0) {
|
||||
trkpt_found = true;
|
||||
line++;
|
||||
foreach (const QXmlStreamAttribute &attr, gpxReader.attributes()) {
|
||||
@ -53,7 +54,7 @@ int getCoordsFromGPXFile(struct dive_coords *coords, QString fileName)
|
||||
lon = attr.value().toString().toDouble();
|
||||
}
|
||||
}
|
||||
if (gpxReader.name() == "time" && trkpt_found) { // Ignore the <time> element in the GPX file header
|
||||
if (nameCmp(gpxReader, "time") == 0 && trkpt_found) { // Ignore the <time> element in the GPX file header
|
||||
QString dateTimeString = gpxReader.readElementText();
|
||||
bool ok;
|
||||
tm1.tm_year = dateTimeString.left(4).toInt(&ok, 10); // Extract the date/time components:
|
||||
|
||||
@ -20,6 +20,7 @@ enum watertypes {FRESHWATER, BRACKISHWATER, EN13319WATER, SALTWATER, DC_WATERTYP
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <QString>
|
||||
#include <QXmlStreamReader>
|
||||
#include "core/gettextfromc.h"
|
||||
class QImage;
|
||||
|
||||
@ -29,6 +30,12 @@ class QImage;
|
||||
#define SKIP_EMPTY QString::SkipEmptyParts
|
||||
#endif
|
||||
|
||||
// this is annoying Qt5 / Qt6 incompatibility where we can't compare against string literals anymore
|
||||
static inline int nameCmp(QXmlStreamReader &r, const char * cs)
|
||||
{
|
||||
return r.name().compare(QLatin1String(cs));
|
||||
}
|
||||
|
||||
QString weight_string(int weight_in_grams);
|
||||
QString distance_string(int distanceInMeters);
|
||||
bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_text, bool *parsed_out = 0);
|
||||
|
||||
@ -157,7 +157,7 @@ static DiveListResult parseDiveLogsDeDiveList(const QByteArray &xmlData)
|
||||
DiveListResult result;
|
||||
result.idCount = 0;
|
||||
|
||||
if (reader.readNextStartElement() && reader.name() != "DiveDateReader") {
|
||||
if (reader.readNextStartElement() && nameCmp(reader, "DiveDateReader") != 0) {
|
||||
result.errorCondition = invalidXmlError;
|
||||
result.errorDetails =
|
||||
gettextFromC::tr("Expected XML tag 'DiveDateReader', got instead '%1")
|
||||
@ -166,8 +166,8 @@ static DiveListResult parseDiveLogsDeDiveList(const QByteArray &xmlData)
|
||||
}
|
||||
|
||||
while (reader.readNextStartElement()) {
|
||||
if (reader.name() != "DiveDates") {
|
||||
if (reader.name() == "Login") {
|
||||
if (nameCmp(reader, "DiveDates") != 0) {
|
||||
if (nameCmp(reader, "Login") == 0) {
|
||||
QString status = reader.readElementText();
|
||||
// qDebug() << "Login status:" << status;
|
||||
|
||||
@ -185,11 +185,11 @@ static DiveListResult parseDiveLogsDeDiveList(const QByteArray &xmlData)
|
||||
// process <DiveDates>
|
||||
seenDiveDates = true;
|
||||
while (reader.readNextStartElement()) {
|
||||
if (reader.name() != "date") {
|
||||
if (nameCmp(reader, "date") != 0) {
|
||||
// qDebug() << "Skipping" << reader.name();
|
||||
continue;
|
||||
}
|
||||
QStringRef id = reader.attributes().value("divelogsId");
|
||||
auto id = reader.attributes().value("divelogsId");
|
||||
// qDebug() << "Found" << reader.name() << "with id =" << id;
|
||||
if (!id.isEmpty()) {
|
||||
result.idList += id.toLatin1();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user