MauiKit Image Tools

geolocation/cities.cpp
1//
2// Created by gabridc on 5/6/21.
3//
4#include "cities.h"
5
6#include <QStringList>
7
8#include <QCoreApplication>
9
10#include "city.h"
11#include "citiesdb.h"
12#include "kdtree.hpp"
13
14static KDTree& getCitiesTree()
15{
16 static KDTree tree((CitiesDB()).cities());
17 return tree;
18}
19
20Q_GLOBAL_STATIC(Cities, citiesInstance)
21
22Cities::Cities(QObject * parent) : QObject(parent)
23{
24 qDebug() << "Setting up Cities instance";
25}
26
27Cities *Cities::getInstance()
28{
29 return citiesInstance();
30}
31
32Cities::~Cities()
33{
34 qDeleteAll(m_dbs);
35 m_dbs.clear();
36}
37
38City Cities::findCity(double latitude, double longitude)
39{
40 // CitiesDB db;
41 auto pointNear = getCitiesTree().nearest_point({latitude, longitude});
42 return db()->findCity(pointNear[0], pointNear[1]);
43}
44
45City Cities::city(const QString &id)
46{
47 // CitiesDB db;
48 return db()->city(id);
49}
50
51CitiesDB *Cities::db()
52{
54 {
55 qDebug() << "Using existing CITIESDB instance" << QThread::currentThread();
56
57 return m_dbs[QThread::currentThread()];
58 }
59
60 qDebug() << "Creating new CITIESDB instance" << QThread::currentThread();
61
62 auto new_db = new CitiesDB;
63 m_dbs.insert(QThread::currentThread(), new_db);
64 return new_db;
65}
66
A wrapper to give access to al the cities information in the data base.
A class for representing the GPS coordinates and information of a city.
void clear()
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
QThread * currentThread()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.