bool PositionTracking::saveTrack( const QString& fileName ) { if ( fileName.isEmpty() ) { return false; } GeoWriter writer; //FIXME: a better way to do this? writer.setDocumentType( kml::kmlTag_nameSpaceOgc22 ); GeoDataDocument *document = new GeoDataDocument; QFileInfo fileInfo( fileName ); QString name = fileInfo.baseName(); document->setName( name ); foreach( const GeoDataStyle &style, d->m_document.styles() ) { document->addStyle( style ); } foreach( const GeoDataStyleMap &map, d->m_document.styleMaps() ) { document->addStyleMap( map ); } GeoDataPlacemark *track = new GeoDataPlacemark( *d->m_currentTrackPlacemark ); track->setName( "Track " + name ); document->append( track ); QFile file( fileName ); file.open( QIODevice::WriteOnly ); bool const result = writer.write( &file, document ); file.close(); delete document; return result; }
void CountryByFlag::initiateGame() { /** * First remove the GeoDataDocument, which displays * country names, from map. */ if ( !d->m_countryNames ) { const GeoDataTreeModel *const treeModel = d->m_marbleWidget->model()->treeModel(); for ( int i = 0; i < treeModel->rowCount(); ++i ) { QVariant const data = treeModel->data ( treeModel->index ( i, 0 ), MarblePlacemarkModel::ObjectPointerRole ); GeoDataObject *object = qvariant_cast<GeoDataObject*>( data ); Q_ASSERT_X( object, "CountryByFlag::initiateGame", "failed to get valid data from treeModel for GeoDataObject" ); if ( object->nodeType() == GeoDataTypes::GeoDataDocumentType ) { GeoDataDocument *doc = static_cast<GeoDataDocument*>( object ); QFileInfo fileInfo( doc->fileName() ); if ( fileInfo.fileName() == QString("boundaryplacemarks.cache") ) { d->m_countryNames = doc; break; } } } } if ( d->m_countryNames ) { d->m_countryNames->setVisible( false ); d->m_marbleWidget->model()->treeModel()->updateFeature( d->m_countryNames ); d->m_marbleWidget->centerOn( 23.0, 42.0 ); d->m_marbleWidget->setDistance( 7500 ); d->m_marbleWidget->setHighlightEnabled( false ); emit gameInitialized(); } }
void TestGxTimeStamp::simpleParseTest() { QString const centerContent ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Document>" "<Placemark>" "<Camera>" "<gx:TimeStamp>" "<when>1987-06-05T04:03:02-01:00</when>" "</gx:TimeStamp>" "</Camera>" "</Placemark>" "</Document>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( centerContent ); QCOMPARE( dataDocument->placemarkList().size(), 1 ); GeoDataPlacemark *placemark = dataDocument->placemarkList().at( 0 ); GeoDataAbstractView* view = placemark->abstractView(); QVERIFY( view != 0 ); GeoDataCamera* camera = dynamic_cast<GeoDataCamera*>( view ); QVERIFY( camera != 0 ); QCOMPARE( camera->timeStamp().when().toUTC(), QDateTime::fromString( "1987-06-05T04:03:02-01:00", Qt::ISODate).toUTC() ); delete dataDocument; }
GeoDataDocument *GpsbabelRunner::parseFile(const QString &fileName, DocumentRole role, QString &error) { // Check and see if the file exists if ( !QFileInfo( fileName ).exists() ) { error = QStringLiteral("File %1 does not exist").arg(fileName); mDebug() << error; return nullptr; } // Inspect the filename suffix QString const fileSuffix = QFileInfo( fileName ).suffix(); // Determine if fileName suffix is supported by this plugin QMap<QString,QString> fileTypes; fileTypes["nmea"] = "nmea"; fileTypes["igc"] = "igc"; fileTypes["tiger"] = "tiger"; fileTypes["ov2"] = "tomtom"; fileTypes["garmin"] = "garmin_txt"; fileTypes["magellan"] = "magellan"; fileTypes["csv"] = "csv"; QString const inputFileType = fileTypes[fileSuffix]; if ( inputFileType.isEmpty() ) { error = QStringLiteral("Unsupported file extension for").arg(fileName); mDebug() << error; return nullptr; } // Set up temporary file to hold output KML from gpsbabel executable QTemporaryFile tempKmlFile(QDir::tempPath() + QLatin1String("/marble-gpsbabel-XXXXXX.kml")); tempKmlFile.open(); QFile kmlFile( tempKmlFile.fileName() ); // Set up gpsbabel command line const QString command = QLatin1String("gpsbabel -i ") + inputFileType + QLatin1String(" -f ") + fileName + QLatin1String(" -o kml -F ") + tempKmlFile.fileName(); // Execute gpsbabel to parse the input file int const exitStatus = QProcess::execute( command ); if ( exitStatus == 0 ) { kmlFile.open( QIODevice::ReadWrite ); GeoDataParser parser( GeoData_KML ); parser.read( &kmlFile ); GeoDataDocument *document = dynamic_cast<GeoDataDocument*>( parser.releaseDocument() ); if ( !document ) { error = parser.errorString(); mDebug() << error; return nullptr; } document->setDocumentRole( role ); return document; } else { error = QStringLiteral("Gpsbabel returned error code %1").arg(exitStatus); mDebug() << error; return nullptr; } }
void TestCamera::simpleParseTest() { QString const kmlContent ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Document>" " <Camera id=\"myCam\">" " <longitude>1</longitude>" " <latitude>2</latitude>" " <altitude>3</altitude>" " <heading>4</heading>" " <tilt>5</tilt>" " <roll>6</roll>" " <altitudeMode>relativeToGround</altitudeMode>" " </Camera>" "</Document>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( kmlContent ); GeoDataCamera *camera = dynamic_cast<GeoDataCamera*>( dataDocument->abstractView() ); QVERIFY( camera != 0); GeoDataCoordinates::Unit const degree = GeoDataCoordinates::Degree; QCOMPARE( camera->longitude( degree ), 1.0 ); QCOMPARE( camera->latitude( degree ), 2.0 ); QCOMPARE( camera->altitude(), 3.0 ); QCOMPARE( camera->heading(), 4.0 ); QCOMPARE( camera->tilt(), 5.0 ); QCOMPARE( camera->roll(), 6.0 ); QCOMPARE( camera->altitudeMode(), RelativeToGround ); delete dataDocument; }
void RoutingManagerPrivate::saveRoute(const QString &filename) { GeoWriter writer; writer.setDocumentType( kml::kmlTag_nameSpaceOgc22 ); QMutexLocker locker( &m_fileMutex ); QFile file( filename ); if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) { mDebug() << "Cannot write to " << file.fileName(); return; } GeoDataDocument container; container.setName(QStringLiteral("Route")); GeoDataFolder* request = routeRequest(); if ( request ) { container.append( request ); } GeoDataDocument *route = m_alternativeRoutesModel.currentRoute(); if ( route ) { container.append( new GeoDataDocument( *route ) ); } if ( !writer.write( &file, &container ) ) { mDebug() << "Can not write route state to " << file.fileName(); } file.close(); }
void MainWindow::browseMapButtonClicked() { d->m_marbleWidget->setMapThemeId(QStringLiteral("earth/political/political.dgml")); /** * Now display the country names which * were removed to initiate the game */ const GeoDataTreeModel *const treeModel = d->m_marbleWidget->model()->treeModel(); for ( int i = 0; i < treeModel->rowCount(); ++i ) { QVariant const data = treeModel->data ( treeModel->index ( i, 0 ), MarblePlacemarkModel::ObjectPointerRole ); GeoDataObject *object = qvariant_cast<GeoDataObject*>( data ); Q_ASSERT_X( object, "MainWindow::browseMapButtonClicked", "failed to get valid data from treeModel for GeoDataObject" ); if ( object->nodeType() == GeoDataTypes::GeoDataDocumentType ) { GeoDataDocument *doc = static_cast<GeoDataDocument*>( object ); QFileInfo fileInfo( doc->fileName() ); QString fileName = fileInfo.fileName(); if (fileName == QLatin1String("boundaryplacemarks.cache")) { doc->setVisible( true ); d->m_marbleWidget->model()->treeModel()->updateFeature( doc ); d->m_marbleWidget->setHighlightEnabled( true ); break; } } } }
GeoDataDocument* GosmoreRunnerPrivate::createDocument( GeoDataLineString* routeWaypoints, const QVector<GeoDataPlacemark*> instructions ) { if ( !routeWaypoints || routeWaypoints->isEmpty() ) { return nullptr; } GeoDataDocument* result = new GeoDataDocument(); GeoDataPlacemark* routePlacemark = new GeoDataPlacemark; routePlacemark->setName(QStringLiteral("Route")); routePlacemark->setGeometry( routeWaypoints ); result->append( routePlacemark ); QString name = QStringLiteral("%1 %2 (Gosmore)"); QString unit = QLatin1String( "m" ); qreal length = routeWaypoints->length( EARTH_RADIUS ); if (length >= 1000) { length /= 1000.0; unit = "km"; } result->setName( name.arg( length, 0, 'f', 1 ).arg( unit ) ); for( GeoDataPlacemark* placemark: instructions ) { result->append( placemark ); } return result; }
void TestGxTimeSpan::simpleParseTest() { QString const centerContent ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Document>" "<Placemark>" "<LookAt>" "<gx:TimeSpan>" "<begin>2010-05-28T02:02:09Z</begin>" "<end>2010-05-28T02:02:56Z</end>" "</gx:TimeSpan>" "</LookAt>" "</Placemark>" "</Document>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( centerContent ); QCOMPARE( dataDocument->placemarkList().size(), 1 ); GeoDataPlacemark *placemark = dataDocument->placemarkList().at( 0 ); QVERIFY( placemark->lookAt() != 0 ); QCOMPARE( placemark->lookAt()->timeSpan().begin().when(), QDateTime::fromString( "2010-05-28T02:02:09Z", Qt::ISODate) ); QCOMPARE( placemark->lookAt()->timeSpan().end().when(), QDateTime::fromString( "2010-05-28T02:02:56Z", Qt::ISODate) ); delete dataDocument; }
void TestGeoDataPack::saveKMLToCache() { GeoDataParser parser( GeoData_KML ); QByteArray array( content.toUtf8() ); QBuffer buffer( &array ); buffer.open( QIODevice::ReadOnly ); if ( !parser.read( &buffer ) ) { qWarning( "Could not parse data!" ); QFAIL( "Could not parse data!" ); return; } GeoDocument* document = parser.releaseDocument(); QVERIFY( document ); qDebug() << " parse Timer " << timer.elapsed(); GeoDataDocument *dataDocument = static_cast<GeoDataDocument*>( document ); QString path = QString( "%1/%2.cache" ); path = path.arg( QCoreApplication::applicationDirPath() ); path = path.arg( QString( "KMLTest" ) ); QFile cacheFile( path ); if ( cacheFile.open( QIODevice::WriteOnly ) ) { QDataStream stream ( &cacheFile ); dataDocument->pack( stream ); cacheFile.close(); qDebug( "Saved kml document to cache: %s", path.toLatin1().data() ); } qDebug() << "write Timer " << timer.elapsed(); delete document; }
void TestGeoDataPack::saveCitiesToCache() { GeoDataParser parser( GeoData_KML ); QFile citiesFile( CITIES_PATH ); citiesFile.open( QIODevice::ReadOnly ); if ( !parser.read( &citiesFile ) ) { qWarning( "Could not parse data!" ); QFAIL( "Could not parse data!" ); return; } GeoDocument* document = parser.releaseDocument(); QVERIFY( document ); qDebug() << "read Timer " << timer.elapsed(); GeoDataDocument *dataDocument = static_cast<GeoDataDocument*>( document ); QString path = QString( "%1/%2.cache" ); path = path.arg( QCoreApplication::applicationDirPath() ); path = path.arg( QString( "CitiesTest" ) ); QFile cacheFile( path ); if ( cacheFile.open( QIODevice::WriteOnly ) ) { QDataStream stream ( &cacheFile ); dataDocument->pack( stream ); cacheFile.close(); qDebug( "Saved kml document to cache: %s", path.toLatin1().data() ); } QVERIFY( cacheFile.size() > 0 ); qDebug() << "write Timer " << timer.elapsed(); delete document; }
void TestGeoDataTrack::simpleParseTest() { GeoDataDocument* dataDocument = parseKml( simpleExampleContent ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->placemarkList().size(), 1 ); GeoDataPlacemark* placemark = folder->placemarkList().at( 0 ); QCOMPARE( placemark->geometry()->geometryId(), GeoDataTrackId ); GeoDataTrack* track = static_cast<GeoDataTrack*>( placemark->geometry() ); QCOMPARE( track->size(), 7 ); { QDateTime when = track->whenList().at( 0 ); QCOMPARE( when, QDateTime( QDate( 2010, 5, 28 ), QTime( 2, 2, 9 ), Qt::UTC ) ); } { GeoDataCoordinates coord = track->coordinatesList().at( 0 ); QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), -122.207881 ); QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 37.371915 ); QCOMPARE( coord.altitude(), 156.000000 ); } { GeoDataCoordinates coord = track->coordinatesAt( QDateTime( QDate( 2010, 5, 28 ), QTime( 2, 2, 9 ), Qt::UTC ) ); QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), -122.207881 ); QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 37.371915 ); QCOMPARE( coord.altitude(), 156.000000 ); } delete dataDocument; }
GeoDataDocument *VectorClipper::clipTo(const GeoDataLatLonBox &tileBoundary, int zoomLevel) { bool const useBaseClipper = false; if (useBaseClipper) { return clipToBaseClipper(tileBoundary); } bool const filterSmallAreas = zoomLevel > 10 && zoomLevel < 17; GeoDataDocument* tile = new GeoDataDocument(); auto const clip = clipPath(tileBoundary, zoomLevel); GeoDataLinearRing ring; ring << GeoDataCoordinates(tileBoundary.west(), tileBoundary.north()); ring << GeoDataCoordinates(tileBoundary.east(), tileBoundary.north()); ring << GeoDataCoordinates(tileBoundary.east(), tileBoundary.south()); ring << GeoDataCoordinates(tileBoundary.west(), tileBoundary.south()); qreal const minArea = filterSmallAreas ? 0.01 * area(ring) : 0.0; foreach (GeoDataPlacemark const * placemark, potentialIntersections(tileBoundary)) { GeoDataGeometry const * const geometry = placemark ? placemark->geometry() : nullptr; if (geometry && tileBoundary.intersects(geometry->latLonAltBox())) { if(geometry->nodeType() == GeoDataTypes::GeoDataPolygonType) { clipPolygon(placemark, clip, minArea, tile); } else if (geometry->nodeType() == GeoDataTypes::GeoDataLineStringType) { clipString<GeoDataLineString>(placemark, clip, minArea, tile); } else if (geometry->nodeType() == GeoDataTypes::GeoDataLinearRingType) { clipString<GeoDataLinearRing>(placemark, clip, minArea, tile); } else { tile->append(new GeoDataPlacemark(*placemark)); } } }
void TestPhotoOverlay::simpleParseTest() { QString const centerContent ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Folder>" " <PhotoOverlay>" " <rotation>12.455</rotation>" " <ViewVolume>" " <near>1000</near>" " <leftFov>-60</leftFov>" " <rightFov>60</rightFov>" " <bottomFov>-45</bottomFov>" " <topFov>45</topFov>" " </ViewVolume>" " <ImagePyramid>" " <tileSize>219</tileSize>" " <maxWidth>22</maxWidth>" " <maxHeight>36</maxHeight>" " <gridOrigin>lowerLeft</gridOrigin>" " </ImagePyramid>" " <Point>" " <coordinates>45.78665,0.6565</coordinates>" " </Point>" " <shape>sphere</shape>" " </PhotoOverlay>" "</Folder>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( centerContent ); QCOMPARE( dataDocument->folderList().size(), 1 ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->size(), 1 ); GeoDataPhotoOverlay *overlay = dynamic_cast<GeoDataPhotoOverlay*>( folder->child( 0 ) ); QVERIFY( overlay != 0 ); QFUZZYCOMPARE( overlay->rotation(), 12.455, 0.0001 ); QFUZZYCOMPARE( overlay->viewVolume().near(), 1000.0, 0.0001 ); QFUZZYCOMPARE( overlay->viewVolume().leftFov(), -60.0, 0.0001 ); QFUZZYCOMPARE( overlay->viewVolume().rightFov(), 60.0, 0.0001 ); QFUZZYCOMPARE( overlay->viewVolume().bottomFov(), -45.0, 0.0001 ); QFUZZYCOMPARE( overlay->viewVolume().topFov(), 45.0, 0.0001 ); QFUZZYCOMPARE( overlay->imagePyramid().tileSize(), 219, 0.0001 ); QFUZZYCOMPARE( overlay->imagePyramid().maxWidth(), 22, 0.0001 ); QFUZZYCOMPARE( overlay->imagePyramid().maxHeight(), 36, 0.0001 ); QFUZZYCOMPARE( overlay->imagePyramid().gridOrigin(), GeoDataImagePyramid::LowerLeft, 0.0001 ); QFUZZYCOMPARE( overlay->point().coordinates().longitude( GeoDataCoordinates::Degree ), 45.78665, 0.0001 ); QFUZZYCOMPARE( overlay->point().coordinates().latitude( GeoDataCoordinates::Degree ), 0.6565, 0.0001 ); QFUZZYCOMPARE( overlay->shape(), GeoDataPhotoOverlay::Sphere, 0.0001 ); delete dataDocument; }
void MonavMap::parseBoundingBox( const QFileInfo &file ) { GeoDataLineString points; bool tooLarge = false; QFile input( file.absoluteFilePath() ); if ( input.open( QFile::ReadOnly ) ) { GeoDataParser parser( GeoData_KML ); if ( !parser.read( &input ) ) { mDebug() << "Could not parse file: " << parser.errorString(); return; } GeoDocument *doc = parser.releaseDocument(); input.close(); GeoDataDocument *document = dynamic_cast<GeoDataDocument*>( doc ); QVector<GeoDataPlacemark*> placemarks = document->placemarkList(); if ( placemarks.size() == 1 ) { GeoDataPlacemark* placemark = placemarks.first(); m_name = placemark->name(); m_version = placemark->extendedData().value( "version" ).value().toString(); m_date = placemark->extendedData().value( "date" ).value().toString(); m_transport = placemark->extendedData().value( "transport" ).value().toString(); m_payload = placemark->extendedData().value( "payload" ).value().toString(); GeoDataMultiGeometry* geometry = dynamic_cast<GeoDataMultiGeometry*>( placemark->geometry() ); if ( geometry->size() > 1500 ) { tooLarge = true; } for ( int i = 0; geometry && i < geometry->size(); ++i ) { GeoDataLinearRing* poly = dynamic_cast<GeoDataLinearRing*>( geometry->child( i ) ); if ( poly ) { for ( int j = 0; j < poly->size(); ++j ) { points << poly->at( j ); } m_tiles.push_back( *poly ); } if ( poly->size() > 1500 ) { tooLarge = true; } } } else { mDebug() << "File " << file.absoluteFilePath() << " does not contain one placemark, but " << placemarks.size(); } delete doc; } m_boundingBox = points.latLonAltBox(); if ( tooLarge ) { // The bounding box polygon is rather complicated, therefore not allowing a quick check // and also occupying memory. Discard the polygon and only store the rectangular bounding // box. Only happens for non-simplified bounding box polygons. mDebug() << "Discarding too large bounding box poylgon for " << file.absoluteFilePath() << ". Please check for a map update."; m_tiles.clear(); } }
void TestGeoDataTrack::withoutTimeTest() { //"Simple Example" from kmlreference; when elements emptied QString content( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Folder>" " <Placemark>" " <gx:Track>" " <when></when>" " <when></when>" " <when></when>" " <when></when>" " <when></when>" " <when></when>" " <when></when>" " <gx:coord>-122.207881 37.371915 156.000000</gx:coord>" " <gx:coord>-122.205712 37.373288 152.000000</gx:coord>" " <gx:coord>-122.204678 37.373939 147.000000</gx:coord>" " <gx:coord>-122.203572 37.374630 142.199997</gx:coord>" " <gx:coord>-122.203451 37.374706 141.800003</gx:coord>" " <gx:coord>-122.203329 37.374780 141.199997</gx:coord>" " <gx:coord>-122.203207 37.374857 140.199997</gx:coord>" " </gx:Track>" " </Placemark>" "</Folder>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( content ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->placemarkList().size(), 1 ); GeoDataPlacemark* placemark = folder->placemarkList().at( 0 ); QCOMPARE( placemark->geometry()->geometryId(), GeoDataTrackId ); GeoDataTrack* track = static_cast<GeoDataTrack*>( placemark->geometry() ); QCOMPARE( track->size(), 7 ); { GeoDataCoordinates coord = track->coordinatesList().at( 0 ); QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), -122.207881 ); QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 37.371915 ); QCOMPARE( coord.altitude(), 156.000000 ); } { const GeoDataLineString *lineString = track->lineString(); QCOMPARE( lineString->size(), 7 ); GeoDataCoordinates coord = lineString->at( 0 ); QCOMPARE( coord.longitude( GeoDataCoordinates::Degree ), -122.207881 ); QCOMPARE( coord.latitude( GeoDataCoordinates::Degree ), 37.371915 ); QCOMPARE( coord.altitude(), 156.000000 ); } delete dataDocument; }
void TestScreenOverlay::simpleParseTest() { QString const centerContent ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Folder>" " <ScreenOverlay>" " <overlayXY x=\"2.5\" y=\"-0.5\" xunits=\"fraction\" yunits=\"fraction\"/>" " <screenXY x=\"0.5\" y=\"0.5\" xunits=\"insetpixels\" yunits=\"pixels\"/>" " <rotationXY x=\"1.5\" y=\"3.5\" xunits=\"fraction\" yunits=\"insetPixels\"/>" " <size x=\"23\" y=\"0.5\" xunits=\"pixels\" yunits=\"insetPixels\"/>" " <rotation>23</rotation>" " <drawOrder>9</drawOrder>" " </ScreenOverlay>" "</Folder>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( centerContent ); QCOMPARE( dataDocument->folderList().size(), 1 ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->size(), 1 ); GeoDataScreenOverlay *overlay = dynamic_cast<GeoDataScreenOverlay*>( folder->child( 0 ) ); QVERIFY( overlay != 0 ); QCOMPARE( overlay->overlayXY().xunit(), GeoDataVec2::Fraction ); QCOMPARE( overlay->overlayXY().yunit(), GeoDataVec2::Fraction ); QCOMPARE( overlay->overlayXY().y(), -0.5 ); QCOMPARE( overlay->overlayXY().x(), 2.5 ); QCOMPARE( overlay->screenXY().xunit(), GeoDataVec2::Fraction ); // spelling error in kml, so fallback to default QCOMPARE( overlay->screenXY().yunit(), GeoDataVec2::Pixels ); QCOMPARE( overlay->screenXY().x(), 0.5 ); QCOMPARE( overlay->screenXY().y(), 0.5 ); QCOMPARE( overlay->rotationXY().xunit(), GeoDataVec2::Fraction ); QCOMPARE( overlay->rotationXY().yunit(), GeoDataVec2::InsetPixels ); QCOMPARE( overlay->rotationXY().x(), 1.5 ); QCOMPARE( overlay->rotationXY().y(), 3.5 ); QCOMPARE( overlay->size().xunit(), GeoDataVec2::Pixels ); QCOMPARE( overlay->size().yunit(), GeoDataVec2::InsetPixels ); QCOMPARE( overlay->size().x(), 23.0 ); QCOMPARE( overlay->size().y(), 0.5 ); QCOMPARE( overlay->rotation(), 23.0 ); QCOMPARE( overlay->drawOrder(), 9 ); delete dataDocument; }
void TestListStyle::simpleParseTest() { QString const content ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Document>" " <name>The one and only BalloonStyle test case</name>" " <Style id=\"my-list-style\">" " <ListStyle>" " <listItemType>checkOffOnly</listItemType>" " <bgColor>aa112233</bgColor>" " <ItemIcon>" " <state>open error</state>" " <href>https://developers.google.com/kml/documentation/images/itemicons.jpg</href>" " </ItemIcon>" " <ItemIcon>" " <state>closed</state>" " <href>https://developers.google.com/kml/documentation/images/itemicons1.jpg</href>" " </ItemIcon>" " </ListStyle>" " </Style>" " <Folder>" " <Placemark>" " <name>The first placemark</name>" " <styleUrl>#my-list-style</styleUrl>" " <Point><coordinates>80.0,30.0</coordinates></Point>" " </Placemark>" " </Folder>" "</Document>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( content ); QCOMPARE( dataDocument->folderList().size(), 1 ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->size(), 1 ); GeoDataPlacemark *placemark1 = dynamic_cast<GeoDataPlacemark*>( folder->child( 0 ) ); QVERIFY( placemark1 != nullptr ); QCOMPARE( placemark1->name(), QString( "The first placemark" ) ); QCOMPARE( placemark1->style()->listStyle().listItemType(), GeoDataListStyle::CheckOffOnly ); QCOMPARE( placemark1->style()->listStyle().backgroundColor().red(), 51 ); QCOMPARE( placemark1->style()->listStyle().itemIconList().at(0)->state(), GeoDataItemIcon::Open | GeoDataItemIcon::Error ); QCOMPARE( placemark1->style()->listStyle().itemIconList().at(0)->iconPath(), QString( "https://developers.google.com/kml/documentation/images/itemicons.jpg" ) ); QCOMPARE( placemark1->style()->listStyle().itemIconList().at(1)->state(), GeoDataItemIcon::Closed ); QCOMPARE( placemark1->style()->listStyle().itemIconList().at(1)->iconPath(), QString( "https://developers.google.com/kml/documentation/images/itemicons1.jpg" ) ); delete dataDocument; }
GeoDataDocument *OsmParser::createDocument(OsmNodes &nodes, OsmWays &ways, OsmRelations &relations) { GeoDataDocument* document = new GeoDataDocument; GeoDataPolyStyle backgroundPolyStyle; backgroundPolyStyle.setFill( true ); backgroundPolyStyle.setOutline( false ); backgroundPolyStyle.setColor("#f1eee8"); GeoDataStyle backgroundStyle; backgroundStyle.setPolyStyle( backgroundPolyStyle ); backgroundStyle.setId( "background" ); document->addStyle( backgroundStyle ); foreach(OsmRelation const &relation, relations) { relation.create(document, ways, nodes); }
void CountryByShape::initiateGame() { if ( !d->m_countryNames ) { const GeoDataTreeModel *const treeModel = d->m_marbleWidget->model()->treeModel(); for ( int i = 0; i < treeModel->rowCount(); ++i ) { QVariant const data = treeModel->data ( treeModel->index ( i, 0 ), MarblePlacemarkModel::ObjectPointerRole ); GeoDataObject *object = qvariant_cast<GeoDataObject*>( data ); Q_ASSERT_X( object, "CountryByShape::initiateGame", "failed to get valid data from treeModel for GeoDataObject" ); if ( object->nodeType() == GeoDataTypes::GeoDataDocumentType ) { GeoDataDocument *doc = static_cast<GeoDataDocument*>( object ); QFileInfo fileInfo( doc->fileName() ); if (fileInfo.fileName() == QLatin1String("boundaryplacemarks.cache")) { d->m_countryNames = doc; break; } } } } if ( !d->m_countryBoundaries ) { const GeoDataTreeModel *const treeModel = d->m_marbleWidget->model()->treeModel(); for ( int i = 0; i < treeModel->rowCount(); ++i ) { QVariant const data = treeModel->data ( treeModel->index ( i, 0 ), MarblePlacemarkModel::ObjectPointerRole ); GeoDataObject *object = qvariant_cast<GeoDataObject*>( data ); Q_ASSERT_X( object, "MainWindow::initiateGame", "failed to get valid data from treeModel for GeoDataObject" ); if ( object->nodeType() == GeoDataTypes::GeoDataDocumentType ) { GeoDataDocument *const doc = static_cast<GeoDataDocument*>( object ); QFileInfo fileInfo( doc->fileName() ); if (fileInfo.fileName() == QLatin1String("ne_50m_admin_0_countries.pn2")) { d->m_countryBoundaries = doc; break; } } } } d->m_marbleWidget->setHighlightEnabled( true ); if ( d->m_countryBoundaries && d->m_countryNames ) { d->m_countryNames->setVisible( false ); d->m_marbleWidget->model()->treeModel()->updateFeature( d->m_countryNames ); emit gameInitialized(); } }
bool GeoDataDocument::operator==( const GeoDataDocument &other ) const { if (!GeoDataContainer::equals(other)) { return false; } Q_D(const GeoDataDocument); const GeoDataDocumentPrivate* const other_d = other.d_func(); if (!(d->m_styleHash.size() == other_d->m_styleHash.size() && d->m_styleMapHash == other_d->m_styleMapHash && d->m_schemaHash == other_d->m_schemaHash && d->m_filename == other_d->m_filename && d->m_baseUri == other_d->m_baseUri && d->m_networkLinkControl == other_d->m_networkLinkControl && d->m_property == other_d->m_property && d->m_documentRole == other_d->m_documentRole)) { return false; } auto iter = d->m_styleHash.constBegin(); auto const end = d->m_styleHash.constEnd(); for (; iter != end; ++iter) { if (!other_d->m_styleHash.contains(iter.key())) { return false; } if (*iter.value() != *other_d->m_styleHash[iter.key()]) { return false; } } return true; }
void RouteSimulationPositionProviderPlugin::initialize() { m_currentIndex = -1; m_lineString.clear(); GeoDataDocument* document = const_cast<MarbleModel *>( marbleModel() )->routingManager()->alternativeRoutesModel()->currentRoute(); if ( document && document->size() > 0 ) { foreach( const GeoDataPlacemark *placemark, document->placemarkList() ) { GeoDataGeometry* geometry = placemark->geometry(); GeoDataLineString* lineString = dynamic_cast<GeoDataLineString*>( geometry ); if ( lineString ) { m_lineString << *lineString; } } }
GeoDataDocument* MonavRunnerPrivate::createDocument( Marble::GeoDataLineString* geometry, const QVector< Marble::GeoDataPlacemark* >& instructions, const QString& name, const Marble::GeoDataExtendedData& data ) { if ( !geometry || geometry->isEmpty() ) { return 0; } GeoDataDocument* result = new GeoDataDocument; GeoDataPlacemark* routePlacemark = new GeoDataPlacemark; routePlacemark->setName(QStringLiteral("Route")); routePlacemark->setGeometry( geometry ); routePlacemark->setExtendedData( data ); result->append( routePlacemark ); foreach( GeoDataPlacemark* placemark, instructions ) { result->append( placemark ); }
void TourWidgetPrivate::createTour() { if ( overrideModifications() ) { GeoDataDocument *document = new GeoDataDocument(); document->setDocumentRole( UserDocument ); document->setName( "New Tour" ); document->setId( "new_tour" ); GeoDataTour *tour = new GeoDataTour(); tour->setName( "New Tour" ); GeoDataPlaylist *playlist = new GeoDataPlaylist; tour->setPlaylist( playlist ); document->append( static_cast<GeoDataFeature*>( tour ) ); m_playback.setBaseUrl( QUrl::fromLocalFile( MarbleDirs::marbleDataPath() ) ); openDocument( document ); m_isChanged = true; m_tourUi.m_actionSaveTour->setEnabled( true ); } }
void TestNetworkLink::simpleParseTest() { QString const centerContent ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Folder>" " <NetworkLink>" " <refreshVisibility>1</refreshVisibility> <!-- boolean -->" " <flyToView>1</flyToView> <!-- boolean -->" " <Link>" " <href>http://files.kde.org/marble/examples/kml/</href>" " <refreshMode>onChange</refreshMode>" " <refreshInterval>2.1</refreshInterval>" " <viewRefreshMode>never</viewRefreshMode>" " <viewRefreshTime>4.2</viewRefreshTime>" " <viewBoundScale>1.5</viewBoundScale>" " <viewFormat>BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]</viewFormat>" " <httpQuery>SiteType=sw,gw,sp&SiteCode=all&Format=ge</httpQuery>" " </Link>" " </NetworkLink>" "</Folder>" "</kml>"); GeoDataDocument* dataDocument = parseKml( centerContent ); QCOMPARE( dataDocument->folderList().size(), 1 ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->size(), 1 ); GeoDataNetworkLink *networkLink = dynamic_cast<GeoDataNetworkLink*>( folder->child( 0 ) ); QVERIFY( networkLink != 0 ); QCOMPARE( networkLink->refreshVisibility(), true ); QCOMPARE( networkLink->flyToView(), true ); QCOMPARE( networkLink->link().href(), QString("http://files.kde.org/marble/examples/kml/") ); QCOMPARE( networkLink->link().refreshMode(), GeoDataLink::OnChange ); QFUZZYCOMPARE( networkLink->link().refreshInterval(), 2.1, 0.0001 ); QCOMPARE( networkLink->link().viewRefreshMode(), GeoDataLink::Never); QFUZZYCOMPARE( networkLink->link().viewRefreshTime(), 4.2, 0.0001 ); QFUZZYCOMPARE( networkLink->link().viewBoundScale(), 1.5, 0.0001 ); QCOMPARE( networkLink->link().viewFormat(), QString("BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]") ); QCOMPARE( networkLink->link().httpQuery(), QString("SiteType=sw,gw,sp&SiteCode=all&Format=ge")); }
void TourWidgetPrivate::addPlacemark() { // Get the normalized coordinates of the focus point. There will be automatically added a new // placemark. qreal lat = m_widget->focusPoint().latitude(); qreal lon = m_widget->focusPoint().longitude(); GeoDataCoordinates::normalizeLonLat( lon, lat ); GeoDataDocument *document = new GeoDataDocument; if( m_document->id().isEmpty() ) { if( m_document->name().isEmpty() ) { m_document->setId( "untitled_tour" ); } else { m_document->setId( m_document->name().trimmed().replace( " ", "_" ).toLower() ); } } document->setTargetId( m_document->id() ); GeoDataPlacemark *placemark = new GeoDataPlacemark; placemark->setCoordinate( lon, lat ); placemark->setVisible( true ); placemark->setBalloonVisible( true ); GeoDataStyle *newStyle = new GeoDataStyle( *placemark->style() ); newStyle->iconStyle().setIcon( QImage() ); newStyle->iconStyle().setIconPath( MarbleDirs::path("bitmaps/redflag_22.png") ); placemark->setStyle( newStyle ); document->append( placemark ); GeoDataCreate *create = new GeoDataCreate; create->append( document ); GeoDataUpdate *update = new GeoDataUpdate; update->setCreate( create ); GeoDataAnimatedUpdate *animatedUpdate = new GeoDataAnimatedUpdate; animatedUpdate->setUpdate( update ); if( m_delegate->editAnimatedUpdate( animatedUpdate ) ) { addTourPrimitive( animatedUpdate ); m_delegate->setDefaultFeatureId( placemark->id() ); } else { delete animatedUpdate; } }
void TestBalloonStyle::simpleParseTest() { QString const content ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<kml xmlns=\"http://www.opengis.net/kml/2.2\"" " xmlns:gx=\"http://www.google.com/kml/ext/2.2\">" "<Document>" " <name>The one and only BalloonStyle test case</name>" " <Style id=\"my-balloon-style\">" " <BalloonStyle>" " <bgColor>aa112233</bgColor>" " <textColor>bb445566</textColor>" " <text>This is my balloon style. There are many like it, but this is mine.</text>" " <displayMode>hide</displayMode>" " </BalloonStyle>" " </Style>" " <Folder>" " <Placemark>" " <name>The first placemark</name>" " <styleUrl>#my-balloon-style</styleUrl>" " <Point><coordinates>80.0,30.0</coordinates></Point>" " </Placemark>" " </Folder>" "</Document>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( content ); QCOMPARE( dataDocument->folderList().size(), 1 ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->size(), 1 ); GeoDataPlacemark *placemark1 = dynamic_cast<GeoDataPlacemark*>( folder->child( 0 ) ); QVERIFY( placemark1 != 0 ); QCOMPARE( placemark1->name(), QString( "The first placemark" ) ); QCOMPARE( placemark1->style()->balloonStyle().backgroundColor().red(), 51 ); QCOMPARE( placemark1->style()->balloonStyle().textColor().blue(), 68 ); QCOMPARE( placemark1->style()->balloonStyle().displayMode(), GeoDataBalloonStyle::Hide ); QString const text = "This is my balloon style. There are many like it, but this is mine."; QCOMPARE( placemark1->style()->balloonStyle().text(), text ); delete dataDocument; }
void GeoDataFeature::setStyleUrl( const QString &value) { detach(); d->m_styleUrl = value; QString styleUrl = value; styleUrl.remove('#'); GeoDataObject *object = parent(); bool found = false; while ( object && !found ) { if( object->nodeType() == GeoDataTypes::GeoDataDocumentType ) { GeoDataDocument *doc = static_cast<GeoDataDocument*> ( object ); GeoDataStyleMap &styleMap = doc->styleMap( styleUrl ); if( !styleMap.value( QString( "normal" ) ).isEmpty() ) { styleUrl = styleMap.value( QString( "normal" ) ); styleUrl.remove('#'); } setStyle( &doc->style( styleUrl ) ); found = true; } object = object->parent(); } }
GeoDataDocument* MonavRunnerPrivate::createDocument( GeoDataLineString *geometry, const QVector<GeoDataPlacemark*> &instructions ) const { if ( !geometry || geometry->isEmpty() ) { return 0; } GeoDataDocument* result = new GeoDataDocument; GeoDataPlacemark* routePlacemark = new GeoDataPlacemark; routePlacemark->setName( "Route" ); routePlacemark->setGeometry( geometry ); result->append( routePlacemark ); QString name = "%1 %2 (Monav)"; QString unit = "m"; qreal length = geometry->length( EARTH_RADIUS ); if ( length >= 1000 ) { length /= 1000.0; unit = "km"; } foreach( GeoDataPlacemark* placemark, instructions ) { result->append( placemark ); }
void TestGeoDataPack::loadCitiesFromCache() { GeoDataDocument *cacheDocument = new GeoDataDocument(); QString path = QString( "%1/%2.cache" ); path = path.arg( QCoreApplication::applicationDirPath() ); path = path.arg( QString( "CitiesTest" ) ); QFile cacheFile( path ); if ( cacheFile.open( QIODevice::ReadOnly ) ) { QDataStream stream ( &cacheFile ); cacheDocument->unpack( stream ); cacheFile.close(); qDebug( "Loaded kml document from cache: %s", path.toLatin1().data() ); } QVERIFY( cacheDocument ); qDebug() << "read Timer " << timer.elapsed(); GeoDataParser parser( GeoData_KML ); QFile citiesFile( CITIES_PATH ); citiesFile.open( QIODevice::ReadOnly ); if ( !parser.read( &citiesFile ) ) { qWarning( "Could not parse data!" ); QFAIL( "Could not parse data!" ); return; } GeoDocument* document = parser.releaseDocument(); QVERIFY( document ); qDebug() << "parse Timer " << timer.elapsed(); // commented out as it timeouts the test on build.kde.org // GeoDataDocument *dataDocument = static_cast<GeoDataDocument*>( document ); // QVERIFY( compareDocuments( cacheDocument, dataDocument ) ); // qDebug() << "compare Timer " << timer.elapsed(); delete cacheDocument; // delete dataDocument; }