Skip to content
Permalink
Browse files

Fix undefined behavior when closing layout designer

  • Loading branch information
nyalldawson committed Feb 11, 2018
1 parent 779fe1a commit db9db58e711e0102bff762494a55c752277f4479
@@ -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.
@@ -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:
@@ -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() );
@@ -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()
@@ -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;
@@ -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
@@ -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;

0 comments on commit db9db58

Please sign in to comment.
You can’t perform that action at this time.