1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-28 03:59:15 +02:00

Preserve directory structure when loading the maps

This commit is contained in:
2021-03-20 09:59:03 +01:00
parent 8196b96f65
commit 659cf4cc7a
6 changed files with 157 additions and 66 deletions

View File

@ -18,23 +18,23 @@
#include "maplist.h"
Map *MapList::loadFile(const QString &path, bool *terminate)
Map *MapList::loadFile(const QString &path, bool *isDir)
{
QFileInfo fi(path);
QString suffix = fi.suffix().toLower();
Map *map = 0;
if (Atlas::isAtlas(path)) {
if (terminate)
*terminate = true;
if (isDir)
*isDir = true;
map = new Atlas(path);
} else if (suffix == "xml") {
if (MapSource::isMap(path)) {
map = MapSource::loadMap(path);
} else if (GMAP::isGMAP(path)) {
map = new IMGMap(path);
if (terminate)
*terminate = true;
if (isDir)
*isDir = true;
}
} else if (suffix == "jnx")
map = new JNXMap(path);
@ -60,39 +60,44 @@ Map *MapList::loadFile(const QString &path, bool *terminate)
return map ? map : new InvalidMap(path, "Unknown file format");
}
QList<Map*> MapList::loadDir(const QString &path)
TreeNode<Map *> MapList::loadDir(const QString &path, TreeNode<Map *> *parent)
{
QDir md(path);
md.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
md.setSorting(QDir::DirsLast);
QFileInfoList ml = md.entryInfoList();
QList<Map*> list;
TreeNode<Map*> tree(md.dirName());
for (int i = 0; i < ml.size(); i++) {
const QFileInfo &fi = ml.at(i);
QString suffix = fi.suffix().toLower();
bool terminate = false;
if (fi.isDir() && fi.fileName() != "set")
list.append(loadDir(fi.absoluteFilePath()));
else if (filter().contains("*." + suffix)) {
list.append(loadFile(fi.absoluteFilePath(), &terminate));
if (terminate)
if (fi.isDir()) {
TreeNode<Map*> child(loadDir(fi.absoluteFilePath(), &tree));
if (!child.isEmpty())
tree.addChild(child);
} else if (filter().contains("*." + suffix)) {
bool isDir = false;
Map *map = loadFile(fi.absoluteFilePath(), &isDir);
if (isDir) {
parent->addItem(map);
break;
} else
tree.addItem(map);
}
}
return list;
return tree;
}
QList<Map*> MapList::loadMaps(const QString &path)
TreeNode<Map *> MapList::loadMaps(const QString &path)
{
if (QFileInfo(path).isDir())
return loadDir(path);
else {
QList<Map*> list;
list.append(loadFile(path, 0));
return list;
TreeNode<Map*> tree;
tree.addItem(loadFile(path));
return tree;
}
}

View File

@ -2,19 +2,21 @@
#define MAPLIST_H
#include <QString>
#include "common/treenode.h"
class Map;
class MapList
{
public:
static QList<Map*> loadMaps(const QString &path);
static TreeNode<Map*> loadMaps(const QString &path);
static QString formats();
static QStringList filter();
private:
static Map *loadFile(const QString &path, bool *terminate);
static QList<Map*> loadDir(const QString &path);
static Map *loadFile(const QString &path, bool *isDir = 0);
static TreeNode<Map*> loadDir(const QString &path,
TreeNode<Map *> *parent = 0);
};
#endif // MAPLIST_H