12#include "GeoDataParser.h"
13#include "GeoDataFolder.h"
14#include "GeoDataGroundOverlay.h"
15#include "GeoDataPlacemark.h"
16#include "GeoDataData.h"
17#include "GeoDataExtendedData.h"
18#include "GeoDataStyle.h"
19#include "GeoDataStyleMap.h"
20#include "GeoDataPhotoOverlay.h"
21#include "GeoDataPoint.h"
22#include "GeoDataPolyStyle.h"
23#include "GeoDataLineStyle.h"
24#include "GeoDataPolygon.h"
25#include "GeoDataRelation.h"
26#include "GeoDataScreenOverlay.h"
27#include "GeoDataTour.h"
28#include "GeoDataTrack.h"
29#include "MarbleDirs.h"
30#include "MarbleDebug.h"
32#include "ParsingRunnerManager.h"
37class FileLoaderPrivate
40 FileLoaderPrivate(
FileLoader* parent,
const PluginManager *pluginManager,
bool recenter,
41 const QString &file,
const QString &property,
const GeoDataStyle::Ptr &style, DocumentRole role,
int renderOrder) :
43 m_runner(pluginManager),
47 m_styleMap(new GeoDataStyleMap),
49 m_renderOrder(renderOrder),
54 m_styleMap->
setId(QStringLiteral(
"default-map"));
59 FileLoaderPrivate(
FileLoader* parent,
const PluginManager *pluginManager,
62 m_runner(pluginManager),
77 void createFilterProperties( GeoDataContainer *container );
78 static int cityPopIdx( qint64 population );
79 static int spacePopIdx( qint64 population );
80 static int areaPopIdx( qreal area );
82 void documentParsed( GeoDataDocument *doc,
const QString& error);
85 ParsingRunnerManager m_runner;
89 GeoDataStyle::Ptr m_style;
90 GeoDataStyleMap* m_styleMap;
91 GeoDataDocument *m_document;
94 DocumentRole m_documentRole;
98FileLoader::FileLoader(
QObject* parent,
const PluginManager *pluginManager,
bool recenter,
const QString& file,
99 const QString& property,
const GeoDataStyle::Ptr &style, DocumentRole role,
int renderOrder )
101 d( new FileLoaderPrivate( this, pluginManager, recenter, file, property, style, role, renderOrder ) )
105FileLoader::FileLoader(
QObject* parent,
const PluginManager *pluginManager,
108 d( new FileLoaderPrivate( this, pluginManager, contents, file, role ) )
112FileLoader::~FileLoader()
117QString FileLoader::path()
const
119 return d->m_filepath;
122GeoDataDocument* FileLoader::document()
124 return d->m_document;
127QString FileLoader::error()
const
132void FileLoader::run()
134 if ( d->m_contents.isEmpty() ) {
137 mDebug() <<
"starting parser for" << d->m_filepath;
143 QString suffix = fileinfo.suffix();
146 if ( fileinfo.isAbsolute() ) {
150 else if ( d->m_filepath.contains(
'/' ) ) {
166 mDebug() <<
"No recent Default Placemark Cache File available!";
169 connect( &d->m_runner, SIGNAL(parsingFinished(GeoDataDocument*,
QString)),
170 this, SLOT(documentParsed(GeoDataDocument*,
QString)) );
171 d->m_runner.parseFile( defaultSourceName, d->m_documentRole );
174 mDebug() <<
"No Default Placemark Source File for " <<
name;
179 GeoDataParser parser( GeoData_KML );
185 if ( !parser.read( &buffer ) ) {
186 qWarning(
"Could not import kml buffer!" );
187 emit loaderFinished(
this );
191 GeoDocument* document = parser.releaseDocument();
192 Q_ASSERT( document );
194 d->m_document =
static_cast<GeoDataDocument*
>( document );
195 d->m_document->setProperty( d->m_property );
196 d->m_document->setDocumentRole( d->m_documentRole );
197 d->createFilterProperties( d->m_document );
200 mDebug() <<
"newGeoDataDocumentAdded" << d->m_filepath;
202 emit newGeoDataDocumentAdded( d->m_document );
203 emit loaderFinished(
this );
208bool FileLoader::recenter()
const
210 return d->m_recenter;
213void FileLoaderPrivate::documentParsed( GeoDataDocument* doc,
const QString& error )
218 doc->setProperty( m_property );
220 doc->addStyleMap( *m_styleMap );
221 doc->addStyle( m_style );
224 if (m_renderOrder != 0) {
225 for (GeoDataPlacemark* placemark: doc->placemarkList()) {
226 if (GeoDataPolygon *polygon = geodata_cast<GeoDataPolygon>(placemark->geometry())) {
227 polygon->setRenderOrder(m_renderOrder);
232 createFilterProperties( doc );
233 emit q->newGeoDataDocumentAdded( m_document );
235 emit q->loaderFinished( q );
238void FileLoaderPrivate::createFilterProperties( GeoDataContainer *container )
244 for (; i !=
end; ++i ) {
245 if (
auto child =
dynamic_cast<GeoDataContainer *
>(*i)) {
246 createFilterProperties( child );
247 }
else if (geodata_cast<GeoDataTour>(*i)
248 || geodata_cast<GeoDataRelation>(*i)
249 || geodata_cast<GeoDataGroundOverlay>(*i)
250 || geodata_cast<GeoDataPhotoOverlay>(*i)
251 || geodata_cast<GeoDataScreenOverlay>(*i)) {
253 }
else if (
auto placemark = geodata_cast<GeoDataPlacemark>(*i)) {
254 const QString placemarkRole = placemark->role();
255 Q_ASSERT( placemark->geometry() );
257 bool hasPopularity =
false;
259 if (!geodata_cast<GeoDataTrack>(placemark->geometry()) &&
260 !geodata_cast<GeoDataPoint>(placemark->geometry())
261 && m_documentRole == MapDocument
263 placemark->setStyleUrl(styleUrl);
271 qreal altitude = placemark->coordinate().altitude();
272 if ( altitude != 0.0 )
274 hasPopularity =
true;
275 placemark->setPopularity( (qint64)(altitude * 1000.0) );
276 placemark->setZoomLevel( cityPopIdx( qAbs( (qint64)(altitude * 1000.0) ) ) );
284 qreal area = placemark->area();
287 hasPopularity =
true;
289 placemark->setPopularity( (qint64)(area * 100) );
290 placemark->setZoomLevel( areaPopIdx( area ) );
296 placemark->setPopularity( 1000000000 );
297 placemark->setZoomLevel( 1 );
302 placemark->setPopularity( 10000000 );
303 placemark->setZoomLevel( 3 );
308 placemark->setPopularity( 1000000000 );
309 placemark->setZoomLevel( 1 );
314 placemark->setPopularity( 10000000 );
315 placemark->setZoomLevel( 2 );
320 placemark->setPopularity( 1000000 );
321 placemark->setZoomLevel( 3 );
326 placemark->setPopularity( 1000000 );
327 placemark->setZoomLevel( 3 );
336 qint64 diameter = placemark->population();
339 hasPopularity =
true;
340 placemark->setPopularity( diameter );
342 placemark->setZoomLevel( spacePopIdx( diameter ) );
345 placemark->setZoomLevel( 1 );
349 placemark->setZoomLevel( spacePopIdx( diameter ) );
353 placemark->setPopularity( 1000000000 );
354 placemark->setZoomLevel( 1 );
360 qint64 population = placemark->population();
361 if ( population >= 0 )
363 hasPopularity =
true;
364 placemark->setPopularity( population );
365 placemark->setZoomLevel( cityPopIdx( population ) );
371 if (placemarkRole ==
QLatin1String(
"H")) placemark->setVisualCategory( GeoDataPlacemark::Mountain );
372 else if (placemarkRole ==
QLatin1String(
"V")) placemark->setVisualCategory( GeoDataPlacemark::Volcano );
374 else if (placemarkRole ==
QLatin1String(
"m")) placemark->setVisualCategory( GeoDataPlacemark::Mons );
375 else if (placemarkRole ==
QLatin1String(
"v")) placemark->setVisualCategory( GeoDataPlacemark::Valley );
376 else if (placemarkRole ==
QLatin1String(
"o")) placemark->setVisualCategory( GeoDataPlacemark::OtherTerrain );
377 else if (placemarkRole ==
QLatin1String(
"c")) placemark->setVisualCategory( GeoDataPlacemark::Crater );
378 else if (placemarkRole ==
QLatin1String(
"a")) placemark->setVisualCategory( GeoDataPlacemark::Mare );
380 else if (placemarkRole ==
QLatin1String(
"P")) placemark->setVisualCategory( GeoDataPlacemark::GeographicPole );
381 else if (placemarkRole ==
QLatin1String(
"M")) placemark->setVisualCategory( GeoDataPlacemark::MagneticPole );
382 else if (placemarkRole ==
QLatin1String(
"W")) placemark->setVisualCategory( GeoDataPlacemark::ShipWreck );
383 else if (placemarkRole ==
QLatin1String(
"F")) placemark->setVisualCategory( GeoDataPlacemark::AirPort );
384 else if (placemarkRole ==
QLatin1String(
"A")) placemark->setVisualCategory( GeoDataPlacemark::Observatory );
385 else if (placemarkRole ==
QLatin1String(
"K")) placemark->setVisualCategory( GeoDataPlacemark::Continent );
386 else if (placemarkRole ==
QLatin1String(
"O")) placemark->setVisualCategory( GeoDataPlacemark::Ocean );
387 else if (placemarkRole ==
QLatin1String(
"S")) placemark->setVisualCategory( GeoDataPlacemark::Nation );
396 switch (placemark->zoomLevel()) {
399 placemark->setVisualCategory(GeoDataPlacemark::LargeCity);
403 placemark->setVisualCategory(GeoDataPlacemark::BigCity);
407 placemark->setVisualCategory(GeoDataPlacemark::MediumCity);
410 placemark->setVisualCategory(GeoDataPlacemark::SmallCity);
415 switch (placemark->zoomLevel()) {
418 placemark->setVisualCategory(GeoDataPlacemark::LargeStateCapital);
422 placemark->setVisualCategory(GeoDataPlacemark::BigStateCapital);
426 placemark->setVisualCategory(GeoDataPlacemark::MediumStateCapital);
429 placemark->setVisualCategory(GeoDataPlacemark::SmallStateCapital);
434 switch (placemark->zoomLevel()) {
437 placemark->setVisualCategory(GeoDataPlacemark::LargeNationCapital);
441 placemark->setVisualCategory(GeoDataPlacemark::BigNationCapital);
445 placemark->setVisualCategory(GeoDataPlacemark::MediumNationCapital);
448 placemark->setVisualCategory(GeoDataPlacemark::SmallNationCapital);
455 switch (placemark->zoomLevel()) {
458 placemark->setVisualCategory(GeoDataPlacemark::LargeCountyCapital);
462 placemark->setVisualCategory(GeoDataPlacemark::BigCountyCapital);
466 placemark->setVisualCategory(GeoDataPlacemark::MediumCountyCapital);
469 placemark->setVisualCategory(GeoDataPlacemark::SmallCountyCapital);
473 else if (placemarkRole ==
QLatin1String(
" ") && !hasPopularity && placemark->visualCategory() == GeoDataPlacemark::Unknown) {
474 placemark->setVisualCategory( GeoDataPlacemark::Unknown );
475 placemark->setZoomLevel(0);
478 placemark->setVisualCategory( GeoDataPlacemark::MannedLandingSite );
481 placemark->setVisualCategory( GeoDataPlacemark::RoboticRover );
484 placemark->setVisualCategory( GeoDataPlacemark::UnmannedSoftLandingSite );
487 placemark->setVisualCategory( GeoDataPlacemark::UnmannedHardLandingSite );
491 if (!placemark->isVisible()) {
492 placemark->setZoomLevel( 18 );
496 else if (placemark->population() < -1) {
497 placemark->setZoomLevel( 18 );
500 if (placemark->zoomLevel() < 4) {
501 placemark->setZoomLevel( 4 );
505 placemark->setZoomLevel( 2 );
508 placemark->setZoomLevel( 0 );
511 qWarning() <<
"Unknown feature" << (*i)->nodeType() <<
". Skipping.";
516int FileLoaderPrivate::cityPopIdx( qint64 population )
520 if ( population < 2500 ) popidx=10;
521 else if ( population < 5000) popidx=9;
522 else if ( population < 25000) popidx=8;
523 else if ( population < 75000) popidx=7;
524 else if ( population < 250000) popidx=6;
525 else if ( population < 750000) popidx=5;
526 else if ( population < 2500000) popidx=4;
531int FileLoaderPrivate::spacePopIdx( qint64 population )
535 if ( population < 1000 ) popidx=10;
536 else if ( population < 2000) popidx=9;
537 else if ( population < 8000) popidx=8;
538 else if ( population < 20000) popidx=7;
539 else if ( population < 60000) popidx=6;
540 else if ( population < 100000) popidx=5;
541 else if ( population < 200000 ) popidx=4;
542 else if ( population < 400000 ) popidx=2;
543 else if ( population < 600000 ) popidx=1;
548int FileLoaderPrivate::areaPopIdx( qreal area )
551 if ( area < 200000 ) popidx=5;
552 else if ( area < 1000000 ) popidx=4;
553 else if ( area < 2500000 ) popidx=3;
554 else if ( area < 5000000 ) popidx=2;
561#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)