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 PositionTracking::readSettings() { QFile file( d->statusFile() ); if ( !file.open( QIODevice::ReadOnly ) ) { mDebug() << "Can not read track from " << file.fileName(); return; } GeoDataParser parser( GeoData_KML ); if ( !parser.read( &file ) ) { mDebug() << "Could not parse tracking file: " << parser.errorString(); return; } GeoDataDocument *doc = dynamic_cast<GeoDataDocument*>( parser.releaseDocument() ); file.close(); if( !doc ){ mDebug() << "tracking document not available"; return; } GeoDataPlacemark *track = dynamic_cast<GeoDataPlacemark*>( doc->child( 0 ) ); if( !track ) { mDebug() << "tracking document doesn't have a placemark"; delete doc; return; } d->m_trackSegments = dynamic_cast<GeoDataMultiTrack*>( track->geometry() ); if( !d->m_trackSegments ) { mDebug() << "tracking document doesn't have a multitrack"; delete doc; return; } if( d->m_trackSegments->size() < 1 ) { mDebug() << "tracking document doesn't have a track"; delete doc; return; } d->m_currentTrack = dynamic_cast<GeoDataTrack*>( d->m_trackSegments->child( d->m_trackSegments->size() - 1 ) ); if( !d->m_currentTrack ) { mDebug() << "tracking document doesn't have a last track"; delete doc; return; } doc->remove( 0 ); delete doc; d->m_treeModel->removeDocument( &d->m_document ); d->m_document.remove( 1 ); delete d->m_currentTrackPlacemark; d->m_currentTrackPlacemark = track; d->m_currentTrackPlacemark->setName("Current Track"); d->m_document.append( d->m_currentTrackPlacemark ); d->m_currentTrackPlacemark->setStyleUrl( d->m_currentTrackPlacemark->styleUrl() ); d->m_treeModel->addDocument( &d->m_document ); d->m_length = 0.0; for ( int i = 0; i < d->m_trackSegments->size(); ++i ) { d->m_length += d->m_trackSegments->at( i ).lineString()->length( 1 ); } }