1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Added support for waypoint addresses

This commit is contained in:
Martin Tůma 2019-11-08 21:00:59 +01:00
parent d292b5f533
commit 96e0b584a0
8 changed files with 158 additions and 17 deletions

View File

@ -187,7 +187,8 @@ HEADERS += src/common/config.h \
src/map/IMG/label.h \
src/data/csv.h \
src/data/cupparser.h \
src/data/gpiparser.h
src/data/gpiparser.h \
src/data/address.h
SOURCES += src/main.cpp \
src/GUI/popup.cpp \
src/common/coordinates.cpp \

View File

@ -1,5 +1,3 @@
#include <QImageReader>
#include <QLabel>
#include "popup.h"
#include "tooltip.h"

View File

@ -30,6 +30,19 @@ QString WaypointItem::info() const
if (!_waypoint.description().isEmpty())
tt.insert(qApp->translate("WaypointItem", "Description"),
_waypoint.description());
if (_waypoint.address().isValid()) {
QString addr("<address>");
addr += _waypoint.address().street();
addr += "<br/>" + _waypoint.address().city();
if (!_waypoint.address().postalCode().isEmpty())
addr += "<br/>" + _waypoint.address().postalCode();
if (!_waypoint.address().state().isEmpty())
addr += "<br/>" + _waypoint.address().state();
if (!_waypoint.address().country().isEmpty())
addr += "<br/>" + _waypoint.address().country();
addr += "</address>";
tt.insert(qApp->translate("WaypointItem", "Address"), addr);
}
if (!_waypoint.links().isEmpty()) {
QString links;
for (int i = 0; i < _waypoint.links().size(); i++) {

35
src/data/address.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef ADDRESS_H
#define ADDRESS_H
#include <QString>
class Address
{
public:
Address() {}
Address(const QString &street, const QString &city)
: _street(street), _city(city) {}
const QString &street() const {return _street;}
const QString &city() const {return _city;}
const QString &state() const {return _state;}
const QString &country() const {return _country;}
const QString &postalCode() const {return _postalCode;}
void setStreet(const QString &street) {_street = street;}
void setCity(const QString &city) {_city = city;}
void setState(const QString &state) {_state = state;}
void setCountry(const QString &country) {_country = country;}
void setPostalCode(const QString &postalCode) {_postalCode = postalCode;}
bool isValid() const {return !(_street.isEmpty() || _city.isEmpty());}
private:
QString _street;
QString _city;
QString _state;
QString _country;
QString _postalCode;
};
#endif // ADDRESS_H

View File

@ -294,29 +294,29 @@ static quint32 readContact(QDataStream &stream, QTextCodec *codec,
{
RecordHeader rh;
quint8 rs;
quint16 s1;
quint16 flags;
quint32 ds = 2;
QString str;
QList<TranslatedString> obj;
rs = readRecordHeader(stream, rh);
stream >> s1;
stream >> flags;
if (s1 & 0x1) // phone
if (flags & 0x1) // phone
ds += readString(stream, codec, str);
if (s1 & 0x2) // phone2
if (flags & 0x2) // phone2
ds += readString(stream, codec, str);
if (s1 & 0x4) // fax
if (flags & 0x4) // fax
ds += readString(stream, codec, str);
if (s1 & 0x8) // mail
if (flags & 0x8) // mail
ds += readString(stream, codec, str);
if (s1 & 0x10) { // web
if (flags & 0x10) { // web
ds += readString(stream, codec, str);
QUrl url(str);
waypoint.addLink(Link(url.scheme().isEmpty()
? "http://" + str : str, str));
}
if (s1 & 0x20) // unknown
if (flags & 0x20) // unknown
ds += readTranslatedObjects(stream, codec, obj);
if (ds != rh.size)
@ -325,6 +325,55 @@ static quint32 readContact(QDataStream &stream, QTextCodec *codec,
return rs + rh.size;
}
static quint32 readAddress(QDataStream &stream, QTextCodec *codec,
Waypoint &waypoint)
{
RecordHeader rh;
quint8 rs;
quint16 flags;
quint32 ds = 2;
QList<TranslatedString> obj;
QString str;
Address addr;
rs = readRecordHeader(stream, rh);
stream >> flags;
if (flags & 0x1) {
ds += readTranslatedObjects(stream, codec, obj);
if (!obj.isEmpty())
addr.setCity(obj.first().str());
}
if (flags & 0x2) {
ds += readTranslatedObjects(stream, codec, obj);
if (!obj.isEmpty())
addr.setCountry(obj.first().str());
}
if (flags & 0x4) {
ds += readTranslatedObjects(stream, codec, obj);
if (!obj.isEmpty())
addr.setState(obj.first().str());
}
if (flags & 0x8) {
ds += readString(stream, codec, str);
addr.setPostalCode(str);
}
if (flags & 0x10) {
ds += readTranslatedObjects(stream, codec, obj);
if (!obj.isEmpty())
addr.setStreet(obj.first().str());
}
if (flags & 0x20) // unknown
ds += readString(stream, codec, str);
waypoint.setAddress(addr);
if (ds != rh.size)
stream.setStatus(QDataStream::ReadCorruptData);
return rs + rh.size;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
static const QTemporaryDir &tempDir()
{
@ -391,6 +440,9 @@ static quint32 readPOI(QDataStream &stream, QTextCodec *codec,
case 10:
ds += readDescription(stream, codec, waypoints.last());
break;
case 11:
ds += readAddress(stream, codec, waypoints.last());
break;
case 12:
ds += readContact(stream, codec, waypoints.last());
break;

View File

@ -69,8 +69,10 @@ Coordinates GPXParser::coordinates()
void GPXParser::rpExtension(SegmentData *autoRoute)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("rpt"))
if (_reader.name() == QLatin1String("rpt")) {
if (autoRoute)
autoRoute->append(Trackpoint(coordinates()));
}
_reader.skipCurrentElement();
}
}
@ -91,11 +93,45 @@ void GPXParser::tpExtension(Trackpoint &trackpoint)
}
}
void GPXParser::rteptExtensions(SegmentData *autoRoute)
void GPXParser::address(Waypoint &waypoint)
{
Address addr;
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("StreetAddress"))
addr.setStreet(_reader.readElementText());
else if (_reader.name() == QLatin1String("City"))
addr.setCity(_reader.readElementText());
else if (_reader.name() == QLatin1String("PostalCode"))
addr.setPostalCode(_reader.readElementText());
else if (_reader.name() == QLatin1String("State"))
addr.setState(_reader.readElementText());
else if (_reader.name() == QLatin1String("Country"))
addr.setCountry(_reader.readElementText());
else
_reader.skipCurrentElement();
}
waypoint.setAddress(addr);
}
void GPXParser::wpExtension(Waypoint &waypoint)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("Address"))
address(waypoint);
else
_reader.skipCurrentElement();
}
}
void GPXParser::waypointExtensions(Waypoint &waypoint, SegmentData *autoRoute)
{
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("RoutePointExtension"))
rpExtension(autoRoute);
else if (_reader.name() == QLatin1String("WaypointExtension"))
wpExtension(waypoint);
else
_reader.skipCurrentElement();
}
@ -170,8 +206,8 @@ void GPXParser::waypointData(Waypoint &waypoint, SegmentData *autoRoute)
link10.setURL(_reader.readElementText());
else if (_reader.name() == QLatin1String("urlname"))
link10.setText(_reader.readElementText());
else if (autoRoute && _reader.name() == QLatin1String("extensions"))
rteptExtensions(autoRoute);
else if (_reader.name() == QLatin1String("extensions"))
waypointExtensions(waypoint, autoRoute);
else
_reader.skipCurrentElement();
}

View File

@ -21,11 +21,13 @@ private:
void rpExtension(SegmentData *autoRoute);
void tpExtension(Trackpoint &trackpoint);
void trkptExtensions(Trackpoint &trackpoint);
void rteptExtensions(SegmentData *autoRoute);
void wpExtension(Waypoint &waypoint);
void waypointExtensions(Waypoint &waypoint, SegmentData *autoRoute);
void area(Area &area);
void gpxExtensions(QList<Area> &areas);
void trackpointData(Trackpoint &trackpoint);
void waypointData(Waypoint &waypoint, SegmentData *autoRoute = 0);
void address(Waypoint &waypoint);
qreal number();
QDateTime time();
Coordinates coordinates();

View File

@ -8,6 +8,7 @@
#include "common/coordinates.h"
#include "imageinfo.h"
#include "link.h"
#include "address.h"
class Waypoint
{
@ -19,6 +20,7 @@ public:
const Coordinates &coordinates() const {return _coordinates;}
const QString &name() const {return _name;}
const QString &description() const {return _description;}
const Address &address() const {return _address;}
const ImageInfo &image() const {return _image;}
const QVector<Link> &links() const {return _links;}
const QDateTime &timestamp() const {return _timestamp;}
@ -29,6 +31,7 @@ public:
void setName(const QString &name) {_name = name;}
void setDescription(const QString &description)
{_description = description;}
void setAddress(const Address &address) {_address = address;}
void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;}
void setElevation(qreal elevation) {_elevation = elevation;}
void setImage(const ImageInfo &image) {_image = image;}
@ -44,6 +47,7 @@ private:
Coordinates _coordinates;
QString _name;
QString _description;
Address _address;
ImageInfo _image;
QVector<Link> _links;
QDateTime _timestamp;