1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-08 16:24:28 +02:00

Fixed POI crash on vector reallocation

Improved error reporting
This commit is contained in:
2015-11-26 19:13:59 +01:00
parent d1bf74f43b
commit 4e543782ec
11 changed files with 135 additions and 129 deletions

View File

@ -11,9 +11,10 @@ bool POI::loadFile(const QString &fileName)
{
QFile file(fileName);
bool ret;
int ln = 1;
int ln = 1, cnt = _data.size();
_error.clear();
_errorLine = 0;
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
@ -24,18 +25,21 @@ bool POI::loadFile(const QString &fileName)
QByteArray line = file.readLine();
QList<QByteArray> list = line.split(',');
if (list.size() < 3) {
_error = QString("Parse error\nLine %1").arg(ln);
_error = "Parse error";
_errorLine = ln;
return false;
}
qreal lat = list[0].trimmed().toDouble(&ret);
if (!ret) {
_error = QObject::tr("Invalid latitude\nLine %1").arg(ln);
_error = "Invalid latitude";
_errorLine = ln;
return false;
}
qreal lon = list[1].trimmed().toDouble(&ret);
if (!ret) {
_error = QObject::tr("Invalid longitude\nLine %1").arg(ln);
_error = "Invalid longitude";
_errorLine = ln;
return false;
}
QByteArray ba = list[2].trimmed();
@ -48,20 +52,20 @@ bool POI::loadFile(const QString &fileName)
ln++;
}
for (int i = 0; i < _data.size(); ++i) {
for (int i = cnt; i < _data.size(); ++i) {
qreal c[2];
c[0] = _data.at(i).coordinates.x();
c[1] = _data.at(i).coordinates.y();
_tree.Insert(c, c, &_data.at(i));
_tree.Insert(c, c, i);
}
return true;
}
static bool cb(const Entry* data, void* context)
static bool cb(size_t data, void* context)
{
QSet<const Entry*> *set = (QSet<const Entry*>*) context;
set->insert(data);
QSet<int> *set = (QSet<int>*) context;
set->insert((int)data);
return true;
}
@ -69,7 +73,7 @@ static bool cb(const Entry* data, void* context)
QVector<Entry> POI::points(const QVector<QPointF> &path) const
{
QVector<Entry> ret;
QSet<const Entry*> set;
QSet<int> set;
qreal min[2], max[2];
for (int i = 0; i < path.count(); i++) {
@ -80,10 +84,10 @@ QVector<Entry> POI::points(const QVector<QPointF> &path) const
_tree.Search(min, max, cb, &set);
}
QSet<const Entry *>::const_iterator i = set.constBegin();
QSet<int>::const_iterator i = set.constBegin();
while (i != set.constEnd()) {
ret.append(*(*i));
++i;
ret.append(_data.at(*i));
++i;
}
return ret;