Skip to content

Commit

Permalink
fix updating vertex selection
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Feb 23, 2019
1 parent f77538e commit 4c1f08c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/app/vertextool/qgslockedfeature.cpp
Expand Up @@ -13,8 +13,8 @@
* * * *
***************************************************************************/ ***************************************************************************/


#include "vertextool/qgslockedfeature.h" #include "qgslockedfeature.h"
#include "vertextool/qgsvertexentry.h" #include "qgsvertexeditor.h"


#include "qgsfeatureiterator.h" #include "qgsfeatureiterator.h"
#include "qgspoint.h" #include "qgspoint.h"
Expand Down Expand Up @@ -283,7 +283,7 @@ void QgsLockedFeature::selectVertex( int vertexNr )
return; return;


QgsVertexEntry *entry = mVertexMap.at( vertexNr ); QgsVertexEntry *entry = mVertexMap.at( vertexNr );
entry->setSelected(); entry->setSelected( true );


emit selectionChanged(); emit selectionChanged();
} }
Expand Down
12 changes: 8 additions & 4 deletions src/app/vertextool/qgsvertexeditor.cpp
Expand Up @@ -374,30 +374,33 @@ void QgsVertexEditor::updateTableSelection()
} }
} }
disconnect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection ); disconnect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
disconnect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsVertexEditor::updateVertexSelection );
mTableView->selectionModel()->select( selection, QItemSelectionModel::ClearAndSelect ); mTableView->selectionModel()->select( selection, QItemSelectionModel::ClearAndSelect );
connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection ); connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
connect( mTableView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsVertexEditor::updateVertexSelection );


if ( firstSelectedRow >= 0 ) if ( firstSelectedRow >= 0 )
mTableView->scrollTo( mVertexModel->index( firstSelectedRow, 0 ), QAbstractItemView::PositionAtTop ); mTableView->scrollTo( mVertexModel->index( firstSelectedRow, 0 ), QAbstractItemView::PositionAtTop );


mUpdatingTableSelection = false; mUpdatingTableSelection = false;
} }


void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, const QItemSelection & ) void QgsVertexEditor::updateVertexSelection( const QItemSelection &, const QItemSelection & )
{ {
if ( !mLockedFeature || mUpdatingTableSelection ) if ( !mLockedFeature || mUpdatingTableSelection )
return; return;


mUpdatingVertexSelection = true; mUpdatingVertexSelection = true;
disconnect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );


mLockedFeature->deselectAllVertices(); mLockedFeature->deselectAllVertices();


QgsCoordinateTransform t( mLockedFeature->layer()->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() ); QgsCoordinateTransform t( mLockedFeature->layer()->crs(), mCanvas->mapSettings().destinationCrs(), QgsProject::instance() );
std::unique_ptr<QgsRectangle> bbox; std::unique_ptr<QgsRectangle> bbox;
QModelIndexList indexList = selected.indexes(); const QModelIndexList indexList = mTableView->selectionModel()->selectedRows();
for ( int i = 0; i < indexList.length(); ++i ) for ( const QModelIndex &index : indexList )
{ {
int vertexIdx = indexList.at( i ).row(); int vertexIdx = index.row();
mLockedFeature->selectVertex( vertexIdx ); mLockedFeature->selectVertex( vertexIdx );


// create a bounding box of selected vertices // create a bounding box of selected vertices
Expand Down Expand Up @@ -425,6 +428,7 @@ void QgsVertexEditor::updateVertexSelection( const QItemSelection &selected, con
} }


mUpdatingVertexSelection = false; mUpdatingVertexSelection = false;
connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
} }


void QgsVertexEditor::keyPressEvent( QKeyEvent *e ) void QgsVertexEditor::keyPressEvent( QKeyEvent *e )
Expand Down
6 changes: 2 additions & 4 deletions src/app/vertextool/qgsvertexeditor.h
Expand Up @@ -81,15 +81,13 @@ class QgsVertexEditor : public QgsDockWidget
void deleteSelectedRequested(); void deleteSelectedRequested();
void editorClosed(); void editorClosed();


public slots:
void updateTableSelection();

protected: protected:
void keyPressEvent( QKeyEvent *event ) override; void keyPressEvent( QKeyEvent *event ) override;
void closeEvent( QCloseEvent *event ) override; void closeEvent( QCloseEvent *event ) override;


private slots: private slots:
void updateVertexSelection( const QItemSelection &selected, const QItemSelection &deselected ); void updateTableSelection();
void updateVertexSelection( const QItemSelection &, const QItemSelection &deselected );


private: private:


Expand Down
3 changes: 0 additions & 3 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -2328,9 +2328,6 @@ void QgsVertexTool::setHighlightedVertices( const QList<Vertex> &listVertices, H
mLockedFeature->selectVertex( vertex.vertexId ); mLockedFeature->selectVertex( vertex.vertexId );
} }


// if ( mVertexEditor )
// mVertexEditor->updateTableSelection();

connect( mLockedFeature.get(), &QgsLockedFeature::selectionChanged, this, &QgsVertexTool::lockedFeatureSelectionChanged ); connect( mLockedFeature.get(), &QgsLockedFeature::selectionChanged, this, &QgsVertexTool::lockedFeatureSelectionChanged );
} }
} }
Expand Down

0 comments on commit 4c1f08c

Please sign in to comment.