Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add record snapping cursor #156

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions python/PyQt6/gui/auto_generated/qgsmaptooldigitizefeature.sip
Original file line number Diff line number Diff line change
@@ -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 *
************************************************************************/
109 changes: 109 additions & 0 deletions python/gui/auto_generated/qgsmaptooldigitizefeature.sip
Original file line number Diff line number Diff line change
@@ -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 *
************************************************************************/
26 changes: 25 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
{
Expand Down
16 changes: 15 additions & 1 deletion src/gui/qgsmaptooladvanceddigitizing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
}
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/gui/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 )
{
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsmaptooldigitizefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void QgsMapToolDigitizeFeature::activate()

if ( vlayer && vlayer->geometryType() == Qgis::GeometryType::Null )
{
setCursor( QCursor( Qt::ArrowCursor ) );
layerGeometryCaptured( QgsGeometry() );
return;
}
Expand All @@ -121,6 +122,12 @@ void QgsMapToolDigitizeFeature::activate()
QgsMapToolCaptureLayerGeometry::activate();
}

void QgsMapToolDigitizeFeature::reactivate()
{
activate();
QgsMapToolCaptureLayerGeometry::reactivate();
}

void QgsMapToolDigitizeFeature::deactivate()
{
QgsMapToolCaptureLayerGeometry::deactivate();
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsmaptooldigitizefeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading