Skip to content

Commit

Permalink
Force geometry copy in offset curve tool if control key pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Feb 22, 2012
1 parent 802dda1 commit c7c840f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/app/qgsmaptooloffsetcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
}

Expand All @@ -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();
Expand All @@ -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 )
Expand All @@ -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 );
}
Expand All @@ -114,6 +116,7 @@ void QgsMapToolOffsetCurve::canvasReleaseEvent( QMouseEvent * e )
deleteRubberBandAndGeometry();
deleteDistanceItem();
delete mSnapVertexMarker; mSnapVertexMarker = 0;
mForceCopy = false;
mCanvas->refresh();
}

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgsmaptooloffsetcurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c7c840f

Please sign in to comment.