Better synchronisation between node editor and node tool

This commit is contained in:
Marco Hugentobler 2015-07-20 15:56:23 +02:00
parent 9f8aa8494a
commit 863bf88f2b
5 changed files with 36 additions and 4 deletions

View File

@ -90,6 +90,7 @@ void QgsMapToolNodeTool::canvasMapPressEvent( QgsMapMouseEvent* e )
mSelectedFeature = new QgsSelectedFeature( snapResults[0].snappedAtGeometry, vlayer, mCanvas );
connect( QgisApp::instance()->layerTreeView(), SIGNAL( currentLayerChanged( QgsMapLayer* ) ), this, SLOT( currentLayerChanged( QgsMapLayer* ) ) );
connect( mSelectedFeature, SIGNAL( destroyed() ), this, SLOT( selectedFeatureDestroyed() ) );
connect( mSelectedFeature, SIGNAL( lastVertexChanged( const QgsPointV2& ) ), this, SLOT( changeLastVertex( const QgsPointV2& ) ) );
connect( vlayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
mIsPoint = vlayer->geometryType() == QGis::Point;
mNodeEditor = new QgsNodeEditor( vlayer, mSelectedFeature, mCanvas );
@ -113,7 +114,7 @@ void QgsMapToolNodeTool::canvasMapPressEvent( QgsMapMouseEvent* e )
QgsPoint closestLayerVertex = mSelectedFeature->geometry()->closestVertex( e->mapPoint(), atVertex, beforeVertex, afterVertex, dist );
mSelectedFeature->selectVertex( atVertex );
mClosestMapVertex = toMapCoordinates( vlayer, closestLayerVertex );
//mClosestMapVertex = toMapCoordinates( vlayer, closestLayerVertex );
}
}
}
@ -309,3 +310,8 @@ int QgsMapToolNodeTool::insertSegmentVerticesForSnap( const QList<QgsSnappingRes
return editedLayer->insertSegmentVerticesForSnap( transformedSnapResults );
}
void QgsMapToolNodeTool::changeLastVertex( const QgsPointV2& pt )
{
mClosestMapVertex = toMapCoordinates( currentVectorLayer(), QgsPoint( pt.x(), pt.y() ) );
}

View File

@ -57,6 +57,8 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
*/
void editingToggled();
void changeLastVertex( const QgsPointV2& pt );
private:
/**
* Deletes the rubber band pointers and clears mRubberBands

View File

@ -225,12 +225,14 @@ void QgsNodeEditor::updateTableSelection()
void QgsNodeEditor::updateNodeSelection()
{
mSelectedFeature->blockSignals( true );
disconnect( mSelectedFeature, SIGNAL( selectionChanged() ), this, SLOT( updateTableSelection() ) );
mSelectedFeature->deselectAllVertexes();
foreach ( const QModelIndex& index, mTableWidget->selectionModel()->selectedRows() )
{
int nodeIdx = mTableWidget->item( index.row(), 0 )->data( Qt::DisplayRole ).toInt();
mSelectedFeature->selectVertex( nodeIdx );
}
mSelectedFeature->blockSignals( false );
connect( mSelectedFeature, SIGNAL( selectionChanged() ), this, SLOT( updateTableSelection() ) );
}

View File

@ -433,6 +433,7 @@ void QgsSelectedFeature::selectVertex( int vertexNr )
entry->setSelected();
emit selectionChanged();
emit lastVertexChanged( entry->point() );
}
void QgsSelectedFeature::deselectVertex( int vertexNr )
@ -442,8 +443,23 @@ void QgsSelectedFeature::deselectVertex( int vertexNr )
QgsVertexEntry *entry = mVertexMap[vertexNr];
entry->setSelected( false );
emit selectionChanged();
//todo: take another selected vertex as 'lastVertexChanged'
QList<QgsVertexEntry*>::const_iterator vIt = mVertexMap.constBegin();
for ( ; vIt != mVertexMap.constEnd(); ++vIt )
{
if (( *vIt )->isSelected() )
{
emit lastVertexChanged(( *vIt )->point() );
return;
}
}
if ( vIt == mVertexMap.constEnd() )
{
emit lastVertexChanged( QgsPointV2() ); //no selection anymore
}
}
void QgsSelectedFeature::deselectAllVertexes()
@ -453,6 +469,7 @@ void QgsSelectedFeature::deselectAllVertexes()
mVertexMap[i]->setSelected( false );
}
emit selectionChanged();
emit lastVertexChanged( QgsPointV2() );
}
void QgsSelectedFeature::invertVertexSelection( int vertexNr )
@ -466,6 +483,10 @@ void QgsSelectedFeature::invertVertexSelection( int vertexNr )
entry->setSelected( selected );
emit selectionChanged();
if ( selected )
{
emit lastVertexChanged( entry->point() );
}
}
void QgsSelectedFeature::updateVertexMarkersPosition()

View File

@ -133,6 +133,7 @@ class QgsSelectedFeature: public QObject
signals:
void selectionChanged();
void lastVertexChanged( const QgsPointV2& pt );
void vertexMapChanged();
public slots: