1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 19:52:09 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2021-03-21 21:04:26 +01:00
parent 11082fe2a6
commit 80d54bda58
2 changed files with 38 additions and 37 deletions

View File

@ -10,6 +10,14 @@
#include "poi.h"
static bool cb(size_t data, void* context)
{
QSet<int> *set = (QSet<int>*) context;
set->insert((int)data);
return true;
}
POI::File::File(int start, int end, const QVector<Waypoint> &data)
: _enabled(true)
{
@ -24,6 +32,33 @@ POI::File::File(int start, int end, const QVector<Waypoint> &data)
}
}
void POI::File::search(const RectC &rect, QSet<int> &set) const
{
qreal min[2], max[2];
if (_enabled) {
if (rect.left() > rect.right()) {
min[0] = rect.topLeft().lon();
min[1] = rect.bottomRight().lat();
max[0] = 180.0;
max[1] = rect.topLeft().lat();
_tree.Search(min, max, cb, &set);
min[0] = -180.0;
min[1] = rect.bottomRight().lat();
max[0] = rect.bottomRight().lon();
max[1] = rect.topLeft().lat();
_tree.Search(min, max, cb, &set);
} else {
min[0] = rect.topLeft().lon();
min[1] = rect.bottomRight().lat();
max[0] = rect.bottomRight().lon();
max[1] = rect.topLeft().lat();
_tree.Search(min, max, cb, &set);
}
}
}
POI::POI(QObject *parent) : QObject(parent)
{
@ -83,43 +118,10 @@ TreeNode<QString> POI::loadDir(const QString &path)
return tree;
}
static bool cb(size_t data, void* context)
{
QSet<int> *set = (QSet<int>*) context;
set->insert((int)data);
return true;
}
void POI::search(const RectC &rect, QSet<int> &set) const
{
qreal min[2], max[2];
for (ConstIterator it = _files.constBegin(); it != _files.constEnd(); ++it) {
const File *file = *it;
if (file->isEnabled()) {
if (rect.left() > rect.right()) {
min[0] = rect.topLeft().lon();
min[1] = rect.bottomRight().lat();
max[0] = 180.0;
max[1] = rect.topLeft().lat();
file->tree().Search(min, max, cb, &set);
min[0] = -180.0;
min[1] = rect.bottomRight().lat();
max[0] = rect.bottomRight().lon();
max[1] = rect.topLeft().lat();
file->tree().Search(min, max, cb, &set);
} else {
min[0] = rect.topLeft().lon();
min[1] = rect.bottomRight().lat();
max[0] = rect.bottomRight().lon();
max[1] = rect.topLeft().lat();
file->tree().Search(min, max, cb, &set);
}
}
}
for (ConstIterator it = _files.constBegin(); it != _files.constEnd(); ++it)
(*it)->search(rect, set);
}
QList<Waypoint> POI::points(const Path &path) const

View File

@ -44,8 +44,7 @@ private:
public:
File(int start, int end, const QVector<Waypoint> &data);
const POITree &tree() const {return _tree;}
bool isEnabled() const {return _enabled;}
void search(const RectC &rect, QSet<int> &set) const;
void enable(bool enable) {_enabled = enable;}
private: