Skip to content
Permalink
Browse files
Force geometry copy in offset curve tool if control key pressed
  • Loading branch information
mhugent committed Feb 22, 2012
1 parent 802dda1 commit c7c840fb879f7b44a36ead988037428a401ed5f0
Showing with 9 additions and 4 deletions.
  1. +7 −4 src/app/qgsmaptooloffsetcurve.cpp
  2. +2 −0 src/app/qgsmaptooloffsetcurve.h
@@ -25,7 +25,7 @@
#include "qgisapp.h"

QgsMapToolOffsetCurve::QgsMapToolOffsetCurve( QgsMapCanvas* canvas ): QgsMapToolEdit( canvas ), mRubberBand( 0 ),
mOriginalGeometry( 0 ), mGeometryModified( false ), mDistanceItem( 0 ), mDistanceSpinBox( 0 ), mSnapVertexMarker( 0 )
mOriginalGeometry( 0 ), mGeometryModified( false ), mDistanceItem( 0 ), mDistanceSpinBox( 0 ), mSnapVertexMarker( 0 ), mForceCopy( false )
{
}

@@ -36,10 +36,11 @@ QgsMapToolOffsetCurve::~QgsMapToolOffsetCurve()
delete mSnapVertexMarker;
}

void QgsMapToolOffsetCurve::canvasPressEvent( QMouseEvent * e )
void QgsMapToolOffsetCurve::canvasPressEvent( QMouseEvent* e )
{
deleteRubberBandAndGeometry();
mGeometryModified = false;
mForceCopy = false;

//get selected features or snap to nearest feature if no selection
QgsVectorLayer* layer = currentVectorLayer();
@@ -65,6 +66,7 @@ void QgsMapToolOffsetCurve::canvasPressEvent( QMouseEvent * e )
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( mSourceLayerId ) );
if ( vl && vl->featureAtId( snapResult.snappedAtGeometry, fet ) )
{
mForceCopy = ( e->modifiers() & Qt::ControlModifier ); //no geometry modification if ctrl is pressed
mOriginalGeometry = createOriginGeometry( vl, snapResult, fet );
mRubberBand = createRubberBand();
if ( mRubberBand )
@@ -91,7 +93,7 @@ void QgsMapToolOffsetCurve::canvasReleaseEvent( QMouseEvent * e )
vlayer->beginEditCommand( tr( "Offset curve" ) );

bool editOk;
if ( mSourceLayerId == vlayer->id() )
if ( mSourceLayerId == vlayer->id() && !mForceCopy )
{
editOk = vlayer->changeGeometry( mModifiedFeature, &mModifiedGeometry );
}
@@ -114,6 +116,7 @@ void QgsMapToolOffsetCurve::canvasReleaseEvent( QMouseEvent * e )
deleteRubberBandAndGeometry();
deleteDistanceItem();
delete mSnapVertexMarker; mSnapVertexMarker = 0;
mForceCopy = false;
mCanvas->refresh();
}

@@ -206,7 +209,7 @@ QgsGeometry* QgsMapToolOffsetCurve::createOriginGeometry( QgsVectorLayer* vl, co
return 0;
}

if ( vl == currentVectorLayer() )
if ( vl == currentVectorLayer() && !mForceCopy )
{
//don't consider selected geometries, only the snap result
return snappedFeature.geometryAndOwnership();
@@ -59,6 +59,8 @@ class QgsMapToolOffsetCurve: public QgsMapToolEdit
QDoubleSpinBox* mDistanceSpinBox;
/**Marker to show the cursor was snapped to another location*/
QgsVertexMarker* mSnapVertexMarker;
/**Forces geometry copy (no modification of geometry in current layer)*/
bool mForceCopy;


void deleteRubberBandAndGeometry();

0 comments on commit c7c840f

Please sign in to comment.