Skip to content
Permalink
Browse files
freeze canvas instead of modifying the render flag when changing lege…
…nd (fixes #4982)
  • Loading branch information
jef-n committed Feb 11, 2012
1 parent d7811a1 commit 53c31cf48c09a1e27710e6a02d6e4427e304f5ea
Showing with 42 additions and 62 deletions.
  1. +13 −29 src/app/legend/qgslegend.cpp
  2. +29 −33 src/gui/qgsmapcanvas.cpp
@@ -218,9 +218,7 @@ void QgsLegend::setLayersVisible( bool visible )
}

// Turn off rendering to improve speed.
bool renderFlagState = mMapCanvas->renderFlag();
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );
mMapCanvas->freeze();

for ( QTreeWidgetItem* theItem = firstItem(); theItem; theItem = nextItem( theItem ) )
{
@@ -233,8 +231,7 @@ void QgsLegend::setLayersVisible( bool visible )
}

// Turn on rendering (if it was on previously)
if ( renderFlagState )
mMapCanvas->setRenderFlag( true );
mMapCanvas->freeze( false );

QgsProject::instance()->dirty( true );
}
@@ -1034,9 +1031,7 @@ void QgsLegend::legendGroupRemove()
}

// Turn off rendering to improve speed.
bool renderFlagState = mMapCanvas->renderFlag();
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );
mMapCanvas->freeze();

QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( currentItem() );
if ( lg )
@@ -1045,8 +1040,7 @@ void QgsLegend::legendGroupRemove()
}

// Turn on rendering (if it was on previously)
if ( renderFlagState )
mMapCanvas->setRenderFlag( true );
mMapCanvas->freeze( false );
}

void QgsLegend::legendGroupSetCRS()
@@ -1961,15 +1955,12 @@ void QgsLegend::handleItemChange( QTreeWidgetItem* item, int column )
ll->layer()->setLayerName( ll->text( 0 ) );
}

bool renderFlagState = false;
bool changing = mChanging;
mChanging = true;

if ( !changing )
{
renderFlagState = mMapCanvas->renderFlag();
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );
mMapCanvas->freeze();

if ( item->isSelected() )
{
@@ -2018,13 +2009,12 @@ void QgsLegend::handleItemChange( QTreeWidgetItem* item, int column )

if ( !changing )
{
// update layer set
updateMapCanvasLayerSet();

// If it was on, turn it back on, otherwise leave it
// off, as turning it on causes a refresh.
if ( renderFlagState )
mMapCanvas->setRenderFlag( true );
mMapCanvas->freeze( false );

// update layer set
updateMapCanvasLayerSet();
}

mChanging = changing;
@@ -2302,9 +2292,7 @@ void QgsLegend::refreshCheckStates()
void QgsLegend::removeSelectedLayers()
{
// Turn off rendering to improve speed.
bool renderFlagState = mMapCanvas->renderFlag();
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );
mMapCanvas->freeze();

foreach( QTreeWidgetItem * item, selectedItems() )
{
@@ -2324,16 +2312,13 @@ void QgsLegend::removeSelectedLayers()
}

// Turn on rendering (if it was on previously)
if ( renderFlagState )
mMapCanvas->setRenderFlag( true );
mMapCanvas->freeze( false );
}

void QgsLegend::setCRSForSelectedLayers( const QgsCoordinateReferenceSystem &crs )
{
// Turn off rendering to improve speed.
bool renderFlagState = mMapCanvas->renderFlag();
if ( renderFlagState )
mMapCanvas->setRenderFlag( false );
mMapCanvas->freeze();

foreach( QTreeWidgetItem * item, selectedItems() )
{
@@ -2353,8 +2338,7 @@ void QgsLegend::setCRSForSelectedLayers( const QgsCoordinateReferenceSystem &crs
}

// Turn on rendering (if it was on previously)
if ( renderFlagState )
mMapCanvas->setRenderFlag( true );
mMapCanvas->freeze( false );
}

bool QgsLegend::parentGroupEmbedded( QTreeWidgetItem* item ) const
@@ -272,42 +272,41 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
bool layerSetChanged = layerSetOld != layerSet;

// update only if needed
if ( layerSetChanged )
{
QgsDebugMsg( "Layer changed to: " + layerSet.join( ", " ) );
if ( !layerSetChanged )
return;

for ( i = 0; i < layerCount(); i++ )
QgsDebugMsg( "Layer changed to: " + layerSet.join( ", " ) );

for ( i = 0; i < layerCount(); i++ )
{
// Add check if vector layer when disconnecting from selectionChanged slot
// Ticket #811 - racicot
QgsMapLayer *currentLayer = layer( i );
disconnect( currentLayer, SIGNAL( repaintRequested() ), this, SLOT( refresh() ) );
disconnect( currentLayer, SIGNAL( screenUpdateRequested() ), this, SLOT( updateMap() ) );
QgsVectorLayer *isVectLyr = qobject_cast<QgsVectorLayer *>( currentLayer );
if ( isVectLyr )
{
// Add check if vector layer when disconnecting from selectionChanged slot
// Ticket #811 - racicot
QgsMapLayer *currentLayer = layer( i );
disconnect( currentLayer, SIGNAL( repaintRequested() ), this, SLOT( refresh() ) );
disconnect( currentLayer, SIGNAL( screenUpdateRequested() ), this, SLOT( updateMap() ) );
QgsVectorLayer *isVectLyr = qobject_cast<QgsVectorLayer *>( currentLayer );
if ( isVectLyr )
{
disconnect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
}
disconnect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
}
}

mMapRenderer->setLayerSet( layerSet );
mMapRenderer->setLayerSet( layerSet );

for ( i = 0; i < layerCount(); i++ )
for ( i = 0; i < layerCount(); i++ )
{
// Add check if vector layer when connecting to selectionChanged slot
// Ticket #811 - racicot
QgsMapLayer *currentLayer = layer( i );
connect( currentLayer, SIGNAL( repaintRequested() ), this, SLOT( refresh() ) );
connect( currentLayer, SIGNAL( screenUpdateRequested() ), this, SLOT( updateMap() ) );
QgsVectorLayer *isVectLyr = qobject_cast<QgsVectorLayer *>( currentLayer );
if ( isVectLyr )
{
// Add check if vector layer when connecting to selectionChanged slot
// Ticket #811 - racicot
QgsMapLayer *currentLayer = layer( i );
connect( currentLayer, SIGNAL( repaintRequested() ), this, SLOT( refresh() ) );
connect( currentLayer, SIGNAL( screenUpdateRequested() ), this, SLOT( updateMap() ) );
QgsVectorLayer *isVectLyr = qobject_cast<QgsVectorLayer *>( currentLayer );
if ( isVectLyr )
{
connect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
}
connect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
}
}


if ( mMapOverview )
{
mMapOverview->updateFullExtent( fullExtent() );
@@ -323,13 +322,10 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
updateOverview();
}

if ( layerSetChanged )
{
QgsDebugMsg( "Layers have changed, refreshing" );
emit layersChanged();
QgsDebugMsg( "Layers have changed, refreshing" );
emit layersChanged();

refresh();
}
refresh();

} // setLayerSet

0 comments on commit 53c31cf

Please sign in to comment.