Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-3_38] Fix crash when extracting symbols from project with layout legend #58214

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Returns whether the legend should automatically resize to fit its contents.
Returns the legend model.
%End


void setAutoUpdateModel( bool autoUpdate );
%Docstring
Sets whether the legend content should auto update to reflect changes in the project's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Returns whether the legend should automatically resize to fit its contents.
Returns the legend model.
%End


void setAutoUpdateModel( bool autoUpdate );
%Docstring
Sets whether the legend content should auto update to reflect changes in the project's
Expand Down
15 changes: 11 additions & 4 deletions src/core/layout/qgslayoutitemlegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,13 @@ void QgsLayoutItemLegend::setCustomLayerTree( QgsLayerTree *rootGroup )
mCustomLayerTree.reset( rootGroup );
}

void QgsLayoutItemLegend::ensureModelIsInitialized()
void QgsLayoutItemLegend::ensureModelIsInitialized() const
{
if ( mDeferLegendModelInitialization )
{
mDeferLegendModelInitialization = false;
setCustomLayerTree( mCustomLayerTree.release() );
QgsLayoutItemLegend *mutableThis = const_cast< QgsLayoutItemLegend * >( this );
mutableThis->mDeferLegendModelInitialization = false;
mutableThis->setCustomLayerTree( mutableThis->mCustomLayerTree.release() );
}
}

Expand All @@ -334,6 +335,12 @@ QgsLegendModel *QgsLayoutItemLegend::model()
return mLegendModel.get();
}

const QgsLegendModel *QgsLayoutItemLegend::model() const
{
ensureModelIsInitialized();
return mLegendModel.get();
}

void QgsLayoutItemLegend::setAutoUpdateModel( bool autoUpdate )
{
if ( autoUpdate == autoUpdateModel() )
Expand Down Expand Up @@ -1345,7 +1352,7 @@ bool QgsLayoutItemLegend::accept( QgsStyleEntityVisitorInterface *visitor ) cons
}
return true;
};
return visit( mLegendModel->rootGroup( ) );
return visit( model()->rootGroup( ) );
}

bool QgsLayoutItemLegend::isRefreshing() const
Expand Down
9 changes: 8 additions & 1 deletion src/core/layout/qgslayoutitemlegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ class CORE_EXPORT QgsLayoutItemLegend : public QgsLayoutItem
*/
QgsLegendModel *model();

/**
* Returns the legend model.
*
* \note Not available in Python bindings
*/
const QgsLegendModel *model() const SIP_SKIP;

/**
* Sets whether the legend content should auto update to reflect changes in the project's
* layer tree.
Expand Down Expand Up @@ -634,7 +641,7 @@ class CORE_EXPORT QgsLayoutItemLegend : public QgsLayoutItem

void setModelStyleOverrides( const QMap<QString, QString> &overrides );

void ensureModelIsInitialized();
void ensureModelIsInitialized() const;
std::unique_ptr< QgsLegendModel > mLegendModel;
std::unique_ptr< QgsLayerTree > mCustomLayerTree;
bool mDeferLegendModelInitialization = true;
Expand Down
Loading