Skip to content

Commit

Permalink
[FEATURE] Applied patch from #1974 to enable render caching capabilit…
Browse files Browse the repository at this point in the history
…y in QGIS. This speeds up common operations such as layer re-ordering, changing symbology, WMS / WFS client, hiding / showing layers and opens the door for future enhancements such as threaded rendering and pre-compositing layer cache manipulation.

git-svn-id: http://svn.osgeo.org/qgis/trunk@11831 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Oct 24, 2009
1 parent ba793a5 commit 763fbb2
Show file tree
Hide file tree
Showing 14 changed files with 241 additions and 31 deletions.
7 changes: 7 additions & 0 deletions python/core/qgsmaplayer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ public:
/** Return pointer to layer's undo stack */
QUndoStack* undoStack();

/** Get the QImage used for caching render operations
* @note This method was added in QGIS 1.4 **/
QImage * cacheImage() { return mpCacheImage; }
/** Set the QImage used for caching render operations
* @note This method was added in QGIS 1.4 **/
void setCacheImage( QImage * thepImage );

public slots:

/** Event handler for when a coordinate transform fails due to bad vertex error */
Expand Down
8 changes: 8 additions & 0 deletions python/core/qgsmaplayerregistry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public:
*/
void removeAllMapLayers();

/* Clears all layer caches, resetting them to zero and
* freeing up any memory they may have been using. Layer
* caches are used to speed up rendering in certain situations
* see ticket #1974 for more details.
* @note this method was added in QGIS 1.4
*/
void clearAllLayerCaches();

signals:

/** emitted when a layer is removed from the registry
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4476,6 +4476,9 @@ void QgisApp::pasteTransformations()

void QgisApp::refreshMapCanvas()
{
//clear all caches first
QgsMapLayerRegistry::instance()->clearAllLayerCaches();
//then refresh
mMapCanvas->refresh();
}

Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :

//set the state of the checkboxes
chkAntiAliasing->setChecked( settings.value( "/qgis/enable_anti_aliasing", false ).toBool() );
chkUseRenderCaching->setChecked( settings.value( "/qgis/enable_render_caching", false ).toBool() );

// Slightly awkard here at the settings value is true to use QImage,
// but the checkbox is true to use QPixmap
Expand Down Expand Up @@ -365,6 +366,7 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() );
settings.setValue( "/qgis/new_layers_visible", chkAddedVisibility->isChecked() );
settings.setValue( "/qgis/enable_anti_aliasing", chkAntiAliasing->isChecked() );
settings.setValue( "/qgis/enable_render_caching", chkUseRenderCaching->isChecked() );
settings.setValue( "/qgis/use_qimage_to_render", !( chkUseQPixmap->isChecked() ) );
settings.setValue( "qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
settings.setValue( "qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked() );
Expand Down Expand Up @@ -530,7 +532,9 @@ void QgsOptions::on_chkAntiAliasing_stateChanged()
// used (we we can. but it then doesn't do anti-aliasing, and this
// will confuse people).
if ( chkAntiAliasing->isChecked() )
{
chkUseQPixmap->setChecked( false );
}

}

Expand All @@ -540,7 +544,9 @@ void QgsOptions::on_chkUseQPixmap_stateChanged()
// used (we we can. but it then doesn't do anti-aliasing, and this
// will confuse people).
if ( chkUseQPixmap->isChecked() )
{
chkAntiAliasing->setChecked( false );
}

}

Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,9 @@ void QgsRasterLayerProperties::apply()
// update symbology
emit refreshLegend( mRasterLayer->getLayerID(), false );

//no need to delete the old one, maplayer will do it if needed
mRasterLayer->setCacheImage( 0 );

//make sure the layer is redrawn
mRasterLayer->triggerRepaint();

Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ void QgsVectorLayerProperties::apply()
// update symbology
emit refreshLegend( layer->getLayerID(), false );

//no need to delete the old one, maplayer will do it if needed
layer->setCacheImage( 0 );

layer->triggerRepaint();
// notify the project we've made a change
QgsProject::instance()->dirty( true );
Expand Down
15 changes: 15 additions & 0 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
mMinScale = 0;
mMaxScale = 100000000;
mScaleBasedVisibility = false;
mpCacheImage = 0;
}



QgsMapLayer::~QgsMapLayer()
{
delete mCRS;
if ( mpCacheImage )
{
delete mpCacheImage;
}
}

QgsMapLayer::LayerType QgsMapLayer::type() const
Expand Down Expand Up @@ -729,3 +734,13 @@ QUndoStack* QgsMapLayer::undoStack()
{
return &mUndoStack;
}

void QgsMapLayer::setCacheImage( QImage * thepImage )
{
QgsDebugMsg( "cache Image set!" );
if ( mpCacheImage )
{
delete mpCacheImage;
}
mpCacheImage = thepImage;
}
13 changes: 13 additions & 0 deletions src/core/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <QObject>
#include <QUndoStack>
#include <QImage>

#include "qgsrectangle.h"

Expand Down Expand Up @@ -263,6 +264,13 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Return pointer to layer's undo stack */
QUndoStack* undoStack();

/** Get the QImage used for caching render operations
* @note This method was added in QGIS 1.4 **/
QImage * cacheImage() { return mpCacheImage; }
/** Set the QImage used for caching render operations
* @note This method was added in QGIS 1.4 **/
void setCacheImage( QImage * thepImage );

public slots:

/** Event handler for when a coordinate transform fails due to bad vertex error */
Expand Down Expand Up @@ -360,8 +368,13 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** A flag that tells us whether to use the above vars to restrict layer visibility */
bool mScaleBasedVisibility;

/** Collection of undoable operations for this layer. **/
QUndoStack mUndoStack;

/**QImage for caching of rendering operations
* @note This property was added in QGIS 1.4 **/
QImage * mpCacheImage;

};

#endif
10 changes: 10 additions & 0 deletions src/core/qgsmaplayerregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ void QgsMapLayerRegistry::removeAllMapLayers()

} // QgsMapLayerRegistry::removeAllMapLayers()

//Added in QGIS 1.4
void QgsMapLayerRegistry::clearAllLayerCaches()
{
QMap<QString, QgsMapLayer *>::iterator it;
for ( it = mMapLayers.begin(); it != mMapLayers.end() ; ++it )
{
//the map layer will take care of deleting the QImage
it.value()->setCacheImage( 0 );
}
} // QgsMapLayerRegistry::clearAllLayerCaches()

QMap<QString, QgsMapLayer*> & QgsMapLayerRegistry::mapLayers()
{
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsmaplayerregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
*/
void removeAllMapLayers();

/* Clears all layer caches, resetting them to zero and
* freeing up any memory they may have been using. Layer
* caches are used to speed up rendering in certain situations
* see ticket #1974 for more details.
* @note this method was added in QGIS 1.4
*/
void clearAllLayerCaches();
signals:

/** emitted when a layer is removed from the registry
Expand Down
Loading

0 comments on commit 763fbb2

Please sign in to comment.