mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Fixed POI crash on vector reallocation
Improved error reporting
This commit is contained in:
parent
d1bf74f43b
commit
4e543782ec
@ -1,45 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="cs_CZ">
|
||||
<TS version="2.0" language="cs_CZ">
|
||||
<context>
|
||||
<name>ElevationGraph</name>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="12"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="13"/>
|
||||
<source>Distance</source>
|
||||
<translation>Vzdálenost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="13"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="14"/>
|
||||
<source>Elevation</source>
|
||||
<translation>Výška</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="14"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="15"/>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="15"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="16"/>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="51"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="52"/>
|
||||
<source>Ascent</source>
|
||||
<translation>Stoupání</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="53"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="54"/>
|
||||
<source>Descent</source>
|
||||
<translation>Klesání</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="57"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="58"/>
|
||||
<source>Minimum</source>
|
||||
<translation>Minimum</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/elevationgraph.cpp" line="55"/>
|
||||
<location filename="../src/elevationgraph.cpp" line="56"/>
|
||||
<source>Maximum</source>
|
||||
<translation>Maximum</translation>
|
||||
</message>
|
||||
@ -47,282 +47,259 @@
|
||||
<context>
|
||||
<name>GUI</name>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="125"/>
|
||||
<location filename="../src/gui.cpp" line="133"/>
|
||||
<source>About Qt</source>
|
||||
<translation>O Qt</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="284"/>
|
||||
<location filename="../src/gui.cpp" line="292"/>
|
||||
<source>GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at </source>
|
||||
<translation>Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese </translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="314"/>
|
||||
<location filename="../src/gui.cpp" line="322"/>
|
||||
<source>Open file</source>
|
||||
<translation>Otevřít soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="139"/>
|
||||
<location filename="../src/gui.cpp" line="147"/>
|
||||
<source>Save as</source>
|
||||
<translation>Uložit jako</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="360"/>
|
||||
<location filename="../src/gui.cpp" line="373"/>
|
||||
<source>Open POI file</source>
|
||||
<translation>Otevřít POI soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="130"/>
|
||||
<location filename="../src/gui.cpp" line="138"/>
|
||||
<source>Open</source>
|
||||
<translation>Otevřít</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="115"/>
|
||||
<location filename="../src/gui.cpp" line="123"/>
|
||||
<source>Quit</source>
|
||||
<translation>Ukončit</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="120"/>
|
||||
<location filename="../src/gui.cpp" line="300"/>
|
||||
<location filename="../src/gui.cpp" line="301"/>
|
||||
<location filename="../src/gui.cpp" line="128"/>
|
||||
<location filename="../src/gui.cpp" line="308"/>
|
||||
<location filename="../src/gui.cpp" line="309"/>
|
||||
<source>Keyboard controls</source>
|
||||
<translation>Ovládací klávesy</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="134"/>
|
||||
<location filename="../src/gui.cpp" line="142"/>
|
||||
<source>Save</source>
|
||||
<translation>Uložit</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="144"/>
|
||||
<location filename="../src/gui.cpp" line="152"/>
|
||||
<source>Close</source>
|
||||
<translation>Zavřít</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="149"/>
|
||||
<location filename="../src/gui.cpp" line="157"/>
|
||||
<source>Reload</source>
|
||||
<translation>Znovu načíst</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="233"/>
|
||||
<location filename="../src/gui.cpp" line="241"/>
|
||||
<source>Show</source>
|
||||
<translation>Zobrazit</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="188"/>
|
||||
<location filename="../src/gui.cpp" line="224"/>
|
||||
<location filename="../src/gui.cpp" line="196"/>
|
||||
<location filename="../src/gui.cpp" line="232"/>
|
||||
<source>File</source>
|
||||
<translation>Soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="156"/>
|
||||
<location filename="../src/gui.cpp" line="164"/>
|
||||
<source>Load POI file</source>
|
||||
<translation>Nahrát POI soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="159"/>
|
||||
<location filename="../src/gui.cpp" line="167"/>
|
||||
<source>Show POIs</source>
|
||||
<translation>Zobrazit POI</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="164"/>
|
||||
<location filename="../src/gui.cpp" line="172"/>
|
||||
<source>Show map</source>
|
||||
<translation>Zobrazit mapu</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="174"/>
|
||||
<location filename="../src/gui.cpp" line="182"/>
|
||||
<source>Show graphs</source>
|
||||
<translation>Zobrazovat grafy</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="179"/>
|
||||
<location filename="../src/gui.cpp" line="187"/>
|
||||
<source>Show toolbars</source>
|
||||
<translation>Zobrazovat nástrojové lišty</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="202"/>
|
||||
<location filename="../src/gui.cpp" line="210"/>
|
||||
<source>Map</source>
|
||||
<translation>Mapa</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="207"/>
|
||||
<location filename="../src/gui.cpp" line="215"/>
|
||||
<source>POI</source>
|
||||
<translation>POI</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="211"/>
|
||||
<location filename="../src/gui.cpp" line="219"/>
|
||||
<source>Settings</source>
|
||||
<translation>Nastavení</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="215"/>
|
||||
<location filename="../src/gui.cpp" line="223"/>
|
||||
<source>Help</source>
|
||||
<translation>Nápověda</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="252"/>
|
||||
<location filename="../src/gui.cpp" line="260"/>
|
||||
<source>Elevation</source>
|
||||
<translation>Výška</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="253"/>
|
||||
<location filename="../src/gui.cpp" line="261"/>
|
||||
<source>Speed</source>
|
||||
<translation>Rychlost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="303"/>
|
||||
<location filename="../src/gui.cpp" line="311"/>
|
||||
<source>Next file</source>
|
||||
<translation>Následující soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="304"/>
|
||||
<location filename="../src/gui.cpp" line="312"/>
|
||||
<source>Previous file</source>
|
||||
<translation>Předchozí soubor</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="306"/>
|
||||
<location filename="../src/gui.cpp" line="314"/>
|
||||
<source>Append modifier</source>
|
||||
<translation>Modifikátor nahradit/přidat</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="416"/>
|
||||
<location filename="../src/gui.cpp" line="364"/>
|
||||
<location filename="../src/gui.cpp" line="380"/>
|
||||
<source>Line: %1</source>
|
||||
<translation>Řádka: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="432"/>
|
||||
<source>Maximum</source>
|
||||
<translation>Maximum</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="418"/>
|
||||
<location filename="../src/gui.cpp" line="434"/>
|
||||
<source>Minimum</source>
|
||||
<translation>Minimum</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="123"/>
|
||||
<location filename="../src/gui.cpp" line="280"/>
|
||||
<location filename="../src/gui.cpp" line="131"/>
|
||||
<location filename="../src/gui.cpp" line="288"/>
|
||||
<source>About GPXSee</source>
|
||||
<translation>O aplikaci GPXSee</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="282"/>
|
||||
<location filename="../src/gui.cpp" line="290"/>
|
||||
<source>GPX viewer and analyzer</source>
|
||||
<translation>Prohlížeč a analyzátor GPX</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="409"/>
|
||||
<location filename="../src/gui.cpp" line="425"/>
|
||||
<source>Distance</source>
|
||||
<translation>Vzdálenost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="411"/>
|
||||
<location filename="../src/gui.cpp" line="427"/>
|
||||
<source>Time</source>
|
||||
<translation>Čas</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="412"/>
|
||||
<location filename="../src/gui.cpp" line="428"/>
|
||||
<source>Ascent</source>
|
||||
<translation>Stoupání</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="413"/>
|
||||
<location filename="../src/gui.cpp" line="415"/>
|
||||
<location filename="../src/gui.cpp" line="417"/>
|
||||
<location filename="../src/gui.cpp" line="419"/>
|
||||
<location filename="../src/gui.cpp" line="429"/>
|
||||
<location filename="../src/gui.cpp" line="431"/>
|
||||
<location filename="../src/gui.cpp" line="433"/>
|
||||
<location filename="../src/gui.cpp" line="435"/>
|
||||
<source>m</source>
|
||||
<translation>m</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="414"/>
|
||||
<location filename="../src/gui.cpp" line="430"/>
|
||||
<source>Descent</source>
|
||||
<translation>Klesání</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="510"/>
|
||||
<location filename="../src/gui.cpp" line="526"/>
|
||||
<source>%1 tracks</source>
|
||||
<translation>Počet tras: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="410"/>
|
||||
<location filename="../src/gui.cpp" line="513"/>
|
||||
<location filename="../src/gui.cpp" line="426"/>
|
||||
<location filename="../src/gui.cpp" line="529"/>
|
||||
<source>km</source>
|
||||
<translation>km</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="352"/>
|
||||
<location filename="../src/gui.cpp" line="364"/>
|
||||
<location filename="../src/gui.cpp" line="366"/>
|
||||
<location filename="../src/gui.cpp" line="381"/>
|
||||
<source>Error</source>
|
||||
<translation>Chyba</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="353"/>
|
||||
<location filename="../src/gui.cpp" line="361"/>
|
||||
<source>Error loading GPX file:
|
||||
%1</source>
|
||||
<translation>Soubor GPX nelze otevřít:
|
||||
%1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/gui.cpp" line="365"/>
|
||||
<location filename="../src/gui.cpp" line="377"/>
|
||||
<source>Error loading POI file:
|
||||
%1</source>
|
||||
<translation>Soubor POI nelze otevřít:
|
||||
%1</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>QObject</name>
|
||||
<message>
|
||||
<location filename="../src/parser.cpp" line="97"/>
|
||||
<source>Not a GPX file.</source>
|
||||
<translation>Neplatný GPX soubor.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/parser.cpp" line="106"/>
|
||||
<source>%1
|
||||
Line %2</source>
|
||||
<translation>%1
|
||||
Rádka %2</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/poi.cpp" line="31"/>
|
||||
<source>Invalid latitude
|
||||
Line %1</source>
|
||||
<translation>Neplatná zeměpisná šířka
|
||||
Rádka %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/poi.cpp" line="36"/>
|
||||
<source>Invalid longitude
|
||||
Line %1</source>
|
||||
<translation>Neplatná zeměpisná délka
|
||||
Rádka %1</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>SpeedGraph</name>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="11"/>
|
||||
<location filename="../src/speedgraph.cpp" line="9"/>
|
||||
<source>Distance</source>
|
||||
<translation>Vzdálenost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="12"/>
|
||||
<location filename="../src/speedgraph.cpp" line="10"/>
|
||||
<source>Speed</source>
|
||||
<translation>Rychlost</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="13"/>
|
||||
<location filename="../src/speedgraph.cpp" line="11"/>
|
||||
<source>km</source>
|
||||
<translation></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="14"/>
|
||||
<location filename="../src/speedgraph.cpp" line="12"/>
|
||||
<source>km/h</source>
|
||||
<translation>km/h</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="37"/>
|
||||
<location filename="../src/speedgraph.cpp" line="35"/>
|
||||
<source>Average</source>
|
||||
<translation>Průměr</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../src/speedgraph.cpp" line="39"/>
|
||||
<location filename="../src/speedgraph.cpp" line="37"/>
|
||||
<source>Maximum</source>
|
||||
<translation>Maximum</translation>
|
||||
</message>
|
||||
|
@ -8,6 +8,7 @@
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12
|
||||
|
||||
#define POI_DIR "POI"
|
||||
#define TILES_DIR "tiles"
|
||||
#define MAP_LIST_FILE TILES_DIR"/list.txt"
|
||||
|
||||
|
@ -87,14 +87,17 @@ bool GPX::loadFile(const QString &fileName)
|
||||
|
||||
_data.clear();
|
||||
_error.clear();
|
||||
_errorLine = 0;
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
_error = qPrintable(file.errorString());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(ret = _parser.loadFile(&file, _data)))
|
||||
if (!(ret = _parser.loadFile(&file, _data))) {
|
||||
_error = _parser.errorString();
|
||||
_errorLine = _parser.errorLine();
|
||||
}
|
||||
file.close();
|
||||
|
||||
return ret;
|
||||
|
@ -11,6 +11,7 @@ class GPX
|
||||
public:
|
||||
bool loadFile(const QString &fileName);
|
||||
const QString &errorString() const {return _error;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
void elevationGraph(QVector<QPointF> &graph) const;
|
||||
void speedGraph(QVector<QPointF> &graph) const;
|
||||
@ -23,6 +24,7 @@ private:
|
||||
Parser _parser;
|
||||
QVector<TrackPoint> _data;
|
||||
QString _error;
|
||||
int _errorLine;
|
||||
};
|
||||
|
||||
#endif // GPX_H
|
||||
|
32
src/gui.cpp
32
src/gui.cpp
@ -37,7 +37,7 @@ static QString timeSpan(qreal time)
|
||||
|
||||
GUI::GUI()
|
||||
{
|
||||
loadMaps();
|
||||
loadFiles();
|
||||
|
||||
createActions();
|
||||
createMenus();
|
||||
@ -71,9 +71,20 @@ GUI::GUI()
|
||||
resize(600, 800);
|
||||
}
|
||||
|
||||
void GUI::loadMaps()
|
||||
void GUI::loadFiles()
|
||||
{
|
||||
// Maps
|
||||
_maps = MapList::load(QString("%1/"MAP_LIST_FILE).arg(QDir::homePath()));
|
||||
|
||||
// POI files
|
||||
QDir dir(QString("%1/"POI_DIR).arg(QDir::homePath()));
|
||||
QFileInfoList list = dir.entryInfoList(QStringList(), QDir::Files);
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
if (!_poi.loadFile(list.at(i).absoluteFilePath()))
|
||||
fprintf(stderr, "Error loading POI file: %s: %s",
|
||||
qPrintable(list.at(i).absoluteFilePath()),
|
||||
qPrintable(_poi.errorString()));
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::createMapActions()
|
||||
@ -346,8 +357,13 @@ bool GUI::loadFile(const QString &fileName)
|
||||
|
||||
return true;
|
||||
} else {
|
||||
QMessageBox::critical(this, tr("Error"), fileName + QString("\n\n")
|
||||
+ tr("Error loading GPX file:\n%1").arg(gpx.errorString()));
|
||||
QString error = fileName + QString("\n\n")
|
||||
+ tr("Error loading GPX file:\n%1").arg(gpx.errorString())
|
||||
+ QString("\n");
|
||||
if (gpx.errorLine())
|
||||
error.append(tr("Line: %1").arg(gpx.errorLine()));
|
||||
|
||||
QMessageBox::critical(this, tr("Error"), error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -358,8 +374,11 @@ void GUI::openPOIFile()
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!_poi.loadFile(fileName)) {
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Error loading POI file:\n%1").arg(_poi.errorString()));
|
||||
QString error = tr("Error loading POI file:\n%1")
|
||||
.arg(_poi.errorString()) + QString("\n");
|
||||
if (_poi.errorLine())
|
||||
error.append(tr("Line: %1").arg(_poi.errorLine()));
|
||||
QMessageBox::critical(this, tr("Error"), error);
|
||||
} else {
|
||||
_showPOIAction->setChecked(true);
|
||||
_track->loadPOI(_poi);
|
||||
@ -527,7 +546,6 @@ void GUI::graphChanged(int index)
|
||||
_speedGraph->setSliderPosition(_elevationGraph->sliderPosition());
|
||||
}
|
||||
|
||||
|
||||
void GUI::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
QString file;
|
||||
|
@ -45,7 +45,7 @@ private slots:
|
||||
void graphChanged(int);
|
||||
|
||||
private:
|
||||
void loadMaps();
|
||||
void loadFiles();
|
||||
|
||||
void createMapActions();
|
||||
void createActions();
|
||||
|
@ -1,13 +1,17 @@
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include "maplist.h"
|
||||
|
||||
|
||||
QList<Map*> MapList::load(const QString &fileName)
|
||||
{
|
||||
QFile file(fileName);
|
||||
QList<Map*> mapList;
|
||||
int ln = 1;
|
||||
QFileInfo fi(fileName);
|
||||
|
||||
if (!fi.exists())
|
||||
return mapList;
|
||||
|
||||
QFile file(fileName);
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
fprintf(stderr, "Error opening map list file: %s: %s\n",
|
||||
@ -15,6 +19,7 @@ QList<Map*> MapList::load(const QString &fileName)
|
||||
return mapList;
|
||||
}
|
||||
|
||||
int ln = 1;
|
||||
while (!file.atEnd()) {
|
||||
QByteArray line = file.readLine();
|
||||
QList<QByteArray> list = line.split('\t');
|
||||
|
@ -92,20 +92,12 @@ bool Parser::parse(QVector<TrackPoint> &data)
|
||||
if (_reader.name() == "gpx")
|
||||
gpx(data);
|
||||
else
|
||||
_reader.raiseError(QObject::tr("Not a GPX file."));
|
||||
_reader.raiseError("Not a GPX file.");
|
||||
}
|
||||
|
||||
return !_reader.error();
|
||||
}
|
||||
|
||||
|
||||
QString Parser::errorString() const
|
||||
{
|
||||
return QObject::tr("%1\nLine %2")
|
||||
.arg(_reader.errorString())
|
||||
.arg(_reader.lineNumber());
|
||||
}
|
||||
|
||||
bool Parser::loadFile(QIODevice *device, QVector<TrackPoint> &data)
|
||||
{
|
||||
_reader.clear();
|
||||
|
@ -20,7 +20,8 @@ class Parser
|
||||
{
|
||||
public:
|
||||
bool loadFile(QIODevice *device, QVector<TrackPoint> &data);
|
||||
QString errorString() const;
|
||||
QString errorString() const {return _reader.errorString();}
|
||||
int errorLine() const {return _reader.lineNumber();}
|
||||
|
||||
private:
|
||||
bool parse(QVector<TrackPoint> &data);
|
||||
|
30
src/poi.cpp
30
src/poi.cpp
@ -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;
|
||||
|
@ -28,16 +28,19 @@ class POI
|
||||
public:
|
||||
bool loadFile(const QString &fileName);
|
||||
QString errorString() const {return _error;}
|
||||
int errorLine() const {return _errorLine;}
|
||||
|
||||
QVector<Entry> points(const QVector<QPointF> &path) const;
|
||||
|
||||
void clear();
|
||||
|
||||
private:
|
||||
typedef RTree<const Entry*, qreal, 2> POITree;
|
||||
typedef RTree<size_t, qreal, 2> POITree;
|
||||
|
||||
POITree _tree;
|
||||
QVector<Entry> _data;
|
||||
QString _error;
|
||||
int _errorLine;
|
||||
};
|
||||
|
||||
#endif // POI_H
|
||||
|
Loading…
Reference in New Issue
Block a user