Skip to content

Commit 763fbb2

Browse files
author
timlinux
committed
[FEATURE] Applied patch from #1974 to enable render caching capability 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
1 parent ba793a5 commit 763fbb2

14 files changed

Lines changed: 241 additions & 31 deletions

‎python/core/qgsmaplayer.sip‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ public:
252252
/** Return pointer to layer's undo stack */
253253
QUndoStack* undoStack();
254254

255+
/** Get the QImage used for caching render operations
256+
* @note This method was added in QGIS 1.4 **/
257+
QImage * cacheImage() { return mpCacheImage; }
258+
/** Set the QImage used for caching render operations
259+
* @note This method was added in QGIS 1.4 **/
260+
void setCacheImage( QImage * thepImage );
261+
255262
public slots:
256263

257264
/** Event handler for when a coordinate transform fails due to bad vertex error */

‎python/core/qgsmaplayerregistry.sip‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public:
5959
*/
6060
void removeAllMapLayers();
6161

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

6472
/** emitted when a layer is removed from the registry

‎src/app/qgisapp.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,6 +4476,9 @@ void QgisApp::pasteTransformations()
44764476

44774477
void QgisApp::refreshMapCanvas()
44784478
{
4479+
//clear all caches first
4480+
QgsMapLayerRegistry::instance()->clearAllLayerCaches();
4481+
//then refresh
44794482
mMapCanvas->refresh();
44804483
}
44814484

‎src/app/qgsoptions.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
149149

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

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

535539
}
536540

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

545551
}
546552

‎src/app/qgsrasterlayerproperties.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,9 @@ void QgsRasterLayerProperties::apply()
14391439
// update symbology
14401440
emit refreshLegend( mRasterLayer->getLayerID(), false );
14411441

1442+
//no need to delete the old one, maplayer will do it if needed
1443+
mRasterLayer->setCacheImage( 0 );
1444+
14421445
//make sure the layer is redrawn
14431446
mRasterLayer->triggerRepaint();
14441447

‎src/app/qgsvectorlayerproperties.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,9 @@ void QgsVectorLayerProperties::apply()
658658
// update symbology
659659
emit refreshLegend( layer->getLayerID(), false );
660660

661+
//no need to delete the old one, maplayer will do it if needed
662+
layer->setCacheImage( 0 );
663+
661664
layer->triggerRepaint();
662665
// notify the project we've made a change
663666
QgsProject::instance()->dirty( true );

‎src/core/qgsmaplayer.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,18 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
7575
mMinScale = 0;
7676
mMaxScale = 100000000;
7777
mScaleBasedVisibility = false;
78+
mpCacheImage = 0;
7879
}
7980

8081

8182

8283
QgsMapLayer::~QgsMapLayer()
8384
{
8485
delete mCRS;
86+
if ( mpCacheImage )
87+
{
88+
delete mpCacheImage;
89+
}
8590
}
8691

8792
QgsMapLayer::LayerType QgsMapLayer::type() const
@@ -729,3 +734,13 @@ QUndoStack* QgsMapLayer::undoStack()
729734
{
730735
return &mUndoStack;
731736
}
737+
738+
void QgsMapLayer::setCacheImage( QImage * thepImage )
739+
{
740+
QgsDebugMsg( "cache Image set!" );
741+
if ( mpCacheImage )
742+
{
743+
delete mpCacheImage;
744+
}
745+
mpCacheImage = thepImage;
746+
}

‎src/core/qgsmaplayer.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <QObject>
2626
#include <QUndoStack>
27+
#include <QImage>
2728

2829
#include "qgsrectangle.h"
2930

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

267+
/** Get the QImage used for caching render operations
268+
* @note This method was added in QGIS 1.4 **/
269+
QImage * cacheImage() { return mpCacheImage; }
270+
/** Set the QImage used for caching render operations
271+
* @note This method was added in QGIS 1.4 **/
272+
void setCacheImage( QImage * thepImage );
273+
266274
public slots:
267275

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

371+
/** Collection of undoable operations for this layer. **/
363372
QUndoStack mUndoStack;
364373

374+
/**QImage for caching of rendering operations
375+
* @note This property was added in QGIS 1.4 **/
376+
QImage * mpCacheImage;
377+
365378
};
366379

367380
#endif

‎src/core/qgsmaplayerregistry.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ void QgsMapLayerRegistry::removeAllMapLayers()
118118

119119
} // QgsMapLayerRegistry::removeAllMapLayers()
120120

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

122132
QMap<QString, QgsMapLayer*> & QgsMapLayerRegistry::mapLayers()
123133
{

‎src/core/qgsmaplayerregistry.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ class CORE_EXPORT QgsMapLayerRegistry : public QObject
8282
*/
8383
void removeAllMapLayers();
8484

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

8794
/** emitted when a layer is removed from the registry

0 commit comments

Comments
 (0)