Skip to content

Commit

Permalink
Better synchronisation between node editor and node tool
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 20, 2015
1 parent 9f8aa84 commit 863bf88
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/app/nodetool/qgsmaptoolnodetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
}
}
}
Expand Down Expand Up @@ -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() ) );
}
2 changes: 2 additions & 0 deletions src/app/nodetool/qgsmaptoolnodetool.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
*/
void editingToggled();

void changeLastVertex( const QgsPointV2& pt );

private:
/**
* Deletes the rubber band pointers and clears mRubberBands
Expand Down
6 changes: 4 additions & 2 deletions src/app/nodetool/qgsnodeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
}
23 changes: 22 additions & 1 deletion src/app/nodetool/qgsselectedfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ void QgsSelectedFeature::selectVertex( int vertexNr )
entry->setSelected();

emit selectionChanged();
emit lastVertexChanged( entry->point() );
}

void QgsSelectedFeature::deselectVertex( int vertexNr )
Expand All @@ -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()
Expand All @@ -453,6 +469,7 @@ void QgsSelectedFeature::deselectAllVertexes()
mVertexMap[i]->setSelected( false );
}
emit selectionChanged();
emit lastVertexChanged( QgsPointV2() );
}

void QgsSelectedFeature::invertVertexSelection( int vertexNr )
Expand All @@ -466,6 +483,10 @@ void QgsSelectedFeature::invertVertexSelection( int vertexNr )

entry->setSelected( selected );
emit selectionChanged();
if ( selected )
{
emit lastVertexChanged( entry->point() );
}
}

void QgsSelectedFeature::updateVertexMarkersPosition()
Expand Down
1 change: 1 addition & 0 deletions src/app/nodetool/qgsselectedfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class QgsSelectedFeature: public QObject

signals:
void selectionChanged();
void lastVertexChanged( const QgsPointV2& pt );
void vertexMapChanged();

public slots:
Expand Down

0 comments on commit 863bf88

Please sign in to comment.