Skip to content

Commit

Permalink
add button in tool bar to switch between linear/circular digitizing
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Jul 29, 2020
1 parent 488efcb commit fd81a2e
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 18 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -284,6 +284,7 @@
<file>themes/default/mActionDeleteTable.svg</file>
<file>themes/default/mActionDeselectAll.svg</file>
<file>themes/default/mActionDeselectActiveLayer.svg</file>
<file>themes/default/mActionDigitizeWithCurve.svg</file>
<file>themes/default/mActionDuplicateLayer.svg</file>
<file>themes/default/mActionDuplicateComposer.svg</file>
<file>themes/default/mActionEditCopy.svg</file>
Expand Down
72 changes: 72 additions & 0 deletions images/themes/default/mActionDigitizeWithCurve.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions python/gui/auto_generated/qgsmaptoolcapture.sip.in
Expand Up @@ -119,9 +119,9 @@ transfers ownership to the caller.
%End

public slots:
void toggleLinearCircularDigitizing();
void setCircularDigitizingEnable( bool enable );
%Docstring
Changes the digitizing shape to linear or circular
Enable the digitizing with curve
%End

protected:
Expand Down
46 changes: 41 additions & 5 deletions src/app/qgisapp.cpp
Expand Up @@ -1571,11 +1571,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
QShortcut *shortcutTracing = new QShortcut( QKeySequence( tr( "Ctrl+Shift+." ) ), this );
connect( shortcutTracing, &QShortcut::activated, this, &QgisApp::toggleEventTracing );

QShortcut *shortcutToggleLinearCircularDigitizing = new QShortcut( QKeySequence( tr( "Ctrl+Shift+G" ) ), this );
connect( shortcutToggleLinearCircularDigitizing, &QShortcut::activated, mMapTools.mAddFeature, &QgsMapToolCapture::toggleLinearCircularDigitizing );
connect( shortcutToggleLinearCircularDigitizing, &QShortcut::activated,
static_cast<QgsMapToolSplitFeatures *>( mMapTools.mSplitFeatures ), &QgsMapToolCapture::toggleLinearCircularDigitizing );

if ( ! QTouchDevice::devices().isEmpty() )
{
//add reacting to long click in touch
Expand Down Expand Up @@ -2590,6 +2585,7 @@ void QgisApp::createActions()
connect( mActionRegularPolygon2Points, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygon2Points, true ); } );
connect( mActionRegularPolygonCenterPoint, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterPoint, true ); } );
connect( mActionRegularPolygonCenterCorner, &QAction::triggered, this, [ = ] { setMapTool( mMapTools.mRegularPolygonCenterCorner, true ); } );
connect( mActionDigitizeWithCurve, &QAction::triggered, this, &QgisApp::enableDigitizeWithCurve );
connect( mActionMoveFeature, &QAction::triggered, this, &QgisApp::moveFeature );
connect( mActionMoveFeatureCopy, &QAction::triggered, this, &QgisApp::moveFeatureCopy );
connect( mActionRotateFeature, &QAction::triggered, this, &QgisApp::rotateFeature );
Expand Down Expand Up @@ -2840,6 +2836,9 @@ void QgisApp::createActions()

connect( mActionDiagramProperties, &QAction::triggered, this, &QgisApp::diagramProperties );

connect( mActionAddFeature, &QAction::toggled, this, &QgisApp::enableDigitizeWithCurveAction );
connect( mActionSplitFeatures, &QAction::toggled, this, &QgisApp::enableDigitizeWithCurveAction );

// we can't set the shortcut these actions, because we need to restrict their context to the canvas and it's children..
QShortcut *copyShortcut = new QShortcut( QKeySequence::Copy, mMapCanvas );
copyShortcut->setContext( Qt::WidgetWithChildrenShortcut );
Expand Down Expand Up @@ -9925,6 +9924,34 @@ void QgisApp::snappingOptions()
mSnappingDialogContainer->show();
}

void QgisApp::enableDigitizeWithCurve( bool enable )
{
mMapTools.mAddFeature->setCircularDigitizingEnable( enable );
static_cast<QgsMapToolCapture *>( mMapTools.mSplitFeatures )->setCircularDigitizingEnable( enable );
static_cast<QgsMapToolCapture *>( mMapTools.mReshapeFeatures )->setCircularDigitizingEnable( enable );
QgsSettings settings;
settings.setValue( QStringLiteral( "UI/digitizeWithCurve" ), enable ? 1 : 0 );
}

void QgisApp::enableDigitizeWithCurveAction( bool enable )
{
QgsSettings settings;

QObject *sender = QObject::sender();
if ( sender && sender != this )
enable &= ( sender == mActionAddFeature && mMapTools.mAddFeature->mode() != QgsMapToolCapture::CapturePoint ) ||
sender == mActionSplitFeatures;

else
enable &= ( mMapCanvas->mapTool() == mMapTools.mAddFeature && mMapTools.mAddFeature->mode() != QgsMapToolCapture::CapturePoint ) ||
mMapCanvas->mapTool() == mMapTools.mSplitFeatures;

bool isChecked = settings.value( QStringLiteral( "UI/digitizeWithCurve" ) ).toInt() && enable;
mActionDigitizeWithCurve->setChecked( isChecked );

mActionDigitizeWithCurve->setEnabled( enable );
}

void QgisApp::splitFeatures()
{
mMapCanvas->setMapTool( mMapTools.mSplitFeatures );
Expand Down Expand Up @@ -14140,6 +14167,9 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionDecreaseContrast->setEnabled( false );
mActionZoomActualSize->setEnabled( false );
mActionZoomToLayer->setEnabled( false );

enableDigitizeWithCurveAction( false );

return;
}

Expand Down Expand Up @@ -14283,6 +14313,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionVertexTool->setEnabled( isEditable && canChangeGeometry );
mActionVertexToolActiveLayer->setEnabled( isEditable && canChangeGeometry );

enableDigitizeWithCurveAction( isEditable && canChangeGeometry );

if ( vlayer->geometryType() == QgsWkbTypes::PointGeometry )
{
mActionAddFeature->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionCapturePoint.svg" ) ) );
Expand Down Expand Up @@ -14482,6 +14514,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionLabeling->setEnabled( false );
mActionDiagramProperties->setEnabled( false );

enableDigitizeWithCurveAction( false );

//NOTE: This check does not really add any protection, as it is called on load not on layer select/activate
//If you load a layer with a provider and idenitfy ability then load another without, the tool would be disabled for both

Expand Down Expand Up @@ -14569,6 +14603,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionLabeling->setEnabled( false );
mActionDiagramProperties->setEnabled( false );
mActionIdentify->setEnabled( true );
enableDigitizeWithCurveAction( false );
break;

case QgsMapLayerType::VectorTileLayer:
Expand Down Expand Up @@ -14631,6 +14666,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
mActionLabeling->setEnabled( false );
mActionDiagramProperties->setEnabled( false );
mActionIdentify->setEnabled( true );
enableDigitizeWithCurveAction( false );
break;

case QgsMapLayerType::PluginLayer:
Expand Down
12 changes: 12 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -1855,6 +1855,18 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Enable or disable event tracing (for debugging)
void toggleEventTracing();

/**
* Enables or disables digitizing with curve for map tool that support this capabilities
* \since QGIS 3.16
*/
void enableDigitizeWithCurve( bool enable );

/**
* Enables the action that allows to enable or disable digitizing with curve
* \since QGIS 3.16
*/
void enableDigitizeWithCurveAction( bool enable );

#ifdef HAVE_GEOREFERENCER
void showGeoreferencer();
#endif
Expand Down
11 changes: 4 additions & 7 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -349,13 +349,9 @@ QgsRubberBand *QgsMapToolCapture::takeRubberBand()
return mRubberBand.release();
}

void QgsMapToolCapture::toggleLinearCircularDigitizing()
void QgsMapToolCapture::setCircularDigitizingEnable( bool enable )
{
if ( mDigitizingType == QgsWkbTypes::LineString )
mDigitizingType = QgsWkbTypes::CircularString ;
else
mDigitizingType = QgsWkbTypes::LineString;

mDigitizingType = enable ? QgsWkbTypes::CircularString : QgsWkbTypes::LineString;
if ( mTempRubberBand )
mTempRubberBand->setStringType( mDigitizingType );
}
Expand Down Expand Up @@ -716,7 +712,8 @@ void QgsMapToolCapture::undo()
mCaptureCurve.deleteVertex( vertexToRemove );
int pointsCountAfter = mCaptureCurve.numPoints();
for ( ; pointsCountAfter < pointsCountBefore; pointsCountAfter++ )
mSnappingMatches.removeLast();
if ( !mSnappingMatches.empty() )
mSnappingMatches.removeLast();
}

updateExtraSnapLayer();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsmaptoolcapture.h
Expand Up @@ -212,8 +212,8 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
QgsRubberBand *takeRubberBand() SIP_FACTORY;

public slots:
//! Changes the digitizing shape to linear or circular
void toggleLinearCircularDigitizing();
//! Enable the digitizing with curve
void setCircularDigitizingEnable( bool enable );

private slots:
void addError( const QgsGeometry::Error &error );
Expand Down
22 changes: 22 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -489,6 +489,7 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionDigitizeWithCurve"/>
<addaction name="mActionRotateFeature"/>
<addaction name="mActionSimplifyFeature"/>
<addaction name="mActionAddRing"/>
Expand Down Expand Up @@ -3363,6 +3364,27 @@ Shows placeholders for labels which could not be placed, e.g. due to overlaps wi
<string>Increase Gamma</string>
</property>
</action>
<action name="mActionDigitizeWithCurve">
<property name="checkable">
<bool>true</bool>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionDigitizeWithCurve.svg</normaloff>:/images/themes/default/mActionDigitizeWithCurve.svg</iconset>
</property>
<property name="text">
<string>Digitize with curve</string>
</property>
<property name="toolTip">
<string>Digitize with curve</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+G</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down
4 changes: 2 additions & 2 deletions tests/src/app/testqgsmaptooladdfeatureline.cpp
Expand Up @@ -283,7 +283,7 @@ void TestQgsMapToolAddFeatureLine::testNoTracing()
mLayerLine->undoStack()->undo();
QCOMPARE( mLayerLine->undoStack()->index(), 1 );

mCaptureTool->toggleLinearCircularDigitizing();
mCaptureTool->setCircularDigitizingEnable( true );

utils.mouseClick( 1, 1, Qt::LeftButton );
utils.mouseClick( 3, 2, Qt::LeftButton );
Expand All @@ -305,7 +305,7 @@ void TestQgsMapToolAddFeatureLine::testNoTracing()

mLayerLine->undoStack()->undo();
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
mCaptureTool->toggleLinearCircularDigitizing();
mCaptureTool->setCircularDigitizingEnable( false );
}

void TestQgsMapToolAddFeatureLine::testTracing()
Expand Down

0 comments on commit fd81a2e

Please sign in to comment.