Skip to content

Commit

Permalink
Fix atlas segfaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Mercier committed Oct 5, 2012
1 parent d904da4 commit e3536e4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
42 changes: 36 additions & 6 deletions src/app/composer/qgsatlascompositionwidget.cpp
Expand Up @@ -98,6 +98,10 @@ void QgsAtlasCompositionWidget::onLayerRemoved( QString layerName )
break;
}
}
if ( mAtlasCoverageLayerComboBox->count() == 0 )
{
mAtlas->setCoverageLayer( 0 );
}
}

void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map )
Expand All @@ -108,24 +112,36 @@ void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map )
{
mAtlasCoverageLayerComboBox->addItem( map->id(), qVariantFromValue( (void*)map ) );
}
if ( mAtlasCoverageLayerComboBox->count() == 1 )
{
mAtlas->setCoverageLayer( vectorLayer );
}
}

void QgsAtlasCompositionWidget::onComposerMapAdded( QgsComposerMap* map )
{
mComposerMapComboBox->addItem( tr( "Map %1" ).arg( map->id() ), map->id() );
mComposerMapComboBox->addItem( tr( "Map %1" ).arg( map->id() ), qVariantFromValue( (void*)map ) );
if ( mComposerMapComboBox->count() == 1 )
{
mAtlas->setComposerMap( map );
}
}

void QgsAtlasCompositionWidget::onItemRemoved( QgsComposerItem* item )
{
QgsComposerMap* map = dynamic_cast<QgsComposerMap*>( item );
if ( map )
{
int idx = mComposerMapComboBox->findData( map->id() );
int idx = mComposerMapComboBox->findData( qVariantFromValue( (void*)map ) );
if ( idx != -1 )
{
mComposerMapComboBox->removeItem( idx );
}
}
if ( mComposerMapComboBox->count() == 0 )
{
mAtlas->setComposerMap( 0 );
}
}

void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index )
Expand All @@ -135,8 +151,15 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
{
return;
}
QgsVectorLayer* layer = reinterpret_cast<QgsVectorLayer*>(mAtlasCoverageLayerComboBox->itemData( index ).value<void*>());
atlasMap->setCoverageLayer( layer );
if ( index == -1 )
{
atlasMap->setCoverageLayer( 0 );
}
else
{
QgsVectorLayer* layer = reinterpret_cast<QgsVectorLayer*>(mAtlasCoverageLayerComboBox->itemData( index ).value<void*>());
atlasMap->setCoverageLayer( layer );
}
}

void QgsAtlasCompositionWidget::on_mComposerMapComboBox_currentIndexChanged( int index )
Expand All @@ -146,8 +169,15 @@ void QgsAtlasCompositionWidget::on_mComposerMapComboBox_currentIndexChanged( int
{
return;
}
QgsComposerMap* map = reinterpret_cast<QgsComposerMap*>(mComposerMapComboBox->itemData( index ).value<void*>());
atlasMap->setComposerMap( map );
if ( index == -1 )
{
atlasMap->setComposerMap( 0 );
}
else
{
QgsComposerMap* map = reinterpret_cast<QgsComposerMap*>(mComposerMapComboBox->itemData( index ).value<void*>());
atlasMap->setComposerMap( map );
}
}

void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const QString& text )
Expand Down
9 changes: 6 additions & 3 deletions src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -48,9 +48,12 @@ void QgsAtlasComposition::setCoverageLayer( QgsVectorLayer* layer )
{
mCoverageLayer = layer;

// update the number of features
QgsVectorDataProvider* provider = mCoverageLayer->dataProvider();
QgsExpression::setSpecialColumn( "$numfeatures", QVariant( (int)provider->featureCount() ) );
if ( mCoverageLayer != 0 )
{
// update the number of features
QgsVectorDataProvider* provider = mCoverageLayer->dataProvider();
QgsExpression::setSpecialColumn( "$numfeatures", QVariant( (int)provider->featureCount() ) );
}
}

void QgsAtlasComposition::beginRender()
Expand Down

0 comments on commit e3536e4

Please sign in to comment.