Skip to content
Permalink
Browse files

[Fix] Don't recreate vertex editor each time

  • Loading branch information
NathanW2 authored and nyalldawson committed Mar 19, 2018
1 parent c923d5b commit 614800c918485e26fa4c152a7f7bf25b02538ff3
@@ -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 );
@@ -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()
@@ -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;
@@ -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 );
}

0 comments on commit 614800c

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