Skip to content

Commit

Permalink
[Fix] Don't recreate vertex editor each time
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 authored and nyalldawson committed May 28, 2018
1 parent c923d5b commit 614800c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
30 changes: 21 additions & 9 deletions src/app/vertextool/qgsvertexeditor.cpp
Expand Up @@ -277,18 +277,12 @@ QgsVertexEditor::QgsVertexEditor(
QgsVectorLayer *layer,
QgsSelectedFeature *selectedFeature,
QgsMapCanvas *canvas )
: mUpdatingTableSelection( false )
: mCanvas( canvas )
, mUpdatingTableSelection( false )
, mUpdatingVertexSelection( false )
{
setWindowTitle( tr( "Vertex Editor" ) );

mLayer = layer;
mSelectedFeature = selectedFeature;
mCanvas = canvas;

mTableView = new QTableView( this );
mVertexModel = new QgsVertexEditorModel( mLayer, mSelectedFeature, mCanvas, this );
mTableView->setModel( mVertexModel );

mTableView->setSelectionMode( QTableWidget::ExtendedSelection );
mTableView->setSelectionBehavior( QTableWidget::SelectRows );
Expand All @@ -300,8 +294,26 @@ QgsVertexEditor::QgsVertexEditor(

setWidget( mTableView );

connect( mSelectedFeature, &QgsSelectedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
connect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsVertexEditor::updateVertexSelection );

updateEditor( layer, selectedFeature );
}

void QgsVertexEditor::updateEditor( QgsVectorLayer *layer, QgsSelectedFeature *selectedFeature )
{
if ( mVertexModel )
{
delete mVertexModel;
}

mLayer = layer;
mSelectedFeature = selectedFeature;

// TOOD We really should just update the model itself.
mVertexModel = new QgsVertexEditorModel( mLayer, mSelectedFeature, mCanvas, this );
mTableView->setModel( mVertexModel );

connect( mSelectedFeature, &QgsSelectedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
}

void QgsVertexEditor::updateTableSelection()
Expand Down
1 change: 1 addition & 0 deletions src/app/vertextool/qgsvertexeditor.h
Expand Up @@ -75,6 +75,7 @@ class QgsVertexEditor : public QgsDockWidget
QgsMapCanvas *canvas );

public:
void updateEditor( QgsVectorLayer *layer, QgsSelectedFeature *selectedFeature );
QgsVectorLayer *mLayer = nullptr;
QgsSelectedFeature *mSelectedFeature = nullptr;
QgsMapCanvas *mCanvas = nullptr;
Expand Down
16 changes: 12 additions & 4 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -1036,10 +1036,18 @@ void QgsVertexTool::showVertexEditor() //#spellok
return;

mSelectedFeature.reset( new QgsSelectedFeature( m.featureId(), m.layer(), mCanvas ) );
mVertexEditor.reset( new QgsVertexEditor( m.layer(), mSelectedFeature.get(), mCanvas ) );
QgisApp::instance()->addDockWidget( Qt::LeftDockWidgetArea, mVertexEditor.get() );
connect( mVertexEditor.get(), &QgsVertexEditor::deleteSelectedRequested, this, &QgsVertexTool::deleteVertexEditorSelection );
connect( mVertexEditor.get(), &QgsVertexEditor::editorClosed, this, &QgsVertexTool::cleanupVertexEditor );
if ( !mVertexEditor )
{
mVertexEditor.reset( new QgsVertexEditor( m.layer(), mSelectedFeature.get(), mCanvas ) );
QgisApp::instance()->addDockWidget( Qt::LeftDockWidgetArea, mVertexEditor.get() );
connect( mVertexEditor.get(), &QgsVertexEditor::deleteSelectedRequested, this, &QgsVertexTool::deleteVertexEditorSelection );
connect( mVertexEditor.get(), &QgsVertexEditor::editorClosed, this, &QgsVertexTool::cleanupVertexEditor );
}
else
{
mVertexEditor->updateEditor( m.layer(), mSelectedFeature.get() );
}

connect( mSelectedFeature.get()->vlayer(), &QgsVectorLayer::featureDeleted, this, &QgsVertexTool::cleanEditor );
}

Expand Down

0 comments on commit 614800c

Please sign in to comment.