Skip to content

Commit

Permalink
RAII
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Jun 11, 2019
1 parent 40b3e82 commit e422aa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
27 changes: 10 additions & 17 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -294,9 +294,7 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )

QgsRubberBand *QgsMapToolCapture::takeRubberBand()
{
QgsRubberBand *rb = mRubberBand;
mRubberBand = nullptr;
return rb;
return mTempRubberBand.release();
}


Expand All @@ -309,7 +307,7 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )

if ( !mTempRubberBand && mCaptureCurve.numPoints() > 0 )
{
mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true ) );
QgsPoint pt = mCaptureCurve.endPoint();
mTempRubberBand->addPoint( QgsPointXY( pt.x(), pt.y() ) );
mTempRubberBand->addPoint( point );
Expand Down Expand Up @@ -451,12 +449,12 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator

if ( !mRubberBand )
{
mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );
mRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry ) );
}

if ( !mTempRubberBand )
{
mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true ) );
}
else
{
Expand Down Expand Up @@ -507,7 +505,7 @@ int QgsMapToolCapture::addCurve( QgsCurve *c )

if ( !mRubberBand )
{
mRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );
mRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry ) );
}

QgsLineString *lineString = c->curveToLine();
Expand All @@ -522,7 +520,7 @@ int QgsMapToolCapture::addCurve( QgsCurve *c )

if ( !mTempRubberBand )
{
mTempRubberBand = createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true );
mTempRubberBand.reset( createRubberBand( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, true ) );
}
else
{
Expand Down Expand Up @@ -629,16 +627,12 @@ bool QgsMapToolCapture::isCapturing() const

void QgsMapToolCapture::stopCapturing()
{
delete mRubberBand;
mRubberBand = nullptr;
mRubberBand.reset();

deleteTempRubberBand();

while ( !mGeomErrorMarkers.isEmpty() )
{
delete mGeomErrorMarkers.takeFirst();
}

qDeleteAll( mGeomErrorMarkers );
mGeomErrorMarkers.clear();
mGeomErrors.clear();

mTracingStartPoint = QgsPointXY();
Expand All @@ -652,8 +646,7 @@ void QgsMapToolCapture::stopCapturing()

void QgsMapToolCapture::deleteTempRubberBand()
{
delete mTempRubberBand;
mTempRubberBand = nullptr;
mTempRubberBand.reset();
}

void QgsMapToolCapture::clean()
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsmaptoolcapture.h
Expand Up @@ -263,10 +263,10 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
bool mCapturing = false;

//! Rubber band for polylines and polygons
QgsRubberBand *mRubberBand = nullptr;
std::unique_ptr<QgsRubberBand> mRubberBand;

//! Temporary rubber band for polylines and polygons. this connects the last added point to the mouse cursor position
QgsRubberBand *mTempRubberBand = nullptr;
std::unique_ptr<QgsRubberBand> mTempRubberBand;

//! List to store the points of digitized lines and polygons (in layer coordinates)
QgsCompoundCurve mCaptureCurve;
Expand Down

0 comments on commit e422aa6

Please sign in to comment.