GeoDataFeature* TourWidgetPrivate::getPlaylistFeature() const { GeoDataObject *rootObject = rootIndexObject(); if ( rootObject && rootObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) { GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( rootObject ); GeoDataObject *object = playlist->parent(); if ( object && object->nodeType() == GeoDataTypes::GeoDataTourType ) { return static_cast<GeoDataFeature*>( object ); } } return 0; }
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(); } }
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; } } } }
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(); } }
GeoDataFlyTo* FlyToEditWidget::flyToElement() { GeoDataObject *object = qvariant_cast<GeoDataObject*>(m_index.data( MarblePlacemarkModel::ObjectPointerRole ) ); Q_ASSERT( object ); Q_ASSERT( object->nodeType() == GeoDataTypes::GeoDataFlyToType ); return static_cast<GeoDataFlyTo*>( object ); }
void TourWidgetPrivate::addTourPrimitive( GeoDataTourPrimitive *primitive ) { GeoDataObject *rootObject = rootIndexObject(); if ( rootObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) { GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( rootObject ); QModelIndex currentIndex = m_tourUi.m_listView->currentIndex(); QModelIndex playlistIndex = m_widget->model()->treeModel()->index( playlist ); int row = currentIndex.isValid() ? currentIndex.row()+1 : playlist->size(); m_widget->model()->treeModel()->addTourPrimitive( playlistIndex, primitive, row ); m_isChanged = true; m_tourUi.m_actionSaveTour->setEnabled( true ); } }
void TourWidgetPrivate::moveDown() { GeoDataObject *rootObject = rootIndexObject(); if ( rootObject && rootObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) { GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( rootObject ); QModelIndex playlistIndex = m_widget->model()->treeModel()->index( playlist ); QModelIndexList selected = m_tourUi.m_listView->selectionModel()->selectedIndexes(); qSort( selected.begin(), selected.end(), qGreater<QModelIndex>() ); QModelIndexList::iterator end = selected.end(); QModelIndexList::iterator iter = selected.begin(); for( ; iter != end; ++iter ) { int const index = iter->row(); Q_ASSERT( index < playlist->size()-1 ); m_widget->model()->treeModel()->swapTourPrimitives( playlistIndex, index, index+1 ); } m_isChanged = true; m_tourUi.m_actionSaveTour->setEnabled( true ); updateButtonsStates(); } }
void TourWidgetPrivate::updateButtonsStates() { QModelIndexList selectedIndexes = m_tourUi.m_listView->selectionModel()->selectedIndexes(); if ( selectedIndexes.isEmpty() ) { m_tourUi.m_actionDelete->setEnabled( false ); m_tourUi.m_actionMoveDown->setEnabled( false ); m_tourUi.m_actionMoveUp->setEnabled( false ); } else { m_tourUi.m_actionDelete->setEnabled( true ); qSort( selectedIndexes.begin(), selectedIndexes.end(), qLess<QModelIndex>() ); QModelIndexList::iterator end = selectedIndexes.end()-1; QModelIndexList::iterator start = selectedIndexes.begin(); m_tourUi.m_actionMoveUp->setEnabled( ( start->row() != 0 ) ); // if we can move up enable action else disable. GeoDataObject *rootObject = rootIndexObject(); if ( rootObject && rootObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) { GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( rootObject ); m_tourUi.m_actionMoveDown->setEnabled( ( end->row() != playlist->size()-1 ) ); // if we can move down enable action else disable. } } }
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(); } }
void TourWidgetPrivate::deleteSelected() { QString title = QObject::tr( "Remove Selected Items" ); QString text = QObject::tr( "Are you sure want to remove selected items?" ); QPointer<QMessageBox> dialog = new QMessageBox( QMessageBox::Question, title, text, QMessageBox::Yes | QMessageBox::No, q ); dialog->setDefaultButton( QMessageBox::No ); if ( dialog->exec() == QMessageBox::Yes ) { GeoDataObject *rootObject = rootIndexObject(); if ( rootObject && rootObject->nodeType() == GeoDataTypes::GeoDataPlaylistType ) { GeoDataPlaylist *playlist = static_cast<GeoDataPlaylist*>( rootObject ); QModelIndex playlistIndex = m_widget->model()->treeModel()->index( playlist ); QModelIndexList selected = m_tourUi.m_listView->selectionModel()->selectedIndexes(); qSort( selected.begin(), selected.end(), qGreater<QModelIndex>() ); QModelIndexList::iterator end = selected.end(); QModelIndexList::iterator iter = selected.begin(); for( ; iter != end; ++iter ) { m_widget->model()->treeModel()->removeTourPrimitive( playlistIndex, iter->row() ); } m_isChanged = true; m_tourUi.m_actionSaveTour->setEnabled( true ); } } delete dialog; }