Skip to content

Commit 4c6d03c

Browse files
committed
Add Z support for AddRectangle map tools
1 parent 79cdaa6 commit 4c6d03c

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

src/app/qgsmaptooladdrectangle.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ void QgsMapToolAddRectangle::keyReleaseEvent( QKeyEvent *e )
8484
QgsLineString *QgsMapToolAddRectangle::rectangleToLinestring( const bool isOriented ) const
8585
{
8686
std::unique_ptr<QgsLineString> ext( new QgsLineString() );
87-
if ( mRectangle.isEmpty() )
87+
if ( mRectangle.toRectangle().isEmpty() )
8888
{
8989
return ext.release();
9090
}
9191

92-
QgsPoint x0( mRectangle.xMinimum(), mRectangle.yMinimum() );
92+
QgsPoint x0( mRectangle.xMinimum(), mRectangle.yMinimum(), mRectangle.zMinimum() );
9393

9494
QgsPoint x1, x2, x3;
9595
if ( isOriented )
@@ -101,10 +101,11 @@ QgsLineString *QgsMapToolAddRectangle::rectangleToLinestring( const bool isOrien
101101
}
102102
else
103103
{
104-
x1 = QgsPoint( mRectangle.xMinimum(), mRectangle.yMaximum() );
105-
x2 = QgsPoint( mRectangle.xMaximum(), mRectangle.yMaximum() );
106-
x3 = QgsPoint( mRectangle.xMaximum(), mRectangle.yMinimum() );
104+
x1 = QgsPoint( mRectangle.xMinimum(), mRectangle.yMaximum(), mRectangle.zMinimum() );
105+
x2 = QgsPoint( mRectangle.xMaximum(), mRectangle.yMaximum(), mRectangle.zMinimum() );
106+
x3 = QgsPoint( mRectangle.xMaximum(), mRectangle.yMinimum(), mRectangle.zMinimum() );
107107
}
108+
108109
ext->addVertex( x0 );
109110
ext->addVertex( x1 );
110111
ext->addVertex( x2 );
@@ -117,7 +118,7 @@ QgsLineString *QgsMapToolAddRectangle::rectangleToLinestring( const bool isOrien
117118
QgsPolygon *QgsMapToolAddRectangle::rectangleToPolygon( const bool isOriented ) const
118119
{
119120
std::unique_ptr<QgsPolygon> polygon( new QgsPolygon() );
120-
if ( mRectangle.isEmpty() )
121+
if ( mRectangle.toRectangle().isEmpty() )
121122
{
122123
return polygon.release();
123124
}
@@ -129,7 +130,7 @@ QgsPolygon *QgsMapToolAddRectangle::rectangleToPolygon( const bool isOriented )
129130

130131
void QgsMapToolAddRectangle::deactivate( const bool isOriented )
131132
{
132-
if ( !mParentTool || mRectangle.isEmpty() )
133+
if ( !mParentTool || mRectangle.toRectangle().isEmpty() )
133134
{
134135
return;
135136
}
@@ -162,5 +163,5 @@ void QgsMapToolAddRectangle::clean()
162163
mParentTool->deleteTempRubberBand();
163164
}
164165

165-
mRectangle = QgsRectangle();
166+
mRectangle = QgsBox3d();
166167
}

src/app/qgsmaptooladdrectangle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#define QGSMAPTOOLADDRECTANGLE_H
1818

1919
#include "qgspolygon.h"
20-
#include "qgsrectangle.h"
2120
#include "qgsmaptoolcapture.h"
21+
#include "qgsbox3d.h"
2222

2323
class QgsPolygon;
2424

@@ -51,7 +51,7 @@ class QgsMapToolAddRectangle: public QgsMapToolCapture
5151
//! The rubberband to show the rectangle currently working on
5252
QgsGeometryRubberBand *mTempRubberBand = nullptr;
5353
//! Rectangle
54-
QgsRectangle mRectangle;
54+
QgsBox3d mRectangle;
5555

5656
//! Convenient method to export a QgsRectangle to a LineString
5757
QgsLineString *rectangleToLinestring( const bool isOriented = false ) const;

src/app/qgsmaptoolrectangle3points.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ QgsMapToolRectangle3Points::QgsMapToolRectangle3Points( QgsMapToolCapture *paren
3131

3232
void QgsMapToolRectangle3Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
3333
{
34-
QgsPoint mapPoint( e->mapPoint() );
34+
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
3535

3636
if ( e->button() == Qt::LeftButton )
3737
{
@@ -56,7 +56,7 @@ void QgsMapToolRectangle3Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
5656

5757
void QgsMapToolRectangle3Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
5858
{
59-
QgsPoint mapPoint( e->mapPoint() );
59+
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
6060

6161
if ( mTempRubberBand )
6262
{
@@ -82,14 +82,15 @@ void QgsMapToolRectangle3Points::cadCanvasMoveEvent( QgsMapMouseEvent *e )
8282

8383
setSide( side < 0 ? -1 : 1 );
8484

85-
double xMin = mPoints.at( 0 ).x();
86-
double xMax = mPoints.at( 0 ).x() + distance2( );
85+
const double xMin = mPoints.at( 0 ).x();
86+
const double xMax = mPoints.at( 0 ).x() + distance2( );
8787

88-
double yMin = mPoints.at( 0 ).y();
89-
double yMax = mPoints.at( 0 ).y() + distance1();
88+
const double yMin = mPoints.at( 0 ).y();
89+
const double yMax = mPoints.at( 0 ).y() + distance1();
9090

91-
mRectangle = QgsRectangle( xMin, yMin,
92-
xMax, yMax );
91+
const double z = mPoints.at( 0 ).z();
92+
93+
mRectangle = QgsBox3d( xMin, yMin, z, xMax, yMax, z );
9394

9495

9596
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon( true ) );

src/app/qgsmaptoolrectanglecenter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ QgsMapToolRectangleCenter::QgsMapToolRectangleCenter( QgsMapToolCapture *parentT
3131

3232
void QgsMapToolRectangleCenter::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
3333
{
34-
QgsPoint mapPoint( e->mapPoint() );
34+
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
3535

3636
if ( e->button() == Qt::LeftButton )
3737
{
@@ -55,7 +55,7 @@ void QgsMapToolRectangleCenter::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
5555

5656
void QgsMapToolRectangleCenter::cadCanvasMoveEvent( QgsMapMouseEvent *e )
5757
{
58-
QgsPoint mapPoint( e->mapPoint() );
58+
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
5959

6060
if ( mTempRubberBand )
6161
{
@@ -68,7 +68,7 @@ void QgsMapToolRectangleCenter::cadCanvasMoveEvent( QgsMapMouseEvent *e )
6868
double xOffset = fabs( mapPoint.x() - mPoints.at( 0 ).x() );
6969
double yOffset = fabs( mapPoint.y() - mPoints.at( 0 ).y() );
7070

71-
mRectangle = QgsRectangle( QgsPoint( mPoints.at( 0 ).x() - xOffset, mPoints.at( 0 ).y() - yOffset ), QgsPoint( mPoints.at( 0 ).x() + xOffset, mPoints.at( 0 ).y() + yOffset ) );
71+
mRectangle = QgsBox3d( QgsPoint( mPoints.at( 0 ).x() - xOffset, mPoints.at( 0 ).y() - yOffset, mPoints.at( 0 ).z() ), QgsPoint( mPoints.at( 0 ).x() + xOffset, mPoints.at( 0 ).y() + yOffset, mPoints.at( 0 ).z() ) );
7272

7373
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon() );
7474
}
@@ -77,7 +77,7 @@ void QgsMapToolRectangleCenter::cadCanvasMoveEvent( QgsMapMouseEvent *e )
7777
double dist = mPoints.at( 0 ).distance( mapPoint );
7878
double angle = mPoints.at( 0 ).azimuth( mapPoint );
7979

80-
mRectangle = QgsRectangle( mPoints.at( 0 ).project( -dist, angle ), mPoints.at( 0 ).project( dist, angle ) );
80+
mRectangle = QgsBox3d( mPoints.at( 0 ).project( -dist, angle ), mPoints.at( 0 ).project( dist, angle ) );
8181
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon() );
8282
}
8383
}

src/app/qgsmaptoolrectangleextent.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ QgsMapToolRectangleExtent::QgsMapToolRectangleExtent( QgsMapToolCapture *parentT
3131

3232
void QgsMapToolRectangleExtent::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
3333
{
34-
QgsPoint mapPoint( e->mapPoint() );
34+
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
3535

3636
if ( e->button() == Qt::LeftButton )
3737
{
@@ -55,7 +55,7 @@ void QgsMapToolRectangleExtent::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
5555

5656
void QgsMapToolRectangleExtent::cadCanvasMoveEvent( QgsMapMouseEvent *e )
5757
{
58-
QgsPoint mapPoint( e->mapPoint() );
58+
QgsPoint mapPoint = fromPointXY( e->mapPoint() );
5959

6060
if ( mTempRubberBand )
6161
{
@@ -65,15 +65,15 @@ void QgsMapToolRectangleExtent::cadCanvasMoveEvent( QgsMapMouseEvent *e )
6565
{
6666
if ( qgsDoubleNear( mCanvas->rotation(), 0.0 ) )
6767
{
68-
mRectangle = QgsRectangle( mPoints.at( 0 ), mapPoint );
68+
mRectangle = QgsBox3d( mPoints.at( 0 ), mapPoint );
6969
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon( ) );
7070
}
7171
else
7272
{
7373
double dist = mPoints.at( 0 ).distance( mapPoint );
7474
double angle = mPoints.at( 0 ).azimuth( mapPoint );
7575

76-
mRectangle = QgsRectangle( mPoints.at( 0 ), mPoints.at( 0 ).project( dist, angle ) );
76+
mRectangle = QgsBox3d( mPoints.at( 0 ), mPoints.at( 0 ).project( dist, angle ) );
7777
mTempRubberBand->setGeometry( QgsMapToolAddRectangle::rectangleToPolygon() );
7878
}
7979
}

0 commit comments

Comments
 (0)