Skip to content

Commit

Permalink
[offset tool] Also check for ctrl modifier on final click
Browse files Browse the repository at this point in the history
Otherwise copies are only made if ctrl was held on the first click,
but holding ctrl on the second click is also a natural behavior
  • Loading branch information
nyalldawson committed Nov 28, 2017
1 parent 9aa5752 commit 8a7fc25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/app/qgsmaptooloffsetcurve.cpp
Expand Up @@ -67,9 +67,10 @@ void QgsMapToolOffsetCurve::canvasReleaseEvent( QgsMapMouseEvent *e )

if ( mOriginalGeometry.isNull() )
{
// first click, get feature to modify
deleteRubberBandAndGeometry();
mGeometryModified = false;
mForceCopy = false;
mCtrlWasHeldOnFeatureSelection = false;

QgsSnappingUtils *snapping = mCanvas->snappingUtils();

Expand All @@ -96,7 +97,7 @@ void QgsMapToolOffsetCurve::canvasReleaseEvent( QgsMapMouseEvent *e )
QgsFeature fet;
if ( match.layer()->getFeatures( QgsFeatureRequest( match.featureId() ) ).nextFeature( fet ) )
{
mForceCopy = ( e->modifiers() & Qt::ControlModifier ); //no geometry modification if ctrl is pressed
mCtrlWasHeldOnFeatureSelection = ( e->modifiers() & Qt::ControlModifier ); //no geometry modification if ctrl is pressed
mOriginalGeometry = createOriginGeometry( match.layer(), match, fet );
mRubberBand = createRubberBand();
if ( mRubberBand )
Expand All @@ -115,11 +116,12 @@ void QgsMapToolOffsetCurve::canvasReleaseEvent( QgsMapMouseEvent *e )
}
else
{
applyOffset();
// second click - apply changes
applyOffset( e->modifiers() & Qt::ControlModifier );
}
}

void QgsMapToolOffsetCurve::applyOffset()
void QgsMapToolOffsetCurve::applyOffset( bool forceCopy )
{
QgsVectorLayer *layer = currentVectorLayer();
if ( !layer )
Expand All @@ -146,7 +148,7 @@ void QgsMapToolOffsetCurve::applyOffset()
layer->beginEditCommand( tr( "Offset curve" ) );

bool editOk;
if ( mSourceLayerId == layer->id() && !mForceCopy )
if ( mSourceLayerId == layer->id() && !mCtrlWasHeldOnFeatureSelection && !forceCopy )
{
editOk = layer->changeGeometry( mModifiedFeature, mModifiedGeometry );
}
Expand Down Expand Up @@ -179,7 +181,7 @@ void QgsMapToolOffsetCurve::applyOffset()
deleteDistanceWidget();
delete mSnapVertexMarker;
mSnapVertexMarker = nullptr;
mForceCopy = false;
mCtrlWasHeldOnFeatureSelection = false;
layer->triggerRepaint();
}

Expand Down Expand Up @@ -260,7 +262,7 @@ QgsGeometry QgsMapToolOffsetCurve::createOriginGeometry( QgsVectorLayer *vl, con
//assign feature part by vertex number (snap to vertex) or by before vertex number (snap to segment)
int partVertexNr = match.vertexIndex();

if ( vl == currentVectorLayer() && !mForceCopy )
if ( vl == currentVectorLayer() && !mCtrlWasHeldOnFeatureSelection )
{
//don't consider selected geometries, only the snap result
return convertToSingleLine( snappedFeature.geometry(), partVertexNr, mMultiPartGeometry );
Expand Down Expand Up @@ -324,15 +326,14 @@ void QgsMapToolOffsetCurve::createDistanceWidget()
mDistanceWidget->setFocus( Qt::TabFocusReason );

connect( mDistanceWidget, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsMapToolOffsetCurve::placeOffsetCurveToValue );
connect( mDistanceWidget, &QAbstractSpinBox::editingFinished, this, &QgsMapToolOffsetCurve::applyOffset );
connect( mDistanceWidget, &QAbstractSpinBox::editingFinished, this, [ = ] { applyOffset(); } );
}

void QgsMapToolOffsetCurve::deleteDistanceWidget()
{
if ( mDistanceWidget )
{
disconnect( mDistanceWidget, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsMapToolOffsetCurve::placeOffsetCurveToValue );
disconnect( mDistanceWidget, &QAbstractSpinBox::editingFinished, this, &QgsMapToolOffsetCurve::applyOffset );
mDistanceWidget->releaseKeyboard();
mDistanceWidget->deleteLater();
}
Expand Down Expand Up @@ -371,7 +372,7 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
deleteDistanceWidget();
delete mSnapVertexMarker;
mSnapVertexMarker = nullptr;
mForceCopy = false;
mCtrlWasHeldOnFeatureSelection = false;
mGeometryModified = false;
deleteDistanceWidget();
emit messageEmitted( tr( "Creating offset geometry failed: %1" ).arg( offsetGeom.lastError() ), QgsMessageBar::CRITICAL );
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsmaptooloffsetcurve.h
Expand Up @@ -39,7 +39,7 @@ class APP_EXPORT QgsMapToolOffsetCurve: public QgsMapToolEdit
void placeOffsetCurveToValue();

//! Apply the offset either from the spin box or from the mouse event
void applyOffset();
void applyOffset( bool forceCopy = false );

private:
//! Rubberband that shows the position of the offset curve
Expand All @@ -59,7 +59,7 @@ class APP_EXPORT QgsMapToolOffsetCurve: public QgsMapToolEdit
//! Marker to show the cursor was snapped to another location
QgsVertexMarker *mSnapVertexMarker = nullptr;
//! Forces geometry copy (no modification of geometry in current layer)
bool mForceCopy = false;
bool mCtrlWasHeldOnFeatureSelection = false;
bool mMultiPartGeometry = false;


Expand Down

0 comments on commit 8a7fc25

Please sign in to comment.