1
1
/* **************************************************************************
2
- qgmaptoolextendfeature .cpp - map tool for extending feature
2
+ qgmaptooltrimextendfeature .cpp - map tool to trim or extend feature
3
3
---------------------
4
4
begin : October 2018
5
5
copyright : (C) 2018 by Loïc Bartoletti
@@ -73,19 +73,19 @@ static void getPoints( const QgsPointLocator::Match &match, QgsPoint &p1, QgsPoi
73
73
74
74
void QgsMapToolTrimExtendFeature::canvasMoveEvent ( QgsMapMouseEvent *e )
75
75
{
76
- mapPoint = e->mapPoint ();
76
+ mMapPoint = e->mapPoint ();
77
77
78
78
FeatureFilter filter;
79
79
QgsPointLocator::Match match;
80
80
81
- switch ( step )
81
+ switch ( mStep )
82
82
{
83
- case 0 :
83
+ case StepLimit :
84
84
85
- match = mCanvas ->snappingUtils ()->snapToMap ( mapPoint , &filter );
85
+ match = mCanvas ->snappingUtils ()->snapToMap ( mMapPoint , &filter );
86
86
if ( match.isValid () )
87
87
{
88
- is3DLayer = QgsWkbTypes::hasZ ( match.layer ()->wkbType () );
88
+ mIs3DLayer = QgsWkbTypes::hasZ ( match.layer ()->wkbType () );
89
89
90
90
QgsPointXY p1, p2;
91
91
match.edgePoints ( p1, p2 );
@@ -96,31 +96,30 @@ void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
96
96
mRubberBandLimit ->show ();
97
97
98
98
}
99
- else
99
+ else if ( mRubberBandLimit )
100
100
{
101
- if ( mRubberBandLimit )
102
101
mRubberBandLimit ->hide ();
103
102
}
104
103
break ;
105
- case 1 :
104
+ case StepExtend :
106
105
107
106
QgsMapLayer *currentLayer = mCanvas ->currentLayer ();
108
107
if ( !currentLayer )
109
108
break ;
110
109
111
- vlayer = qobject_cast<QgsVectorLayer *>( currentLayer );
112
- if ( !vlayer )
110
+ mVlayer = qobject_cast<QgsVectorLayer *>( currentLayer );
111
+ if ( !mVlayer )
113
112
break ;
114
113
115
- if ( !vlayer ->isEditable () )
114
+ if ( !mVlayer ->isEditable () )
116
115
break ;
117
116
118
- filter.setLayer ( vlayer );
119
- match = mCanvas ->snappingUtils ()->snapToMap ( mapPoint , &filter );
117
+ filter.setLayer ( mVlayer );
118
+ match = mCanvas ->snappingUtils ()->snapToMap ( mMapPoint , &filter );
120
119
121
120
if ( match.isValid () )
122
121
{
123
- if ( match.layer () != vlayer )
122
+ if ( match.layer () != mVlayer )
124
123
break ;
125
124
126
125
QgsPointXY p1, p2;
@@ -132,34 +131,35 @@ void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
132
131
if ( ( ( pLimit1 == pExtend1 ) || ( pLimit1 == pExtend2 ) ) || ( ( pLimit2 == pExtend1 ) || ( pLimit2 == pExtend2 ) ) )
133
132
break ;
134
133
135
- segmentIntersects = QgsGeometryUtils::segmentIntersection ( pLimit1, pLimit2, pExtend1, pExtend2, intersection, isIntersection , 1e-8 , true );
134
+ mSegmentIntersects = QgsGeometryUtils::segmentIntersection ( pLimit1, pLimit2, pExtend1, pExtend2, mIntersection , mIsIntersection , 1e-8 , true );
136
135
137
- if ( is3DLayer && QgsWkbTypes::hasZ ( match.layer ()->wkbType () ) )
136
+ if ( mIs3DLayer && QgsWkbTypes::hasZ ( match.layer ()->wkbType () ) )
138
137
{
139
138
/* Z Interpolation */
140
139
QgsLineString line ( pLimit1, pLimit2 );
141
140
142
- intersection = QgsGeometryUtils::closestPoint ( line, QgsPoint ( intersection ) );
141
+ mIntersection = QgsGeometryUtils::closestPoint ( line, QgsPoint ( mIntersection ) );
143
142
}
144
143
145
- if ( isIntersection )
144
+ if ( mIsIntersection )
146
145
{
147
146
mRubberBandIntersection .reset ( createRubberBand ( QgsWkbTypes::PointGeometry ) );
148
- mRubberBandIntersection ->addPoint ( QgsPointXY ( intersection ) );
147
+ mRubberBandIntersection ->addPoint ( QgsPointXY ( mIntersection ) );
149
148
mRubberBandIntersection ->show ();
150
149
151
150
mRubberBandExtend .reset ( createRubberBand ( match.layer ()->geometryType () ) );
152
151
153
- geom = match.layer ()->getGeometry ( match.featureId () );
152
+ mGeom = match.layer ()->getGeometry ( match.featureId () );
154
153
int index = match.vertexIndex ();
155
154
156
- if ( !segmentIntersects )
155
+ if ( !mSegmentIntersects )
157
156
{
158
- QgsPoint ptInter ( intersection .x (), intersection .y () );
157
+ QgsPoint ptInter ( mIntersection .x (), mIntersection .y () );
159
158
if ( pExtend2.distance ( ptInter ) < pExtend1.distance ( ptInter ) )
160
159
index += 1 ;
161
160
}
162
- else // TRIM PART
161
+ // TRIM PART
162
+ else if ( QgsGeometryUtils::leftOfLine ( QgsPoint ( mMapPoint ), pLimit1, pLimit2 ) != QgsGeometryUtils::leftOfLine ( pExtend1, pLimit1, pLimit2 ) )
163
163
{
164
164
// Part where the mouse is (+) will be trimed
165
165
/* |
@@ -177,15 +177,14 @@ void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
177
177
* +
178
178
* |
179
179
*/
180
- if ( QgsGeometryUtils::leftOfLine ( QgsPoint ( mapPoint ), pLimit1, pLimit2 ) != QgsGeometryUtils::leftOfLine ( pExtend1, pLimit1, pLimit2 ) )
181
180
index += 1 ;
182
181
}
183
182
184
- isModified = geom .moveVertex ( intersection , index );
183
+ mIsModified = mGeom .moveVertex ( mIntersection , index );
185
184
186
- if ( isModified )
185
+ if ( mIsModified )
187
186
{
188
- mRubberBandExtend ->setToGeometry ( geom );
187
+ mRubberBandExtend ->setToGeometry ( mGeom );
189
188
mRubberBandExtend ->show ();
190
189
}
191
190
}
@@ -210,31 +209,31 @@ void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
210
209
211
210
void QgsMapToolTrimExtendFeature::canvasReleaseEvent ( QgsMapMouseEvent *e )
212
211
{
213
- mapPoint = e->mapPoint ();
212
+ mMapPoint = e->mapPoint ();
214
213
215
214
FeatureFilter filter;
216
215
QgsPointLocator::Match match;
217
216
218
217
if ( e->button () == Qt::LeftButton )
219
218
{
220
- switch ( step )
219
+ switch ( mStep )
221
220
{
222
- case 0 :
223
- match = mCanvas ->snappingUtils ()->snapToMap ( mapPoint , &filter );
221
+ case StepLimit :
222
+ match = mCanvas ->snappingUtils ()->snapToMap ( mMapPoint , &filter );
224
223
if ( mRubberBandLimit && mRubberBandLimit ->isVisible () )
225
224
{
226
225
getPoints ( match, pLimit1, pLimit2 );
227
- step += 1 ;
226
+ mStep += 1 ;
228
227
}
229
228
break ;
230
- case 1 :
231
- if ( isModified )
229
+ case StepExtend :
230
+ if ( mIsModified )
232
231
{
233
- filter.setLayer ( vlayer );
234
- match = mCanvas ->snappingUtils ()->snapToMap ( mapPoint , &filter );
232
+ filter.setLayer ( mVlayer );
233
+ match = mCanvas ->snappingUtils ()->snapToMap ( mMapPoint , &filter );
235
234
236
235
match.layer ()->beginEditCommand ( tr ( " Trim/Extend feature" ) );
237
- match.layer ()->changeGeometry ( match.featureId (), geom );
236
+ match.layer ()->changeGeometry ( match.featureId (), mGeom );
238
237
match.layer ()->endEditCommand ();
239
238
match.layer ()->triggerRepaint ();
240
239
@@ -270,11 +269,11 @@ void QgsMapToolTrimExtendFeature::keyPressEvent( QKeyEvent *e )
270
269
271
270
void QgsMapToolTrimExtendFeature::deactivate ()
272
271
{
273
- step = 0 ;
274
- isModified = false ;
275
- is3DLayer = false ;
276
- isIntersection = false ;
277
- segmentIntersects = false ;
272
+ mStep = 0 ;
273
+ mIsModified = false ;
274
+ mIs3DLayer = false ;
275
+ mIsIntersection = false ;
276
+ mSegmentIntersects = false ;
278
277
mRubberBandLimit .reset ();
279
278
mRubberBandExtend .reset ();
280
279
mRubberBandIntersection .reset ();
0 commit comments