Skip to content

Commit 6b4451d

Browse files
committed
Fix crash in graduated symbol renderer widget
Caused by 75c8e3e -- the previous code was relying on the leak to reference processing parameter owned by the leaked object Fixes #60865
1 parent b3cdf9e commit 6b4451d

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp

+11-15
Original file line numberDiff line numberDiff line change
@@ -877,26 +877,26 @@ void QgsGraduatedSymbolRendererWidget::updateMethodParameters()
877877
clearParameterWidgets();
878878

879879
const QString methodId = cboGraduatedMode->currentData().toString();
880-
std::unique_ptr< QgsClassificationMethod > method = QgsApplication::classificationMethodRegistry()->method( methodId );
881-
Q_ASSERT( method );
880+
mClassificationMethod = QgsApplication::classificationMethodRegistry()->method( methodId );
881+
Q_ASSERT( mClassificationMethod.get() );
882882

883883
// need more context?
884884
QgsProcessingContext context;
885885

886-
for ( const QgsProcessingParameterDefinition *def : method->parameterDefinitions() )
886+
for ( const QgsProcessingParameterDefinition *def : mClassificationMethod->parameterDefinitions() )
887887
{
888888
QgsAbstractProcessingParameterWidgetWrapper *ppww = QgsGui::processingGuiRegistry()->createParameterWidgetWrapper( def, QgsProcessingGui::Standard );
889889
mParametersLayout->addRow( ppww->createWrappedLabel(), ppww->createWrappedWidget( context ) );
890890

891-
QVariant value = method->parameterValues().value( def->name(), def->defaultValueForGui() );
891+
QVariant value = mClassificationMethod->parameterValues().value( def->name(), def->defaultValueForGui() );
892892
ppww->setParameterValue( value, context );
893893

894894
connect( ppww, &QgsAbstractProcessingParameterWidgetWrapper::widgetValueHasChanged, this, &QgsGraduatedSymbolRendererWidget::classifyGraduated );
895895

896896
mParameterWidgetWrappers.push_back( std::unique_ptr<QgsAbstractProcessingParameterWidgetWrapper>( ppww ) );
897897
}
898898

899-
spinGraduatedClasses->setEnabled( !( method->flags() & QgsClassificationMethod::MethodProperty::IgnoresClassCount ) );
899+
spinGraduatedClasses->setEnabled( !( mClassificationMethod->flags() & QgsClassificationMethod::MethodProperty::IgnoresClassCount ) );
900900
}
901901

902902
void QgsGraduatedSymbolRendererWidget::toggleMethodWidgets( MethodMode mode )
@@ -1041,17 +1041,13 @@ void QgsGraduatedSymbolRendererWidget::classifyGraduated()
10411041

10421042
void QgsGraduatedSymbolRendererWidget::classifyGraduatedImpl()
10431043
{
1044-
if ( mBlockUpdates )
1044+
if ( mBlockUpdates || !mClassificationMethod )
10451045
return;
10461046

10471047
QgsTemporaryCursorOverride override( Qt::WaitCursor );
10481048
QString attrName = mExpressionWidget->currentField();
10491049
int nclasses = spinGraduatedClasses->value();
10501050

1051-
const QString methodId = cboGraduatedMode->currentData().toString();
1052-
std::unique_ptr< QgsClassificationMethod > method = QgsApplication::classificationMethodRegistry()->method( methodId );
1053-
Q_ASSERT( method );
1054-
10551051
int attrNum = mLayer->fields().lookupField( attrName );
10561052

10571053
QVariant minVal;
@@ -1064,29 +1060,29 @@ void QgsGraduatedSymbolRendererWidget::classifyGraduatedImpl()
10641060
mSymmetryPointValidator->setTop( maximum );
10651061
mSymmetryPointValidator->setMaxDecimals( spinPrecision->value() );
10661062

1067-
if ( method->id() == QgsClassificationEqualInterval::METHOD_ID || method->id() == QgsClassificationStandardDeviation::METHOD_ID )
1063+
if ( mClassificationMethod->id() == QgsClassificationEqualInterval::METHOD_ID || mClassificationMethod->id() == QgsClassificationStandardDeviation::METHOD_ID )
10681064
{
10691065
// knowing that spinSymmetryPointForOtherMethods->value() is automatically put at minimum when out of min-max
10701066
// using "(maximum-minimum)/100)" to avoid direct comparison of doubles
10711067
double currentValue = QgsDoubleValidator::toDouble( cboSymmetryPoint->currentText() );
10721068
if ( currentValue < ( minimum + ( maximum - minimum ) / 100. ) || currentValue > ( maximum - ( maximum - minimum ) / 100. ) )
1073-
cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QLocale().toString( minimum + ( maximum - minimum ) / 2., 'f', method->labelPrecision() + 2 ) );
1069+
cboSymmetryPoint->setItemText( cboSymmetryPoint->currentIndex(), QLocale().toString( minimum + ( maximum - minimum ) / 2., 'f', mClassificationMethod->labelPrecision() + 2 ) );
10741070
}
10751071

10761072
if ( mGroupBoxSymmetric->isChecked() )
10771073
{
10781074
double symmetryPoint = QgsDoubleValidator::toDouble( cboSymmetryPoint->currentText() );
10791075
bool astride = cbxAstride->isChecked();
1080-
method->setSymmetricMode( true, symmetryPoint, astride );
1076+
mClassificationMethod->setSymmetricMode( true, symmetryPoint, astride );
10811077
}
10821078

10831079
QVariantMap parameterValues;
10841080
for ( const auto &ppww : std::as_const( mParameterWidgetWrappers ) )
10851081
parameterValues.insert( ppww->parameterDefinition()->name(), ppww->parameterValue() );
1086-
method->setParameterValues( parameterValues );
1082+
mClassificationMethod->setParameterValues( parameterValues );
10871083

10881084
// set method to renderer
1089-
mRenderer->setClassificationMethod( method.release() );
1085+
mRenderer->setClassificationMethod( mClassificationMethod->clone().release() );
10901086

10911087
// create and set new renderer
10921088
mRenderer->setClassAttribute( attrName );

src/gui/symbology/qgsgraduatedsymbolrendererwidget.h

+2
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ class GUI_EXPORT QgsGraduatedSymbolRendererWidget : public QgsRendererWidget, pr
203203

204204
QgsDoubleValidator *mSymmetryPointValidator = nullptr;
205205
QAction *mActionLevels = nullptr;
206+
207+
std::unique_ptr< QgsClassificationMethod > mClassificationMethod;
206208
std::vector<std::unique_ptr<QgsAbstractProcessingParameterWidgetWrapper>> mParameterWidgetWrappers;
207209

208210
int mBlockUpdates = 0;

0 commit comments

Comments
 (0)