Skip to content
Permalink
Browse files
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 2613cf6ad5ec0afcb033e59e60af89384e234f99
Showing with 50 additions and 43 deletions.
  1. +1 −1 python/gui/qgsmapoverviewcanvas.sip
  2. +31 −39 src/gui/qgsmapcanvas.cpp
  3. +17 −2 src/gui/qgsmapoverviewcanvas.cpp
  4. +1 −1 src/gui/qgsmapoverviewcanvas.h
@@ -26,7 +26,7 @@ class QgsMapOverviewCanvas : QWidget

void enableAntiAliasing( bool flag );

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

public slots:

@@ -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 )
{
@@ -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 )
@@ -514,11 +511,6 @@ void QgsMapCanvas::updateFullExtent()
QgsDebugMsg( "updating full extent" );

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

@@ -95,6 +95,7 @@ void QgsMapOverviewCanvas::paintEvent( QPaintEvent* pe )
{
mPixmap = QPixmap( mNewSize );
mMapRenderer->setOutputSize( mNewSize, mPixmap.logicalDpiX() );
updateFullExtent();
mNewSize = QSize();
refresh();
}
@@ -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;
@@ -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();
}
@@ -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:

0 comments on commit 2613cf6

Please sign in to comment.