Skip to content

Commit 8b2331a

Browse files
committed
Paul's review
1 parent a8f8659 commit 8b2331a

File tree

4 files changed

+59
-55
lines changed

4 files changed

+59
-55
lines changed

src/app/qgsmaptooltrimextendfeature.cpp

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgmaptoolextendfeature.cpp - map tool for extending feature
2+
qgmaptooltrimextendfeature.cpp - map tool to trim or extend feature
33
---------------------
44
begin : October 2018
55
copyright : (C) 2018 by Loïc Bartoletti
@@ -73,19 +73,19 @@ static void getPoints( const QgsPointLocator::Match &match, QgsPoint &p1, QgsPoi
7373

7474
void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
7575
{
76-
mapPoint = e->mapPoint();
76+
mMapPoint = e->mapPoint();
7777

7878
FeatureFilter filter;
7979
QgsPointLocator::Match match;
8080

81-
switch ( step )
81+
switch ( mStep )
8282
{
83-
case 0:
83+
case StepLimit:
8484

85-
match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );
85+
match = mCanvas->snappingUtils()->snapToMap( mMapPoint, &filter );
8686
if ( match.isValid() )
8787
{
88-
is3DLayer = QgsWkbTypes::hasZ( match.layer()->wkbType() );
88+
mIs3DLayer = QgsWkbTypes::hasZ( match.layer()->wkbType() );
8989

9090
QgsPointXY p1, p2;
9191
match.edgePoints( p1, p2 );
@@ -96,31 +96,30 @@ void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
9696
mRubberBandLimit->show();
9797

9898
}
99-
else
99+
else if ( mRubberBandLimit )
100100
{
101-
if ( mRubberBandLimit )
102101
mRubberBandLimit->hide();
103102
}
104103
break;
105-
case 1:
104+
case StepExtend:
106105

107106
QgsMapLayer *currentLayer = mCanvas->currentLayer();
108107
if ( !currentLayer )
109108
break;
110109

111-
vlayer = qobject_cast<QgsVectorLayer *>( currentLayer );
112-
if ( !vlayer )
110+
mVlayer = qobject_cast<QgsVectorLayer *>( currentLayer );
111+
if ( !mVlayer )
113112
break;
114113

115-
if ( !vlayer->isEditable() )
114+
if ( !mVlayer->isEditable() )
116115
break;
117116

118-
filter.setLayer( vlayer );
119-
match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );
117+
filter.setLayer( mVlayer );
118+
match = mCanvas->snappingUtils()->snapToMap( mMapPoint, &filter );
120119

121120
if ( match.isValid() )
122121
{
123-
if ( match.layer() != vlayer )
122+
if ( match.layer() != mVlayer )
124123
break;
125124

126125
QgsPointXY p1, p2;
@@ -132,34 +131,35 @@ void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
132131
if ( ( ( pLimit1 == pExtend1 ) || ( pLimit1 == pExtend2 ) ) || ( ( pLimit2 == pExtend1 ) || ( pLimit2 == pExtend2 ) ) )
133132
break;
134133

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

137-
if ( is3DLayer && QgsWkbTypes::hasZ( match.layer()->wkbType() ) )
136+
if ( mIs3DLayer && QgsWkbTypes::hasZ( match.layer()->wkbType() ) )
138137
{
139138
/* Z Interpolation */
140139
QgsLineString line( pLimit1, pLimit2 );
141140

142-
intersection = QgsGeometryUtils::closestPoint( line, QgsPoint( intersection ) );
141+
mIntersection = QgsGeometryUtils::closestPoint( line, QgsPoint( mIntersection ) );
143142
}
144143

145-
if ( isIntersection )
144+
if ( mIsIntersection )
146145
{
147146
mRubberBandIntersection.reset( createRubberBand( QgsWkbTypes::PointGeometry ) );
148-
mRubberBandIntersection->addPoint( QgsPointXY( intersection ) );
147+
mRubberBandIntersection->addPoint( QgsPointXY( mIntersection ) );
149148
mRubberBandIntersection->show();
150149

151150
mRubberBandExtend.reset( createRubberBand( match.layer()->geometryType() ) );
152151

153-
geom = match.layer()->getGeometry( match.featureId() );
152+
mGeom = match.layer()->getGeometry( match.featureId() );
154153
int index = match.vertexIndex();
155154

156-
if ( !segmentIntersects )
155+
if ( !mSegmentIntersects )
157156
{
158-
QgsPoint ptInter( intersection.x(), intersection.y() );
157+
QgsPoint ptInter( mIntersection.x(), mIntersection.y() );
159158
if ( pExtend2.distance( ptInter ) < pExtend1.distance( ptInter ) )
160159
index += 1;
161160
}
162-
else // TRIM PART
161+
// TRIM PART
162+
else if ( QgsGeometryUtils::leftOfLine( QgsPoint( mMapPoint ), pLimit1, pLimit2 ) != QgsGeometryUtils::leftOfLine( pExtend1, pLimit1, pLimit2 ) )
163163
{
164164
// Part where the mouse is (+) will be trimed
165165
/* |
@@ -177,15 +177,14 @@ void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
177177
* +
178178
* |
179179
*/
180-
if ( QgsGeometryUtils::leftOfLine( QgsPoint( mapPoint ), pLimit1, pLimit2 ) != QgsGeometryUtils::leftOfLine( pExtend1, pLimit1, pLimit2 ) )
181180
index += 1;
182181
}
183182

184-
isModified = geom.moveVertex( intersection, index );
183+
mIsModified = mGeom.moveVertex( mIntersection, index );
185184

186-
if ( isModified )
185+
if ( mIsModified )
187186
{
188-
mRubberBandExtend->setToGeometry( geom );
187+
mRubberBandExtend->setToGeometry( mGeom );
189188
mRubberBandExtend->show();
190189
}
191190
}
@@ -210,31 +209,31 @@ void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
210209

211210
void QgsMapToolTrimExtendFeature::canvasReleaseEvent( QgsMapMouseEvent *e )
212211
{
213-
mapPoint = e->mapPoint();
212+
mMapPoint = e->mapPoint();
214213

215214
FeatureFilter filter;
216215
QgsPointLocator::Match match;
217216

218217
if ( e->button() == Qt::LeftButton )
219218
{
220-
switch ( step )
219+
switch ( mStep )
221220
{
222-
case 0:
223-
match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );
221+
case StepLimit:
222+
match = mCanvas->snappingUtils()->snapToMap( mMapPoint, &filter );
224223
if ( mRubberBandLimit && mRubberBandLimit->isVisible() )
225224
{
226225
getPoints( match, pLimit1, pLimit2 );
227-
step += 1;
226+
mStep += 1;
228227
}
229228
break;
230-
case 1:
231-
if ( isModified )
229+
case StepExtend:
230+
if ( mIsModified )
232231
{
233-
filter.setLayer( vlayer );
234-
match = mCanvas->snappingUtils()->snapToMap( mapPoint, &filter );
232+
filter.setLayer( mVlayer );
233+
match = mCanvas->snappingUtils()->snapToMap( mMapPoint, &filter );
235234

236235
match.layer()->beginEditCommand( tr( "Trim/Extend feature" ) );
237-
match.layer()->changeGeometry( match.featureId(), geom );
236+
match.layer()->changeGeometry( match.featureId(), mGeom );
238237
match.layer()->endEditCommand();
239238
match.layer()->triggerRepaint();
240239

@@ -270,11 +269,11 @@ void QgsMapToolTrimExtendFeature::keyPressEvent( QKeyEvent *e )
270269

271270
void QgsMapToolTrimExtendFeature::deactivate()
272271
{
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;
278277
mRubberBandLimit.reset();
279278
mRubberBandExtend.reset();
280279
mRubberBandIntersection.reset();

src/app/qgsmaptooltrimextendfeature.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***************************************************************************
2-
qgmaptoolextendfeature.h - map tool for extending feature
2+
qgmaptooltrimextendfeature.h - map tool to trim or extend feature
33
---------------------
44
begin : October 2018
55
copyright : (C) 2018 by Loïc Bartoletti
@@ -51,23 +51,28 @@ class APP_EXPORT QgsMapToolTrimExtendFeature : public QgsMapToolEdit
5151
//! Points for extend
5252
QgsPoint pExtend1, pExtend2;
5353
//! intersection point between the projection of [pExtend1 - pExtend2] on [pLimit1 - pLimit2]
54-
QgsPoint intersection;
54+
QgsPoint mIntersection;
5555
//! map point used to determine which edges will be used for trim the feature
56-
QgsPointXY mapPoint;
56+
QgsPointXY mMapPoint;
5757
//! geometry that will be returned
58-
QgsGeometry geom;
58+
QgsGeometry mGeom;
5959
//! Current layer which will be modified
60-
QgsVectorLayer *vlayer = nullptr;
60+
QgsVectorLayer *mVlayer = nullptr;
6161
//! Keep information about the state of the intersection
62-
bool isIntersection = false;
62+
bool mIsIntersection = false;
6363
//! Keep information of the first layer snapped is 3D or not
64-
bool is3DLayer = false;
64+
bool mIs3DLayer = false;
6565
//! if feature is modified
66-
bool isModified = false;
66+
bool mIsModified = false;
6767
//! if the segments are intersected = trim
68-
bool segmentIntersects = false;
68+
bool mSegmentIntersects = false;
69+
enum Step
70+
{
71+
StepLimit,
72+
StepExtend,
73+
};
6974
//! The first step (0): choose the limit. The second step (1): choose the segment to trim/extend
70-
int step = 0;
75+
int mStep = StepLimit;
7176
};
7277

7378
#endif // QGSMAPTOOLTRIMEXTENDFEATURE_H

src/core/geometry/qgsgeometryutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ QVector<QgsGeometryUtils::SelfIntersection> QgsGeometryUtils::selfIntersections(
529529
return intersections;
530530
}
531531

532-
int QgsGeometryUtils::leftOfLine( const QgsPoint point, const QgsPoint p1, const QgsPoint p2 )
532+
int QgsGeometryUtils::leftOfLine( const QgsPoint &point, const QgsPoint &p1, const QgsPoint &p2 )
533533
{
534534
return leftOfLine( point.x(), point.y(), p1.x(), p1.y(), p2.x(), p2.y() );
535535
}

src/core/geometry/qgsgeometryutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class CORE_EXPORT QgsGeometryUtils
255255
*
256256
* \since QGIS 3.6
257257
*/
258-
static int leftOfLine( const QgsPoint point, const QgsPoint p1, const QgsPoint p2 );
258+
static int leftOfLine(const QgsPoint &point, const QgsPoint &p1, const QgsPoint &p2 );
259259

260260
/**
261261
* Returns a point a specified \a distance toward a second point.

0 commit comments

Comments
 (0)