Skip to content

Commit

Permalink
synchronize selection from the editor to the tool
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Feb 23, 2019
1 parent 5427392 commit 21fb442
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/app/vertextool/qgsvertexeditor.cpp
Expand Up @@ -339,6 +339,24 @@ void QgsVertexEditor::updateEditor( QgsLockedFeature *lockedFeature )

mVertexModel->setFeature( mLockedFeature );

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 );
Expand Down
33 changes: 33 additions & 0 deletions src/app/vertextool/qgsvertextool.cpp
Expand Up @@ -1337,6 +1337,8 @@ void QgsVertexTool::updateVertexEditor( QgsVectorLayer *layer, QgsFeatureId fid
mLockedFeature->selectVertex( mSelectedVertices.at( i ).vertexId );
}
}

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

// make sure the vertex editor is alive and visible
Expand Down Expand Up @@ -1372,6 +1374,25 @@ void QgsVertexTool::cleanupVertexEditor()
mVertexEditor.reset();
}

void QgsVertexTool::lockedFeatureSelectionChanged()
{
Q_ASSERT( mLockedFeature );
QList<QgsVertexEntry *> &vertexMap = mLockedFeature->vertexMap();
QList<Vertex> vertices;
for ( int i = 0, n = vertexMap.size(); i < n; ++i )
{
if ( vertexMap[i]->isSelected() )
{
vertices << Vertex( mLockedFeature->layer(), mLockedFeature->featureId(), i );
}
}

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

}

static int _firstSelectedVertex( QgsLockedFeature &selectedFeature )
{
QList<QgsVertexEntry *> &vertexMap = selectedFeature.vertexMap();
Expand Down Expand Up @@ -2288,6 +2309,18 @@ void QgsVertexTool::setHighlightedVertices( const QList<Vertex> &listVertices, H
createMarkerForVertex( vertex );
}
}

if ( mLockedFeature )
{
for ( const Vertex &vertex : qgis::as_const( mSelectedVertices ) )
{
if ( mLockedFeature->featureId() != vertex.fid || mLockedFeature->layer() != vertex.layer )
continue;

if ( mVertexEditor )
mVertexEditor->updateEditor( mLockedFeature.get() );
}
}
}

void QgsVertexTool::setHighlightedVerticesVisible( bool visible )
Expand Down
9 changes: 4 additions & 5 deletions src/app/vertextool/qgsvertextool.h
Expand Up @@ -65,7 +65,8 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
public:

enum VertexToolMode

{
ActiveLayer,
AllLayers
};
Q_ENUM( VertexToolMode )
Expand Down Expand Up @@ -116,6 +117,8 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing

void cleanEditor( QgsFeatureId id );

void lockedFeatureSelectionChanged();

private:

void buildDragBandsForVertices( const QSet<Vertex> &movingVertices, const QgsPointXY &dragVertexMapPoint );
Expand Down Expand Up @@ -452,11 +455,7 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
};

//! Keeps information about other possible features to select with right click. Null if no info is currently held.
<<<<<<< HEAD
std::unique_ptr<LockedFeatureAlternatives> mLockedFeatureAlternatives;
=======
std::unique_ptr<SelectedFeatureAlternatives> mLockedFeatureAlternatives;
>>>>>>> remove vertex highlighting from editor

// support for validation of geometries

Expand Down

0 comments on commit 21fb442

Please sign in to comment.