From 948c9641d378dd9750150b7ec70281627a7bf310 Mon Sep 17 00:00:00 2001 From: nirvn Date: Wed, 14 Aug 2019 08:13:43 +0000 Subject: [PATCH] [layout] Fix crash an attribute table item tries to access a destroyed map --- .../layout/qgslayoutitemattributetable.cpp | 21 +++++++++++++------ src/core/layout/qgslayoutitemattributetable.h | 4 ++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/core/layout/qgslayoutitemattributetable.cpp b/src/core/layout/qgslayoutitemattributetable.cpp index b4bc414fffd5..f26c500199fe 100644 --- a/src/core/layout/qgslayoutitemattributetable.cpp +++ b/src/core/layout/qgslayoutitemattributetable.cpp @@ -224,6 +224,19 @@ void QgsLayoutItemAttributeTable::resetColumns() } } +void QgsLayoutItemAttributeTable::disconnectCurrentMap() +{ + if ( !mMap ) + { + return; + } + + disconnect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutTable::refreshAttributes ); + disconnect( mMap, &QgsLayoutItemMap::mapRotationChanged, this, &QgsLayoutTable::refreshAttributes ); + disconnect( mMap, &QObject::destroyed, this, &QgsLayoutItemAttributeTable::disconnectCurrentMap ); + mMap = nullptr; +} + void QgsLayoutItemAttributeTable::setMap( QgsLayoutItemMap *map ) { if ( map == mMap ) @@ -231,19 +244,15 @@ void QgsLayoutItemAttributeTable::setMap( QgsLayoutItemMap *map ) //no change return; } + disconnectCurrentMap(); - if ( mMap ) - { - //disconnect from previous map - disconnect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutTable::refreshAttributes ); - disconnect( mMap, &QgsLayoutItemMap::mapRotationChanged, this, &QgsLayoutTable::refreshAttributes ); - } mMap = map; if ( mMap ) { //listen out for extent changes in linked map connect( mMap, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutTable::refreshAttributes ); connect( mMap, &QgsLayoutItemMap::mapRotationChanged, this, &QgsLayoutTable::refreshAttributes ); + connect( mMap, &QObject::destroyed, this, &QgsLayoutItemAttributeTable::disconnectCurrentMap ); } refreshAttributes(); emit changed(); diff --git a/src/core/layout/qgslayoutitemattributetable.h b/src/core/layout/qgslayoutitemattributetable.h index 220a075ad307..f6b9bc7cf71d 100644 --- a/src/core/layout/qgslayoutitemattributetable.h +++ b/src/core/layout/qgslayoutitemattributetable.h @@ -299,6 +299,10 @@ class CORE_EXPORT QgsLayoutItemAttributeTable: public QgsLayoutTable bool writePropertiesToElement( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const override; bool readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context ) override; + private slots: + + void disconnectCurrentMap(); + private: //! Attribute source