Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

favorites_gpx_refactor #427

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/OsmAndCore/FavoriteLocationsCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace OsmAnd

virtual std::shared_ptr<IFavoriteLocation> createFavoriteLocation(
const PointI position31,
const QString& elevation = QString(),
const double elevation = NAN,
const QString& time = QString(),
const QString& creationTime = QString(),
const QString& title = QString(),
Expand All @@ -46,7 +46,7 @@ namespace OsmAnd
const bool calendarEvent = false);
virtual std::shared_ptr<IFavoriteLocation> createFavoriteLocation(
const LatLon latLon,
const QString& elevation = QString(),
const double elevation = NAN,
const QString& time = QString(),
const QString& creationTime = QString(),
const QString& title = QString(),
Expand Down
4 changes: 2 additions & 2 deletions include/OsmAndCore/IFavoriteLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace OsmAnd
virtual bool isHidden() const = 0;
virtual void setIsHidden(const bool isHidden) = 0;

virtual QString getElevation() const = 0;
virtual void setElevation(const QString& newElevation) = 0;
virtual double getElevation() const = 0;
virtual void setElevation(const double newElevation) = 0;

virtual QString getTime() const = 0;
virtual void setTime(const QString& newTime) = 0;
Expand Down
4 changes: 2 additions & 2 deletions include/OsmAndCore/IFavoriteLocationsCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace OsmAnd

virtual std::shared_ptr<IFavoriteLocation> createFavoriteLocation(
const PointI position31,
const QString& elevation = QString(),
const double elevation = NAN,
const QString& time = QString(),
const QString& creationTime = QString(),
const QString& title = QString(),
Expand All @@ -46,7 +46,7 @@ namespace OsmAnd
const bool calendarEvent = false) = 0;
virtual std::shared_ptr<IFavoriteLocation> createFavoriteLocation(
const LatLon latLon,
const QString& elevation = QString(),
const double elevation = NAN,
const QString& time = QString(),
const QString& creationTime = QString(),
const QString& title = QString(),
Expand Down
8 changes: 4 additions & 4 deletions src/FavoriteLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
OsmAnd::FavoriteLocation::FavoriteLocation(
const std::shared_ptr< Link<FavoriteLocationsCollection*> >& containerLink_,
const PointI position31_,
const QString& elevation_,
const double elevation_,
const QString& time_,
const QString& pickupTime_,
const QString& title_,
Expand Down Expand Up @@ -41,7 +41,7 @@ OsmAnd::FavoriteLocation::FavoriteLocation(
OsmAnd::FavoriteLocation::FavoriteLocation(
const std::shared_ptr< Link<FavoriteLocationsCollection*> >& containerLink_,
const LatLon latLon_,
const QString& elevation_,
const double elevation_,
const QString& time_,
const QString& pickupTime_,
const QString& title_,
Expand Down Expand Up @@ -119,12 +119,12 @@ void OsmAnd::FavoriteLocation::setIsHidden(const bool isHidden)
_p->setIsHidden(isHidden);
}

QString OsmAnd::FavoriteLocation::getElevation() const
double OsmAnd::FavoriteLocation::getElevation() const
{
return _p->getElevation();
}

void OsmAnd::FavoriteLocation::setElevation(const QString& newElevation)
void OsmAnd::FavoriteLocation::setElevation(const double newElevation)
{
_p->setElevation(newElevation);
}
Expand Down
8 changes: 4 additions & 4 deletions src/FavoriteLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace OsmAnd
FavoriteLocation(
const std::shared_ptr< Link<FavoriteLocationsCollection*> >& containerLink,
const PointI position31,
const QString& elevation,
const double elevation,
const QString& time,
const QString& creationTime,
const QString& title,
Expand All @@ -45,7 +45,7 @@ namespace OsmAnd
FavoriteLocation(
const std::shared_ptr< Link<FavoriteLocationsCollection*> >& containerLink,
const LatLon latLon,
const QString& elevation,
const double elevation,
const QString& time,
const QString& creationTime,
const QString& title,
Expand Down Expand Up @@ -77,8 +77,8 @@ namespace OsmAnd
virtual bool isHidden() const;
virtual void setIsHidden(const bool isHidden);

virtual QString getElevation() const;
virtual void setElevation(const QString& newElevation);
virtual double getElevation() const;
virtual void setElevation(const double newElevation);

virtual QString getTime() const;
virtual void setTime(const QString& newTime);
Expand Down
4 changes: 2 additions & 2 deletions src/FavoriteLocation_P.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ void OsmAnd::FavoriteLocation_P::setIsHidden(const bool isHidden)
link->_p->notifyFavoriteLocationChanged(owner);
}

QString OsmAnd::FavoriteLocation_P::getElevation() const
double OsmAnd::FavoriteLocation_P::getElevation() const
{
QReadLocker scopedLocker(&_lock);

return _elevation;
}

void OsmAnd::FavoriteLocation_P::setElevation(const QString& newElevation)
void OsmAnd::FavoriteLocation_P::setElevation(const double newElevation)
{
QWriteLocker scopedLocker(&_lock);

Expand Down
6 changes: 3 additions & 3 deletions src/FavoriteLocation_P.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace OsmAnd
mutable QReadWriteLock _lock;

bool _isHidden;
QString _elevation;
double _elevation;
QString _time;
QString _pickupTime;
QString _title;
Expand All @@ -58,8 +58,8 @@ namespace OsmAnd
bool isHidden() const;
void setIsHidden(const bool isHidden);

QString getElevation() const;
void setElevation(const QString& newElevation);
double getElevation() const;
void setElevation(const double newElevation);

QString getTime() const;
void setTime(const QString& newTitle);
Expand Down
4 changes: 2 additions & 2 deletions src/FavoriteLocationsCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ OsmAnd::FavoriteLocationsCollection::~FavoriteLocationsCollection()

std::shared_ptr<OsmAnd::IFavoriteLocation> OsmAnd::FavoriteLocationsCollection::createFavoriteLocation(
const PointI position31,
const QString& elevation /*= QString::null*/,
const double elevation /*= QString::null*/,
const QString& time /*= QString::null*/,
const QString& pickupTime /*= QString::null*/,
const QString& title /*= QString::null*/,
Expand All @@ -38,7 +38,7 @@ std::shared_ptr<OsmAnd::IFavoriteLocation> OsmAnd::FavoriteLocationsCollection::

std::shared_ptr<OsmAnd::IFavoriteLocation> OsmAnd::FavoriteLocationsCollection::createFavoriteLocation(
const LatLon latLon,
const QString& elevation /*= QString::null*/,
const double elevation /*= QString::null*/,
const QString& time /*= QString::null*/,
const QString& pickupTime /*= QString::null*/,
const QString& title /*= QString::null*/,
Expand Down
4 changes: 2 additions & 2 deletions src/FavoriteLocationsCollection_P.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void OsmAnd::FavoriteLocationsCollection_P::notifyFavoriteLocationChanged(Favori

std::shared_ptr<OsmAnd::IFavoriteLocation> OsmAnd::FavoriteLocationsCollection_P::createFavoriteLocation(
const PointI position,
const QString& elevation,
const double elevation,
const QString& time,
const QString& pickupTime,
const QString& title,
Expand All @@ -52,7 +52,7 @@ std::shared_ptr<OsmAnd::IFavoriteLocation> OsmAnd::FavoriteLocationsCollection_P

std::shared_ptr<OsmAnd::IFavoriteLocation> OsmAnd::FavoriteLocationsCollection_P::createFavoriteLocation(
const LatLon latLon,
const QString& elevation,
const double elevation,
const QString& time,
const QString& pickupTime,
const QString& title,
Expand Down
4 changes: 2 additions & 2 deletions src/FavoriteLocationsCollection_P.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace OsmAnd

std::shared_ptr<IFavoriteLocation> createFavoriteLocation(
const PointI position,
const QString& elevation,
const double elevation,
const QString& time,
const QString& creationTime,
const QString& title,
Expand All @@ -63,7 +63,7 @@ namespace OsmAnd
const bool calendarEvent);
std::shared_ptr<IFavoriteLocation> createFavoriteLocation(
const LatLon latLon,
const QString& elevation,
const double elevation,
const QString& time,
const QString& creationTime,
const QString& title,
Expand Down
13 changes: 10 additions & 3 deletions src/FavoriteLocationsGpxCollection_P.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ bool OsmAnd::FavoriteLocationsGpxCollection_P::saveTo(QXmlStreamWriter& writer)
writer.writeAttribute(QLatin1String("lat"), QString::number(item->latLon.latitude, 'f', 7));
writer.writeAttribute(QLatin1String("lon"), QString::number(item->latLon.longitude, 'f', 7));

if (!item->getElevation().isNull() && item->getElevation().toDouble() > 0.)
if (!isnan(item->getElevation()))
{
// <ele>
writer.writeTextElement(QLatin1String("ele"), item->getElevation());
writer.writeTextElement(QLatin1String("ele"), QString::number(item->getElevation(), 'f', 1));
}

if (!item->getComment().isNull())
Expand Down Expand Up @@ -284,7 +284,14 @@ bool OsmAnd::FavoriteLocationsGpxCollection_P::loadFrom(QXmlStreamReader& xmlRea
return false;
}

newItem->setElevation(xmlReader.readElementText());
bool ok = true;
double ele = xmlReader.readElementText().toDouble(&ok);
if (!ok)
{
LogPrintf(LogSeverityLevel::Warning, "Malformed favorites GPX file: invalid <ele>");
return false;
}
newItem->setElevation(ele);
}
else if (tagName == QLatin1String("cmt"))
{
Expand Down