@@ -110,32 +110,32 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
110
110
#ifdef QGISDEBUG
111
111
std::cout << " QgsMapCanvas::mousePressEvent: QGis::AddVertex." << std::endl;
112
112
#endif
113
-
114
- // Find nearest segment of the selected line, move that node to the mouse location
115
- if (!snapSegmentWithContext (point))
116
- {
117
- QMessageBox::warning (0 , " Error" ,
118
- QObject::tr (" Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?" ),
119
- QMessageBox::Ok, Qt::NoButton);
120
- return ;
121
- }
122
-
123
- index = mSnappedBeforeVertex ;
124
- // Get the endpoint of the snapped-to segment
125
- mSnappedAtGeometry .vertexAt (x2, y2, index );
126
-
127
- // Get the startpoint of the snapped-to segment
128
- index .decrement_back ();
129
- mStartPointValid = mSnappedAtGeometry .vertexAt (x1, y1 , index );
130
-
131
- createRubberBand ();
132
-
133
- if (mStartPointValid )
134
- {
135
- mRubberBand ->addPoint (QgsPoint (x1,y1 ));
136
- }
137
- mRubberBand ->addPoint (toMapCoords (e->pos ()));
138
- mRubberBand ->addPoint (QgsPoint (x2,y2));
113
+
114
+ // Find nearest segment of the selected line, move that node to the mouse location
115
+ if (!snapSegmentWithContext (point))
116
+ {
117
+ QMessageBox::warning (0 , " Error" ,
118
+ QObject::tr (" Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?" ),
119
+ QMessageBox::Ok, Qt::NoButton);
120
+ return ;
121
+ }
122
+
123
+ index = mSnappedBeforeVertex ;
124
+ // Get the endpoint of the snapped-to segment
125
+ mSnappedAtGeometry .vertexAt (x2, y2, index );
126
+
127
+ // Get the startpoint of the snapped-to segment
128
+ index .decrement_back ();
129
+ mStartPointValid = mSnappedAtGeometry .vertexAt (x1, y1 , index );
130
+
131
+ createRubberBand ();
132
+
133
+ if (mStartPointValid )
134
+ {
135
+ mRubberBand ->addPoint (QgsPoint (x1,y1 ));
136
+ }
137
+ mRubberBand ->addPoint (toMapCoords (e->pos ()));
138
+ mRubberBand ->addPoint (QgsPoint (x2,y2));
139
139
}
140
140
else if (mTool == MoveVertex)
141
141
{
@@ -150,53 +150,67 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
150
150
QgsPoint snapPoint;
151
151
152
152
snapPoint = point;
153
- if (!snapSegmentWithContext (snapPoint))
154
- {
155
- QMessageBox::warning (0 , " Error" ,
156
- QObject::tr (" Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?" ),
157
- QMessageBox::Ok, Qt::NoButton);
158
- return ;
159
- }
160
-
161
- snapPoint = point;
162
- if (!snapVertexOfSnappedSegment (snapPoint))
163
- {
164
- QMessageBox::warning (0 , " Error" ,
165
- QObject::tr (" Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?" ),
166
- QMessageBox::Ok, Qt::NoButton);
167
- return ;
168
- }
169
-
170
- #ifdef QGISDEBUG
171
- qWarning (" Creating rubber band for moveVertex" );
172
- #endif
173
-
174
- index = mSnappedAtVertex ;
175
- createRubberBand ();
176
- if (mRubberBandIndex1 != -1 )
177
- {
178
- rb1Index.push_back (mRubberBandIndex1 );
179
- mSnappedAtGeometry .vertexAt (x1, y1 , rb1Index);
180
- mRubberBand ->addPoint (QgsPoint (x1,y1 ));
181
- mStartPointValid = true ;
182
- }
183
- else
153
+ QgsVectorLayer* vlayer = dynamic_cast <QgsVectorLayer*>(mCanvas ->currentLayer ());
154
+ if (vlayer->vectorType () == QGis::Point )// snap to point for point/multipoint layers
184
155
{
185
- mStartPointValid = false ;
186
- }
187
- if (mRubberBandIndex1 != -1 && mRubberBandIndex2 != -1 )
188
- {
189
- mRubberBand ->addPoint (toMapCoords (e->pos ()));
156
+ if (!snapVertexWithContext (snapPoint))
157
+ {
158
+ QMessageBox::warning (0 , " Error" ,
159
+ QObject::tr (" Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?" ),
160
+ QMessageBox::Ok, Qt::NoButton);
161
+ return ;
162
+ }
190
163
}
191
- if ( mRubberBandIndex2 != - 1 )
164
+ else // snap to segment and take the closest vertex in case of line/multiline/polygon/multipolygon layers
192
165
{
193
- rb2Index.push_back (mRubberBandIndex2 );
194
- mSnappedAtGeometry .vertexAt (x2, y2, rb2Index);
195
- mRubberBand ->addPoint (QgsPoint (x2,y2));
196
- }
166
+ if (!snapSegmentWithContext (snapPoint))
167
+ {
168
+ QMessageBox::warning (0 , " Error" ,
169
+ QObject::tr (" Could not snap segment. Have you set the tolerance in Settings > Project Properties > General?" ),
170
+ QMessageBox::Ok, Qt::NoButton);
171
+ return ;
172
+ }
173
+
174
+ snapPoint = point;
175
+ if (!snapVertexOfSnappedSegment (snapPoint))
176
+ {
177
+ QMessageBox::warning (0 , " Error" ,
178
+ QObject::tr (" Could not snap vertex. Have you set the tolerance in Settings > Project Properties > General?" ),
179
+ QMessageBox::Ok, Qt::NoButton);
180
+ return ;
181
+ }
182
+
183
+ #ifdef QGISDEBUG
184
+ qWarning (" Creating rubber band for moveVertex" );
185
+ #endif
186
+
187
+ index = mSnappedAtVertex ;
188
+ createRubberBand ();
189
+ if (mRubberBandIndex1 != -1 )
190
+ {
191
+ rb1Index.push_back (mRubberBandIndex1 );
192
+ mSnappedAtGeometry .vertexAt (x1, y1 , rb1Index);
193
+ mRubberBand ->addPoint (QgsPoint (x1,y1 ));
194
+ mStartPointValid = true ;
195
+ }
196
+ else
197
+ {
198
+ mStartPointValid = false ;
199
+ }
200
+ if (mRubberBandIndex1 != -1 && mRubberBandIndex2 != -1 )
201
+ {
202
+ mRubberBand ->addPoint (toMapCoords (e->pos ()));
203
+ }
204
+ if (mRubberBandIndex2 != -1 )
205
+ {
206
+ rb2Index.push_back (mRubberBandIndex2 );
207
+ mSnappedAtGeometry .vertexAt (x2, y2, rb2Index);
208
+ mRubberBand ->addPoint (QgsPoint (x2,y2));
209
+ }
197
210
#ifdef QGISDEBUG
198
211
qWarning (" Creating rubber band for moveVertex" );
199
212
#endif
213
+ }
200
214
}
201
215
else if (mTool == DeleteVertex)
202
216
{
0 commit comments