Skip to content

Commit

Permalink
Fix undefined behavior when closing layout designer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent 779fe1a commit db9db58
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions python/gui/layout/qgslayoutview.sip.in
Expand Up @@ -42,6 +42,8 @@ QgsLayoutView manages the layout interaction tools and mouse/key events.
Constructor for QgsLayoutView.
%End

~QgsLayoutView();

QgsLayout *currentLayout();
%Docstring
Returns the current layout associated with the view.
Expand Down Expand Up @@ -540,6 +542,12 @@ status bar.
%Docstring
Emitted when an ``item`` is "focused" in the view, i.e. it becomes the active
item and should have its properties displayed in any designer windows.
%End

void willBeDeleted();
%Docstring
Emitted in the destructor when the view is about to be deleted,
but is still in a perfectly valid state.
%End

protected:
Expand Down
5 changes: 5 additions & 0 deletions src/gui/layout/qgslayoutview.cpp
Expand Up @@ -68,6 +68,11 @@ QgsLayoutView::QgsLayoutView( QWidget *parent )
connect( this, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutView::invalidateCachedRenders );
}

QgsLayoutView::~QgsLayoutView()
{
emit willBeDeleted();
}

QgsLayout *QgsLayoutView::currentLayout()
{
return qobject_cast<QgsLayout *>( scene() );
Expand Down
8 changes: 8 additions & 0 deletions src/gui/layout/qgslayoutview.h
Expand Up @@ -76,6 +76,8 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
*/
QgsLayoutView( QWidget *parent SIP_TRANSFERTHIS = nullptr );

~QgsLayoutView();

/**
* Returns the current layout associated with the view.
* \see setCurrentLayout()
Expand Down Expand Up @@ -515,6 +517,12 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
*/
void itemFocused( QgsLayoutItem *item );

/**
* Emitted in the destructor when the view is about to be deleted,
* but is still in a perfectly valid state.
*/
void willBeDeleted();

protected:
void mousePressEvent( QMouseEvent *event ) override;
void mouseReleaseEvent( QMouseEvent *event ) override;
Expand Down
5 changes: 4 additions & 1 deletion src/gui/layout/qgslayoutviewtool.cpp
Expand Up @@ -22,7 +22,10 @@ QgsLayoutViewTool::QgsLayoutViewTool( QgsLayoutView *view, const QString &name )
, mView( view )
, mToolName( name )
{

connect( mView, &QgsLayoutView::willBeDeleted, this, [ = ]
{
mView = nullptr;
} );
}

bool QgsLayoutViewTool::isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) const
Expand Down
2 changes: 1 addition & 1 deletion src/gui/layout/qgslayoutviewtool.h
Expand Up @@ -215,7 +215,7 @@ class GUI_EXPORT QgsLayoutViewTool : public QObject
private:

//! Pointer to layout view.
QPointer< QgsLayoutView > mView;
QgsLayoutView *mView = nullptr;

QgsLayoutViewTool::Flags mFlags = nullptr;

Expand Down

0 comments on commit db9db58

Please sign in to comment.