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

Added support for waypoint phone data

+ address waypoint data where missing
This commit is contained in:
Martin Tůma 2021-05-12 21:58:46 +02:00
parent 4b2bee2368
commit b9e3e81ac1
9 changed files with 62 additions and 28 deletions

View File

@ -279,6 +279,7 @@ SOURCES += src/main.cpp \
src/GUI/gearratiographitem.cpp \
src/GUI/mapview.cpp \
src/GUI/areaitem.cpp \
src/data/address.cpp \
src/data/itnparser.cpp \
src/data/ov2parser.cpp \
src/data/waypoint.cpp \

View File

@ -45,19 +45,14 @@ QString WaypointItem::info() const
&& _waypoint.comment() != _waypoint.description())
tt.insert(qApp->translate("WaypointItem", "Comment"),
_waypoint.comment());
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>";
if (!_waypoint.address().isEmpty()) {
QString addr(_waypoint.address());
addr.replace('\n', "<br/>");
addr = "<address>" + addr + "</address>";
tt.insert(qApp->translate("WaypointItem", "Address"), addr);
}
if (!_waypoint.phone().isEmpty())
tt.insert(qApp->translate("WaypointItem", "Phone"), _waypoint.phone());
if (!_waypoint.links().isEmpty()) {
QString links;
for (int i = 0; i < _waypoint.links().size(); i++) {

19
src/data/address.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "address.h"
QString Address::address() const
{
QString addr(_street);
if (addr.isEmpty())
addr = _city;
else
addr += "\n" + _city;
if (!_postalCode.isEmpty())
addr += "\n" + _postalCode;
if (!_state.isEmpty())
addr += "\n" + _state;
if (!_country.isEmpty())
addr += "\n" + _country;
return addr;
}

View File

@ -10,11 +10,7 @@ public:
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;}
QString address() const;
void setStreet(const QString &street) {_street = street;}
void setCity(const QString &city) {_city = city;}
@ -22,7 +18,7 @@ public:
void setCountry(const QString &country) {_country = country;}
void setPostalCode(const QString &postalCode) {_postalCode = postalCode;}
bool isValid() const {return !(_street.isEmpty() || _city.isEmpty());}
bool isValid() const {return !_city.isEmpty();}
private:
QString _street;

View File

@ -10,6 +10,7 @@
#include <QTemporaryDir>
#include "common/garmin.h"
#include "common/textcodec.h"
#include "address.h"
#include "gpiparser.h"
@ -324,15 +325,19 @@ static quint32 readContact(DataStream &stream, Waypoint &waypoint)
rs = stream.readRecordHeader(rh);
stream >> flags;
if (flags & 0x1) // phone
if (flags & 0x1) {
ds += stream.readString(str);
waypoint.setPhone(str);
}
if (flags & 0x2) // phone2
ds += stream.readString(str);
if (flags & 0x4) // fax
ds += stream.readString(str);
if (flags & 0x8) // mail
if (flags & 0x8) {
ds += stream.readString(str);
if (flags & 0x10) { // web
waypoint.addLink(Link("mailto:" + str, str));
}
if (flags & 0x10) {
ds += stream.readString(str);
QUrl url(str);
waypoint.addLink(Link(url.scheme().isEmpty()
@ -387,7 +392,8 @@ static quint32 readAddress(DataStream &stream, Waypoint &waypoint)
if (flags & 0x20) // unknown
ds += stream.readString(str);
waypoint.setAddress(addr);
if (addr.isValid())
waypoint.setAddress(addr.address());
if (ds != rh.size)
stream.setStatus(QDataStream::ReadCorruptData);

View File

@ -1,3 +1,4 @@
#include "address.h"
#include "gpxparser.h"
@ -103,7 +104,8 @@ void GPXParser::address(Waypoint &waypoint)
_reader.skipCurrentElement();
}
waypoint.setAddress(addr);
if (addr.isValid())
waypoint.setAddress(addr.address());
}
void GPXParser::wpExtension(Waypoint &waypoint)
@ -111,6 +113,8 @@ void GPXParser::wpExtension(Waypoint &waypoint)
while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("Address"))
address(waypoint);
else if (_reader.name() == QLatin1String("PhoneNumber"))
waypoint.setPhone(_reader.readElementText());
else
_reader.skipCurrentElement();
}

View File

@ -492,7 +492,7 @@ void KMLParser::multiGeometry(QList<TrackData> &tracks, QList<Area> &areas,
void KMLParser::placemark(QList<TrackData> &tracks, QList<Area> &areas,
QVector<Waypoint> &waypoints)
{
QString name, desc;
QString name, desc, phone, address;
QDateTime timestamp;
while (_reader.readNextStartElement()) {
@ -500,6 +500,10 @@ void KMLParser::placemark(QList<TrackData> &tracks, QList<Area> &areas,
name = _reader.readElementText();
else if (_reader.name() == QLatin1String("description"))
desc = _reader.readElementText();
else if (_reader.name() == QLatin1String("phoneNumber"))
phone = _reader.readElementText();
else if (_reader.name() == QLatin1String("address"))
address = _reader.readElementText();
else if (_reader.name() == QLatin1String("TimeStamp"))
timestamp = timeStamp();
else if (_reader.name() == QLatin1String("MultiGeometry"))
@ -510,6 +514,8 @@ void KMLParser::placemark(QList<TrackData> &tracks, QList<Area> &areas,
w.setName(name);
w.setDescription(desc);
w.setTimestamp(timestamp);
w.setAddress(address);
w.setPhone(phone);
point(w);
} else if (_reader.name() == QLatin1String("LineString")
|| _reader.name() == QLatin1String("LinearRing")) {

View File

@ -53,7 +53,12 @@ bool OV2Parser::parse(QFile *file, QList<TrackData> &tracks,
}
Waypoint wp(Coordinates(lon/1e5, lat/1e5));
QList<QByteArray> parts(ba.split('\0'));
wp.setName(codec.toString(parts.first()));
int pp = parts.first().indexOf('>');
if (pp >= 0) {
wp.setName(codec.toString(parts.first().left(pp)));
wp.setPhone(parts.first().mid(pp+1));
} else
wp.setName(codec.toString(parts.first()));
waypoints.append(wp);}
break;
default:

View File

@ -10,7 +10,6 @@
#include "common/coordinates.h"
#include "imageinfo.h"
#include "link.h"
#include "address.h"
class Waypoint
{
@ -24,7 +23,8 @@ public:
const QString &name() const {return _name;}
const QString &description() const {return _description;}
const QString &comment() const {return _comment;}
const Address &address() const {return _address;}
const QString &address() const {return _address;}
const QString &phone() const {return _phone;}
const QVector<ImageInfo> &images() const {return _images;}
const QVector<Link> &links() const {return _links;}
const QDateTime &timestamp() const {return _timestamp;}
@ -38,7 +38,8 @@ public:
void setDescription(const QString &description)
{_description = description;}
void setComment(const QString &comment) {_comment = comment;}
void setAddress(const Address &address) {_address = address;}
void setAddress(const QString &address) {_address = address;}
void setPhone(const QString &phone) {_phone = phone;}
void setTimestamp(const QDateTime &timestamp) {_timestamp = timestamp;}
void setElevation(qreal elevation) {_elevation = elevation;}
void addImage(const ImageInfo &image) {_images.append(image);}
@ -59,7 +60,8 @@ private:
QString _name;
QString _description;
QString _comment;
Address _address;
QString _address;
QString _phone;
QVector<ImageInfo> _images;
QVector<Link> _links;
QDateTime _timestamp;