Skip to content
Permalink
Browse files

Use advanced editing for node tool

  • Loading branch information
mhugent committed Jul 10, 2015
1 parent 0661b2f commit 2dac1399240a2f9bf64729c3bba9282516b6d168
@@ -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 )
@@ -66,6 +65,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
}

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

if ( !mSelectedFeature || !hasVertexSelection )
{
//try to select feature
@@ -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 );
}
@@ -145,9 +140,6 @@ void QgsMapToolNodeTool::editingToggled()
void QgsMapToolNodeTool::deactivate()
{
cleanTool();
mSelectAnother = false;
mMoving = true;

QgsMapTool::deactivate();
}

@@ -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 ||
@@ -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 );

@@ -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;

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

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

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

#endif
@@ -853,8 +853,7 @@ bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent* e, CadCo

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

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

0 comments on commit 2dac139

Please sign in to comment.
You can’t perform that action at this time.