Skip to content
Permalink
Browse files
[composer] Always update map caches when zoom changes
Before this would only happen with the "render" mode, not "cache"
mode. Now updating caches is so responsive and transparent to users
we can safely trigger the background cache update whenever the
zoom changes without any performance impact.
  • Loading branch information
nyalldawson committed May 8, 2017
1 parent 491abc2 commit 3f595ee8e1897d587deebdd8c3f863a12ca979e8
Showing with 11 additions and 15 deletions.
  1. +10 −4 src/app/composer/qgscomposer.cpp
  2. +1 −1 src/app/composer/qgscomposer.h
  3. +0 −10 src/gui/qgscomposerview.cpp
@@ -763,6 +763,8 @@ void QgsComposer::connectViewSlots()
//listen out for position updates from the QgsComposerView
connect( mView, &QgsComposerView::cursorPosChanged, this, &QgsComposer::updateStatusCursorPos );
connect( mView, &QgsComposerView::zoomLevelChanged, this, &QgsComposer::updateStatusZoom );

connect( mView, &QgsComposerView::zoomLevelChanged, this, &QgsComposer::invalidateCachedRenders );
}

void QgsComposer::connectCompositionSlots()
@@ -774,7 +776,6 @@ void QgsComposer::connectCompositionSlots()

connect( mComposition, &QgsComposition::nameChanged, this, &QgsComposer::setWindowTitle );
connect( mComposition, &QgsComposition::selectedItemChanged, this, &QgsComposer::showItemOptions );
connect( mComposition, &QgsComposition::itemAdded, this, &QgsComposer::compositionItemAdded );
connect( mComposition, &QgsComposition::itemRemoved, this, &QgsComposer::deleteItem );
connect( mComposition, &QgsComposition::paperSizeChanged, this, [ = ]
{
@@ -802,6 +803,7 @@ void QgsComposer::connectOtherSlots()
connect( mVerticalRuler, &QgsComposerRuler::cursorPosChanged, this, &QgsComposer::updateStatusCursorPos );
//listen out for zoom updates
connect( this, &QgsComposer::zoomLevelChanged, this, &QgsComposer::updateStatusZoom );
connect( this, &QgsComposer::zoomLevelChanged, this, &QgsComposer::invalidateCachedRenders );
}

void QgsComposer::open()
@@ -1007,11 +1009,15 @@ void QgsComposer::atlasFeatureChanged( QgsFeature *feature )
mapCanvas()->expressionContextScope().addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_geometry" ), QVariant::fromValue( atlasFeature.geometry() ), true ) );
}

void QgsComposer::compositionItemAdded( QgsComposerItem *item )
void QgsComposer::invalidateCachedRenders()
{
if ( item && item->type() == QgsComposerItem::ComposerMap )
//redraw cached map items
QList< QgsComposerMap *> maps;
mComposition->composerItems( maps );

Q_FOREACH ( QgsComposerMap *map, maps )
{
connect( this, &QgsComposer::zoomLevelChanged, static_cast< QgsComposerMap *>( item ), &QgsComposerMap::renderModeUpdateCachedImage );
map->invalidateCache();
}
}

@@ -614,7 +614,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

void atlasFeatureChanged( QgsFeature *feature );

void compositionItemAdded( QgsComposerItem *item );
void invalidateCachedRenders();



@@ -2054,16 +2054,6 @@ void QgsComposerView::wheelZoom( QWheelEvent *event )
emit zoomLevelChanged();
updateRulers();
update();
//redraw cached map items
QList<QGraphicsItem *> itemList = composition()->items();
QList<QGraphicsItem *>::iterator itemIt = itemList.begin();
for ( ; itemIt != itemList.end(); ++itemIt )
{
if ( QgsComposerMap *mypItem = dynamic_cast<QgsComposerMap *>( *itemIt ) )
{
mypItem->renderModeUpdateCachedImage();
}
}
}

void QgsComposerView::setZoomLevel( double zoomLevel )

0 comments on commit 3f595ee

Please sign in to comment.