Skip to content

Commit

Permalink
fix #30028 Closing Vertex Edititor crashes the app
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed May 30, 2019
1 parent b31f516 commit ed365cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/app/vertextool/qgsvertextool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ QgsVertexTool::~QgsVertexTool()
delete mVertexBand;
delete mEdgeBand;
delete mEndpointMarker;
delete mVertexEditor;
}

void QgsVertexTool::activate()
Expand Down Expand Up @@ -1391,12 +1392,12 @@ void QgsVertexTool::showVertexEditor() //#spellok
{
if ( !mVertexEditor )
{
mVertexEditor.reset( new QgsVertexEditor( mCanvas ) );
if ( !QgisApp::instance()->restoreDockWidget( mVertexEditor.get() ) )
QgisApp::instance()->addDockWidget( Qt::LeftDockWidgetArea, mVertexEditor.get() );
mVertexEditor = new QgsVertexEditor( mCanvas );
if ( !QgisApp::instance()->restoreDockWidget( mVertexEditor ) )
QgisApp::instance()->addDockWidget( Qt::LeftDockWidgetArea, mVertexEditor );

connect( mVertexEditor.get(), &QgsVertexEditor::deleteSelectedRequested, this, &QgsVertexTool::deleteVertexEditorSelection );
connect( mVertexEditor.get(), &QgsVertexEditor::editorClosed, this, &QgsVertexTool::cleanupVertexEditor );
connect( mVertexEditor, &QgsVertexEditor::deleteSelectedRequested, this, &QgsVertexTool::deleteVertexEditorSelection );
connect( mVertexEditor, &QgsVertexEditor::editorClosed, this, &QgsVertexTool::cleanupVertexEditor );

// timer required as showing/raising the vertex editor in the same function following restoreDockWidget fails
QTimer::singleShot( 200, this, [ = ] { mVertexEditor->show(); mVertexEditor->raise(); } );
Expand All @@ -1411,7 +1412,10 @@ void QgsVertexTool::showVertexEditor() //#spellok
void QgsVertexTool::cleanupVertexEditor()
{
mLockedFeature.reset();
mVertexEditor.reset();
// do not delete immediately because vertex editor
// can be still used in the qt event loop
mVertexEditor->deleteLater();

updateLockedFeatureVertices();
}

Expand Down
4 changes: 3 additions & 1 deletion src/app/vertextool/qgsvertextool.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <memory>

#include <QPointer>

#include "qgis_app.h"
#include "qgsmaptooladvanceddigitizing.h"
#include "qgsgeometry.h"
Expand Down Expand Up @@ -447,7 +449,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
//! Locked feature for the vertex editor
std::unique_ptr<QgsLockedFeature> mLockedFeature;
//! Dock widget which allows editing vertices
std::unique_ptr<QgsVertexEditor> mVertexEditor;
QPointer<QgsVertexEditor> mVertexEditor;

/**
* Data structure that stores alternative features to the currently selected (locked) feature.
Expand Down

0 comments on commit ed365cb

Please sign in to comment.