Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix rectangle from 3 points
Fixes #35043, fixes #35671

The initial version of this class presupposed the possibility of constructing a rectangle by 3 points where each point had a  Z. Very useful to make 3D plans, but this is not always what we want...
  • Loading branch information
lbartoletti committed May 19, 2020
1 parent e6fef7a commit 8249dcc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/app/qgsmaptooladdrectangle.cpp
Expand Up @@ -93,6 +93,7 @@ void QgsMapToolAddRectangle::deactivate( )
}

mParentTool->clearCurve( );

// keep z value from the first snapped point
std::unique_ptr<QgsLineString> lineString( mRectangle.toLineString() );
for ( const QgsPoint &point : qgis::as_const( mPoints ) )
Expand Down
25 changes: 19 additions & 6 deletions src/app/qgsmaptoolrectangle3points.cpp
Expand Up @@ -46,8 +46,14 @@ void QgsMapToolRectangle3Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )

if ( e->button() == Qt::LeftButton )
{
if ( !point.is3D() )
bool is3D = false;
QgsVectorLayer *currentLayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( currentLayer )
is3D = QgsWkbTypes::hasZ( currentLayer->wkbType() );

if ( is3D && !point.is3D() )
point.addZValue( defaultZValue() );

if ( mPoints.size() < 2 )
{
mPoints.append( point );
Expand Down Expand Up @@ -86,12 +92,18 @@ void QgsMapToolRectangle3Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
line->addVertex( mPoints.at( 0 ) );
line->addVertex( point );
mTempRubberBand->setGeometry( line.release() );
break;
}
break;
case 2:
{
if ( !point.is3D() )
bool is3D = false;
QgsVectorLayer *currentLayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( currentLayer )
is3D = QgsWkbTypes::hasZ( currentLayer->wkbType() );

if ( is3D && !point.is3D() )
point.addZValue( defaultZValue() );

switch ( mCreateMode )
{
case DistanceMode:
Expand All @@ -101,10 +113,11 @@ void QgsMapToolRectangle3Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
mRectangle = QgsQuadrilateral::rectangleFrom3Points( mPoints.at( 0 ), mPoints.at( 1 ), point, QgsQuadrilateral::Projected );
break;
}

mTempRubberBand->setGeometry( mRectangle.toPolygon() );
break;
mTempRubberBand->setGeometry( mRectangle.toPolygon( ) );
}
break;
default:
break;
}
}
}

0 comments on commit 8249dcc

Please sign in to comment.