Skip to content

Commit

Permalink
[layout] Fix crash an attribute table item tries to access a destroye…
Browse files Browse the repository at this point in the history
…d map
  • Loading branch information
nirvn committed Aug 14, 2019
1 parent d7426b2 commit 21d01b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/core/layout/qgslayoutitemattributetable.cpp
Expand Up @@ -224,26 +224,35 @@ 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 )
{
//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();
Expand Down
4 changes: 4 additions & 0 deletions src/core/layout/qgslayoutitemattributetable.h
Expand Up @@ -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
Expand Down

0 comments on commit 21d01b7

Please sign in to comment.