MauiKit Image Tools

modules/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
13Cities *Cities::m_instance = nullptr;
14KDTree *Cities::m_citiesTree = nullptr;
15
16Cities::Cities(QObject * parent) : QObject(parent)
17{
18 qDebug() << "Setting up Cities instance";
19
21 {
22 qDebug() << "Lets remove Tagging singleton instance";
23
24 qDeleteAll(m_dbs);
25 m_dbs.clear();
26
27 delete m_instance;
28 m_instance = nullptr;
29 });
30
31 parseCities();
32}
33
34Cities::~Cities()
35{
36 delete Cities::m_citiesTree;
37}
38
39City* Cities::findCity(double latitude, double longitude)
40{
41 qDebug() << "Latitude: " << latitude << "Longitud: " << longitude;
42 auto pointNear = Cities::m_citiesTree->nearest_point({latitude, longitude});
43 qDebug() << pointNear[0] << pointNear[1];
44
45 return db()->findCity(pointNear[0], pointNear[1]);
46}
47
48City *Cities::city(const QString &id)
49{
50 return db()->city(id);
51}
52
53void Cities::parseCities()
54{
55 if(!Cities::m_citiesTree || Cities::m_citiesTree->empty())
56 {
57 qDebug() << "KDE TREE EMPTY FILLING IT";
58
59 Cities::m_citiesTree = new KDTree(db()->cities());
60 Q_EMIT citiesReady();
61 }
62}
63
64CitiesDB *Cities::db()
65{
67 {
68 qDebug() << "Using existing CITIESDB instance" << QThread::currentThreadId();
69
70 return m_dbs[QThread::currentThreadId()];
71 }
72
73 qDebug() << "Creating new CITIESDB instance" << QThread::currentThreadId();
74
75 auto new_db = new CitiesDB;
76 m_dbs.insert(QThread::currentThreadId(), new_db);
77 return new_db;
78}
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.
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
Qt::HANDLE currentThreadId()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.