diff --git a/python/PyQt6/gui/auto_generated/qgsmaptooldigitizefeature.sip b/python/PyQt6/gui/auto_generated/qgsmaptooldigitizefeature.sip new file mode 100644 index 000000000000..511ca0170033 --- /dev/null +++ b/python/PyQt6/gui/auto_generated/qgsmaptooldigitizefeature.sip @@ -0,0 +1,109 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/qgsmaptooldigitizefeature.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + +class QgsMapToolDigitizeFeature : QgsMapToolCaptureLayerGeometry +{ +%Docstring(signature="appended") +This tool digitizes geometry of new point/line/polygon features on already existing vector layers +Once the map tool is enabled, user can digitize the feature geometry. +A signal will then be emitted. + +.. versionadded:: 3.10 +%End + +%TypeHeaderCode +#include "qgsmaptooldigitizefeature.h" +%End + public: + + QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode = QgsMapToolCapture::CaptureNone ); +%Docstring +QgsMapToolDigitizeFeature is a map tool to digitize a feature geometry + +:param canvas: the map canvas +:param cadDockWidget: widget to setup advanced digitizing parameters +:param mode: type of geometry to capture (point/line/polygon), :py:class:`QgsMapToolCapture`.CaptureNone to autodetect geometry +%End + + virtual QgsMapToolCapture::Capabilities capabilities() const; + + virtual bool supportsTechnique( Qgis::CaptureTechnique technique ) const; + + + virtual void cadCanvasReleaseEvent( QgsMapMouseEvent *e ); + + + void setLayer( QgsMapLayer *vl ); +%Docstring +Change the layer edited by the map tool + +:param vl: the layer to be edited by the map tool +%End + + virtual void activate(); + + virtual void reactivate(); + + virtual void deactivate(); + + + virtual void keyPressEvent( QKeyEvent *e ); + + + signals: + + void digitizingCompleted( const QgsFeature &feature ); +%Docstring +Emitted whenever the digitizing has been successfully completed + +:param feature: the new digitized feature +%End + + void digitizingFinished(); +%Docstring +Emitted whenever the digitizing has been ended without digitizing +any feature +%End + + void digitizingCanceled(); +%Docstring +Emitted when the digitizing process was interrupted by the user. + +.. versionadded:: 3.28 +%End + + protected: + + bool checkGeometryType() const; +%Docstring +Check if CaptureMode matches layer type. Default is ``True``. +%End + + void setCheckGeometryType( bool checkGeometryType ); +%Docstring +Check if CaptureMode matches layer type. Default is ``True``. +%End + + private: + virtual void featureDigitized( const QgsFeature &feature ); +%Docstring +Called when the feature has been digitized + +.. versionadded:: 3.26 +%End +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/qgsmaptooldigitizefeature.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/python/gui/auto_generated/qgsmaptooldigitizefeature.sip b/python/gui/auto_generated/qgsmaptooldigitizefeature.sip new file mode 100644 index 000000000000..511ca0170033 --- /dev/null +++ b/python/gui/auto_generated/qgsmaptooldigitizefeature.sip @@ -0,0 +1,109 @@ +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/qgsmaptooldigitizefeature.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ + + + +class QgsMapToolDigitizeFeature : QgsMapToolCaptureLayerGeometry +{ +%Docstring(signature="appended") +This tool digitizes geometry of new point/line/polygon features on already existing vector layers +Once the map tool is enabled, user can digitize the feature geometry. +A signal will then be emitted. + +.. versionadded:: 3.10 +%End + +%TypeHeaderCode +#include "qgsmaptooldigitizefeature.h" +%End + public: + + QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode = QgsMapToolCapture::CaptureNone ); +%Docstring +QgsMapToolDigitizeFeature is a map tool to digitize a feature geometry + +:param canvas: the map canvas +:param cadDockWidget: widget to setup advanced digitizing parameters +:param mode: type of geometry to capture (point/line/polygon), :py:class:`QgsMapToolCapture`.CaptureNone to autodetect geometry +%End + + virtual QgsMapToolCapture::Capabilities capabilities() const; + + virtual bool supportsTechnique( Qgis::CaptureTechnique technique ) const; + + + virtual void cadCanvasReleaseEvent( QgsMapMouseEvent *e ); + + + void setLayer( QgsMapLayer *vl ); +%Docstring +Change the layer edited by the map tool + +:param vl: the layer to be edited by the map tool +%End + + virtual void activate(); + + virtual void reactivate(); + + virtual void deactivate(); + + + virtual void keyPressEvent( QKeyEvent *e ); + + + signals: + + void digitizingCompleted( const QgsFeature &feature ); +%Docstring +Emitted whenever the digitizing has been successfully completed + +:param feature: the new digitized feature +%End + + void digitizingFinished(); +%Docstring +Emitted whenever the digitizing has been ended without digitizing +any feature +%End + + void digitizingCanceled(); +%Docstring +Emitted when the digitizing process was interrupted by the user. + +.. versionadded:: 3.28 +%End + + protected: + + bool checkGeometryType() const; +%Docstring +Check if CaptureMode matches layer type. Default is ``True``. +%End + + void setCheckGeometryType( bool checkGeometryType ); +%Docstring +Check if CaptureMode matches layer type. Default is ``True``. +%End + + private: + virtual void featureDigitized( const QgsFeature &feature ); +%Docstring +Called when the feature has been digitized + +.. versionadded:: 3.26 +%End +}; + +/************************************************************************ + * This file has been generated automatically from * + * * + * src/gui/qgsmaptooldigitizefeature.h * + * * + * Do not edit manually ! Edit header and run scripts/sipify.pl again * + ************************************************************************/ diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 8de2a1a87477..e53860e70f9d 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -10001,7 +10001,23 @@ void QgisApp::reshapeFeatures() void QgisApp::addFeature() { - mMapCanvas->setMapTool( mMapTools->mapTool( QgsAppMapTools::AddFeature ) ); + if ( mMapCanvas->mapTool()->toolName() != tr( "Add feature" ) ) + { + mMapCanvas->setMapTool( mMapTools->mapTool( QgsAppMapTools::AddFeature ) ); + if ( !mMapCanvas->currentLayer()->isSpatial() ) + { + mMapCanvas->setCursor( QCursor( Qt::ArrowCursor ) ); + mMapCanvas->mapTool()->action()->setChecked( false ); + mDigitizingTechniqueManager->enableDigitizingTechniqueActions( false ); + return; + } + mMapCanvas->setCursor( QgsApplication::getThemeCursor( QgsApplication::Cursor::CapturePoint ) ); + } + if ( !mMapCanvas->currentLayer()->isSpatial() ) + { + mMapCanvas->mapTool()->activate(); + mMapCanvas->mapTool()->action()->setChecked( false ); + } } void QgisApp::setMapTool( QgsMapTool *tool, bool clean ) @@ -15286,6 +15302,14 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer ) mActionCopyFeatures->setEnabled( layerHasSelection ); mActionFeatureAction->setEnabled( layerHasActions ); + if ( mMapCanvas->mapTool()->toolName() == tr( "Add feature" ) ) + { + if ( vlayer->isSpatial() ) + mMapCanvas->mapTool()->action()->setChecked( true ); + else + mMapCanvas->mapTool()->action()->setChecked( false ); + } + if ( !isEditable && mMapCanvas && mMapCanvas->mapTool() && ( mMapCanvas->mapTool()->flags() & QgsMapTool::EditTool ) && !mSaveRollbackInProgress ) { diff --git a/src/gui/qgsmaptooladvanceddigitizing.cpp b/src/gui/qgsmaptooladvanceddigitizing.cpp index 85fad034aa95..8947d6e48411 100644 --- a/src/gui/qgsmaptooladvanceddigitizing.cpp +++ b/src/gui/qgsmaptooladvanceddigitizing.cpp @@ -31,6 +31,9 @@ QgsMapToolAdvancedDigitizing::QgsMapToolAdvancedDigitizing( QgsMapCanvas *canvas void QgsMapToolAdvancedDigitizing::canvasPressEvent( QgsMapMouseEvent *e ) { + if ( canvas()->currentLayer() && !canvas()->currentLayer()->isSpatial() ) + return; + if ( isAdvancedDigitizingAllowed() && mCadDockWidget->cadEnabled() ) { mCadDockWidget->applyConstraints( e ); // updates event's map point @@ -54,6 +57,9 @@ void QgsMapToolAdvancedDigitizing::canvasPressEvent( QgsMapMouseEvent *e ) void QgsMapToolAdvancedDigitizing::canvasReleaseEvent( QgsMapMouseEvent *e ) { + if ( canvas()->currentLayer() && !canvas()->currentLayer()->isSpatial() ) + return; + if ( isAdvancedDigitizingAllowed() && mCadDockWidget->cadEnabled() ) { if ( e->button() == Qt::RightButton ) @@ -94,6 +100,9 @@ void QgsMapToolAdvancedDigitizing::canvasReleaseEvent( QgsMapMouseEvent *e ) void QgsMapToolAdvancedDigitizing::canvasMoveEvent( QgsMapMouseEvent *e ) { + if ( canvas()->currentLayer() && !canvas()->currentLayer()->isSpatial() ) + return; + if ( isAdvancedDigitizingAllowed() && mCadDockWidget->cadEnabled() ) { mCadDockWidget->applyConstraints( e ); // updates event's map point @@ -165,10 +174,15 @@ void QgsMapToolAdvancedDigitizing::onCurrentLayerChanged() mSnapToGridCanvasItem->setCrs( layer->crs() ); } - if ( !layer ) + if ( !layer || !layer->isSpatial() ) + { mSnapToGridCanvasItem->setEnabled( false ); + mCadDockWidget->clear(); + } else + { mSnapToGridCanvasItem->setEnabled( mSnapToLayerGridEnabled ); + } } } diff --git a/src/gui/qgsmaptoolcapture.cpp b/src/gui/qgsmaptoolcapture.cpp index 4b0c1ac02abe..2a154ce85da0 100644 --- a/src/gui/qgsmaptoolcapture.cpp +++ b/src/gui/qgsmaptoolcapture.cpp @@ -152,6 +152,16 @@ void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer ) return; } + if ( vlayer->isSpatial() ) + { + setCursor( QgsApplication::getThemeCursor( QgsApplication::Cursor::CapturePoint ) ); + } + else + { + setCursor( QCursor( Qt::ArrowCursor ) ); + mCanvas->mapTool()->clean(); + } + switch ( vlayer->geometryType() ) { case Qgis::GeometryType::Point: @@ -475,7 +485,8 @@ void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e ) const QgsPointXY point = e->mapPoint(); - mSnapIndicator->setMatch( e->mapPointMatch() ); + if ( canvas()->currentLayer() && canvas()->currentLayer()->isSpatial() ) + mSnapIndicator->setMatch( e->mapPointMatch() ); if ( mCurrentCaptureTechnique == Qgis::CaptureTechnique::Shape ) { diff --git a/src/gui/qgsmaptooldigitizefeature.cpp b/src/gui/qgsmaptooldigitizefeature.cpp index a50ca56f4963..84d9b35e76a7 100644 --- a/src/gui/qgsmaptooldigitizefeature.cpp +++ b/src/gui/qgsmaptooldigitizefeature.cpp @@ -106,6 +106,7 @@ void QgsMapToolDigitizeFeature::activate() if ( vlayer && vlayer->geometryType() == Qgis::GeometryType::Null ) { + setCursor( QCursor( Qt::ArrowCursor ) ); layerGeometryCaptured( QgsGeometry() ); return; } @@ -121,6 +122,12 @@ void QgsMapToolDigitizeFeature::activate() QgsMapToolCaptureLayerGeometry::activate(); } +void QgsMapToolDigitizeFeature::reactivate() +{ + activate(); + QgsMapToolCaptureLayerGeometry::reactivate(); +} + void QgsMapToolDigitizeFeature::deactivate() { QgsMapToolCaptureLayerGeometry::deactivate(); diff --git a/src/gui/qgsmaptooldigitizefeature.h b/src/gui/qgsmaptooldigitizefeature.h index c1a1f2ef2096..42fb39ceb8b0 100644 --- a/src/gui/qgsmaptooldigitizefeature.h +++ b/src/gui/qgsmaptooldigitizefeature.h @@ -54,6 +54,7 @@ class GUI_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCaptureLayerGeomet void setLayer( QgsMapLayer *vl ); void activate() override; + void reactivate() override; void deactivate() override; // Overridden to emit digitizingCanceled when ESC is pressed