Skip to content
Permalink
Browse files

[FEATURE] Applied patch from #1974 to enable render caching capabilit…

…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
timlinux committed Oct 24, 2009
1 parent ba793a5 commit 763fbb204998e616626e2671e824fcb419f0c843
@@ -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 */
@@ -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
@@ -4476,6 +4476,9 @@ void QgisApp::pasteTransformations()

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

@@ -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
@@ -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() );
@@ -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 );
}

}

@@ -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 );
}

}

@@ -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();

@@ -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 );
@@ -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
@@ -729,3 +734,13 @@ QUndoStack* QgsMapLayer::undoStack()
{
return &mUndoStack;
}

void QgsMapLayer::setCacheImage( QImage * thepImage )
{
QgsDebugMsg( "cache Image set!" );
if ( mpCacheImage )
{
delete mpCacheImage;
}
mpCacheImage = thepImage;
}
@@ -24,6 +24,7 @@

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

#include "qgsrectangle.h"

@@ -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 */
@@ -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
@@ -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()
{
@@ -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

0 comments on commit 763fbb2

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