1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-27 03:29:16 +02:00

Added recursive POI dir searching to be consistent with map dir searching

This commit is contained in:
2018-01-30 00:30:26 +01:00
parent e10f8e9c1b
commit 84d860e2a2
5 changed files with 68 additions and 31 deletions

View File

@ -1,4 +1,5 @@
#include <QFile>
#include <QDir>
#include "data.h"
#include "poi.h"
@ -9,20 +10,25 @@ POI::POI(QObject *parent) : QObject(parent)
_radius = 1000;
}
bool POI::loadFile(const QString &fileName)
bool POI::loadFile(const QString &path, bool dir)
{
Data data;
FileIndex index;
_errorString.clear();
_errorLine = 0;
index.enabled = true;
index.start = _data.size();
if (!data.loadFile(fileName)) {
_errorString = data.errorString();
_errorLine = data.errorLine();
if (!data.loadFile(path)) {
if (dir) {
if (data.errorLine())
_errorString += QString("%1:%2: %3\n").arg(path)
.arg(data.errorLine()).arg(data.errorString());
else
_errorString += path + ": " + data.errorString() + "\n";
} else {
_errorString = data.errorString();
_errorLine = data.errorLine();
}
return false;
}
@ -38,7 +44,7 @@ bool POI::loadFile(const QString &fileName)
_tree.Insert(c, c, i);
}
_files.append(fileName);
_files.append(path);
_indexes.append(index);
emit pointsChanged();
@ -46,6 +52,39 @@ bool POI::loadFile(const QString &fileName)
return true;
}
bool POI::loadFile(const QString &path)
{
_errorString.clear();
_errorLine = 0;
return loadFile(path, false);
}
bool POI::loadDir(const QString &path)
{
QDir md(path);
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
QFileInfoList fl = md.entryInfoList();
bool ret = true;
_errorString.clear();
_errorLine = 0;
for (int i = 0; i < fl.size(); i++) {
const QFileInfo &fi = fl.at(i);
if (fi.isDir()) {
if (!loadDir(fi.absoluteFilePath()))
ret = false;
} else {
if (!loadFile(fi.absoluteFilePath(), true))
ret = false;
}
}
return ret;
}
static bool cb(size_t data, void* context)
{
QSet<int> *set = (QSet<int>*) context;

View File

@ -18,7 +18,8 @@ class POI : public QObject
public:
POI(QObject *parent = 0);
bool loadFile(const QString &fileName);
bool loadFile(const QString &path);
bool loadDir(const QString &path);
const QString &errorString() const {return _errorString;}
int errorLine() const {return _errorLine;}
@ -43,6 +44,8 @@ private:
bool enabled;
};
bool loadFile(const QString &path, bool dir);
POITree _tree;
QVector<Waypoint> _data;
QStringList _files;