Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use advanced editing for node tool
  • Loading branch information
mhugent committed Jul 10, 2015
1 parent 0661b2f commit 2dac139
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
21 changes: 6 additions & 15 deletions src/app/nodetool/qgsmaptoolnodetool.cpp
Expand Up @@ -34,21 +34,20 @@ QgsMapToolNodeTool::QgsMapToolNodeTool( QgsMapCanvas* canvas )
: QgsMapToolEdit( canvas )
, mSelectedFeature( 0 )
, mNodeEditor( 0 )
, mMoving( true )
, mSelectAnother( false )
, mRect( 0 )
, mIsPoint( false )
, mDeselectOnRelease( -1 )
{
mSnapper.setMapCanvas( canvas );
mCadAllowed = true;
mSnapOnPress = true;
}

QgsMapToolNodeTool::~QgsMapToolNodeTool()
{
cleanTool();
}

void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
void QgsMapToolNodeTool::canvasMapPressEvent( QgsMapMouseEvent* e )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
Expand All @@ -66,6 +65,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
}

bool hasVertexSelection = mSelectedFeature && mSelectedFeature->hasSelection();

if ( !mSelectedFeature || !hasVertexSelection )
{
//try to select feature
Expand Down Expand Up @@ -101,22 +101,17 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
{
if ( mSelectedFeature->hasSelection() && !ctrlModifier ) //move vertices
{
//move selected nodes and deselect all //where does 'mClosestMapVertex' come from?
QList<QgsSnappingResult> snapResults;
mSnapper.snapToBackgroundLayers( e->pos(), snapResults, QList<QgsPoint>() << mClosestMapVertex );
QgsPoint targetCoords = toLayerCoordinates( vlayer, snapPointFromResults( snapResults, e->pos() ) );
QgsPoint targetCoords = e->mapPoint();
mSelectedFeature->moveSelectedVertexes( targetCoords - mClosestMapVertex );
mCanvas->refresh();
mSelectedFeature->deselectAllVertexes();
}
else //add vertex selection
{
//snap and add to selection
QgsPoint layerCoordPoint = toLayerCoordinates( vlayer, e->pos() );
int atVertex, beforeVertex, afterVertex;
double dist;

QgsPoint closestLayerVertex = mSelectedFeature->geometry()->closestVertex( layerCoordPoint, atVertex, beforeVertex, afterVertex, dist );
QgsPoint closestLayerVertex = mSelectedFeature->geometry()->closestVertex( e->mapPoint(), atVertex, beforeVertex, afterVertex, dist );
mSelectedFeature->selectVertex( atVertex );
mClosestMapVertex = toMapCoordinates( vlayer, closestLayerVertex );
}
Expand Down Expand Up @@ -145,9 +140,6 @@ void QgsMapToolNodeTool::editingToggled()
void QgsMapToolNodeTool::deactivate()
{
cleanTool();
mSelectAnother = false;
mMoving = true;

QgsMapTool::deactivate();
}

Expand Down Expand Up @@ -184,7 +176,6 @@ void QgsMapToolNodeTool::canvasDoubleClickEvent( QMouseEvent * e )
QMultiMap<double, QgsSnappingResult> currentResultList;

QList<QgsSnappingResult> snapResults;
mMoving = false;
double tol = QgsTolerance::vertexSearchRadius( vlayer, mCanvas->mapSettings() );
mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToSegment, tol );
if ( snapResults.size() < 1 ||
Expand Down
12 changes: 2 additions & 10 deletions src/app/nodetool/qgsmaptoolnodetool.h
Expand Up @@ -36,7 +36,8 @@ class QgsMapToolNodeTool: public QgsMapToolEdit

void canvasDoubleClickEvent( QMouseEvent * e );

void canvasPressEvent( QMouseEvent * e );
//! mouse press event in map coordinates (eventually filtered) to be redefined in subclass
void canvasMapPressEvent( QgsMapMouseEvent* e ) override;

void keyPressEvent( QKeyEvent* e );

Expand Down Expand Up @@ -109,12 +110,6 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
/** Dock widget which allows to edit vertices */
QgsNodeEditor* mNodeEditor;

/** Flag if moving of vertexes is occuring */
bool mMoving;

/** Flag if selection of another feature can occur */
bool mSelectAnother;

/** Feature id of another feature where user clicked */
QgsFeatureId mAnother;

Expand All @@ -129,9 +124,6 @@ class QgsMapToolNodeTool: public QgsMapToolEdit

/** Flag to tell if edition points */
bool mIsPoint;

/** Vertex to deselect on release */
int mDeselectOnRelease;
};

#endif
3 changes: 1 addition & 2 deletions src/app/qgsadvanceddigitizingdockwidget.cpp
Expand Up @@ -853,8 +853,7 @@ bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent* e, CadCo

bool QgsAdvancedDigitizingDockWidget::canvasPressEventFilter( QgsMapMouseEvent* e )
{
Q_UNUSED( e );

applyConstraints( e );
return mCadEnabled && mConstructionMode;
}

Expand Down

0 comments on commit 2dac139

Please sign in to comment.