Skip to content

Commit 889422e

Browse files
committed
better rubberband calculation in maptool circular by radius
The rubberband is only calculated when needed.
1 parent 6ef1706 commit 889422e

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/app/qgsmaptoolcircularstringradius.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent* e
8181
mPoints.append( mTemporaryEndPoint );
8282
deleteRadiusSpinBox();
8383
}
84-
recalculateCircularString();
84+
recalculateRubberBand();
85+
recalculateTempRubberBand( e->mapPoint() );
8586
}
8687
}
8788
else if ( e->button() == Qt::RightButton )
@@ -100,13 +101,12 @@ void QgsMapToolCircularStringRadius::cadCanvasMoveEvent( QgsMapMouseEvent* e )
100101
{
101102
if ( !mPoints.isEmpty() )
102103
{
103-
mLastMouseMapPos = QgsPointV2( e->mapPoint() );
104-
recalculateCircularString();
104+
recalculateTempRubberBand( e->mapPoint() );
105105
updateCenterPointRubberBand( mTemporaryEndPoint );
106106
}
107107
}
108108

109-
void QgsMapToolCircularStringRadius::recalculateCircularString()
109+
void QgsMapToolCircularStringRadius::recalculateRubberBand()
110110
{
111111
if ( mPoints.size() >= 3 )
112112
{
@@ -118,14 +118,17 @@ void QgsMapToolCircularStringRadius::recalculateCircularString()
118118
mRubberBand->setGeometry( cString );
119119
mRubberBand->show();
120120
}
121+
}
121122

123+
void QgsMapToolCircularStringRadius::recalculateTempRubberBand( const QgsPoint& mousePosition )
124+
{
122125
QList<QgsPointV2> rubberBandPoints;
123126
if ( !( mPoints.size() % 2 ) )
124127
{
125128
//recalculate midpoint on circle segment
126129
QgsPointV2 midPoint;
127130
if ( !QgsGeometryUtils::segmentMidPoint( mPoints.at( mPoints.size() - 2 ), mTemporaryEndPoint, midPoint, mRadius,
128-
mLastMouseMapPos ) )
131+
QgsPointV2( mousePosition ) ) )
129132
{
130133
return;
131134
}
@@ -137,7 +140,7 @@ void QgsMapToolCircularStringRadius::recalculateCircularString()
137140
else
138141
{
139142
rubberBandPoints.append( mPoints.last() );
140-
rubberBandPoints.append( mLastMouseMapPos );
143+
rubberBandPoints.append( QgsPointV2( mousePosition ) );
141144
}
142145
QgsCircularStringV2* cString = new QgsCircularStringV2();
143146
cString->setPoints( rubberBandPoints );
@@ -173,5 +176,5 @@ void QgsMapToolCircularStringRadius::deleteRadiusSpinBox()
173176
void QgsMapToolCircularStringRadius::updateRadiusFromSpinBox( double radius )
174177
{
175178
mRadius = radius;
176-
recalculateCircularString();
179+
recalculateTempRubberBand( toMapCoordinates( mCanvas->mouseLastXY() ).toQPointF() );
177180
}

src/app/qgsmaptoolcircularstringradius.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ class QgsMapToolCircularStringRadius: public QgsMapToolAddCircularString
3939
private:
4040
QgsPointV2 mTemporaryEndPoint;
4141
double mRadius;
42-
QgsPointV2 mLastMouseMapPos;
4342
QDoubleSpinBox* mRadiusSpinBox;
4443

45-
//! recalculate the rubberband and the temporary rubberband
46-
void recalculateCircularString();
44+
//! recalculate the rubberband
45+
void recalculateRubberBand();
46+
//! recalculate the temporary rubberband using the given mouse position
47+
void recalculateTempRubberBand( const QgsPoint& mousePosition );
4748
//! (re-)create the spin box to enter the radius
4849
void createRadiusSpinBox();
4950
//! delete the spin box to enter the radius, if it exists

0 commit comments

Comments
 (0)