Skip to content
Permalink
Browse files

Fix regeneration of cached maps when zoom level changes

  • Loading branch information
nyalldawson committed Oct 21, 2017
1 parent 6f59965 commit 7924aa1990146ab44684f6c4dcc1cf1f7889b921
@@ -551,6 +551,11 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
recalculation of its position and size.
%End

virtual void invalidateCache();
%Docstring
Forces a deferred update of any cached image the item uses.
%End

virtual void redraw();
%Docstring
Triggers a redraw (update) of the item.
@@ -447,10 +447,8 @@ Is emitted when the map has been prepared for atlas rendering, just before actua

public slots:

void invalidateCache();
%Docstring
Forces a deferred update of the cached map image on next paint.
%End
virtual void invalidateCache();


void updateBoundingRect();
%Docstring
@@ -945,6 +945,16 @@ void QgsLayoutItem::refresh()
refreshDataDefinedProperty();
}

void QgsLayoutItem::invalidateCache()
{
if ( !mItemCachedImage.isNull() )
{
mItemCachedImage = QImage();
mItemCacheDpi = -1;
update();
}
}

void QgsLayoutItem::redraw()
{
update();
@@ -548,6 +548,11 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
*/
void refresh() override;

/**
* Forces a deferred update of any cached image the item uses.
*/
virtual void invalidateCache();

/**
* Triggers a redraw (update) of the item.
*/
@@ -495,10 +495,7 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem

public slots:

/**
* Forces a deferred update of the cached map image on next paint.
*/
void invalidateCache();
void invalidateCache() override;

//! Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle
void updateBoundingRect();
@@ -327,20 +327,8 @@ void QgsLayoutItemPropertiesWidget::mBackgroundColorButton_colorChanged( const Q
}
mItem->layout()->undoStack()->beginCommand( mItem, tr( "Change Background Color" ), QgsLayoutItem::UndoBackgroundColor );
mItem->setBackgroundColor( newBackgroundColor );

#if 0 //TODO
//if the item is a composer map, we need to regenerate the map image
//because it usually is cached
if ( QgsComposerMap *cm = qobject_cast<QgsComposerMap *>( mItem ) )
{
cm->invalidateCache();
}
else
{
mItem->updateItem();
}
#endif
mItem->layout()->undoStack()->endCommand();
mItem->invalidateCache();
}

void QgsLayoutItemPropertiesWidget::changeItemPosition()
@@ -477,20 +465,8 @@ void QgsLayoutItemPropertiesWidget::mBackgroundGroupBox_toggled( bool state )

mItem->layout()->undoStack()->beginCommand( mItem, state ? tr( "Enable Background" ) : tr( "Disable Background" ) );
mItem->setBackgroundEnabled( state );

#if 0 //TODO
//if the item is a composer map, we need to regenerate the map image
//because it usually is cached
if ( QgsComposerMap *cm = qobject_cast<QgsComposerMap *>( mItem ) )
{
cm->invalidateCache();
}
else
{
mItem->updateItem();
}
#endif
mItem->layout()->undoStack()->endCommand();
mItem->invalidateCache();
}


@@ -58,6 +58,8 @@ QgsLayoutView::QgsLayoutView( QWidget *parent )

mPreviewEffect = new QgsPreviewEffect( this );
viewport()->setGraphicsEffect( mPreviewEffect );

connect( this, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutView::invalidateCachedRenders );
}

QgsLayout *QgsLayoutView::currentLayout()
@@ -899,6 +901,21 @@ void QgsLayoutView::scrollContentsBy( int dx, int dy )
viewChanged();
}

void QgsLayoutView::invalidateCachedRenders()
{
if ( !currentLayout() )
return;

//redraw cached map items
QList< QgsLayoutItem *> items;
currentLayout()->layoutItems( items );

for ( QgsLayoutItem *item : qgis::as_const( items ) )
{
item->invalidateCache();
}
}

void QgsLayoutView::viewChanged()
{
if ( mHorizontalRuler )
@@ -451,6 +451,8 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView

private slots:

void invalidateCachedRenders();

private:

//! Zoom layout from a mouse wheel event

0 comments on commit 7924aa1

Please sign in to comment.
You can’t perform that action at this time.