Skip to content
Permalink
Browse files

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 889422e5ff00a2f802266f4bd390062e65fa6411
Showing with 14 additions and 10 deletions.
  1. +10 −7 src/app/qgsmaptoolcircularstringradius.cpp
  2. +4 −3 src/app/qgsmaptoolcircularstringradius.h
@@ -81,7 +81,8 @@ void QgsMapToolCircularStringRadius::cadCanvasReleaseEvent( QgsMapMouseEvent* e
mPoints.append( mTemporaryEndPoint );
deleteRadiusSpinBox();
}
recalculateCircularString();
recalculateRubberBand();
recalculateTempRubberBand( e->mapPoint() );
}
}
else if ( e->button() == Qt::RightButton )
@@ -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 )
{
@@ -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;
}
@@ -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 );
@@ -173,5 +176,5 @@ void QgsMapToolCircularStringRadius::deleteRadiusSpinBox()
void QgsMapToolCircularStringRadius::updateRadiusFromSpinBox( double radius )
{
mRadius = radius;
recalculateCircularString();
recalculateTempRubberBand( toMapCoordinates( mCanvas->mouseLastXY() ).toQPointF() );
}
@@ -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

0 comments on commit 889422e

Please sign in to comment.
You can’t perform that action at this time.