From 49792064d715cfbe4bacb8d6df2d139848199cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 11 Mar 2018 09:24:04 +0100 Subject: [PATCH] Fixed error handling --- src/map/projection.cpp | 12 ++++++------ src/map/projection.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/map/projection.cpp b/src/map/projection.cpp index 1e19f4b7..ac07272f 100644 --- a/src/map/projection.cpp +++ b/src/map/projection.cpp @@ -68,8 +68,6 @@ Projection::Projection(const GCS *gcs, const Method &method, const Setup &setup, default: _ct = 0; } - - Q_ASSERT(_ct != 0); } Projection::Projection(const GCS *gcs) : _gcs(gcs), _geographic(true) @@ -82,7 +80,7 @@ Projection::Projection(const Projection &p) { _gcs = p._gcs; _units = p._units; - _ct = p._ct->clone(); + _ct = p._ct ? p._ct->clone() : 0; _geographic = p._geographic; } @@ -95,7 +93,7 @@ Projection &Projection::operator=(const Projection &p) { _gcs = p._gcs; _units = p._units; - _ct = p._ct->clone(); + _ct = p._ct ? p._ct->clone() : 0; _geographic = p._geographic; return *this; @@ -103,12 +101,14 @@ Projection &Projection::operator=(const Projection &p) QPointF Projection::ll2xy(const Coordinates &c) const { - return _units.fromMeters(_ct->ll2xy(_gcs->fromWGS84(c))); + return isValid() + ? _units.fromMeters(_ct->ll2xy(_gcs->fromWGS84(c))) : QPointF(); } Coordinates Projection::xy2ll(const QPointF &p) const { - return _gcs->toWGS84(_ct->xy2ll(_units.toMeters(p))); + return isValid() + ? _gcs->toWGS84(_ct->xy2ll(_units.toMeters(p))) : Coordinates(); } #ifndef QT_NO_DEBUG diff --git a/src/map/projection.h b/src/map/projection.h index 6bb1f894..9e9c18f9 100644 --- a/src/map/projection.h +++ b/src/map/projection.h @@ -78,7 +78,7 @@ public: Projection &operator=(const Projection &p); bool isNull() const {return (_gcs == 0 && _ct == 0 && _units.isNull());} - bool isValid() const {return (_gcs == 0 || _ct == 0 || _units.isNull());} + bool isValid() const {return !(_gcs == 0 || _ct == 0 || _units.isNull());} bool isGeographic() const {return _geographic;} QPointF ll2xy(const Coordinates &c) const;