Skip to content

Commit 6036fa6

Browse files
committedJul 31, 2017
clean
1 parent fbdf77d commit 6036fa6

13 files changed

+428
-69
lines changed
 

‎python/core/geometry/qgsrectangle.sip

Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/geometry/qgsrectangle.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
14+
class QgsRectangle
15+
{
16+
%Docstring
17+
A rectangle specified with double values.
18+
19+
QgsRectangle is used to store a rectangle when double values are required.
20+
Examples are storing a layer extent or the current view extent of a map
21+
.. seealso:: QgsBox3d
22+
%End
23+
24+
%TypeHeaderCode
25+
#include "qgsrectangle.h"
26+
%End
27+
public:
28+
QgsRectangle( double xMin = 0, double yMin = 0, double xMax = 0, double yMax = 0 );
29+
%Docstring
30+
Constructor
31+
%End
32+
QgsRectangle( const QgsPointXY &p1, const QgsPointXY &p2 );
33+
%Docstring
34+
Construct a rectangle from two points. The rectangle is normalized after construction.
35+
%End
36+
QgsRectangle( const QRectF &qRectF );
37+
%Docstring
38+
Construct a rectangle from a QRectF. The rectangle is normalized after construction.
39+
%End
40+
QgsRectangle( const QgsRectangle &other );
41+
%Docstring
42+
Copy constructor
43+
%End
44+
45+
void set( const QgsPointXY &p1, const QgsPointXY &p2 );
46+
%Docstring
47+
Sets the rectangle from two QgsPoints. The rectangle is
48+
normalised after construction.
49+
%End
50+
51+
void set( double mXmin, double mYmin, double mXmax, double mYmax );
52+
%Docstring
53+
Sets the rectangle from four points. The rectangle is
54+
normalised after construction.
55+
%End
56+
57+
void setXMinimum( double x );
58+
%Docstring
59+
Set the minimum x value.
60+
%End
61+
62+
void setXMaximum( double x );
63+
%Docstring
64+
Set the maximum x value.
65+
%End
66+
67+
void setYMinimum( double y );
68+
%Docstring
69+
Set the minimum y value.
70+
%End
71+
72+
void setYMaximum( double y );
73+
%Docstring
74+
Set the maximum y value.
75+
%End
76+
77+
void setMinimal();
78+
%Docstring
79+
Set a rectangle so that min corner is at max
80+
and max corner is at min. It is NOT normalized.
81+
%End
82+
83+
double xMaximum() const;
84+
%Docstring
85+
Returns the x maximum value (right side of rectangle).
86+
:rtype: float
87+
%End
88+
89+
double xMinimum() const;
90+
%Docstring
91+
Returns the x minimum value (left side of rectangle).
92+
:rtype: float
93+
%End
94+
95+
double yMaximum() const;
96+
%Docstring
97+
Returns the y maximum value (top side of rectangle).
98+
:rtype: float
99+
%End
100+
101+
double yMinimum() const;
102+
%Docstring
103+
Returns the y minimum value (bottom side of rectangle).
104+
:rtype: float
105+
%End
106+
107+
void normalize();
108+
%Docstring
109+
Normalize the rectangle so it has non-negative width/height.
110+
%End
111+
112+
double width() const;
113+
%Docstring
114+
Returns the width of the rectangle.
115+
.. seealso:: height()
116+
.. seealso:: area()
117+
:rtype: float
118+
%End
119+
120+
double height() const;
121+
%Docstring
122+
Returns the height of the rectangle.
123+
.. seealso:: width()
124+
.. seealso:: area()
125+
:rtype: float
126+
%End
127+
128+
double area() const;
129+
%Docstring
130+
Returns the area of the rectangle.
131+
.. versionadded:: 3.0
132+
.. seealso:: width()
133+
.. seealso:: height()
134+
.. seealso:: perimeter()
135+
:rtype: float
136+
%End
137+
138+
double perimeter() const;
139+
%Docstring
140+
Returns the perimeter of the rectangle.
141+
.. versionadded:: 3.0
142+
.. seealso:: area()
143+
:rtype: float
144+
%End
145+
146+
QgsPointXY center() const;
147+
%Docstring
148+
Returns the center point of the rectangle.
149+
:rtype: QgsPointXY
150+
%End
151+
152+
void scale( double scaleFactor, const QgsPointXY *c = 0 );
153+
%Docstring
154+
Scale the rectangle around its center point.
155+
%End
156+
157+
void scale( double scaleFactor, double centerX, double centerY );
158+
%Docstring
159+
Scale the rectangle around its center point.
160+
%End
161+
162+
void grow( double delta );
163+
%Docstring
164+
Grows the rectangle by the specified amount.
165+
%End
166+
167+
void include( const QgsPointXY &p );
168+
%Docstring
169+
Updates the rectangle to include the specified point.
170+
%End
171+
172+
QgsRectangle buffer( double width );
173+
%Docstring
174+
Get rectangle enlarged by buffer.
175+
.. versionadded:: 2.1
176+
:rtype: QgsRectangle
177+
%End
178+
179+
QgsRectangle intersect( const QgsRectangle *rect ) const;
180+
%Docstring
181+
Return the intersection with the given rectangle.
182+
:rtype: QgsRectangle
183+
%End
184+
185+
bool intersects( const QgsRectangle &rect ) const;
186+
%Docstring
187+
Returns true when rectangle intersects with other rectangle.
188+
:rtype: bool
189+
%End
190+
191+
bool contains( const QgsRectangle &rect ) const;
192+
%Docstring
193+
Return true when rectangle contains other rectangle.
194+
:rtype: bool
195+
%End
196+
197+
bool contains( const QgsPointXY &p ) const;
198+
%Docstring
199+
Return true when rectangle contains a point.
200+
:rtype: bool
201+
%End
202+
203+
void combineExtentWith( const QgsRectangle &rect );
204+
%Docstring
205+
Expand the rectangle so that covers both the original rectangle and the given rectangle.
206+
%End
207+
208+
void combineExtentWith( double x, double y );
209+
%Docstring
210+
Expand the rectangle so that covers both the original rectangle and the given point.
211+
%End
212+
213+
QgsRectangle operator-( const QgsVector v ) const;
214+
%Docstring
215+
Returns a rectangle offset from this one in the direction of the reversed vector.
216+
.. versionadded:: 3.0
217+
:rtype: QgsRectangle
218+
%End
219+
220+
QgsRectangle operator+( const QgsVector v ) const;
221+
%Docstring
222+
Returns a rectangle offset from this one in the direction of the vector.
223+
.. versionadded:: 3.0
224+
:rtype: QgsRectangle
225+
%End
226+
227+
QgsRectangle &operator-=( const QgsVector v );
228+
%Docstring
229+
Moves this rectangle in the direction of the reversed vector.
230+
.. versionadded:: 3.0
231+
:rtype: QgsRectangle
232+
%End
233+
234+
QgsRectangle &operator+=( const QgsVector v );
235+
%Docstring
236+
Moves this rectangle in the direction of the vector.
237+
.. versionadded:: 3.0
238+
:rtype: QgsRectangle
239+
%End
240+
241+
bool isEmpty() const;
242+
%Docstring
243+
Returns true if the rectangle is empty.
244+
An empty rectangle may still be non-null if it contains valid information (e.g. bounding box of a point).
245+
:rtype: bool
246+
%End
247+
248+
bool isNull() const;
249+
%Docstring
250+
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
251+
A null rectangle is also an empty rectangle.
252+
.. versionadded:: 2.4
253+
:rtype: bool
254+
%End
255+
256+
QString asWktCoordinates() const;
257+
%Docstring
258+
Returns a string representation of the rectangle in WKT format.
259+
:rtype: str
260+
%End
261+
262+
QString asWktPolygon() const;
263+
%Docstring
264+
Returns a string representation of the rectangle as a WKT Polygon.
265+
:rtype: str
266+
%End
267+
268+
QRectF toRectF() const;
269+
%Docstring
270+
Returns a QRectF with same coordinates as the rectangle.
271+
:rtype: QRectF
272+
%End
273+
274+
QString toString( int precision = 16 ) const;
275+
%Docstring
276+
Returns a string representation of form xmin,ymin : xmax,ymax
277+
Coordinates will be truncated to the specified precision.
278+
If the specified precision is less than 0, a suitable minimum precision is used.
279+
:rtype: str
280+
%End
281+
282+
QString asPolygon() const;
283+
%Docstring
284+
Returns the rectangle as a polygon.
285+
:rtype: str
286+
%End
287+
288+
bool operator==( const QgsRectangle &r1 ) const;
289+
290+
bool operator!=( const QgsRectangle &r1 ) const;
291+
%Docstring
292+
Comparison operator
293+
:return: False if rectangles are equal
294+
:rtype: bool
295+
%End
296+
297+
298+
bool isFinite() const;
299+
%Docstring
300+
Returns true if the rectangle has finite boundaries. Will
301+
return false if any of the rectangle boundaries are NaN or Inf.
302+
:rtype: bool
303+
%End
304+
305+
void invert();
306+
%Docstring
307+
Swap x/y coordinates in the rectangle.
308+
%End
309+
310+
QgsBox3d toBox3d( double zMin, double zMax ) const;
311+
%Docstring
312+
Converts the rectangle to a 3D box, with the specified
313+
``zMin`` and ``zMax`` z values.
314+
.. versionadded:: 3.0
315+
:rtype: QgsBox3d
316+
%End
317+
318+
};
319+
320+
321+
/************************************************************************
322+
* This file has been generated automatically from *
323+
* *
324+
* src/core/geometry/qgsrectangle.h *
325+
* *
326+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
327+
************************************************************************/

‎python/gui/qgsmaptoolcapture.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Adds a whole curve (e.g. circularstring) to the captured geometry. Curve must be
3434
:rtype: int
3535
%End
3636

37+
void clearCurve( );
38+
%Docstring
39+
Clear capture curve.
40+
41+
.. versionadded:: 3.0
42+
%End
43+
3744
const QgsCompoundCurve *captureCurve() const;
3845
%Docstring
3946
Get the capture curve

‎src/app/qgsmaptooladdcircle.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ QgsMapToolAddCircle::QgsMapToolAddCircle( QgsMapToolCapture *parentTool, QgsMapC
2929
, mTempRubberBand( nullptr )
3030
, mCircle( QgsCircle() )
3131
{
32+
clean();
3233
if ( mCanvas )
3334
{
3435
connect( mCanvas, &QgsMapCanvas::mapToolSet, this, &QgsMapToolAddCircle::setParentTool );
@@ -41,6 +42,7 @@ QgsMapToolAddCircle::QgsMapToolAddCircle( QgsMapCanvas *canvas )
4142
, mTempRubberBand( nullptr )
4243
, mCircle( QgsCircle() )
4344
{
45+
clean();
4446
if ( mCanvas )
4547
{
4648
connect( mCanvas, &QgsMapCanvas::mapToolSet, this, &QgsMapToolAddCircle::setParentTool );
@@ -49,18 +51,11 @@ QgsMapToolAddCircle::QgsMapToolAddCircle( QgsMapCanvas *canvas )
4951

5052
QgsMapToolAddCircle::~QgsMapToolAddCircle()
5153
{
52-
delete mTempRubberBand;
53-
mPoints.clear();
54+
clean();
5455
}
5556

5657
void QgsMapToolAddCircle::setParentTool( QgsMapTool *newTool, QgsMapTool *oldTool )
5758
{
58-
if ( mTempRubberBand )
59-
{
60-
delete mTempRubberBand;
61-
mTempRubberBand = nullptr;
62-
}
63-
mPoints.clear();
6459
QgsMapToolCapture *tool = dynamic_cast<QgsMapToolCapture *>( oldTool );
6560
QgsMapToolAddCircle *csTool = dynamic_cast<QgsMapToolAddCircle *>( oldTool );
6661
if ( csTool && newTool == this )
@@ -82,9 +77,7 @@ void QgsMapToolAddCircle::keyPressEvent( QKeyEvent *e )
8277

8378
if ( e && e->key() == Qt::Key_Escape )
8479
{
85-
mPoints.clear();
86-
delete mTempRubberBand;
87-
mTempRubberBand = nullptr;
80+
clean();
8881
if ( mParentTool )
8982
mParentTool->keyPressEvent( e );
9083
}
@@ -105,22 +98,29 @@ void QgsMapToolAddCircle::deactivate()
10598
return;
10699
}
107100

101+
mParentTool->clearCurve();
108102
mParentTool->addCurve( mCircle.toCircularString() );
103+
clean();
109104

110-
delete mTempRubberBand;
111-
mTempRubberBand = nullptr;
112-
mPoints.clear();
113-
mCircle = QgsCircle();
114105
QgsMapToolCapture::deactivate();
115106
}
116107

117108
void QgsMapToolAddCircle::activate()
118109
{
119-
mPoints.clear();
110+
clean();
111+
QgsMapToolCapture::activate();
112+
}
120113

114+
void QgsMapToolAddCircle::clean()
115+
{
116+
if ( mTempRubberBand )
117+
{
118+
delete mTempRubberBand;
119+
mTempRubberBand = nullptr;
120+
}
121+
mPoints.clear();
121122
if ( mParentTool )
122123
{
123124
mParentTool->deleteTempRubberBand();
124125
}
125-
QgsMapToolCapture::activate();
126126
}

‎src/app/qgsmaptooladdcircle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class QgsGeometryRubberBand;
2323
class QgsMapToolAddCircle: public QgsMapToolCapture
2424
{
2525
Q_OBJECT
26+
void clean();
2627
public:
2728
QgsMapToolAddCircle( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );
2829
~QgsMapToolAddCircle();

‎src/app/qgsmaptooladdellipse.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ QgsMapToolAddEllipse::QgsMapToolAddEllipse( QgsMapToolCapture *parentTool, QgsMa
2929
, mTempRubberBand( nullptr )
3030
, mEllipse( QgsEllipse() )
3131
{
32+
clean();
3233
if ( mCanvas )
3334
{
3435
connect( mCanvas, &QgsMapCanvas::mapToolSet, this, &QgsMapToolAddEllipse::setParentTool );
@@ -41,6 +42,7 @@ QgsMapToolAddEllipse::QgsMapToolAddEllipse( QgsMapCanvas *canvas )
4142
, mTempRubberBand( nullptr )
4243
, mEllipse( QgsEllipse() )
4344
{
45+
clean();
4446
if ( mCanvas )
4547
{
4648
connect( mCanvas, &QgsMapCanvas::mapToolSet, this, &QgsMapToolAddEllipse::setParentTool );
@@ -49,8 +51,7 @@ QgsMapToolAddEllipse::QgsMapToolAddEllipse( QgsMapCanvas *canvas )
4951

5052
QgsMapToolAddEllipse::~QgsMapToolAddEllipse()
5153
{
52-
delete mTempRubberBand;
53-
mPoints.clear();
54+
clean();
5455
}
5556

5657
void QgsMapToolAddEllipse::setParentTool( QgsMapTool *newTool, QgsMapTool *oldTool )
@@ -76,9 +77,7 @@ void QgsMapToolAddEllipse::keyPressEvent( QKeyEvent *e )
7677

7778
if ( e && e->key() == Qt::Key_Escape )
7879
{
79-
mPoints.clear();
80-
delete mTempRubberBand;
81-
mTempRubberBand = nullptr;
80+
clean();
8281
if ( mParentTool )
8382
mParentTool->keyPressEvent( e );
8483
}
@@ -99,20 +98,30 @@ void QgsMapToolAddEllipse::deactivate()
9998
return;
10099
}
101100

101+
mParentTool->clearCurve();
102102
mParentTool->addCurve( mEllipse.toLineString() );
103103

104-
delete mTempRubberBand;
105-
mTempRubberBand = nullptr;
106-
mPoints.clear();
107-
mEllipse = QgsEllipse();
104+
clean();
108105
QgsMapToolCapture::deactivate();
109106
}
110107

111108
void QgsMapToolAddEllipse::activate()
112109
{
110+
111+
clean();
112+
QgsMapToolCapture::activate();
113+
}
114+
115+
void QgsMapToolAddEllipse::clean()
116+
{
117+
if ( mTempRubberBand )
118+
{
119+
delete mTempRubberBand;
120+
mTempRubberBand = nullptr;
121+
}
122+
mPoints.clear();
113123
if ( mParentTool )
114124
{
115125
mParentTool->deleteTempRubberBand();
116126
}
117-
QgsMapToolCapture::activate();
118127
}

‎src/app/qgsmaptooladdellipse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class QgsGeometryRubberBand;
2323
class QgsMapToolAddEllipse: public QgsMapToolCapture
2424
{
2525
Q_OBJECT
26+
void clean();
2627
public:
2728
QgsMapToolAddEllipse( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );
2829
~QgsMapToolAddEllipse();

‎src/app/qgsmaptooladdrectangle.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ QgsMapToolAddRectangle::QgsMapToolAddRectangle( QgsMapToolCapture *parentTool, Q
3030
, mTempRubberBand( nullptr )
3131
, mRectangle( QgsRectangle() )
3232
{
33+
clean();
3334
if ( mCanvas )
3435
{
3536
connect( mCanvas, &QgsMapCanvas::mapToolSet, this, &QgsMapToolAddRectangle::setParentTool );
@@ -42,6 +43,7 @@ QgsMapToolAddRectangle::QgsMapToolAddRectangle( QgsMapCanvas *canvas )
4243
, mTempRubberBand( nullptr )
4344
, mRectangle( QgsRectangle() )
4445
{
46+
clean();
4547
if ( mCanvas )
4648
{
4749
connect( mCanvas, &QgsMapCanvas::mapToolSet, this, &QgsMapToolAddRectangle::setParentTool );
@@ -50,18 +52,12 @@ QgsMapToolAddRectangle::QgsMapToolAddRectangle( QgsMapCanvas *canvas )
5052

5153
QgsMapToolAddRectangle::~QgsMapToolAddRectangle()
5254
{
53-
delete mTempRubberBand;
54-
mPoints.clear();
55+
clean();
5556
}
5657

5758
void QgsMapToolAddRectangle::setParentTool( QgsMapTool *newTool, QgsMapTool *oldTool )
5859
{
59-
if ( mTempRubberBand )
60-
{
61-
delete mTempRubberBand;
62-
mTempRubberBand = nullptr;
63-
}
64-
mPoints.clear();
60+
6561
QgsMapToolCapture *tool = dynamic_cast<QgsMapToolCapture *>( oldTool );
6662
QgsMapToolAddRectangle *csTool = dynamic_cast<QgsMapToolAddRectangle *>( oldTool );
6763
if ( csTool && newTool == this )
@@ -83,9 +79,7 @@ void QgsMapToolAddRectangle::keyPressEvent( QKeyEvent *e )
8379

8480
if ( e && e->key() == Qt::Key_Escape )
8581
{
86-
mPoints.clear();
87-
delete mTempRubberBand;
88-
mTempRubberBand = nullptr;
82+
clean();
8983
if ( mParentTool )
9084
mParentTool->keyPressEvent( e );
9185
}
@@ -136,6 +130,7 @@ void QgsMapToolAddRectangle::deactivate()
136130
return;
137131
}
138132

133+
mParentTool->clearCurve( );
139134
mParentTool->addCurve( rectangleToLinestring() );
140135
delete mTempRubberBand;
141136
mTempRubberBand = nullptr;
@@ -146,10 +141,20 @@ void QgsMapToolAddRectangle::deactivate()
146141

147142
void QgsMapToolAddRectangle::activate()
148143
{
144+
clean();
145+
QgsMapToolCapture::activate();
146+
}
147+
148+
void QgsMapToolAddRectangle::clean()
149+
{
150+
if ( mTempRubberBand )
151+
{
152+
delete mTempRubberBand;
153+
mTempRubberBand = nullptr;
154+
}
155+
mPoints.clear();
149156
if ( mParentTool )
150157
{
151-
mPoints.clear();
152158
mParentTool->deleteTempRubberBand();
153159
}
154-
QgsMapToolCapture::activate();
155160
}

‎src/app/qgsmaptooladdrectangle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class QgsPolygonV2;
2424
class QgsMapToolAddRectangle: public QgsMapToolCapture
2525
{
2626
Q_OBJECT
27+
//! convenient method to clean members
28+
void clean();
2729
public:
2830
QgsMapToolAddRectangle( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );
2931
~QgsMapToolAddRectangle();

‎src/app/qgsmaptooladdregularpolygon.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ QgsMapToolAddRegularPolygon::QgsMapToolAddRegularPolygon( QgsMapToolCapture *par
2929
, mTempRubberBand( nullptr )
3030
, mRegularPolygon( QgsRegularPolygon() )
3131
{
32+
clean();
3233
if ( mCanvas )
3334
{
3435
connect( mCanvas, &QgsMapCanvas::mapToolSet, this, &QgsMapToolAddRegularPolygon::setParentTool );
@@ -41,6 +42,7 @@ QgsMapToolAddRegularPolygon::QgsMapToolAddRegularPolygon( QgsMapCanvas *canvas )
4142
, mTempRubberBand( nullptr )
4243
, mRegularPolygon( QgsRegularPolygon() )
4344
{
45+
clean();
4446
if ( mCanvas )
4547
{
4648
connect( mCanvas, &QgsMapCanvas::mapToolSet, this, &QgsMapToolAddRegularPolygon::setParentTool );
@@ -49,19 +51,12 @@ QgsMapToolAddRegularPolygon::QgsMapToolAddRegularPolygon( QgsMapCanvas *canvas )
4951

5052
QgsMapToolAddRegularPolygon::~QgsMapToolAddRegularPolygon()
5153
{
52-
delete mTempRubberBand;
53-
mTempRubberBand = nullptr;
54-
mPoints.clear();
54+
clean();
5555
}
5656

5757
void QgsMapToolAddRegularPolygon::setParentTool( QgsMapTool *newTool, QgsMapTool *oldTool )
5858
{
59-
if ( mTempRubberBand )
60-
{
61-
delete mTempRubberBand;
62-
mTempRubberBand = nullptr;
63-
}
64-
mPoints.clear();
59+
clean();
6560
QgsMapToolCapture *tool = dynamic_cast<QgsMapToolCapture *>( oldTool );
6661
QgsMapToolAddRegularPolygon *csTool = dynamic_cast<QgsMapToolAddRegularPolygon *>( oldTool );
6762
if ( csTool && newTool == this )
@@ -105,13 +100,7 @@ void QgsMapToolAddRegularPolygon::keyPressEvent( QKeyEvent *e )
105100

106101
if ( e && e->key() == Qt::Key_Escape )
107102
{
108-
if ( mNumberSidesSpinBox )
109-
{
110-
deleteNumberSidesSpinBox();
111-
}
112-
mPoints.clear();
113-
delete mTempRubberBand;
114-
mTempRubberBand = nullptr;
103+
clean();
115104
if ( mParentTool )
116105
mParentTool->keyPressEvent( e );
117106
}
@@ -131,25 +120,33 @@ void QgsMapToolAddRegularPolygon::deactivate()
131120
{
132121
return;
133122
}
123+
mParentTool->clearCurve( );
134124
mParentTool->addCurve( mRegularPolygon.toLineString() );
135-
delete mTempRubberBand;
136-
mTempRubberBand = nullptr;
137-
mPoints.clear();
138-
mRegularPolygon = QgsRegularPolygon();
139-
if ( mNumberSidesSpinBox )
140-
{
141-
deleteNumberSidesSpinBox();
142-
}
125+
clean();
143126

144127
QgsMapToolCapture::deactivate();
145128
}
146129

147130
void QgsMapToolAddRegularPolygon::activate()
148131
{
132+
clean();
133+
QgsMapToolCapture::activate();
134+
}
135+
136+
void QgsMapToolAddRegularPolygon::clean()
137+
{
138+
if ( mTempRubberBand )
139+
{
140+
delete mTempRubberBand;
141+
mTempRubberBand = nullptr;
142+
}
149143
mPoints.clear();
150144
if ( mParentTool )
151145
{
152146
mParentTool->deleteTempRubberBand();
153147
}
154-
QgsMapToolCapture::activate();
148+
if ( mNumberSidesSpinBox )
149+
{
150+
deleteNumberSidesSpinBox();
151+
}
155152
}

‎src/app/qgsmaptooladdregularpolygon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class QSpinBox;
1010
class QgsMapToolAddRegularPolygon: public QgsMapToolCapture
1111
{
1212
Q_OBJECT
13+
void clean();
1314
public:
1415
QgsMapToolAddRegularPolygon( QgsMapToolCapture *parentTool, QgsMapCanvas *canvas, CaptureMode mode = CaptureLine );
1516
~QgsMapToolAddRegularPolygon();

‎src/app/qgsmaptoolregularpolygon2points.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ void QgsMapToolRegularPolygon2Points::cadCanvasReleaseEvent( QgsMapMouseEvent *e
5050
mTempRubberBand->show();
5151

5252
createNumberSidesSpinBox();
53-
/*if ( mNumberSidesSpinBox )
54-
{
55-
mNumberSidesSpinBox->setMinimum( 3 );
56-
}*/
53+
5754
}
5855
}
5956
}

‎src/gui/qgsmaptoolcapture.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,11 @@ int QgsMapToolCapture::addCurve( QgsCurve *c )
502502
return 0;
503503
}
504504

505+
void QgsMapToolCapture::clearCurve()
506+
{
507+
mCaptureCurve.clear();
508+
}
509+
505510
QList<QgsPointLocator::Match> QgsMapToolCapture::snappingMatches() const
506511
{
507512
return mSnappingMatches;

‎src/gui/qgsmaptoolcapture.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
4949
//! Adds a whole curve (e.g. circularstring) to the captured geometry. Curve must be in map CRS
5050
int addCurve( QgsCurve *c );
5151

52+
/**
53+
* Clear capture curve.
54+
*
55+
* \since QGIS 3.0
56+
*/
57+
void clearCurve( );
58+
5259
/**
5360
* Get the capture curve
5461
*

0 commit comments

Comments
 (0)
Please sign in to comment.