Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix some leaks in symbology widgets
  • Loading branch information
nyalldawson committed Sep 1, 2015
1 parent e602a58 commit d7ab102
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 10 deletions.
13 changes: 10 additions & 3 deletions python/core/symbology-ng/qgscategorizedsymbolrendererv2.sip
Expand Up @@ -113,15 +113,22 @@ class QgsCategorizedSymbolRendererV2 : QgsFeatureRendererV2
void setSourceSymbol( QgsSymbolV2* sym /Transfer/ );

QgsVectorColorRampV2* sourceColorRamp();

/** Sets the source color ramp.
* @param ramp color ramp. Ownership is transferred to the renderer
*/
void setSourceColorRamp( QgsVectorColorRampV2* ramp /Transfer/ );

//! @note added in 2.1
bool invertedColorRamp();
void setInvertedColorRamp( bool inverted );

// Update the color ramp used and all symbols colors.
//! @note added in 2.5
void updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted = false );
/** Update the color ramp used and all symbols colors.
* @param ramp color ramp. Ownership is transferred to the renderer
* @param inverted set to true to invert ramp colors
* @note added in 2.5
*/
void updateColorRamp( QgsVectorColorRampV2* ramp /Transfer/, bool inverted = false );

void setRotationField( QString fieldOrExpression ) /Deprecated/;
QString rotationField() const /Deprecated/;
Expand Down
7 changes: 7 additions & 0 deletions python/core/symbology-ng/qgsgraduatedsymbolrendererv2.sip
Expand Up @@ -213,13 +213,20 @@ class QgsGraduatedSymbolRendererV2 : QgsFeatureRendererV2
void setSourceSymbol( QgsSymbolV2* sym /Transfer/ );

QgsVectorColorRampV2* sourceColorRamp();

/** Sets the source color ramp.
* @param ramp color ramp. Ownership is transferred to the renderer
*/
void setSourceColorRamp( QgsVectorColorRampV2* ramp /Transfer/ );

//! @note added in 2.1
bool invertedColorRamp();
void setInvertedColorRamp( bool inverted );

/** Update the color ramp used. Also updates all symbols colors.
* Doesn't alter current breaks.
* @param ramp color ramp. Ownership is transferred to the renderer
* @param inverted set to true to invert ramp colors
*/
void updateColorRamp( QgsVectorColorRampV2* ramp /Transfer/ = 0, bool inverted = false );

Expand Down
11 changes: 9 additions & 2 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
Expand Up @@ -146,14 +146,21 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2
void setSourceSymbol( QgsSymbolV2* sym );

QgsVectorColorRampV2* sourceColorRamp();

/** Sets the source color ramp.
* @param ramp color ramp. Ownership is transferred to the renderer
*/
void setSourceColorRamp( QgsVectorColorRampV2* ramp );

//! @note added in 2.1
bool invertedColorRamp() { return mInvertedColorRamp; }
void setInvertedColorRamp( bool inverted ) { mInvertedColorRamp = inverted; }

// Update the color ramp used and all symbols colors.
//! @note added in 2.5
/** Update the color ramp used and all symbols colors.
* @param ramp color ramp. Ownership is transferred to the renderer
* @param inverted set to true to invert ramp colors
* @note added in 2.5
*/
void updateColorRamp( QgsVectorColorRampV2* ramp, bool inverted = false );

Q_DECL_DEPRECATED void setRotationField( QString fieldOrExpression ) override;
Expand Down
7 changes: 7 additions & 0 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
Expand Up @@ -259,13 +259,20 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
void setSourceSymbol( QgsSymbolV2* sym );

QgsVectorColorRampV2* sourceColorRamp();

/** Sets the source color ramp.
* @param ramp color ramp. Ownership is transferred to the renderer
*/
void setSourceColorRamp( QgsVectorColorRampV2* ramp );

//! @note added in 2.1
bool invertedColorRamp() { return mInvertedColorRamp; }
void setInvertedColorRamp( bool inverted ) { mInvertedColorRamp = inverted; }

/** Update the color ramp used. Also updates all symbols colors.
* Doesn't alter current breaks.
* @param ramp color ramp. Ownership is transferred to the renderer
* @param inverted set to true to invert ramp colors
*/
void updateColorRamp( QgsVectorColorRampV2* ramp = 0, bool inverted = false );

Expand Down
Expand Up @@ -472,6 +472,7 @@ QgsCategorizedSymbolRendererV2Widget::~QgsCategorizedSymbolRendererV2Widget()
{
if ( mRenderer ) delete mRenderer;
if ( mModel ) delete mModel;
delete mCategorizedSymbol;
}

void QgsCategorizedSymbolRendererV2Widget::updateUiFromRenderer()
Expand Down Expand Up @@ -557,6 +558,7 @@ void QgsCategorizedSymbolRendererV2Widget::changeCategorizedSymbol()
return;
}

delete mCategorizedSymbol;
mCategorizedSymbol = newSymbol;
updateCategorizedSymbolIcon();

Expand Down Expand Up @@ -781,14 +783,15 @@ void QgsCategorizedSymbolRendererV2Widget::addCategories()
delete mRenderer;
mRenderer = r;
if ( ! keepExistingColors && ramp ) applyColorRamp();
delete ramp;
}

void QgsCategorizedSymbolRendererV2Widget::applyColorRamp()
{
QgsVectorColorRampV2* ramp = getColorRamp();
if ( ramp )
{
mRenderer->updateColorRamp( ramp->clone(), cbxInvertedColorRamp->isChecked() );
mRenderer->updateColorRamp( ramp, cbxInvertedColorRamp->isChecked() );
}
mModel->updateSymbology();
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgscolorrampcombobox.cpp
Expand Up @@ -87,6 +87,7 @@ bool QgsColorRampComboBox::createNewColorRampSelected() const

void QgsColorRampComboBox::setSourceColorRamp( QgsVectorColorRampV2* sourceRamp )
{
delete mSourceColorRamp;
mSourceColorRamp = sourceRamp->clone();

QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( mSourceColorRamp, rampIconSize );
Expand Down
6 changes: 4 additions & 2 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
Expand Up @@ -503,6 +503,7 @@ QgsGraduatedSymbolRendererV2Widget::~QgsGraduatedSymbolRendererV2Widget()
{
delete mRenderer;
delete mModel;
delete mGraduatedSymbol;
}

QgsFeatureRendererV2* QgsGraduatedSymbolRendererV2Widget::renderer()
Expand Down Expand Up @@ -645,7 +646,7 @@ void QgsGraduatedSymbolRendererV2Widget::on_methodComboBox_currentIndexChanged(
QMessageBox::critical( this, tr( "Error" ), tr( "The selected color ramp is not available." ) );
return;
}
mRenderer->setSourceColorRamp( ramp->clone() );
mRenderer->setSourceColorRamp( ramp );
reapplyColorRamp();
}
else
Expand Down Expand Up @@ -716,7 +717,7 @@ void QgsGraduatedSymbolRendererV2Widget::classifyGraduated()
QMessageBox::critical( this, tr( "Error" ), tr( "The selected color ramp is not available." ) );
return;
}
mRenderer->setSourceColorRamp( ramp->clone() );
mRenderer->setSourceColorRamp( ramp );
}
else
{
Expand Down Expand Up @@ -775,6 +776,7 @@ void QgsGraduatedSymbolRendererV2Widget::changeGraduatedSymbol()
return;
}

delete mGraduatedSymbol;
mGraduatedSymbol = newSymbol;

mSizeUnitWidget->blockSignals( true );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/symbology-ng/qgssymbolv2selectordialog.cpp
Expand Up @@ -231,7 +231,7 @@ QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsSt
btnUp->setIcon( QIcon( QgsApplication::iconPath( "symbologyUp.svg" ) ) );
btnDown->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.svg" ) ) );

model = new QStandardItemModel();
model = new QStandardItemModel( layersTree );
// Set the symbol
layersTree->setModel( model );
layersTree->setHeaderHidden( true );
Expand Down Expand Up @@ -273,7 +273,7 @@ QMenu* QgsSymbolV2SelectorDialog::advancedMenu()
{
if ( mAdvancedMenu == NULL )
{
mAdvancedMenu = new QMenu;
mAdvancedMenu = new QMenu( this );
// Brute force method to activate the Advanced menu
layerChanged();
}
Expand Down

0 comments on commit d7ab102

Please sign in to comment.