mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-10 00:13:55 -04:00
avoid potential crash
This commit is contained in:
parent
57a9155d27
commit
cf081140d1
@ -54,18 +54,25 @@ QgsMapToolTrimExtendFeature::QgsMapToolTrimExtendFeature( QgsMapCanvas *canvas )
|
||||
mToolName = tr( "Trim/Extend feature" );
|
||||
}
|
||||
|
||||
static void getPoints( const QgsPointLocator::Match &match, QgsPoint &p1, QgsPoint &p2 )
|
||||
static bool getPoints( const QgsPointLocator::Match &match, QgsPoint &p1, QgsPoint &p2 )
|
||||
{
|
||||
bool ret = false;
|
||||
const QgsFeatureId fid = match.featureId();
|
||||
const int vertex = match.vertexIndex();
|
||||
|
||||
const QgsGeometry geom = match.layer()->getGeometry( fid );
|
||||
|
||||
if ( !( geom.isNull() || geom.isEmpty() ) )
|
||||
if ( match.layer() )
|
||||
{
|
||||
p1 = geom.vertexAt( vertex );
|
||||
p2 = geom.vertexAt( vertex + 1 );
|
||||
const QgsGeometry geom = match.layer()->getGeometry( fid );
|
||||
|
||||
if ( !( geom.isNull() || geom.isEmpty() ) )
|
||||
{
|
||||
p1 = geom.vertexAt( vertex );
|
||||
p2 = geom.vertexAt( vertex + 1 );
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
|
||||
@ -122,7 +129,8 @@ void QgsMapToolTrimExtendFeature::canvasMoveEvent( QgsMapMouseEvent *e )
|
||||
QgsPointXY p1, p2;
|
||||
match.edgePoints( p1, p2 );
|
||||
|
||||
getPoints( match, pExtend1, pExtend2 );
|
||||
if ( !getPoints( match, pExtend1, pExtend2 ) )
|
||||
break;
|
||||
|
||||
// No need to trim/extend if segments are continuous
|
||||
if ( ( ( pLimit1 == pExtend1 ) || ( pLimit1 == pExtend2 ) ) || ( ( pLimit2 == pExtend1 ) || ( pLimit2 == pExtend2 ) ) )
|
||||
@ -219,9 +227,11 @@ void QgsMapToolTrimExtendFeature::canvasReleaseEvent( QgsMapMouseEvent *e )
|
||||
match = mCanvas->snappingUtils()->snapToMap( mMapPoint, &filter );
|
||||
if ( mRubberBandLimit && mRubberBandLimit->isVisible() )
|
||||
{
|
||||
getPoints( match, pLimit1, pLimit2 );
|
||||
mStep = StepExtend;
|
||||
mLimitLayer = match.layer();
|
||||
if ( getPoints( match, pLimit1, pLimit2 ) )
|
||||
{
|
||||
mStep = StepExtend;
|
||||
mLimitLayer = match.layer();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case StepExtend:
|
||||
@ -230,14 +240,18 @@ void QgsMapToolTrimExtendFeature::canvasReleaseEvent( QgsMapMouseEvent *e )
|
||||
filter.setLayer( mVlayer );
|
||||
match = mCanvas->snappingUtils()->snapToMap( mMapPoint, &filter );
|
||||
|
||||
match.layer()->beginEditCommand( tr( "Trim/Extend feature" ) );
|
||||
match.layer()->changeGeometry( match.featureId(), mGeom );
|
||||
match.layer()->addTopologicalPoints( mIntersection );
|
||||
mLimitLayer->addTopologicalPoints( mIntersection );
|
||||
match.layer()->endEditCommand();
|
||||
match.layer()->triggerRepaint();
|
||||
if ( match.layer() )
|
||||
{
|
||||
|
||||
emit messageEmitted( tr( "Feature trimmed/extended." ) );
|
||||
match.layer()->beginEditCommand( tr( "Trim/Extend feature" ) );
|
||||
match.layer()->changeGeometry( match.featureId(), mGeom );
|
||||
match.layer()->addTopologicalPoints( mIntersection );
|
||||
mLimitLayer->addTopologicalPoints( mIntersection );
|
||||
match.layer()->endEditCommand();
|
||||
match.layer()->triggerRepaint();
|
||||
|
||||
emit messageEmitted( tr( "Feature trimmed/extended." ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -278,5 +292,7 @@ void QgsMapToolTrimExtendFeature::deactivate()
|
||||
mRubberBandExtend.reset();
|
||||
mRubberBandIntersection.reset();
|
||||
QgsMapTool::deactivate();
|
||||
mVlayer = nullptr;
|
||||
mLimitLayer = nullptr;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user