Skip to content

Commit 2dac139

Browse files
committed
Use advanced editing for node tool
1 parent 0661b2f commit 2dac139

File tree

3 files changed

+9
-27
lines changed

3 files changed

+9
-27
lines changed

src/app/nodetool/qgsmaptoolnodetool.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,20 @@ QgsMapToolNodeTool::QgsMapToolNodeTool( QgsMapCanvas* canvas )
3434
: QgsMapToolEdit( canvas )
3535
, mSelectedFeature( 0 )
3636
, mNodeEditor( 0 )
37-
, mMoving( true )
38-
, mSelectAnother( false )
3937
, mRect( 0 )
4038
, mIsPoint( false )
41-
, mDeselectOnRelease( -1 )
4239
{
4340
mSnapper.setMapCanvas( canvas );
41+
mCadAllowed = true;
42+
mSnapOnPress = true;
4443
}
4544

4645
QgsMapToolNodeTool::~QgsMapToolNodeTool()
4746
{
4847
cleanTool();
4948
}
5049

51-
void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
50+
void QgsMapToolNodeTool::canvasMapPressEvent( QgsMapMouseEvent* e )
5251
{
5352
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
5453
if ( !vlayer )
@@ -66,6 +65,7 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
6665
}
6766

6867
bool hasVertexSelection = mSelectedFeature && mSelectedFeature->hasSelection();
68+
6969
if ( !mSelectedFeature || !hasVertexSelection )
7070
{
7171
//try to select feature
@@ -101,22 +101,17 @@ void QgsMapToolNodeTool::canvasPressEvent( QMouseEvent * e )
101101
{
102102
if ( mSelectedFeature->hasSelection() && !ctrlModifier ) //move vertices
103103
{
104-
//move selected nodes and deselect all //where does 'mClosestMapVertex' come from?
105-
QList<QgsSnappingResult> snapResults;
106-
mSnapper.snapToBackgroundLayers( e->pos(), snapResults, QList<QgsPoint>() << mClosestMapVertex );
107-
QgsPoint targetCoords = toLayerCoordinates( vlayer, snapPointFromResults( snapResults, e->pos() ) );
104+
QgsPoint targetCoords = e->mapPoint();
108105
mSelectedFeature->moveSelectedVertexes( targetCoords - mClosestMapVertex );
109106
mCanvas->refresh();
110107
mSelectedFeature->deselectAllVertexes();
111108
}
112109
else //add vertex selection
113110
{
114-
//snap and add to selection
115-
QgsPoint layerCoordPoint = toLayerCoordinates( vlayer, e->pos() );
116111
int atVertex, beforeVertex, afterVertex;
117112
double dist;
118113

119-
QgsPoint closestLayerVertex = mSelectedFeature->geometry()->closestVertex( layerCoordPoint, atVertex, beforeVertex, afterVertex, dist );
114+
QgsPoint closestLayerVertex = mSelectedFeature->geometry()->closestVertex( e->mapPoint(), atVertex, beforeVertex, afterVertex, dist );
120115
mSelectedFeature->selectVertex( atVertex );
121116
mClosestMapVertex = toMapCoordinates( vlayer, closestLayerVertex );
122117
}
@@ -145,9 +140,6 @@ void QgsMapToolNodeTool::editingToggled()
145140
void QgsMapToolNodeTool::deactivate()
146141
{
147142
cleanTool();
148-
mSelectAnother = false;
149-
mMoving = true;
150-
151143
QgsMapTool::deactivate();
152144
}
153145

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

186178
QList<QgsSnappingResult> snapResults;
187-
mMoving = false;
188179
double tol = QgsTolerance::vertexSearchRadius( vlayer, mCanvas->mapSettings() );
189180
mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToSegment, tol );
190181
if ( snapResults.size() < 1 ||

src/app/nodetool/qgsmaptoolnodetool.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class QgsMapToolNodeTool: public QgsMapToolEdit
3636

3737
void canvasDoubleClickEvent( QMouseEvent * e );
3838

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

4142
void keyPressEvent( QKeyEvent* e );
4243

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

112-
/** Flag if moving of vertexes is occuring */
113-
bool mMoving;
114-
115-
/** Flag if selection of another feature can occur */
116-
bool mSelectAnother;
117-
118113
/** Feature id of another feature where user clicked */
119114
QgsFeatureId mAnother;
120115

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

130125
/** Flag to tell if edition points */
131126
bool mIsPoint;
132-
133-
/** Vertex to deselect on release */
134-
int mDeselectOnRelease;
135127
};
136128

137129
#endif

src/app/qgsadvanceddigitizingdockwidget.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,7 @@ bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent* e, CadCo
853853

854854
bool QgsAdvancedDigitizingDockWidget::canvasPressEventFilter( QgsMapMouseEvent* e )
855855
{
856-
Q_UNUSED( e );
857-
856+
applyConstraints( e );
858857
return mCadEnabled && mConstructionMode;
859858
}
860859

0 commit comments

Comments
 (0)