Skip to content
Permalink
Browse files
Fix memory leaks in renderer widgets
  • Loading branch information
nyalldawson committed May 26, 2021
1 parent 7a8f35f commit f7f43e08c64ab0fdfb7884cefb1be8b260adcf55
Showing with 55 additions and 45 deletions.
  1. +1 −0 python/gui/auto_generated/symbology/qgs25drendererwidget.sip.in
  2. +1 −0 python/gui/auto_generated/symbology/qgsembeddedsymbolrendererwidget.sip.in
  3. +1 −0 python/gui/auto_generated/symbology/qgsheatmaprendererwidget.sip.in
  4. +1 −0 python/gui/auto_generated/symbology/qgsinvertedpolygonrendererwidget.sip.in
  5. +1 −0 python/gui/auto_generated/symbology/qgsmergedfeaturerendererwidget.sip.in
  6. +5 −2 src/gui/symbology/qgs25drendererwidget.cpp
  7. +2 −1 src/gui/symbology/qgs25drendererwidget.h
  8. +2 −0 src/gui/symbology/qgsembeddedsymbolrendererwidget.cpp
  9. +2 −1 src/gui/symbology/qgsembeddedsymbolrendererwidget.h
  10. +1 −1 src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp
  11. +1 −1 src/gui/symbology/qgsgraduatedsymbolrendererwidget.h
  12. +5 −3 src/gui/symbology/qgsheatmaprendererwidget.cpp
  13. +2 −1 src/gui/symbology/qgsheatmaprendererwidget.h
  14. +2 −0 src/gui/symbology/qgsinvertedpolygonrendererwidget.cpp
  15. +2 −1 src/gui/symbology/qgsinvertedpolygonrendererwidget.h
  16. +2 −0 src/gui/symbology/qgsmergedfeaturerendererwidget.cpp
  17. +2 −1 src/gui/symbology/qgsmergedfeaturerendererwidget.h
  18. +4 −8 src/gui/symbology/qgsnullsymbolrendererwidget.cpp
  19. +1 −1 src/gui/symbology/qgsnullsymbolrendererwidget.h
  20. +4 −7 src/gui/symbology/qgspointclusterrendererwidget.cpp
  21. +1 −1 src/gui/symbology/qgspointclusterrendererwidget.h
  22. +4 −7 src/gui/symbology/qgspointdisplacementrendererwidget.cpp
  23. +1 −1 src/gui/symbology/qgspointdisplacementrendererwidget.h
  24. +6 −7 src/gui/symbology/qgsrulebasedrendererwidget.cpp
  25. +1 −1 src/gui/symbology/qgsrulebasedrendererwidget.h
@@ -33,6 +33,7 @@ Constructor
:param style:
:param renderer: the mask renderer (will not take ownership)
%End
~Qgs25DRendererWidget();

virtual QgsFeatureRenderer *renderer();

@@ -38,6 +38,7 @@ Constructor
:param style:
:param renderer: the merged feature renderer (will not take ownership)
%End
~QgsEmbeddedSymbolRendererWidget();

virtual QgsFeatureRenderer *renderer();

@@ -33,6 +33,7 @@ Constructor
:param style:
:param renderer: the mask renderer (will not take ownership)
%End
~QgsHeatmapRendererWidget();

virtual QgsFeatureRenderer *renderer();

@@ -38,6 +38,7 @@ Constructor
:param style:
:param renderer: the mask renderer (will not take ownership)
%End
~QgsInvertedPolygonRendererWidget();

virtual QgsFeatureRenderer *renderer();

@@ -38,6 +38,7 @@ Constructor
:param style:
:param renderer: the merged feature renderer (will not take ownership)
%End
~QgsMergedFeatureRendererWidget();

virtual QgsFeatureRenderer *renderer();

@@ -18,6 +18,7 @@
#include "qgsvectorlayer.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsexpressioncontextutils.h"
#include "qgssymbol.h"

Qgs25DRendererWidget::Qgs25DRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer )
: QgsRendererWidget( layer, style )
@@ -54,7 +55,7 @@ Qgs25DRendererWidget::Qgs25DRendererWidget( QgsVectorLayer *layer, QgsStyle *sty

if ( renderer )
{
mRenderer = Qgs25DRenderer::convertFromRenderer( renderer );
mRenderer.reset( Qgs25DRenderer::convertFromRenderer( renderer ) );
}

mHeightWidget->setLayer( layer );
@@ -85,9 +86,11 @@ Qgs25DRendererWidget::Qgs25DRendererWidget( QgsVectorLayer *layer, QgsStyle *sty
connect( mWallExpositionShading, &QAbstractButton::toggled, this, &Qgs25DRendererWidget::updateRenderer );
}

Qgs25DRendererWidget::~Qgs25DRendererWidget() = default;

QgsFeatureRenderer *Qgs25DRendererWidget::renderer()
{
return mRenderer;
return mRenderer.get();
}

void Qgs25DRendererWidget::updateRenderer()
@@ -48,6 +48,7 @@ class GUI_EXPORT Qgs25DRendererWidget : public QgsRendererWidget, protected Ui::
* \param renderer the mask renderer (will not take ownership)
*/
Qgs25DRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer SIP_TRANSFER );
~Qgs25DRendererWidget() override;

QgsFeatureRenderer *renderer() override;

@@ -57,7 +58,7 @@ class GUI_EXPORT Qgs25DRendererWidget : public QgsRendererWidget, protected Ui::
private:
void apply() override SIP_FORCE;

Qgs25DRenderer *mRenderer = nullptr;
std::unique_ptr< Qgs25DRenderer > mRenderer;

friend class QgsAppScreenShots;
};
@@ -79,6 +79,8 @@ QgsEmbeddedSymbolRendererWidget::QgsEmbeddedSymbolRendererWidget( QgsVectorLayer
} );
}

QgsEmbeddedSymbolRendererWidget::~QgsEmbeddedSymbolRendererWidget() = default;

QgsFeatureRenderer *QgsEmbeddedSymbolRendererWidget::renderer()
{
return mRenderer.get();
@@ -17,11 +17,11 @@

#include "ui_qgsembeddedsymbolrendererwidgetbase.h"
#include "qgis_sip.h"
#include "qgsembeddedsymbolrenderer.h"
#include "qgsrendererwidget.h"
#include "qgis_gui.h"

class QMenu;
class QgsEmbeddedSymbolRenderer;

/**
* \ingroup gui
@@ -50,6 +50,7 @@ class GUI_EXPORT QgsEmbeddedSymbolRendererWidget : public QgsRendererWidget, pub
* \param renderer the merged feature renderer (will not take ownership)
*/
QgsEmbeddedSymbolRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer );
~QgsEmbeddedSymbolRendererWidget() override;

QgsFeatureRenderer *renderer() override;
void setContext( const QgsSymbolWidgetContext &context ) override;
@@ -464,7 +464,7 @@ QgsGraduatedSymbolRendererWidget::QgsGraduatedSymbolRendererWidget( QgsVectorLay
// setup user interface
setupUi( this );

mSymmetryPointValidator = new QDoubleValidator();
mSymmetryPointValidator = new QDoubleValidator( this );
cboSymmetryPoint->setEditable( true );
cboSymmetryPoint->setValidator( mSymmetryPointValidator );

@@ -196,7 +196,7 @@ class GUI_EXPORT QgsGraduatedSymbolRendererWidget : public QgsRendererWidget, pr

QgsRangeList mCopyBuffer;

QDoubleValidator *mSymmetryPointValidator;
QDoubleValidator *mSymmetryPointValidator = nullptr;

std::vector< std::unique_ptr< QgsAbstractProcessingParameterWidgetWrapper >> mParameterWidgetWrappers;
};
@@ -105,11 +105,11 @@ QgsHeatmapRendererWidget::QgsHeatmapRendererWidget( QgsVectorLayer *layer, QgsSt

if ( renderer )
{
mRenderer = QgsHeatmapRenderer::convertFromRenderer( renderer );
mRenderer.reset( QgsHeatmapRenderer::convertFromRenderer( renderer ) );
}
if ( !mRenderer )
{
mRenderer = new QgsHeatmapRenderer();
mRenderer = std::make_unique< QgsHeatmapRenderer >();
}

btnColorRamp->setShowGradientOnly( true );
@@ -141,9 +141,11 @@ QgsHeatmapRendererWidget::QgsHeatmapRendererWidget( QgsVectorLayer *layer, QgsSt
connect( mWeightExpressionWidget, static_cast < void ( QgsFieldExpressionWidget::* )( const QString & ) >( &QgsFieldExpressionWidget::fieldChanged ), this, &QgsHeatmapRendererWidget::weightExpressionChanged );
}

QgsHeatmapRendererWidget::~QgsHeatmapRendererWidget() = default;

QgsFeatureRenderer *QgsHeatmapRendererWidget::renderer()
{
return mRenderer;
return mRenderer.get();
}

void QgsHeatmapRendererWidget::setContext( const QgsSymbolWidgetContext &context )
@@ -48,12 +48,13 @@ class GUI_EXPORT QgsHeatmapRendererWidget : public QgsRendererWidget, private Ui
* \param renderer the mask renderer (will not take ownership)
*/
QgsHeatmapRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer );
~QgsHeatmapRendererWidget() override;

QgsFeatureRenderer *renderer() override;
void setContext( const QgsSymbolWidgetContext &context ) override;

private:
QgsHeatmapRenderer *mRenderer = nullptr;
std::unique_ptr< QgsHeatmapRenderer > mRenderer;

QgsExpressionContext createExpressionContext() const override;

@@ -100,6 +100,8 @@ QgsInvertedPolygonRendererWidget::QgsInvertedPolygonRendererWidget( QgsVectorLay
}
}

QgsInvertedPolygonRendererWidget::~QgsInvertedPolygonRendererWidget() = default;

QgsFeatureRenderer *QgsInvertedPolygonRendererWidget::renderer()
{
if ( mRenderer && mEmbeddedRendererWidget )
@@ -17,11 +17,11 @@

#include "ui_qgsinvertedpolygonrendererwidgetbase.h"
#include "qgis_sip.h"
#include "qgsinvertedpolygonrenderer.h"
#include "qgsrendererwidget.h"
#include "qgis_gui.h"

class QMenu;
class QgsInvertedPolygonRenderer;

/**
* \ingroup gui
@@ -50,6 +50,7 @@ class GUI_EXPORT QgsInvertedPolygonRendererWidget : public QgsRendererWidget, pr
* \param renderer the mask renderer (will not take ownership)
*/
QgsInvertedPolygonRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer );
~QgsInvertedPolygonRendererWidget() override;

QgsFeatureRenderer *renderer() override;

@@ -97,6 +97,8 @@ QgsMergedFeatureRendererWidget::QgsMergedFeatureRendererWidget( QgsVectorLayer *
}
}

QgsMergedFeatureRendererWidget::~QgsMergedFeatureRendererWidget() = default;

QgsFeatureRenderer *QgsMergedFeatureRendererWidget::renderer()
{
if ( mRenderer && mEmbeddedRendererWidget )
@@ -17,11 +17,11 @@

#include "ui_qgsmergedfeaturerendererwidgetbase.h"
#include "qgis_sip.h"
#include "qgsmergedfeaturerenderer.h"
#include "qgsrendererwidget.h"
#include "qgis_gui.h"

class QMenu;
class QgsMergedFeatureRenderer;

/**
* \ingroup gui
@@ -50,6 +50,7 @@ class GUI_EXPORT QgsMergedFeatureRendererWidget : public QgsRendererWidget, priv
* \param renderer the merged feature renderer (will not take ownership)
*/
QgsMergedFeatureRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer );
~QgsMergedFeatureRendererWidget() override;

QgsFeatureRenderer *renderer() override;
void setContext( const QgsSymbolWidgetContext &context ) override;
@@ -26,28 +26,24 @@ QgsRendererWidget *QgsNullSymbolRendererWidget::create( QgsVectorLayer *layer, Q

QgsNullSymbolRendererWidget::QgsNullSymbolRendererWidget( QgsVectorLayer *layer, QgsStyle *style, QgsFeatureRenderer *renderer )
: QgsRendererWidget( layer, style )

{
if ( renderer )
{
mRenderer = QgsNullSymbolRenderer::convertFromRenderer( renderer );
mRenderer.reset( QgsNullSymbolRenderer::convertFromRenderer( renderer ) );
}
if ( !mRenderer )
{
mRenderer = new QgsNullSymbolRenderer();
mRenderer = std::make_unique< QgsNullSymbolRenderer >();
}

QGridLayout *layout = new QGridLayout( this );
QLabel *label = new QLabel( tr( "No symbols will be rendered for features in this layer." ) );
layout->addWidget( label );
}

QgsNullSymbolRendererWidget::~QgsNullSymbolRendererWidget()
{
delete mRenderer;
}
QgsNullSymbolRendererWidget::~QgsNullSymbolRendererWidget() = default;

QgsFeatureRenderer *QgsNullSymbolRendererWidget::renderer()
{
return mRenderer;
return mRenderer.get();
}
@@ -49,7 +49,7 @@ class GUI_EXPORT QgsNullSymbolRendererWidget : public QgsRendererWidget
protected:

//! Renderer being configured by the widget
QgsNullSymbolRenderer *mRenderer = nullptr;
std::unique_ptr< QgsNullSymbolRenderer > mRenderer;

};

@@ -63,11 +63,11 @@ QgsPointClusterRendererWidget::QgsPointClusterRendererWidget( QgsVectorLayer *la

if ( renderer )
{
mRenderer = QgsPointClusterRenderer::convertFromRenderer( renderer );
mRenderer.reset( QgsPointClusterRenderer::convertFromRenderer( renderer ) );
}
if ( !mRenderer )
{
mRenderer = new QgsPointClusterRenderer();
mRenderer = std::make_unique< QgsPointClusterRenderer >();
}

blockAllSignals( true );
@@ -109,14 +109,11 @@ QgsPointClusterRendererWidget::QgsPointClusterRendererWidget( QgsVectorLayer *la
mCenterSymbolToolButton->registerExpressionContextGenerator( this );
}

QgsPointClusterRendererWidget::~QgsPointClusterRendererWidget()
{
delete mRenderer;
}
QgsPointClusterRendererWidget::~QgsPointClusterRendererWidget() = default;

QgsFeatureRenderer *QgsPointClusterRendererWidget::renderer()
{
return mRenderer;
return mRenderer.get();
}

void QgsPointClusterRendererWidget::setContext( const QgsSymbolWidgetContext &context )
@@ -64,7 +64,7 @@ class GUI_EXPORT QgsPointClusterRendererWidget: public QgsRendererWidget, public
QgsExpressionContext createExpressionContext() const override;

private:
QgsPointClusterRenderer *mRenderer = nullptr;
std::unique_ptr< QgsPointClusterRenderer > mRenderer;

void blockAllSignals( bool block );
void setupBlankUi( const QString &layerName );
@@ -71,11 +71,11 @@ QgsPointDisplacementRendererWidget::QgsPointDisplacementRendererWidget( QgsVecto

if ( renderer )
{
mRenderer = QgsPointDisplacementRenderer::convertFromRenderer( renderer );
mRenderer.reset( QgsPointDisplacementRenderer::convertFromRenderer( renderer ) );
}
if ( !mRenderer )
{
mRenderer = new QgsPointDisplacementRenderer();
mRenderer = std::make_unique< QgsPointDisplacementRenderer >();
}

blockAllSignals( true );
@@ -176,14 +176,11 @@ QgsPointDisplacementRendererWidget::QgsPointDisplacementRendererWidget( QgsVecto
mCenterSymbolToolButton->registerExpressionContextGenerator( this );
}

QgsPointDisplacementRendererWidget::~QgsPointDisplacementRendererWidget()
{
delete mRenderer;
}
QgsPointDisplacementRendererWidget::~QgsPointDisplacementRendererWidget() = default;

QgsFeatureRenderer *QgsPointDisplacementRendererWidget::renderer()
{
return mRenderer;
return mRenderer.get();
}

void QgsPointDisplacementRendererWidget::setContext( const QgsSymbolWidgetContext &context )
@@ -44,7 +44,7 @@ class GUI_EXPORT QgsPointDisplacementRendererWidget: public QgsRendererWidget, p
QgsExpressionContext createExpressionContext() const override;

private:
QgsPointDisplacementRenderer *mRenderer = nullptr;
std::unique_ptr< QgsPointDisplacementRenderer > mRenderer;

void blockAllSignals( bool block );
void setupBlankUi( const QString &layerName );

0 comments on commit f7f43e0

Please sign in to comment.