1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Do a propper cleanup on error

This commit is contained in:
Martin Tůma 2018-01-09 23:19:35 +01:00
parent fc80bd1b7c
commit b8102d6bb7
6 changed files with 41 additions and 18 deletions

View File

@ -103,13 +103,19 @@ Datum::Datum(const QString &name)
*this = Datum(); *this = Datum();
} }
void Datum::error(const QString &str)
{
_errorString = str;
_datums = WGS84();
}
bool Datum::loadList(const QString &path) bool Datum::loadList(const QString &path)
{ {
QFile file(path); QFile file(path);
bool res; bool res;
if (!file.open(QFile::ReadOnly)) { if (!file.open(QFile::ReadOnly)) {
_errorString = qPrintable(file.errorString()); error(file.errorString());
return false; return false;
} }
@ -120,7 +126,7 @@ bool Datum::loadList(const QString &path)
QByteArray line = file.readLine(); QByteArray line = file.readLine();
QList<QByteArray> list = line.split(','); QList<QByteArray> list = line.split(',');
if (list.size() != 6) { if (list.size() != 6) {
_errorString = "Format error"; error("Format error");
return false; return false;
} }
@ -129,34 +135,34 @@ bool Datum::loadList(const QString &path)
if (!f1.isEmpty()) { if (!f1.isEmpty()) {
id = f1.toInt(&res); id = f1.toInt(&res);
if (!res) { if (!res) {
_errorString = "Invalid datum id"; error("Invalid datum id");
return false; return false;
} }
} }
int eid = list[2].trimmed().toInt(&res); int eid = list[2].trimmed().toInt(&res);
if (!res) { if (!res) {
_errorString = "Invalid ellipsoid id"; error("Invalid ellipsoid id");
return false; return false;
} }
double dx = list[3].trimmed().toDouble(&res); double dx = list[3].trimmed().toDouble(&res);
if (!res) { if (!res) {
_errorString = "Invalid dx"; error("Invalid dx");
return false; return false;
} }
double dy = list[4].trimmed().toDouble(&res); double dy = list[4].trimmed().toDouble(&res);
if (!res) { if (!res) {
_errorString = "Invalid dy"; error("Invalid dy");
return false; return false;
} }
double dz = list[5].trimmed().toDouble(&res); double dz = list[5].trimmed().toDouble(&res);
if (!res) { if (!res) {
_errorString = "Invalid dz"; error("Invalid dz");
return false; return false;
} }
Ellipsoid e(eid); Ellipsoid e(eid);
if (e.isNull()) { if (e.isNull()) {
_errorString = "Unknown ellipsoid ID"; error("Unknown ellipsoid ID");
return false; return false;
} }

View File

@ -36,6 +36,7 @@ private:
class Entry; class Entry;
static QList<Entry> WGS84(); static QList<Entry> WGS84();
static void error(const QString &str);
Ellipsoid _ellipsoid; Ellipsoid _ellipsoid;
double _dx, _dy, _dz; double _dx, _dy, _dz;

View File

@ -16,6 +16,12 @@ Ellipsoid::Ellipsoid(int id)
*this = it.value(); *this = it.value();
} }
void Ellipsoid::error(const QString &str)
{
_errorString = str;
_ellipsoids.clear();
}
bool Ellipsoid::loadList(const QString &path) bool Ellipsoid::loadList(const QString &path)
{ {
QFile file(path); QFile file(path);
@ -23,7 +29,7 @@ bool Ellipsoid::loadList(const QString &path)
if (!file.open(QFile::ReadOnly)) { if (!file.open(QFile::ReadOnly)) {
_errorString = qPrintable(file.errorString()); error(file.errorString());
return false; return false;
} }
@ -34,23 +40,23 @@ bool Ellipsoid::loadList(const QString &path)
QByteArray line = file.readLine(); QByteArray line = file.readLine();
QList<QByteArray> list = line.split(','); QList<QByteArray> list = line.split(',');
if (list.size() != 4) { if (list.size() != 4) {
_errorString = "Format error"; error("Format error");
return false; return false;
} }
int id = list[1].trimmed().toInt(&res); int id = list[1].trimmed().toInt(&res);
if (!res) { if (!res) {
_errorString = "Invalid ellipsoid id"; error("Invalid ellipsoid id");
return false; return false;
} }
double radius = list[2].trimmed().toDouble(&res); double radius = list[2].trimmed().toDouble(&res);
if (!res) { if (!res) {
_errorString = "Invalid ellipsoid radius"; error("Invalid ellipsoid radius");
return false; return false;
} }
double flattening = list[3].trimmed().toDouble(&res); double flattening = list[3].trimmed().toDouble(&res);
if (!res) { if (!res) {
_errorString = "Invalid ellipsoid flattening"; error("Invalid ellipsoid flattening");
return false; return false;
} }

View File

@ -25,6 +25,8 @@ public:
static int errorLine() {return _errorLine;} static int errorLine() {return _errorLine;}
private: private:
static void error(const QString &str);
double _radius; double _radius;
double _flattening; double _flattening;

View File

@ -58,6 +58,12 @@ PCS::PCS(int gcs, int proj)
*this = PCS(); *this = PCS();
} }
void PCS::error(const QString &str)
{
_errorString = str;
_pcss.clear();
}
bool PCS::loadList(const QString &path) bool PCS::loadList(const QString &path)
{ {
QFile file(path); QFile file(path);
@ -66,7 +72,7 @@ bool PCS::loadList(const QString &path)
if (!file.open(QFile::ReadOnly)) { if (!file.open(QFile::ReadOnly)) {
_errorString = qPrintable(file.errorString()); error(file.errorString());
return false; return false;
} }
@ -77,7 +83,7 @@ bool PCS::loadList(const QString &path)
QByteArray line = file.readLine(); QByteArray line = file.readLine();
QList<QByteArray> list = line.split(','); QList<QByteArray> list = line.split(',');
if (list.size() != 12) { if (list.size() != 12) {
_errorString = "Format error"; error("Format error");
return false; return false;
} }
@ -94,19 +100,19 @@ bool PCS::loadList(const QString &path)
for (int i = 1; i < 12; i++) { for (int i = 1; i < 12; i++) {
if (!res[i]) { if (!res[i]) {
_errorString = "Parse error"; error("Parse error");
return false; return false;
} }
} }
Datum datum(gcs); Datum datum(gcs);
if (datum.isNull()) { if (datum.isNull()) {
_errorString = "Unknown datum"; error("Unknown datum");
return false; return false;
} }
Projection::Method method(transform); Projection::Method method(transform);
if (method.isNull()) { if (method.isNull()) {
_errorString = "Unknown coordinates transformation method"; error("Unknown coordinates transformation method");
return false; return false;
} }

View File

@ -32,6 +32,8 @@ public:
private: private:
class Entry; class Entry;
static void error(const QString &str);
Datum _datum; Datum _datum;
Projection::Method _method; Projection::Method _method;
Projection::Setup _setup; Projection::Setup _setup;