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() ) if ( mOriginalGeometry.isNull() )
{ {
// first click, get feature to modify
deleteRubberBandAndGeometry(); deleteRubberBandAndGeometry();
mGeometryModified = false; mGeometryModified = false;
mForceCopy = false; mCtrlWasHeldOnFeatureSelection = false;


QgsSnappingUtils *snapping = mCanvas->snappingUtils(); QgsSnappingUtils *snapping = mCanvas->snappingUtils();


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


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


bool editOk; bool editOk;
if ( mSourceLayerId == layer->id() && !mForceCopy ) if ( mSourceLayerId == layer->id() && !mCtrlWasHeldOnFeatureSelection && !forceCopy )
{ {
editOk = layer->changeGeometry( mModifiedFeature, mModifiedGeometry ); editOk = layer->changeGeometry( mModifiedFeature, mModifiedGeometry );
} }
Expand Down Expand Up @@ -179,7 +181,7 @@ void QgsMapToolOffsetCurve::applyOffset()
deleteDistanceWidget(); deleteDistanceWidget();
delete mSnapVertexMarker; delete mSnapVertexMarker;
mSnapVertexMarker = nullptr; mSnapVertexMarker = nullptr;
mForceCopy = false; mCtrlWasHeldOnFeatureSelection = false;
layer->triggerRepaint(); 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) //assign feature part by vertex number (snap to vertex) or by before vertex number (snap to segment)
int partVertexNr = match.vertexIndex(); int partVertexNr = match.vertexIndex();


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


connect( mDistanceWidget, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsMapToolOffsetCurve::placeOffsetCurveToValue ); 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() void QgsMapToolOffsetCurve::deleteDistanceWidget()
{ {
if ( mDistanceWidget ) if ( mDistanceWidget )
{ {
disconnect( mDistanceWidget, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsMapToolOffsetCurve::placeOffsetCurveToValue ); disconnect( mDistanceWidget, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsMapToolOffsetCurve::placeOffsetCurveToValue );
disconnect( mDistanceWidget, &QAbstractSpinBox::editingFinished, this, &QgsMapToolOffsetCurve::applyOffset );
mDistanceWidget->releaseKeyboard(); mDistanceWidget->releaseKeyboard();
mDistanceWidget->deleteLater(); mDistanceWidget->deleteLater();
} }
Expand Down Expand Up @@ -371,7 +372,7 @@ void QgsMapToolOffsetCurve::setOffsetForRubberBand( double offset )
deleteDistanceWidget(); deleteDistanceWidget();
delete mSnapVertexMarker; delete mSnapVertexMarker;
mSnapVertexMarker = nullptr; mSnapVertexMarker = nullptr;
mForceCopy = false; mCtrlWasHeldOnFeatureSelection = false;
mGeometryModified = false; mGeometryModified = false;
deleteDistanceWidget(); deleteDistanceWidget();
emit messageEmitted( tr( "Creating offset geometry failed: %1" ).arg( offsetGeom.lastError() ), QgsMessageBar::CRITICAL ); 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(); void placeOffsetCurveToValue();


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


private: private:
//! Rubberband that shows the position of the offset curve //! 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 //! Marker to show the cursor was snapped to another location
QgsVertexMarker *mSnapVertexMarker = nullptr; QgsVertexMarker *mSnapVertexMarker = nullptr;
//! Forces geometry copy (no modification of geometry in current layer) //! Forces geometry copy (no modification of geometry in current layer)
bool mForceCopy = false; bool mCtrlWasHeldOnFeatureSelection = false;
bool mMultiPartGeometry = false; bool mMultiPartGeometry = false;




Expand Down

0 comments on commit 8a7fc25

Please sign in to comment.