Skip to content

Commit

Permalink
only select vertices from locked feature again
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Feb 25, 2019
1 parent 9750868 commit f7ef54e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
23 changes: 4 additions & 19 deletions src/app/vertextool/qgsvertexeditor.cpp
Expand Up @@ -363,28 +363,12 @@ void QgsVertexEditor::updateEditor( QgsLockedFeature *lockedFeature )

updateTableSelection();

// QItemSelectionModel *selectionModel = mTableView->selectionModel();
// QItemSelection selection;
// if ( mLockedFeature )
// {
// QList<QgsVertexEntry *> &vertexMap = mLockedFeature->vertexMap();
// for ( int i = 0, n = vertexMap.size(); i < n; ++i )
// {
// if ( vertexMap[i]->isSelected() )
// {
// QModelIndex index = mVertexModel->index( i, 0 );
// selection.select( index, index );
// }
// }
// }
// selectionModel->select( selection, QItemSelectionModel::ClearAndSelect );

if ( mLockedFeature )
{
mHintLabel->setVisible( false );
mTableView->setVisible( true );

connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
//connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
}
else
{
Expand All @@ -399,7 +383,6 @@ void QgsVertexEditor::updateTableSelection()
return;

mUpdatingTableSelection = true;
mTableView->selectionModel()->clearSelection();
const QList<QgsVertexEntry *> &vertexMap = mLockedFeature->vertexMap();
int firstSelectedRow = -1;
QItemSelection selection;
Expand All @@ -412,7 +395,9 @@ void QgsVertexEditor::updateTableSelection()
selection.select( mVertexModel->index( i, 0 ), mVertexModel->index( i, mVertexModel->columnCount() - 1 ) );
}
}
mTableView->selectionModel()->select( selection, QItemSelectionModel::Select );
//disconnect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );
mTableView->selectionModel()->select( selection, QItemSelectionModel::ClearAndSelect );
//connect( mLockedFeature, &QgsLockedFeature::selectionChanged, this, &QgsVertexEditor::updateTableSelection );

if ( firstSelectedRow >= 0 )
mTableView->scrollTo( mVertexModel->index( firstSelectedRow, 0 ), QAbstractItemView::PositionAtTop );
Expand Down
5 changes: 3 additions & 2 deletions src/app/vertextool/qgsvertexeditor.h
Expand Up @@ -71,7 +71,6 @@ class QgsVertexEditor : public QgsDockWidget
public:
QgsVertexEditor( QgsMapCanvas *canvas );

public:
void updateEditor( QgsLockedFeature *lockedFeature );
QgsLockedFeature *mLockedFeature = nullptr;
QgsMapCanvas *mCanvas = nullptr;
Expand All @@ -82,12 +81,14 @@ 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 updateTableSelection();
void updateVertexSelection( const QItemSelection &selected, const QItemSelection &deselected );

private:
Expand Down
18 changes: 9 additions & 9 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -994,12 +994,12 @@ void QgsVertexTool::tryToSelectFeature( QgsMapMouseEvent *e )
{
// there's really nothing under the cursor or while cycling through the list of available features
// we got to the end of the list - let's deselect any feature we may have had selected
setHighlightedVertices( QList<Vertex>(), ModeReset );
mLockedFeature.reset();
if ( mVertexEditor )
{
mVertexEditor->updateEditor( nullptr );
}
setHighlightedVertices( QList<Vertex>(), ModeReset );
}

// we have either locked ourselves to a feature or unlocked again
Expand Down Expand Up @@ -1396,10 +1396,7 @@ void QgsVertexTool::lockedFeatureSelectionChanged()
}
}

disconnect( mLockedFeature.get(), &QgsLockedFeature::selectionChanged, this, &QgsVertexTool::lockedFeatureSelectionChanged );
setHighlightedVertices( vertices, ModeReset );
connect( mLockedFeature.get(), &QgsLockedFeature::selectionChanged, this, &QgsVertexTool::lockedFeatureSelectionChanged );

}

static int _firstSelectedVertex( QgsLockedFeature &selectedFeature )
Expand Down Expand Up @@ -2321,14 +2318,17 @@ void QgsVertexTool::setHighlightedVertices( const QList<Vertex> &listVertices, H

if ( mLockedFeature )
{
disconnect( mLockedFeature.get(), &QgsLockedFeature::selectionChanged, this, &QgsVertexTool::lockedFeatureSelectionChanged );
for ( const Vertex &vertex : qgis::as_const( mSelectedVertices ) )
{
if ( mLockedFeature->featureId() != vertex.fid || mLockedFeature->layer() != vertex.layer )
continue;

if ( mVertexEditor )
mVertexEditor->updateEditor( mLockedFeature.get() );
// we should never be able to select vertices that are not from the locked feature
Q_ASSERT( mLockedFeature->featureId() == vertex.fid && mLockedFeature->layer() == vertex.layer );
mLockedFeature->selectVertex( vertex.vertexId );
}
connect( mLockedFeature.get(), &QgsLockedFeature::selectionChanged, this, &QgsVertexTool::lockedFeatureSelectionChanged );

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

Expand Down

0 comments on commit f7ef54e

Please sign in to comment.