Skip to content
Permalink
Browse files
Fix memory leaks in renderer widgets
(cherry picked from commit 9a9b7ee)
  • Loading branch information
nyalldawson committed Jun 21, 2021
1 parent f5aed6d commit 1161190ad7e9937386a178fb76d75167419fbe7d
@@ -33,6 +33,7 @@ Constructor
:param style:
:param renderer: the mask renderer (will not take ownership)
%End
~Qgs25DRendererWidget();

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

@@ -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;
};
@@ -463,7 +463,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;

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

};

@@ -62,11 +62,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 );
@@ -108,14 +108,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 );
@@ -70,11 +70,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 );
@@ -175,14 +175,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 );
@@ -61,20 +61,20 @@ QgsRuleBasedRendererWidget::QgsRuleBasedRendererWidget( QgsVectorLayer *layer, Q

if ( renderer )
{
mRenderer = QgsRuleBasedRenderer::convertFromRenderer( renderer );
mRenderer.reset( QgsRuleBasedRenderer::convertFromRenderer( renderer ) );
}
if ( !mRenderer )
{
// some default options
QgsSymbol *symbol = QgsSymbol::defaultSymbol( mLayer->geometryType() );

mRenderer = new QgsRuleBasedRenderer( symbol );
mRenderer = qgis::make_unique< QgsRuleBasedRenderer >( symbol );
}

setupUi( this );
this->layout()->setContentsMargins( 0, 0, 0, 0 );

mModel = new QgsRuleBasedRendererModel( mRenderer, viewRules );
mModel = new QgsRuleBasedRendererModel( mRenderer.get(), viewRules );
#ifdef ENABLE_MODELTEST
new ModelTest( mModel, this ); // for model validity checking
#endif
@@ -135,12 +135,11 @@ QgsRuleBasedRendererWidget::QgsRuleBasedRendererWidget( QgsVectorLayer *layer, Q
QgsRuleBasedRendererWidget::~QgsRuleBasedRendererWidget()
{
qDeleteAll( mCopyBuffer );
delete mRenderer;
}

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

void QgsRuleBasedRendererWidget::setDockMode( bool dockMode )
@@ -452,7 +451,7 @@ void QgsRuleBasedRendererWidget::setRenderingOrder()
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsSymbolLevelsWidget *widget = new QgsSymbolLevelsWidget( mRenderer, true, panel );
QgsSymbolLevelsWidget *widget = new QgsSymbolLevelsWidget( mRenderer.get(), true, panel );
widget->setForceOrderingEnabled( true );
widget->setPanelTitle( tr( "Symbol Levels" ) );
connect( widget, &QgsPanelWidget::widgetChanged, this, [ = ]()
@@ -463,7 +462,7 @@ void QgsRuleBasedRendererWidget::setRenderingOrder()
}
else
{
QgsSymbolLevelsDialog dlg( mRenderer, true, panel );
QgsSymbolLevelsDialog dlg( mRenderer.get(), true, panel );
dlg.setForceOrderingEnabled( true );
if ( dlg.exec() )
{
@@ -166,7 +166,7 @@ class GUI_EXPORT QgsRuleBasedRendererWidget : public QgsRendererWidget, private
void refreshSymbolView() override;
void keyPressEvent( QKeyEvent *event ) override;

QgsRuleBasedRenderer *mRenderer = nullptr;
std::unique_ptr< QgsRuleBasedRenderer > mRenderer;
QgsRuleBasedRendererModel *mModel = nullptr;

QMenu *mRefineMenu = nullptr;

0 comments on commit 1161190

Please sign in to comment.