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

[Backport release-3_40] Fix regression introduced by #58755 #60168

Merged
merged 2 commits into from
Jan 17, 2025
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
8 changes: 6 additions & 2 deletions src/gui/maptools/qgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,15 @@ void QgsMapToolCapture::setCurrentShapeMapTool( const QgsMapToolShapeMetadata *s

void QgsMapToolCapture::cadCanvasMoveEvent( QgsMapMouseEvent *e )
{
// If we are adding a record to a non-spatial layer, just return
if ( mCaptureModeFromLayer && !canvas()->currentLayer()->isSpatial() )
return;

QgsMapToolAdvancedDigitizing::cadCanvasMoveEvent( e );

const QgsPointXY point = e->mapPoint();
if ( canvas()->currentLayer() && canvas()->currentLayer()->isSpatial() )
mSnapIndicator->setMatch( e->mapPointMatch() );

mSnapIndicator->setMatch( e->mapPointMatch() );

if ( mCurrentCaptureTechnique == Qgis::CaptureTechnique::Shape )
{
Expand Down
1 change: 1 addition & 0 deletions tests/src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# the UI file won't be wrapped!
include_directories(
${CMAKE_SOURCE_DIR}/src/test
${CMAKE_SOURCE_DIR}/tests/src/gui
${CMAKE_CURRENT_BINARY_DIR}
)

Expand Down
1 change: 1 addition & 0 deletions tests/src/app/testqgsadvanceddigitizing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* *
***************************************************************************/

#include "qgisapp.h"
#include "qgstest.h"

#include "qgsadvanceddigitizingdockwidget.h"
Expand Down
3 changes: 1 addition & 2 deletions tests/src/app/testqgsmaptoolsplitfeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
* *
***************************************************************************/

#include "qgssnappingutils.h"
#include "qgstest.h"

#include "qgisapp.h"
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgssettings.h"
#include "qgsvectorlayer.h"
#include "qgsmaptoolsplitfeatures.h"
#include "qgsgeometryutils.h"

#include "testqgsmaptoolutils.h"

Expand Down
4 changes: 1 addition & 3 deletions tests/src/app/testqgsvertextool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@
***************************************************************************/

#include "qgstest.h"
#include "qgisapp.h"

#include "qgsadvanceddigitizingdockwidget.h"
#include "qgsgeometry.h"
#include "qgsgeometryoptions.h"
#include "qgsgeos.h"
#include "qgsmapcanvas.h"
#include "qgsmapcanvassnappingutils.h"
#include "qgsproject.h"
#include "qgsvectorlayer.h"
#include "qgsmapmouseevent.h"
#include "vertextool/qgsvertextool.h"
#include "qgslinestring.h"
#include "qgscircularstring.h"
#include "qgssnappingconfig.h"
#include "qgssettingsregistrycore.h"
#include "testqgsmaptoolutils.h"
Expand Down
63 changes: 62 additions & 1 deletion tests/src/gui/testqgsmaptoolcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
***************************************************************************/
#include <QCoreApplication>

#include "qgsmapcanvassnappingutils.h"
#include "qgstest.h"
#include "qgsguiutils.h"
#include "qgsmaptoolcapture.h"
#include "qgsapplication.h"
#include "qgsmapcanvas.h"
#include "qgslogger.h"
#include "qgsannotationlayer.h"
#include "qgsadvanceddigitizingdockwidget.h"
#include "testqgsmaptoolutils.h"


class TestQgsMapToolCapture : public QObject
{
Expand All @@ -36,6 +38,7 @@ class TestQgsMapToolCapture : public QObject
void cleanup(); // will be called after every testfunction.

void addVertexNoLayer();
void addPointNoLayerSnapping();
void addVertexNonVectorLayer();
void addVertexNonVectorLayerTransform();
};
Expand Down Expand Up @@ -88,6 +91,64 @@ void TestQgsMapToolCapture::addVertexNoLayer()
QCOMPARE( layerPoint.y(), 6.0 );
}

void TestQgsMapToolCapture::addPointNoLayerSnapping()
{
// checks that snapping works even if no layer is set as current layer

QgsPoint p = QgsPoint( 2556607, 1115175 );

QgsProject::instance()->clear();

QgsMapCanvas canvas;
canvas.resize( 600, 600 );
canvas.setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:2056" ) ) );
canvas.setFrameStyle( QFrame::NoFrame );
canvas.setExtent( QgsRectangle( p.x() - 50, p.y() - 50, p.x() + 50, p.y() + 50 ) );
canvas.show(); // to make the canvas resize

QgsVectorLayer *layer = new QgsVectorLayer( QStringLiteral( "Point?crs=EPSG:2056" ), QStringLiteral( "point" ), QStringLiteral( "memory" ) );
QgsProject::instance()->addMapLayer( layer );
QgsFeature f( layer->fields() );
f.setGeometry( QgsGeometry( p.clone() ) );
QgsFeatureList flist { f };
layer->dataProvider()->addFeatures( flist );
canvas.setLayers( { layer } );

QgsMapSettings mapSettings = canvas.mapSettings();
QVERIFY( mapSettings.hasValidSettings() );

QgsSnappingUtils u;
u.setMapSettings( mapSettings );

QgsSnappingConfig snappingConfig = u.config();
snappingConfig.setEnabled( true );
snappingConfig.setTolerance( 10 );
snappingConfig.setUnits( Qgis::MapToolUnit::Pixels );
snappingConfig.setMode( Qgis::SnappingMode::AllLayers );
snappingConfig.setTypeFlag( Qgis::SnappingType::Vertex );
u.setConfig( snappingConfig );

QgsMapCanvasSnappingUtils *snappingUtils = new QgsMapCanvasSnappingUtils( &canvas, this );
snappingUtils->setConfig( snappingConfig );
snappingUtils->setMapSettings( mapSettings );
snappingUtils->locatorForLayer( layer )->init();

canvas.setSnappingUtils( snappingUtils );

canvas.setCurrentLayer( nullptr );

QgsAdvancedDigitizingDockWidget cadDock( &canvas );

QgsMapToolCapture tool( &canvas, &cadDock, QgsMapToolCapture::CaptureLine );
canvas.setMapTool( &tool );

TestQgsMapToolAdvancedDigitizingUtils utils( &tool );
utils.mouseClick( p.x() + .5, p.y() + .5, Qt::LeftButton, Qt::KeyboardModifiers(), true );

QgsPoint toolPoint = tool.captureCurve()->vertexAt( QgsVertexId( 0, 0, 0 ) );
QCOMPARE( toolPoint, p );
}

void TestQgsMapToolCapture::addVertexNonVectorLayer()
{
QgsProject::instance()->clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
* *
***************************************************************************/

#include "qgstest.h"

#include "qgisapp.h"
//#include "qgisapp.h"
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsmapmouseevent.h"
#include "qgssnappingutils.h"
#include "qgsmaptooladvanceddigitizing.h"

/**
Expand Down
Loading