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

View File

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

View File

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

View File

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

View File

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

View File

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