Skip to content
Permalink
Browse files

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 8249dccfddda5963e12c4d63f96b51937227eb7e
Showing with 20 additions and 6 deletions.
  1. +1 −0 src/app/qgsmaptooladdrectangle.cpp
  2. +19 −6 src/app/qgsmaptoolrectangle3points.cpp
@@ -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 ) )
@@ -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 );
@@ -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:
@@ -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.
You can’t perform that action at this time.