From 4c1f08cc7a98d93bad1180444abc798cf5b1fe59 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Fri, 22 Feb 2019 11:00:28 -0500 Subject: [PATCH] fix updating vertex selection --- src/app/vertextool/qgslockedfeature.cpp | 6 +++--- src/app/vertextool/qgsvertexeditor.cpp | 12 ++++++++---- src/app/vertextool/qgsvertexeditor.h | 6 ++---- src/app/vertextool/qgsvertextool.cpp | 3 --- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/app/vertextool/qgslockedfeature.cpp b/src/app/vertextool/qgslockedfeature.cpp index bc7bc69000bc..ccb530343dbf 100644 --- a/src/app/vertextool/qgslockedfeature.cpp +++ b/src/app/vertextool/qgslockedfeature.cpp @@ -13,8 +13,8 @@ * * ***************************************************************************/ -#include "vertextool/qgslockedfeature.h" -#include "vertextool/qgsvertexentry.h" +#include "qgslockedfeature.h" +#include "qgsvertexeditor.h" #include "qgsfeatureiterator.h" #include "qgspoint.h" @@ -283,7 +283,7 @@ void QgsLockedFeature::selectVertex( int vertexNr ) return; QgsVertexEntry *entry = mVertexMap.at( vertexNr ); - entry->setSelected(); + entry->setSelected( true ); emit selectionChanged(); } diff --git a/src/app/vertextool/qgsvertexeditor.cpp b/src/app/vertextool/qgsvertexeditor.cpp index 1e8895d3dd10..1e83c6bfdb33 100644 --- a/src/app/vertextool/qgsvertexeditor.cpp +++ b/src/app/vertextool/qgsvertexeditor.cpp @@ -374,8 +374,10 @@ void QgsVertexEditor::updateTableSelection() } } disconnect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection ); + disconnect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsVertexEditor::updateVertexSelection ); mTableView->selectionModel()->select( selection, QItemSelectionModel::ClearAndSelect ); connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection ); + connect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsVertexEditor::updateVertexSelection ); if ( firstSelectedRow >= 0 ) mTableView->scrollTo( mVertexModel->index( firstSelectedRow, 0 ), QAbstractItemView::PositionAtTop ); @@ -383,21 +385,22 @@ void QgsVertexEditor::updateTableSelection() mUpdatingTableSelection = false; } -void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, const QItemSelection & ) +void QgsVertexEditor::updateVertexSelection( const QItemSelection &, const QItemSelection & ) { if ( !mLockedFeature || mUpdatingTableSelection ) return; mUpdatingVertexSelection = true; + disconnect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection ); mLockedFeature->deselectAllVertices(); QgsCoordinateTransform t( mLockedFeature->layer()->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() ); std::unique_ptr bbox; - QModelIndexList indexList = selected.indexes(); - for ( int i = 0; i < indexList.length(); ++i ) + const QModelIndexList indexList = mTableView->selectionModel()->selectedRows(); + for ( const QModelIndex &index : indexList ) { - int vertexIdx = indexList.at( i ).row(); + int vertexIdx = index.row(); mLockedFeature->selectVertex( vertexIdx ); // create a bounding box of selected vertices @@ -425,6 +428,7 @@ void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, con } mUpdatingVertexSelection = false; + connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection ); } void QgsVertexEditor::keyPressEvent( QKeyEvent *e ) diff --git a/src/app/vertextool/qgsvertexeditor.h b/src/app/vertextool/qgsvertexeditor.h index 7e00a58b52d0..7e36c1574f9b 100644 --- a/src/app/vertextool/qgsvertexeditor.h +++ b/src/app/vertextool/qgsvertexeditor.h @@ -81,15 +81,13 @@ class QgsVertexEditor : public QgsDockWidget void deleteSelectedRequested(); void editorClosed(); - public slots: - void updateTableSelection(); - protected: void keyPressEvent( QKeyEvent *event ) override; void closeEvent( QCloseEvent *event ) override; private slots: - void updateVertexSelection( const QItemSelection &selected, const QItemSelection &deselected ); + void updateTableSelection(); + void updateVertexSelection( const QItemSelection &, const QItemSelection &deselected ); private: diff --git a/src/app/vertextool/qgsvertextool.cpp b/src/app/vertextool/qgsvertextool.cpp index f92395f7e663..0b636792e61a 100644 --- a/src/app/vertextool/qgsvertextool.cpp +++ b/src/app/vertextool/qgsvertextool.cpp @@ -2328,9 +2328,6 @@ void QgsVertexTool::setHighlightedVertices( const QList &listVertices, H mLockedFeature->selectVertex( vertex.vertexId ); } -// if ( mVertexEditor ) -// mVertexEditor->updateTableSelection(); - connect( mLockedFeature.get(), &QgsLockedFeature::selectionChanged, this, &QgsVertexTool::lockedFeatureSelectionChanged ); } }