12#include "GeoDataData.h"
13#include "GeoDataExtendedData.h"
14#include "GeoDataFolder.h"
15#include "GeoDataGroundOverlay.h"
16#include "GeoDataLineStyle.h"
17#include "GeoDataParser.h"
18#include "GeoDataPhotoOverlay.h"
19#include "GeoDataPlacemark.h"
20#include "GeoDataPoint.h"
21#include "GeoDataPolyStyle.h"
22#include "GeoDataPolygon.h"
23#include "GeoDataRelation.h"
24#include "GeoDataScreenOverlay.h"
25#include "GeoDataStyle.h"
26#include "GeoDataStyleMap.h"
27#include "GeoDataTour.h"
28#include "GeoDataTrack.h"
29#include "MarbleDebug.h"
30#include "MarbleDirs.h"
32#include "ParsingRunnerManager.h"
37class FileLoaderPrivate
41 const PluginManager *pluginManager,
45 const GeoDataStyle::Ptr &style,
49 , m_runner(pluginManager)
51 , m_property(property)
53 , m_styleMap(new GeoDataStyleMap)
55 , m_renderOrder(renderOrder)
56 , m_documentRole(role)
57 , m_recenter(recenter)
60 m_styleMap->
setId(QStringLiteral(
"default-map"));
65 FileLoaderPrivate(
FileLoader *parent,
const PluginManager *pluginManager,
const QString &contents,
const QString &file, DocumentRole role)
67 , m_runner(pluginManager)
69 , m_contents(contents)
72 , m_documentRole(role)
82 void createFilterProperties(GeoDataContainer *container);
83 static int cityPopIdx(qint64 population);
84 static int spacePopIdx(qint64 population);
85 static int areaPopIdx(qreal area);
87 void documentParsed(GeoDataDocument *doc,
const QString &error);
90 ParsingRunnerManager m_runner;
94 GeoDataStyle::Ptr m_style;
95 GeoDataStyleMap *m_styleMap;
96 GeoDataDocument *m_document;
99 DocumentRole m_documentRole;
103FileLoader::FileLoader(
QObject *parent,
104 const PluginManager *pluginManager,
108 const GeoDataStyle::Ptr &style,
112 , d(new FileLoaderPrivate(this, pluginManager, recenter, file, property, style, role, renderOrder))
116FileLoader::FileLoader(
QObject *parent,
const PluginManager *pluginManager,
const QString &contents,
const QString &file, DocumentRole role)
118 , d(new FileLoaderPrivate(this, pluginManager, contents, file, role))
122FileLoader::~FileLoader()
127QString FileLoader::path()
const
129 return d->m_filepath;
132GeoDataDocument *FileLoader::document()
134 return d->m_document;
137QString FileLoader::error()
const
142void FileLoader::run()
144 if (d->m_contents.isEmpty()) {
147 mDebug() <<
"starting parser for" << d->m_filepath;
154 QString suffix = fileinfo.suffix();
157 if (fileinfo.isAbsolute()) {
160 }
else if (d->m_filepath.contains(
QLatin1Char(
'/'))) {
175 mDebug() <<
"No recent Default Placemark Cache File available!";
178 connect(&d->m_runner, SIGNAL(parsingFinished(GeoDataDocument *,
QString)),
this, SLOT(documentParsed(GeoDataDocument *,
QString)));
179 d->m_runner.parseFile(defaultSourceName, d->m_documentRole);
181 mDebug() <<
"No Default Placemark Source File for " <<
name;
186 GeoDataParser parser(GeoData_KML);
192 if (!parser.read(&buffer)) {
193 qWarning(
"Could not import kml buffer!");
194 Q_EMIT loaderFinished(
this);
198 GeoDocument *document = parser.releaseDocument();
201 d->m_document =
static_cast<GeoDataDocument *
>(document);
202 d->m_document->setProperty(d->m_property);
203 d->m_document->setDocumentRole(d->m_documentRole);
204 d->createFilterProperties(d->m_document);
207 mDebug() <<
"newGeoDataDocumentAdded" << d->m_filepath;
209 Q_EMIT newGeoDataDocumentAdded(d->m_document);
210 Q_EMIT loaderFinished(
this);
214bool FileLoader::recenter()
const
216 return d->m_recenter;
219void FileLoaderPrivate::documentParsed(GeoDataDocument *doc,
const QString &error)
224 doc->setProperty(m_property);
226 doc->addStyleMap(*m_styleMap);
227 doc->addStyle(m_style);
230 if (m_renderOrder != 0) {
231 for (GeoDataPlacemark *placemark : doc->placemarkList()) {
232 if (
auto polygon = geodata_cast<GeoDataPolygon>(placemark->geometry())) {
233 polygon->setRenderOrder(m_renderOrder);
238 createFilterProperties(doc);
239 Q_EMIT q->newGeoDataDocumentAdded(m_document);
241 Q_EMIT q->loaderFinished(q);
244void FileLoaderPrivate::createFilterProperties(GeoDataContainer *container)
250 for (; i !=
end; ++i) {
251 if (
auto child =
dynamic_cast<GeoDataContainer *
>(*i)) {
252 createFilterProperties(child);
253 }
else if (geodata_cast<GeoDataTour>(*i) || geodata_cast<GeoDataRelation>(*i) || geodata_cast<GeoDataGroundOverlay>(*i)
254 || geodata_cast<GeoDataPhotoOverlay>(*i) || geodata_cast<GeoDataScreenOverlay>(*i)) {
256 }
else if (
auto placemark = geodata_cast<GeoDataPlacemark>(*i)) {
257 const QString placemarkRole = placemark->role();
258 Q_ASSERT(placemark->geometry());
260 bool hasPopularity =
false;
262 if (!geodata_cast<GeoDataTrack>(placemark->geometry()) && !geodata_cast<GeoDataPoint>(placemark->geometry()) && m_documentRole == MapDocument
264 placemark->setStyleUrl(styleUrl);
269 qreal altitude = placemark->coordinate().altitude();
270 if (altitude != 0.0) {
271 hasPopularity =
true;
272 placemark->setPopularity((qint64)(altitude * 1000.0));
273 placemark->setZoomLevel(cityPopIdx(qAbs((qint64)(altitude * 1000.0))));
278 qreal area = placemark->area();
280 hasPopularity =
true;
282 placemark->setPopularity((qint64)(area * 100));
283 placemark->setZoomLevel(areaPopIdx(area));
288 placemark->setPopularity(1000000000);
289 placemark->setZoomLevel(1);
293 placemark->setPopularity(10000000);
294 placemark->setZoomLevel(3);
298 placemark->setPopularity(1000000000);
299 placemark->setZoomLevel(1);
303 placemark->setPopularity(10000000);
304 placemark->setZoomLevel(2);
308 placemark->setPopularity(1000000);
309 placemark->setZoomLevel(3);
313 placemark->setPopularity(1000000);
314 placemark->setZoomLevel(3);
319 qint64 diameter = placemark->population();
321 hasPopularity =
true;
322 placemark->setPopularity(diameter);
324 placemark->setZoomLevel(spacePopIdx(diameter));
326 placemark->setZoomLevel(1);
329 placemark->setZoomLevel(spacePopIdx(diameter));
333 placemark->setPopularity(1000000000);
334 placemark->setZoomLevel(1);
338 qint64 population = placemark->population();
339 if (population >= 0) {
340 hasPopularity =
true;
341 placemark->setPopularity(population);
342 placemark->setZoomLevel(cityPopIdx(population));
349 placemark->setVisualCategory(GeoDataPlacemark::Mountain);
351 placemark->setVisualCategory(GeoDataPlacemark::Volcano);
354 placemark->setVisualCategory(GeoDataPlacemark::Mons);
356 placemark->setVisualCategory(GeoDataPlacemark::Valley);
358 placemark->setVisualCategory(GeoDataPlacemark::OtherTerrain);
360 placemark->setVisualCategory(GeoDataPlacemark::Crater);
362 placemark->setVisualCategory(GeoDataPlacemark::Mare);
365 placemark->setVisualCategory(GeoDataPlacemark::GeographicPole);
367 placemark->setVisualCategory(GeoDataPlacemark::MagneticPole);
369 placemark->setVisualCategory(GeoDataPlacemark::ShipWreck);
371 placemark->setVisualCategory(GeoDataPlacemark::AirPort);
373 placemark->setVisualCategory(GeoDataPlacemark::Observatory);
375 placemark->setVisualCategory(GeoDataPlacemark::Continent);
377 placemark->setVisualCategory(GeoDataPlacemark::Ocean);
379 placemark->setVisualCategory(GeoDataPlacemark::Nation);
383 switch (placemark->zoomLevel()) {
386 placemark->setVisualCategory(GeoDataPlacemark::LargeCity);
390 placemark->setVisualCategory(GeoDataPlacemark::BigCity);
394 placemark->setVisualCategory(GeoDataPlacemark::MediumCity);
397 placemark->setVisualCategory(GeoDataPlacemark::SmallCity);
401 switch (placemark->zoomLevel()) {
404 placemark->setVisualCategory(GeoDataPlacemark::LargeStateCapital);
408 placemark->setVisualCategory(GeoDataPlacemark::BigStateCapital);
412 placemark->setVisualCategory(GeoDataPlacemark::MediumStateCapital);
415 placemark->setVisualCategory(GeoDataPlacemark::SmallStateCapital);
419 switch (placemark->zoomLevel()) {
422 placemark->setVisualCategory(GeoDataPlacemark::LargeNationCapital);
426 placemark->setVisualCategory(GeoDataPlacemark::BigNationCapital);
430 placemark->setVisualCategory(GeoDataPlacemark::MediumNationCapital);
433 placemark->setVisualCategory(GeoDataPlacemark::SmallNationCapital);
438 switch (placemark->zoomLevel()) {
441 placemark->setVisualCategory(GeoDataPlacemark::LargeCountyCapital);
445 placemark->setVisualCategory(GeoDataPlacemark::BigCountyCapital);
449 placemark->setVisualCategory(GeoDataPlacemark::MediumCountyCapital);
452 placemark->setVisualCategory(GeoDataPlacemark::SmallCountyCapital);
455 }
else if (placemarkRole ==
QLatin1StringView(
" ") && !hasPopularity && placemark->visualCategory() == GeoDataPlacemark::Unknown) {
456 placemark->setVisualCategory(GeoDataPlacemark::Unknown);
457 placemark->setZoomLevel(0);
459 placemark->setVisualCategory(GeoDataPlacemark::MannedLandingSite);
461 placemark->setVisualCategory(GeoDataPlacemark::RoboticRover);
463 placemark->setVisualCategory(GeoDataPlacemark::UnmannedSoftLandingSite);
465 placemark->setVisualCategory(GeoDataPlacemark::UnmannedHardLandingSite);
469 if (!placemark->isVisible()) {
470 placemark->setZoomLevel(18);
474 else if (placemark->population() < -1) {
475 placemark->setZoomLevel(18);
477 if (placemark->zoomLevel() < 4) {
478 placemark->setZoomLevel(4);
481 placemark->setZoomLevel(2);
483 placemark->setZoomLevel(0);
486 qWarning() <<
"Unknown feature" << (*i)->nodeType() <<
". Skipping.";
491int FileLoaderPrivate::cityPopIdx(qint64 population)
495 if (population < 2500)
497 else if (population < 5000)
499 else if (population < 25000)
501 else if (population < 75000)
503 else if (population < 250000)
505 else if (population < 750000)
507 else if (population < 2500000)
513int FileLoaderPrivate::spacePopIdx(qint64 population)
517 if (population < 1000)
519 else if (population < 2000)
521 else if (population < 8000)
523 else if (population < 20000)
525 else if (population < 60000)
527 else if (population < 100000)
529 else if (population < 200000)
531 else if (population < 400000)
533 else if (population < 600000)
539int FileLoaderPrivate::areaPopIdx(qreal area)
544 else if (area < 1000000)
546 else if (area < 2500000)
548 else if (area < 5000000)
556#include "moc_FileLoader.cpp"
This file contains the headers for MarbleModel.
void setId(const QString &value)
Set the id of the object.
QString name(GameStandardAction id)
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
QString path(const QString &relativePath)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
Binds a QML item to a specific geodetic location in screen coordinates.
bool exists() const const
iterator insert(const Key &key, const T &value)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)