Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
keep extent of overview set to union of extents of layer in overview;…
… dont shrink on resize; fixes #1788
  • Loading branch information
blazek committed Nov 19, 2012
1 parent fad5cf3 commit 2613cf6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 43 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgsmapoverviewcanvas.sip
Expand Up @@ -26,7 +26,7 @@ class QgsMapOverviewCanvas : QWidget

void enableAntiAliasing( bool flag );

void updateFullExtent( const QgsRectangle& rect );
void updateFullExtent();

public slots:

Expand Down
70 changes: 31 additions & 39 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -265,45 +265,48 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
bool layerSetChanged = layerSetOld != layerSet;

// update only if needed
if ( !layerSetChanged )
return;

QgsDebugMsg( "Layer changed to: " + layerSet.join( ", " ) );

for ( i = 0; i < layerCount(); i++ )
if ( layerSetChanged )
{
// 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 )
QgsDebugMsg( "Layers changed to: " + layerSet.join( ", " ) );

for ( i = 0; i < layerCount(); i++ )
{
disconnect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
// 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() ) );
}
}
}

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

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 )
for ( i = 0; i < layerCount(); i++ )
{
connect( currentLayer, SIGNAL( selectionChanged() ), this, SLOT( selectionChangedSlot() ) );
// 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() ) );
}
}

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

refresh();
}

if ( mMapOverview )
{
mMapOverview->updateFullExtent( fullExtent() );

QStringList& layerSetOvOld = mMapOverview->layerSet();
if ( layerSetOvOld != layerSetOverview )
{
Expand All @@ -314,12 +317,6 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
// because full extent might have changed
updateOverview();
}

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

refresh();

} // setLayerSet

void QgsMapCanvas::enableOverviewMode( QgsMapOverviewCanvas* overview )
Expand Down Expand Up @@ -514,11 +511,6 @@ void QgsMapCanvas::updateFullExtent()
QgsDebugMsg( "updating full extent" );

mMapRenderer->updateFullExtent();
if ( mMapOverview )
{
mMapOverview->updateFullExtent( fullExtent() );
updateOverview();
}
refresh();
}

Expand Down
19 changes: 17 additions & 2 deletions src/gui/qgsmapoverviewcanvas.cpp
Expand Up @@ -95,6 +95,7 @@ void QgsMapOverviewCanvas::paintEvent( QPaintEvent* pe )
{
mPixmap = QPixmap( mNewSize );
mMapRenderer->setOutputSize( mNewSize, mPixmap.logicalDpiX() );
updateFullExtent();
mNewSize = QSize();
refresh();
}
Expand All @@ -106,10 +107,12 @@ void QgsMapOverviewCanvas::paintEvent( QPaintEvent* pe )

void QgsMapOverviewCanvas::drawExtentRect()
{
if ( !mMapCanvas || !mMapRenderer ) return;

const QgsRectangle& extent = mMapCanvas->extent();

// show only when valid extent is set
if ( extent.isEmpty() )
if ( extent.isEmpty() || mMapRenderer->extent().isEmpty() )
{
mPanningWidget->hide();
return;
Expand Down Expand Up @@ -290,11 +293,23 @@ void QgsMapOverviewCanvas::setBackgroundColor( const QColor& color )

void QgsMapOverviewCanvas::setLayerSet( const QStringList& layerSet )
{
QgsDebugMsg( "layerSet: " + layerSet.join( ", " ) );
if ( !mMapRenderer ) return;
mMapRenderer->setLayerSet( layerSet );
mMapRenderer->updateFullExtent();
updateFullExtent();
}

void QgsMapOverviewCanvas::updateFullExtent( const QgsRectangle& rect )
void QgsMapOverviewCanvas::updateFullExtent()
{
if ( !mMapRenderer ) return;
QgsRectangle rect;
if ( !mMapRenderer->layerSet().isEmpty() )
{
rect = mMapRenderer->fullExtent();
// expand a bit to keep features on margin
rect.scale( 1.1 );
}
mMapRenderer->setExtent( rect );
drawExtentRect();
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapoverviewcanvas.h
Expand Up @@ -59,7 +59,7 @@ class GUI_EXPORT QgsMapOverviewCanvas : public QWidget

void enableAntiAliasing( bool flag ) { mAntiAliasing = flag; }

void updateFullExtent( const QgsRectangle& rect );
void updateFullExtent();

public slots:

Expand Down

0 comments on commit 2613cf6

Please sign in to comment.