Skip to content
Permalink
Browse files
Avoid redrawing map views multiple times on creation
  • Loading branch information
nyalldawson committed Mar 28, 2017
1 parent 5b9dc9d commit b31d18e5df54fd5910c0651c1decd74a1787b7cd
Showing with 27 additions and 12 deletions.
  1. +24 −12 src/app/qgisapp.cpp
  2. +3 −0 src/app/qgisapp.h
@@ -3141,8 +3141,12 @@ QgsMapCanvas *QgisApp::createNewMapCanvas( const QString &name )
QgsMapCanvasDockWidget *dock = createNewMapCanvasDock( name );
if ( !dock )
return nullptr;
else
return dock->mapCanvas();

dock->mapCanvas()->setLayers( mMapCanvas->layers() );
dock->mapCanvas()->setExtent( mMapCanvas->extent() );
dock->mapCanvas()->setDestinationCrs( QgsProject::instance()->crs() );
dock->mapCanvas()->freeze( false );
return dock->mapCanvas();
}

QgsMapCanvasDockWidget *QgisApp::createNewMapCanvasDock( const QString &name, bool isFloating, const QRect &dockGeometry, Qt::DockWidgetArea area )
@@ -3170,20 +3174,13 @@ QgsMapCanvasDockWidget *QgisApp::createNewMapCanvasDock( const QString &name, bo
applyProjectSettingsToCanvas( mapCanvas );
applyDefaultSettingsToCanvas( mapCanvas );

mapCanvas->setLayers( mMapCanvas->layers() );
mapCanvas->setExtent( mMapCanvas->extent() );

mapCanvas->setDestinationCrs( QgsProject::instance()->crs() );


// add existing annotations to canvas
Q_FOREACH ( QgsAnnotation *annotation, QgsProject::instance()->annotationManager()->annotations() )
{
QgsMapCanvasAnnotationItem *canvasItem = new QgsMapCanvasAnnotationItem( annotation, mapCanvas );
Q_UNUSED( canvasItem ); //item is already added automatically to canvas scene
}

mapCanvas->freeze( false );
markDirty();
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::closed, this, &QgisApp::markDirty );
connect( mapCanvasWidget, &QgsMapCanvasDockWidget::renameTriggered, this, &QgisApp::renameView );
@@ -9809,7 +9806,14 @@ void QgisApp::newMapCanvas()
}
}

createNewMapCanvasDock( name, true );
QgsMapCanvasDockWidget *dock = createNewMapCanvasDock( name, true );
if ( dock )
{
dock->mapCanvas()->setLayers( mMapCanvas->layers() );
dock->mapCanvas()->setExtent( mMapCanvas->extent() );
dock->mapCanvas()->setDestinationCrs( QgsProject::instance()->crs() );
dock->mapCanvas()->freeze( false );
}
}

void QgisApp::setExtent( const QgsRectangle &rect )
@@ -11873,6 +11877,7 @@ void QgisApp::readProject( const QDomDocument &doc )
mLayerTreeCanvasBridge->setAutoSetupOnFirstLayer( true );

QDomNodeList nodes = doc.elementsByTagName( QStringLiteral( "mapViewDocks" ) );
QList< QgsMapCanvas * > views;
if ( !nodes.isEmpty() )
{
QDomNode viewNode = nodes.at( 0 );
@@ -11896,16 +11901,23 @@ void QgisApp::readProject( const QDomDocument &doc )

QgsMapCanvasDockWidget *mapCanvasDock = createNewMapCanvasDock( mapName, floating, QRect( x, y, w, h ), area );
QgsMapCanvas *mapCanvas = mapCanvasDock->mapCanvas();
mapCanvas->readProject( doc );

mapCanvasDock->setViewCenterSynchronized( synced );
mapCanvasDock->setCursorMarkerVisible( showCursor );
mapCanvasDock->setScaleFactor( scaleFactor );
mapCanvasDock->setViewScaleSynchronized( scaleSynced );
mapCanvasDock->setMainCanvasExtentVisible( showExtent );
mapCanvasDock->setLabelsVisible( showLabels );
mapCanvas->readProject( doc );
views << mapCanvas;
}
}
// unfreeze all new views at once. We don't do this as they are created since additional
// views which may exist in project could rearrange the docks and cause the canvases to resize
// resulting in multiple redraws
Q_FOREACH ( QgsMapCanvas *c, views )
{
c->freeze( false );
}
}

void QgisApp::showLayerProperties( QgsMapLayer *ml )
@@ -250,6 +250,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
* Create a new map canvas dock widget with the specified unique \a name. The \a isFloating
* and \a dockGeometry arguments can be used to specify an initial floating state
* and widget geometry rect for the dock.
* \note the mapCanvas() inside the dock widget will initially be frozen to avoid multiple
* unwanted map redraws. Callers must manually unfreeze the map canvas when they have finished
* setting the initial state of the canvas and are ready for it to begin rendering.
*/
QgsMapCanvasDockWidget *createNewMapCanvasDock( const QString &name, bool isFloating = false, const QRect &dockGeometry = QRect(),
Qt::DockWidgetArea area = Qt::RightDockWidgetArea );

0 comments on commit b31d18e

Please sign in to comment.