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; }
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 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; }
void BookmarkManagerPrivate::resetBookmarkDocument() { if ( m_bookmarkDocument ) { m_treeModel->removeDocument( m_bookmarkDocument ); delete m_bookmarkDocument; } GeoDataFolder* folder = new GeoDataFolder; folder->setName( QObject::tr( "Default" ) ); m_bookmarkDocument = new GeoDataDocument; m_bookmarkDocument->setDocumentRole( BookmarkDocument ); m_bookmarkDocument->setName( QObject::tr("Bookmarks") ); m_bookmarkDocument->append( folder ); m_treeModel->addDocument( m_bookmarkDocument ); }
QVariant TargetModel::bookmarkData ( int index, int role ) const { switch( role ) { case Qt::DisplayRole: { GeoDataFolder* folder = dynamic_cast<GeoDataFolder*>( m_bookmarks[index]->parent() ); Q_ASSERT( folder && "Internal bookmark representation has changed. Please report this as a bug at http://bugs.kde.org." ); if ( folder ) { return QString(folder->name() + QLatin1String(" / ") + m_bookmarks[index]->name()); } } case Qt::DecorationRole: return QIcon( ":/icons/bookmarks.png" ); case MarblePlacemarkModel::CoordinateRole: return qVariantFromValue( m_bookmarks[index]->lookAt()->coordinates() ); } return QVariant(); }
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 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 GeoDataContainer::unpack( QDataStream& stream ) { Q_D(GeoDataContainer); GeoDataFeature::unpack( stream ); int count; stream >> count; for ( int i = 0; i < count; ++i ) { int featureId; stream >> featureId; switch( featureId ) { case GeoDataDocumentId: /* not usable!!!! */ break; case GeoDataFolderId: { GeoDataFolder *folder = new GeoDataFolder; folder->unpack( stream ); d->m_vector.append( folder ); } break; case GeoDataPlacemarkId: { GeoDataPlacemark *placemark = new GeoDataPlacemark; placemark->unpack( stream ); d->m_vector.append( placemark ); } break; case GeoDataNetworkLinkId: break; case GeoDataScreenOverlayId: break; case GeoDataGroundOverlayId: break; default: break; }; } }
void TestGroundOverlay::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>" "<GroundOverlay>" "<altitude>0</altitude>" "<altitudeMode>absolute</altitudeMode>" "<LatLonBox>" "<north>37.91904192681665</north>" "<south>37.46543388598137</south>" "<east>15.35832653742206</east>" "<west>14.60128369746704</west>" "<rotation>-0.1556640799496235</rotation>" "</LatLonBox>" "</GroundOverlay>" "<GroundOverlay>" "<altitude>233</altitude>" "<drawOrder>2</drawOrder>" "<LatLonBox>" "<north>23.3765376</north>" "<south>1.5743867869</south>" "<east>33.78365874</east>" "<west>94.352435642</west>" "<rotation>6.346364378</rotation>" "</LatLonBox>" "</GroundOverlay>" "</Folder>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( centerContent ); QCOMPARE( dataDocument->folderList().size(), 1 ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); QCOMPARE( folder->size(), 2 ); GeoDataGroundOverlay *overlayFirst = dynamic_cast<GeoDataGroundOverlay*>( folder->child( 0 ) ); GeoDataGroundOverlay *overlaySecond = dynamic_cast<GeoDataGroundOverlay*>( folder->child( 1 ) ); QVERIFY( overlayFirst != 0 ); QVERIFY( overlaySecond != 0 ); QFUZZYCOMPARE( overlayFirst->altitude(), 0.0, 0.0001 ); QFUZZYCOMPARE( overlayFirst->altitudeMode(), Absolute, 0.0001 ); QCOMPARE( overlayFirst->drawOrder(), 0 ); QFUZZYCOMPARE( overlayFirst->latLonBox().north(), 37.91904192681665 * DEG2RAD, 0.0001 ); QFUZZYCOMPARE( overlayFirst->latLonBox().south(), 37.46543388598137 * DEG2RAD, 0.0001 ); QFUZZYCOMPARE( overlayFirst->latLonBox().east(), 15.35832653742206 * DEG2RAD, 0.0001 ); QFUZZYCOMPARE( overlayFirst->latLonBox().west(), 14.60128369746704 * DEG2RAD, 0.0001 ); QFUZZYCOMPARE( overlayFirst->latLonBox().rotation(), -0.1556640799496235 * DEG2RAD, 0.0001 ); QFUZZYCOMPARE( overlaySecond->altitude(), 233.0, 0.0001 ); QCOMPARE( overlaySecond->altitudeMode(), ClampToGround ); QCOMPARE( overlaySecond->drawOrder(), 2 ); QFUZZYCOMPARE( overlaySecond->latLonBox().north(), 23.3765376 * DEG2RAD, 0.0001 ); QFUZZYCOMPARE( overlaySecond->latLonBox().south(), 1.5743867869 * DEG2RAD, 0.0001 ); QFUZZYCOMPARE( overlaySecond->latLonBox().east(), 33.78365874 * DEG2RAD, 0.0001 ); QFUZZYCOMPARE( overlaySecond->latLonBox().west(), 94.352435642 * DEG2RAD, 0.0001 ); QFUZZYCOMPARE( overlaySecond->latLonBox().rotation(), 6.346364378 * DEG2RAD, 0.0001 ); delete dataDocument; }
void TestTour::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>" " <gx:Tour>" " <name>My Tour</name>" " <description>This is my tour.</description>" " </gx:Tour>" " <gx:Tour id=\"tourId\">" " <gx:Playlist>" " <gx:TourControl id=\"space\">" " <gx:playMode>pause</gx:playMode>" " </gx:TourControl>" " </gx:Playlist>" " </gx:Tour>" " <gx:Tour id=\"animUpd\">" " <name>TourAnim</name>" " <description>Tour with AnimatedUpdate</description>" " <gx:Playlist>" " <gx:AnimatedUpdate>" " <gx:duration>5.0</gx:duration>" " <Update>" " <targetHref>Whatever.jpg</targetHref>" " </Update>" " </gx:AnimatedUpdate>" " </gx:Playlist>" " </gx:Tour>" "</Folder>" "</kml>" ); GeoDataDocument* dataDocument = parseKml( centerContent ); QCOMPARE( dataDocument->folderList().size(), 1 ); GeoDataFolder *folder = dataDocument->folderList().at( 0 ); GeoDataTour *tour_1 = dynamic_cast<GeoDataTour*>(folder->child(0)); GeoDataTour *tour_2 = dynamic_cast<GeoDataTour*>(folder->child(1)); GeoDataTour *tour_3 = dynamic_cast<GeoDataTour*>(folder->child(2)); QVERIFY(tour_1 != 0); QVERIFY(tour_2 != 0); QVERIFY(tour_3 != 0); QCOMPARE(tour_1->id(), QString("")); QCOMPARE(tour_1->name(), QString("My Tour")); QCOMPARE(tour_1->description(), QString("This is my tour.")); QCOMPARE(tour_2->id(), QString("tourId")); QCOMPARE(tour_2->name(), QString()); QCOMPARE(tour_2->description(), QString()); QCOMPARE(tour_3->id(), QString("animUpd")); QCOMPARE(tour_3->name(), QString("TourAnim")); QCOMPARE(tour_3->description(), QString("Tour with AnimatedUpdate")); GeoDataPlaylist *playlist = tour_2->playlist(); QVERIFY(playlist != 0); GeoDataTourControl *control = dynamic_cast<GeoDataTourControl*>( playlist->primitive(0)); QVERIFY(control != 0); QCOMPARE(control->id(), QString("space")); QCOMPARE(control->playMode(), GeoDataTourControl::Pause); GeoDataPlaylist *playlist2 = tour_3->playlist(); QVERIFY(playlist2 != 0); GeoDataAnimatedUpdate *update = dynamic_cast<GeoDataAnimatedUpdate*>(playlist2->primitive(0)); QVERIFY(update != 0); QCOMPARE(update->duration(),5.0); QCOMPARE(update->update()->targetHref(),QString("Whatever.jpg")); delete dataDocument; }
void TestGeoDataTrack::extendedDataParseTest() { //"Example of Track with Extended Data" from kmlreference 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\">" " <Document>" " <name>GPS device</name>" " <Snippet>Created Wed Jun 2 15:33:39 2010</Snippet>" " <Schema id=\"schema\">" " <gx:SimpleArrayField name=\"heartrate\" type=\"int\">" " <displayName>Heart Rate</displayName>" " </gx:SimpleArrayField>" " <gx:SimpleArrayField name=\"cadence\" type=\"int\">" " <displayName>Cadence</displayName>" " </gx:SimpleArrayField>" " <gx:SimpleArrayField name=\"power\" type=\"float\">" " <displayName>Power</displayName>" " </gx:SimpleArrayField>" " </Schema>" " <Folder>" " <name>Tracks</name>" " <Placemark>" " <name>2010-05-28T01:16:35.000Z</name>" " <styleUrl>#multiTrack</styleUrl>" " <gx:Track>" " <when>2010-05-28T02:02:09Z</when>" " <when>2010-05-28T02:02:35Z</when>" " <when>2010-05-28T02:02:44Z</when>" " <when>2010-05-28T02:02:53Z</when>" " <when>2010-05-28T02:02:54Z</when>" " <when>2010-05-28T02:02:55Z</when>" " <when>2010-05-28T02:02:56Z</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>" " <ExtendedData>" " <SchemaData schemaUrl=\"#schema\">" " <gx:SimpleArrayData name=\"cadence\">" " <gx:value>86</gx:value>" " <gx:value>103</gx:value>" " <gx:value>108</gx:value>" " <gx:value>113</gx:value>" " <gx:value>113</gx:value>" " <gx:value>113</gx:value>" " <gx:value>113</gx:value>" " </gx:SimpleArrayData>" " <gx:SimpleArrayData name=\"heartrate\">" " <gx:value>181</gx:value>" " <gx:value>177</gx:value>" " <gx:value>175</gx:value>" " <gx:value>173</gx:value>" " <gx:value>173</gx:value>" " <gx:value>173</gx:value>" " <gx:value>173</gx:value>" " </gx:SimpleArrayData>" " <gx:SimpleArrayData name=\"power\">" " <gx:value>327.0</gx:value>" " <gx:value>177.0</gx:value>" " <gx:value>179.0</gx:value>" " <gx:value>162.0</gx:value>" " <gx:value>166.0</gx:value>" " <gx:value>177.0</gx:value>" " <gx:value>183.0</gx:value>" " </gx:SimpleArrayData>" " </SchemaData>" " </ExtendedData>" " </gx:Track>" " </Placemark>" " </Folder>" " </Document>" "</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 ); { GeoDataSimpleArrayData *cadence = track->extendedData().simpleArrayData( "cadence" ); QCOMPARE( cadence->size(), 7 ); QCOMPARE( cadence->valueAt( 0 ), QVariant( "86" ) ); QCOMPARE( cadence->valueAt( 6 ), QVariant( "113" ) ); } { GeoDataSimpleArrayData *hr = track->extendedData().simpleArrayData( "heartrate" ); QCOMPARE( hr->size(), 7 ); QCOMPARE( hr->valueAt( 0 ), QVariant( "181" ) ); QCOMPARE( hr->valueAt( 6 ), QVariant( "173" ) ); } { GeoDataSimpleArrayData *power = track->extendedData().simpleArrayData( "power" ); QCOMPARE( power->size(), 7 ); QCOMPARE( power->valueAt( 0 ), QVariant( "327.0" ) ); QCOMPARE( power->valueAt( 6 ), QVariant( "183.0" ) ); } delete dataDocument; }
void TestGeoData::parentingTest() { GeoDataDocument *document = new GeoDataDocument; GeoDataFolder *folder = new GeoDataFolder; /// simple parenting test GeoDataPlacemark *placemark = new GeoDataPlacemark; placemark->setParent(document); QCOMPARE(placemark->parent(), document); /// simple append and child count test document->append(placemark); /// appending folder to document before feeding folder document->append(folder); QCOMPARE(document->size(), 2); GeoDataPlacemark *placemark2 = new GeoDataPlacemark; folder->append(placemark2); QCOMPARE(folder->size(), 1); /// retrieve child and check it matches placemark GeoDataPlacemark *placemarkPtr; QCOMPARE(document->child(0)->nodeType(), placemark->nodeType()); placemarkPtr = static_cast<GeoDataPlacemark*>(document->child(0)); QCOMPARE(placemarkPtr, placemark); /// check retrieved placemark matches intented child int position = document->childPosition(placemarkPtr); QCOMPARE(position, 0); /// retrieve child two and check it matches folder GeoDataFolder *folderPtr; QCOMPARE(document->child(1)->nodeType(), folder->nodeType()); folderPtr = static_cast<GeoDataFolder*>(document->child(1)); QCOMPARE(folderPtr, folder); /// check retrieved folder matches intended child position = document->childPosition(folderPtr); QCOMPARE(position, 1); /// retrieve child three and check it matches placemark QCOMPARE(folderPtr->size(), 1); placemarkPtr = static_cast<GeoDataPlacemark*>(folderPtr->child(0)); QCOMPARE(placemarkPtr->nodeType(), placemark2->nodeType()); QCOMPARE(placemarkPtr, placemark2); /// check retrieved placemark matches intended child QCOMPARE(folderPtr->childPosition(placemarkPtr), 0); /// Set a style GeoDataIconStyle iconStyle; iconStyle.setIconPath( "myicon.png" ); GeoDataStyle* style = new GeoDataStyle; style->setStyleId( "mystyle" ); style->setIconStyle( iconStyle ); GeoDataObject* noParent = 0; QCOMPARE( style->parent(), noParent ); QCOMPARE( iconStyle.parent(), noParent ); document->setStyle( style ); QCOMPARE( style->parent(), document ); // Parent should be assigned now QCOMPARE( style->iconStyle().parent(), style ); QCOMPARE( iconStyle.parent(), noParent ); // setIconStyle copies QCOMPARE( placemark->style()->parent(), noParent ); placemark->setStyle( style ); QCOMPARE( placemark->style()->parent(), placemark ); // Parent should be assigned now /// Set a style map GeoDataStyleMap* styleMap = new GeoDataStyleMap; styleMap->setStyleId( "mystylemap" ); styleMap->insert( "normal", "#mystyle" ); styleMap->insert( "highlight", "#mystyle" ); document->addStyle( *style ); document->setStyleMap( styleMap ); QCOMPARE( placemark2->style()->parent(), noParent ); placemark2->setStyleUrl( "#mystyle" ); QCOMPARE( placemark2->style()->parent(), document ); // Parent is document, not placemark2 QCOMPARE( iconStyle.iconPath(), QString( "myicon.png" ) ); QCOMPARE( placemark2->style()->iconStyle().iconPath(), QString( "myicon.png" ) ); }
void RoutingManagerPrivate::loadRoute(const QString &filename) { QFile file( filename ); if ( !file.open( QIODevice::ReadOnly ) ) { mDebug() << "Can not read route from " << file.fileName(); return; } GeoDataParser parser( GeoData_KML ); if ( !parser.read( &file ) ) { mDebug() << "Could not parse file: " << parser.errorString(); return; } GeoDocument *doc = parser.releaseDocument(); file.close(); bool loaded = false; GeoDataDocument* container = dynamic_cast<GeoDataDocument*>( doc ); if ( container && container->size() > 0 ) { GeoDataFolder* viaPoints = dynamic_cast<GeoDataFolder*>( &container->first() ); if ( viaPoints ) { loaded = true; QVector<GeoDataPlacemark*> placemarks = viaPoints->placemarkList(); for( int i=0; i<placemarks.size(); ++i ) { if ( i < m_routeRequest.size() ) { m_routeRequest[i] = *placemarks[i]; } else { m_routeRequest.append( *placemarks[i] ); } } // clear unneeded via points const int viaPoints_needed = placemarks.size(); for ( int i = m_routeRequest.size(); i > viaPoints_needed; --i ) { m_routeRequest.remove( viaPoints_needed ); } } else { mDebug() << "Expected a GeoDataDocument with at least one child, didn't get one though"; } } if ( container && container->size() == 2 ) { GeoDataDocument* route = dynamic_cast<GeoDataDocument*>(&container->last()); if ( route ) { loaded = true; m_alternativeRoutesModel.clear(); m_alternativeRoutesModel.addRoute( route, AlternativeRoutesModel::Instant ); m_alternativeRoutesModel.setCurrentRoute( 0 ); m_state = RoutingManager::Retrieved; emit q->stateChanged( m_state ); emit q->routeRetrieved( route ); } else { mDebug() << "Expected a GeoDataDocument child, didn't get one though"; } } if ( !loaded ) { mDebug() << "File " << filename << " is not a valid Marble route .kml file"; if ( container ) { m_treeModel->addDocument( container ); } } }