Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better rubberband calculation in maptool circular by radius
The rubberband is only calculated when needed.
  • Loading branch information
SebDieBln committed Dec 21, 2015
1 parent 6ef1706 commit 889422e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
17 changes: 10 additions & 7 deletions src/app/qgsmaptoolcircularstringradius.cpp
Expand Up @@ -81,7 +81,8 @@ void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent* e
mPoints.append( mTemporaryEndPoint );
deleteRadiusSpinBox();
}
recalculateCircularString();
recalculateRubberBand();
recalculateTempRubberBand( e->mapPoint() );
}
}
else if ( e->button() == Qt::RightButton )
Expand All @@ -100,13 +101,12 @@ void QgsMapToolCircularStringRadius::cadCanvasMoveEvent( QgsMapMouseEvent* e )
{
if ( !mPoints.isEmpty() )
{
mLastMouseMapPos = QgsPointV2( e->mapPoint() );
recalculateCircularString();
recalculateTempRubberBand( e->mapPoint() );
updateCenterPointRubberBand( mTemporaryEndPoint );
}
}

void QgsMapToolCircularStringRadius::recalculateCircularString()
void QgsMapToolCircularStringRadius::recalculateRubberBand()
{
if ( mPoints.size() >= 3 )
{
Expand All @@ -118,14 +118,17 @@ void QgsMapToolCircularStringRadius::recalculateCircularString()
mRubberBand->setGeometry( cString );
mRubberBand->show();
}
}

void QgsMapToolCircularStringRadius::recalculateTempRubberBand( const QgsPoint& mousePosition )
{
QList<QgsPointV2> rubberBandPoints;
if ( !( mPoints.size() % 2 ) )
{
//recalculate midpoint on circle segment
QgsPointV2 midPoint;
if ( !QgsGeometryUtils::segmentMidPoint( mPoints.at( mPoints.size() - 2 ), mTemporaryEndPoint, midPoint, mRadius,
mLastMouseMapPos ) )
QgsPointV2( mousePosition ) ) )
{
return;
}
Expand All @@ -137,7 +140,7 @@ void QgsMapToolCircularStringRadius::recalculateCircularString()
else
{
rubberBandPoints.append( mPoints.last() );
rubberBandPoints.append( mLastMouseMapPos );
rubberBandPoints.append( QgsPointV2( mousePosition ) );
}
QgsCircularStringV2* cString = new QgsCircularStringV2();
cString->setPoints( rubberBandPoints );
Expand Down Expand Up @@ -173,5 +176,5 @@ void QgsMapToolCircularStringRadius::deleteRadiusSpinBox()
void QgsMapToolCircularStringRadius::updateRadiusFromSpinBox( double radius )
{
mRadius = radius;
recalculateCircularString();
recalculateTempRubberBand( toMapCoordinates( mCanvas->mouseLastXY() ).toQPointF() );
}
7 changes: 4 additions & 3 deletions src/app/qgsmaptoolcircularstringradius.h
Expand Up @@ -39,11 +39,12 @@ class QgsMapToolCircularStringRadius: public QgsMapToolAddCircularString
private:
QgsPointV2 mTemporaryEndPoint;
double mRadius;
QgsPointV2 mLastMouseMapPos;
QDoubleSpinBox* mRadiusSpinBox;

//! recalculate the rubberband and the temporary rubberband
void recalculateCircularString();
//! recalculate the rubberband
void recalculateRubberBand();
//! recalculate the temporary rubberband using the given mouse position
void recalculateTempRubberBand( const QgsPoint& mousePosition );
//! (re-)create the spin box to enter the radius
void createRadiusSpinBox();
//! delete the spin box to enter the radius, if it exists
Expand Down

0 comments on commit 889422e

Please sign in to comment.