Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simplify memory management
(cherry picked from commit ec24825)
  • Loading branch information
nyalldawson committed Jan 7, 2020
1 parent 0f7cdac commit a147311
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
30 changes: 8 additions & 22 deletions src/gui/effects/qgseffectstackpropertieswidget.cpp
Expand Up @@ -153,15 +153,11 @@ QgsEffectStackPropertiesWidget::QgsEffectStackPropertiesWidget( QgsEffectStack *
setPanelTitle( tr( "Effects Properties" ) );
}

QgsEffectStackPropertiesWidget::~QgsEffectStackPropertiesWidget()
{
delete mPreviewPicture;
}
QgsEffectStackPropertiesWidget::~QgsEffectStackPropertiesWidget() = default;

void QgsEffectStackPropertiesWidget::setPreviewPicture( const QPicture &picture )
{
delete mPreviewPicture;
mPreviewPicture = new QPicture( picture );
mPreviewPicture = picture;
updatePreview();
}

Expand Down Expand Up @@ -215,7 +211,7 @@ void QgsEffectStackPropertiesWidget::updatePreview()
painter.begin( &previewImage );
painter.setRenderHint( QPainter::Antialiasing );
QgsRenderContext context = QgsRenderContext::fromQPainter( &painter );
if ( !mPreviewPicture )
if ( mPreviewPicture.isNull() )
{
QPicture previewPic;
QPainter previewPicPainter;
Expand All @@ -229,7 +225,7 @@ void QgsEffectStackPropertiesWidget::updatePreview()
else
{
context.painter()->translate( 20, 20 );
mStack->render( *mPreviewPicture, context );
mStack->render( mPreviewPicture, context );
}
painter.end();

Expand Down Expand Up @@ -423,10 +419,7 @@ QgsEffectStackCompactWidget::QgsEffectStackCompactWidget( QWidget *parent, QgsPa
setPaintEffect( effect );
}

QgsEffectStackCompactWidget::~QgsEffectStackCompactWidget()
{
delete mPreviewPicture;
}
QgsEffectStackCompactWidget::~QgsEffectStackCompactWidget() = default;

void QgsEffectStackCompactWidget::setPaintEffect( QgsPaintEffect *effect )
{
Expand Down Expand Up @@ -460,8 +453,7 @@ QgsPaintEffect *QgsEffectStackCompactWidget::paintEffect() const

void QgsEffectStackCompactWidget::setPreviewPicture( const QPicture &picture )
{
delete mPreviewPicture;
mPreviewPicture = new QPicture( picture );
mPreviewPicture = picture;
}

void QgsEffectStackCompactWidget::showDialog()
Expand All @@ -474,10 +466,7 @@ void QgsEffectStackCompactWidget::showDialog()
if ( panel && panel->dockMode() )
{
QgsEffectStackPropertiesWidget *widget = new QgsEffectStackPropertiesWidget( clone, nullptr );
if ( mPreviewPicture )
{
widget->setPreviewPicture( *mPreviewPicture );
}
widget->setPreviewPicture( mPreviewPicture );

connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsEffectStackCompactWidget::updateEffectLive );
connect( widget, &QgsPanelWidget::panelAccepted, this, &QgsEffectStackCompactWidget::updateAcceptWidget );
Expand All @@ -486,10 +475,7 @@ void QgsEffectStackCompactWidget::showDialog()
else
{
QgsEffectStackPropertiesDialog dlg( clone, this );
if ( mPreviewPicture )
{
dlg.setPreviewPicture( *mPreviewPicture );
}
dlg.setPreviewPicture( mPreviewPicture );

if ( dlg.exec() == QDialog::Accepted )
{
Expand Down
5 changes: 3 additions & 2 deletions src/gui/effects/qgseffectstackpropertieswidget.h
Expand Up @@ -21,6 +21,7 @@
#include "qgis.h"
#include <QWidget>
#include <QStandardItemModel>
#include <QPicture>
#include "qgspanelwidget.h"

#include "ui_qgseffectstackpropertieswidgetbase.h"
Expand Down Expand Up @@ -116,7 +117,7 @@ class GUI_EXPORT QgsEffectStackPropertiesWidget : public QgsPanelWidget, private
QgsEffectStack *mStack = nullptr;
QStandardItemModel *mModel = nullptr;
QWidget *mPresentWidget = nullptr;
QPicture *mPreviewPicture = nullptr;
QPicture mPreviewPicture;

/**
* Refreshes the widget to reflect the current state of the stack.
Expand Down Expand Up @@ -272,7 +273,7 @@ class GUI_EXPORT QgsEffectStackCompactWidget: public QgsPanelWidget
QgsEffectStack *mStack = nullptr;
QCheckBox *mEnabledCheckBox = nullptr;
QToolButton *mButton = nullptr;
QPicture *mPreviewPicture = nullptr;
QPicture mPreviewPicture;

};

Expand Down

0 comments on commit a147311

Please sign in to comment.