mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-07 00:15:48 -04:00
Merge pull request #63071 from nyalldawson/backport_63041
Vertex tool test fixes (backport)
This commit is contained in:
commit
9896f559b9
@ -250,7 +250,7 @@ QgsVertexTool::QgsVertexTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWid
|
||||
{
|
||||
setAdvancedDigitizingAllowed( false );
|
||||
|
||||
mSnapIndicator.reset( new QgsSnapIndicator( canvas ) );
|
||||
mSnapIndicator = std::make_unique< QgsSnapIndicator >( canvas );
|
||||
|
||||
mEdgeCenterMarker = new QgsVertexMarker( canvas );
|
||||
mEdgeCenterMarker->setIconType( QgsVertexMarker::ICON_CROSS );
|
||||
@ -487,7 +487,7 @@ void QgsVertexTool::cadCanvasPressEvent( QgsMapMouseEvent *e )
|
||||
|
||||
// the user may have started dragging a rect to select vertices
|
||||
if ( !mDraggingVertex && !mDraggingEdge )
|
||||
mSelectionRubberBandStartPos.reset( new QPoint( e->pos() ) );
|
||||
mSelectionRubberBandStartPos = std::make_unique< QPoint >( e->pos() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -795,7 +795,7 @@ void QgsVertexTool::canvasDoubleClickEvent( QgsMapMouseEvent *e )
|
||||
if ( !m.hasEdge() )
|
||||
return;
|
||||
|
||||
mNewVertexFromDoubleClick.reset( new QgsPointLocator::Match( m ) );
|
||||
mNewVertexFromDoubleClick = std::make_unique< QgsPointLocator::Match >( m );
|
||||
}
|
||||
|
||||
void QgsVertexTool::removeTemporaryRubberBands()
|
||||
@ -932,7 +932,7 @@ QgsPointLocator::Match QgsVertexTool::snapToEditableLayer( QgsMapMouseEvent *e )
|
||||
|
||||
snapUtils->setConfig( oldConfig );
|
||||
|
||||
mLastSnap.reset( new QgsPointLocator::Match( m ) );
|
||||
mLastSnap = std::make_unique< QgsPointLocator::Match >( m );
|
||||
|
||||
return m;
|
||||
}
|
||||
@ -985,7 +985,7 @@ QgsPointLocator::Match QgsVertexTool::snapToPolygonInterior( QgsMapMouseEvent *e
|
||||
// if we don't have anything in the last snap, keep the area match
|
||||
if ( !mLastSnap && m.isValid() )
|
||||
{
|
||||
mLastSnap.reset( new QgsPointLocator::Match( m ) );
|
||||
mLastSnap = std::make_unique< QgsPointLocator::Match >( m );
|
||||
}
|
||||
|
||||
return m;
|
||||
@ -1066,7 +1066,7 @@ void QgsVertexTool::tryToSelectFeature( QgsMapMouseEvent *e )
|
||||
m = snapToPolygonInterior( e );
|
||||
}
|
||||
|
||||
mLockedFeatureAlternatives.reset( new LockedFeatureAlternatives );
|
||||
mLockedFeatureAlternatives = std::make_unique< LockedFeatureAlternatives >();
|
||||
mLockedFeatureAlternatives->screenPoint = e->pos();
|
||||
mLockedFeatureAlternatives->index = -1;
|
||||
if ( m.isValid() )
|
||||
@ -1203,8 +1203,8 @@ void QgsVertexTool::mouseMoveNotDragging( QgsMapMouseEvent *e )
|
||||
// so user can possibly add a new vertex at the end
|
||||
if ( isMatchAtEndpoint( m ) )
|
||||
{
|
||||
mMouseAtEndpoint.reset( new Vertex( m.layer(), m.featureId(), m.vertexIndex() ) );
|
||||
mEndpointMarkerCenter.reset( new QgsPointXY( positionForEndpointMarker( m ) ) );
|
||||
mMouseAtEndpoint = std::make_unique< Vertex >( m.layer(), m.featureId(), m.vertexIndex() );
|
||||
mEndpointMarkerCenter = std::make_unique< QgsPointXY >( positionForEndpointMarker( m ) );
|
||||
mEndpointMarker->setCenter( *mEndpointMarkerCenter );
|
||||
mEndpointMarker->setColor( Qt::gray );
|
||||
mEndpointMarker->setVisible( true );
|
||||
@ -1759,7 +1759,7 @@ void QgsVertexTool::startDraggingMoveVertex( const QgsPointLocator::Match &m )
|
||||
QgsGeometry geom = cachedGeometry( m.layer(), m.featureId() );
|
||||
|
||||
// start dragging of snapped point of current layer
|
||||
mDraggingVertex.reset( new Vertex( m.layer(), m.featureId(), m.vertexIndex() ) );
|
||||
mDraggingVertex = std::make_unique< Vertex >( m.layer(), m.featureId(), m.vertexIndex() );
|
||||
mDraggingVertexType = MovingVertex;
|
||||
mDraggingExtraVertices.clear();
|
||||
mDraggingExtraVerticesOffset.clear();
|
||||
@ -1919,7 +1919,7 @@ void QgsVertexTool::startDraggingAddVertex( const QgsPointLocator::Match &m )
|
||||
// activate advanced digitizing dock
|
||||
setAdvancedDigitizingAllowed( true );
|
||||
|
||||
mDraggingVertex.reset( new Vertex( m.layer(), m.featureId(), m.vertexIndex() + 1 ) );
|
||||
mDraggingVertex = std::make_unique< Vertex >( m.layer(), m.featureId(), m.vertexIndex() + 1 );
|
||||
mDraggingVertexType = AddingVertex;
|
||||
mDraggingExtraVertices.clear();
|
||||
mDraggingExtraVerticesOffset.clear();
|
||||
@ -1973,7 +1973,7 @@ void QgsVertexTool::startDraggingAddVertexAtEndpoint( const QgsPointXY &mapPoint
|
||||
// activate advanced digitizing dock
|
||||
setAdvancedDigitizingAllowed( true );
|
||||
|
||||
mDraggingVertex.reset( new Vertex( mMouseAtEndpoint->layer, mMouseAtEndpoint->fid, mMouseAtEndpoint->vertexId ) );
|
||||
mDraggingVertex = std::make_unique< Vertex >( mMouseAtEndpoint->layer, mMouseAtEndpoint->fid, mMouseAtEndpoint->vertexId );
|
||||
mDraggingVertexType = AddingEndpoint;
|
||||
mDraggingExtraVertices.clear();
|
||||
mDraggingExtraVerticesOffset.clear();
|
||||
@ -2135,7 +2135,7 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato
|
||||
return;
|
||||
}
|
||||
|
||||
QgsAbstractGeometry *geomTmp = geom.constGet()->clone();
|
||||
std::unique_ptr< QgsAbstractGeometry > geomTmp( geom.constGet()->clone() );
|
||||
|
||||
// If moving point is not 3D but destination yes, check if it can be promoted
|
||||
if ( layerPoint.is3D() && !geomTmp->is3D() && QgsWkbTypes::hasZ( dragLayer->wkbType() ) )
|
||||
@ -2185,10 +2185,10 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato
|
||||
}
|
||||
}
|
||||
|
||||
geom.set( geomTmp );
|
||||
geom = QgsGeometry( std::move( geomTmp ) );
|
||||
|
||||
VertexEdits edits; // dict { layer : { fid : geom } }
|
||||
edits[dragLayer][dragFid] = VertexEdit( geom, geomTmp->vertexAt( vid ) );
|
||||
edits[dragLayer][dragFid] = VertexEdit( geom, geom.get()->vertexAt( vid ) );
|
||||
|
||||
addExtraVerticesToEdits( edits, mapPoint, dragLayer, layerPoint );
|
||||
|
||||
@ -2276,7 +2276,7 @@ void QgsVertexTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocato
|
||||
if ( mMouseAtEndpoint->vertexId != 0 )
|
||||
{
|
||||
// If we were adding at the end of the feature, we need to update the index
|
||||
mMouseAtEndpoint.reset( new Vertex( mMouseAtEndpoint->layer, mMouseAtEndpoint->fid, mMouseAtEndpoint->vertexId + 1 ) );
|
||||
mMouseAtEndpoint = std::make_unique< Vertex >( mMouseAtEndpoint->layer, mMouseAtEndpoint->fid, mMouseAtEndpoint->vertexId + 1 );
|
||||
}
|
||||
// And then we just restart the drag
|
||||
startDraggingAddVertexAtEndpoint( mapPoint );
|
||||
@ -3079,7 +3079,7 @@ void QgsVertexTool::rangeMethodReleaseEvent( QgsMapMouseEvent *e )
|
||||
QgsPointLocator::Match m = snapToEditableLayer( e );
|
||||
if ( m.hasVertex() )
|
||||
{
|
||||
mRangeSelectionFirstVertex.reset( new Vertex( m.layer(), m.featureId(), m.vertexIndex() ) );
|
||||
mRangeSelectionFirstVertex = std::make_unique< Vertex >( m.layer(), m.featureId(), m.vertexIndex() );
|
||||
setHighlightedVertices( QList<Vertex>() << *mRangeSelectionFirstVertex );
|
||||
}
|
||||
}
|
||||
|
@ -510,6 +510,8 @@ class APP_EXPORT QgsVertexTool : public QgsMapToolAdvancedDigitizing
|
||||
std::unique_ptr<Vertex> mRangeSelectionFirstVertex;
|
||||
|
||||
VertexToolMode mMode = AllLayers;
|
||||
|
||||
friend class TestQgsVertexTool;
|
||||
};
|
||||
|
||||
|
||||
|
@ -60,7 +60,9 @@ class TestQgsVertexTool : public QObject
|
||||
TestQgsVertexTool();
|
||||
|
||||
private slots:
|
||||
void initTestCase(); // will be called before the first testfunction is executed.
|
||||
void initTestCase(); // will be called before the first testfunction is executed.
|
||||
void init();
|
||||
void cleanup();
|
||||
void cleanupTestCase(); // will be called after the last testfunction was executed.
|
||||
|
||||
void testSelectVerticesByPolygon();
|
||||
@ -151,19 +153,20 @@ class TestQgsVertexTool : public QObject
|
||||
}
|
||||
|
||||
private:
|
||||
QgsCoordinateReferenceSystem mFake27700;
|
||||
QgsMapCanvas *mCanvas = nullptr;
|
||||
QgisApp *mQgisApp = nullptr;
|
||||
QgsAdvancedDigitizingDockWidget *mAdvancedDigitizingDockWidget = nullptr;
|
||||
QgsVertexTool *mVertexTool = nullptr;
|
||||
QgsVectorLayer *mLayerLine = nullptr;
|
||||
QgsVectorLayer *mLayerMultiLine = nullptr;
|
||||
QgsVectorLayer *mLayerPolygon = nullptr;
|
||||
QgsVectorLayer *mLayerMultiPolygon = nullptr;
|
||||
QgsVectorLayer *mLayerPoint = nullptr;
|
||||
QgsVectorLayer *mLayerPointZ = nullptr;
|
||||
QgsVectorLayer *mLayerLineZ = nullptr;
|
||||
QgsVectorLayer *mLayerCompoundCurve = nullptr;
|
||||
QgsVectorLayer *mLayerLineReprojected = nullptr;
|
||||
QPointer< QgsVectorLayer > mLayerLine;
|
||||
QPointer< QgsVectorLayer > mLayerMultiLine;
|
||||
QPointer< QgsVectorLayer > mLayerPolygon;
|
||||
QPointer< QgsVectorLayer > mLayerMultiPolygon;
|
||||
QPointer< QgsVectorLayer > mLayerPoint;
|
||||
QPointer< QgsVectorLayer > mLayerPointZ;
|
||||
QPointer< QgsVectorLayer > mLayerLineZ;
|
||||
QPointer< QgsVectorLayer > mLayerCompoundCurve;
|
||||
QPointer< QgsVectorLayer > mLayerLineReprojected;
|
||||
QgsFeatureId mFidLineZF1 = 0;
|
||||
QgsFeatureId mFidLineZF2 = 0;
|
||||
QgsFeatureId mFidLineZF3 = 0;
|
||||
@ -186,42 +189,59 @@ void TestQgsVertexTool::initTestCase()
|
||||
{
|
||||
qDebug() << "TestQgsVertexTool::initTestCase()";
|
||||
// init QGIS's paths - true means that all path will be inited from prefix
|
||||
QgsApplication::init();
|
||||
QgsApplication::initQgis();
|
||||
mQgisApp = new QgisApp();
|
||||
|
||||
// Set up the QSettings environment
|
||||
QCoreApplication::setOrganizationName( QStringLiteral( "QGIS" ) );
|
||||
QCoreApplication::setOrganizationDomain( QStringLiteral( "qgis.org" ) );
|
||||
QCoreApplication::setApplicationName( QStringLiteral( "QGIS-TEST" ) );
|
||||
|
||||
mCanvas = new QgsMapCanvas();
|
||||
QgsApplication::init();
|
||||
QgsApplication::initQgis();
|
||||
|
||||
mCanvas->setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:27700" ) ) );
|
||||
QgsSettings().clear();
|
||||
|
||||
mAdvancedDigitizingDockWidget = new QgsAdvancedDigitizingDockWidget( mCanvas );
|
||||
// EPSG:27700 was a silly choice for these tests, as the transformations rely on the presence of a grid shift
|
||||
// file which may or may not be present on some platforms :'(
|
||||
|
||||
// Fake a similar CRS which can't use grid based transforms ;)
|
||||
mFake27700 = QgsCoordinateReferenceSystem::fromProj( "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=4000.0000001 +y_0=-100000 +ellps=airy +units=m +no_defs" );
|
||||
QCOMPARE( mFake27700.authid(), QString() );
|
||||
|
||||
mQgisApp = new QgisApp();
|
||||
}
|
||||
|
||||
void TestQgsVertexTool::init()
|
||||
{
|
||||
// make testing layers
|
||||
mLayerLine = new QgsVectorLayer( QStringLiteral( "LineString?crs=EPSG:27700" ), QStringLiteral( "layer line" ), QStringLiteral( "memory" ) );
|
||||
mLayerLine = new QgsVectorLayer( QStringLiteral( "LineString?" ), QStringLiteral( "layer line" ), QStringLiteral( "memory" ) );
|
||||
mLayerLine->setCrs( mFake27700 );
|
||||
QVERIFY( mLayerLine->isValid() );
|
||||
mLayerMultiLine = new QgsVectorLayer( QStringLiteral( "MultiLineString?crs=EPSG:27700" ), QStringLiteral( "layer multiline" ), QStringLiteral( "memory" ) );
|
||||
mLayerMultiLine = new QgsVectorLayer( QStringLiteral( "MultiLineString?" ), QStringLiteral( "layer multiline" ), QStringLiteral( "memory" ) );
|
||||
mLayerMultiLine->setCrs( mFake27700 );
|
||||
QVERIFY( mLayerMultiLine->isValid() );
|
||||
mLayerLineReprojected = new QgsVectorLayer( QStringLiteral( "LineString?crs=EPSG:3857" ), QStringLiteral( "layer line" ), QStringLiteral( "memory" ) );
|
||||
mLayerLineReprojected = new QgsVectorLayer( QStringLiteral( "LineString?crs=EPSG:3857" ), QStringLiteral( "layer line reprojected" ), QStringLiteral( "memory" ) );
|
||||
QVERIFY( mLayerLineReprojected->isValid() );
|
||||
mLayerPolygon = new QgsVectorLayer( QStringLiteral( "Polygon?crs=EPSG:27700" ), QStringLiteral( "layer polygon" ), QStringLiteral( "memory" ) );
|
||||
mLayerPolygon = new QgsVectorLayer( QStringLiteral( "Polygon?" ), QStringLiteral( "layer polygon" ), QStringLiteral( "memory" ) );
|
||||
QVERIFY( mLayerPolygon->isValid() );
|
||||
mLayerMultiPolygon = new QgsVectorLayer( QStringLiteral( "MultiPolygon?crs=EPSG:27700" ), QStringLiteral( "layer multipolygon" ), QStringLiteral( "memory" ) );
|
||||
mLayerPolygon->setCrs( mFake27700 );
|
||||
mLayerMultiPolygon = new QgsVectorLayer( QStringLiteral( "MultiPolygon?" ), QStringLiteral( "layer multipolygon" ), QStringLiteral( "memory" ) );
|
||||
QVERIFY( mLayerMultiPolygon->isValid() );
|
||||
mLayerPoint = new QgsVectorLayer( QStringLiteral( "Point?crs=EPSG:27700" ), QStringLiteral( "layer point" ), QStringLiteral( "memory" ) );
|
||||
mLayerMultiPolygon->setCrs( mFake27700 );
|
||||
mLayerPoint = new QgsVectorLayer( QStringLiteral( "Point?" ), QStringLiteral( "layer point" ), QStringLiteral( "memory" ) );
|
||||
QVERIFY( mLayerPoint->isValid() );
|
||||
mLayerPointZ = new QgsVectorLayer( QStringLiteral( "PointZ?crs=EPSG:27700" ), QStringLiteral( "layer pointz" ), QStringLiteral( "memory" ) );
|
||||
mLayerPoint->setCrs( mFake27700 );
|
||||
mLayerPointZ = new QgsVectorLayer( QStringLiteral( "PointZ?" ), QStringLiteral( "layer pointz" ), QStringLiteral( "memory" ) );
|
||||
QVERIFY( mLayerPointZ->isValid() );
|
||||
mLayerLineZ = new QgsVectorLayer( QStringLiteral( "LineStringZ?crs=EPSG:27700" ), QStringLiteral( "layer line" ), QStringLiteral( "memory" ) );
|
||||
mLayerPointZ->setCrs( mFake27700 );
|
||||
mLayerLineZ = new QgsVectorLayer( QStringLiteral( "LineStringZ?" ), QStringLiteral( "layer line z" ), QStringLiteral( "memory" ) );
|
||||
QVERIFY( mLayerLineZ->isValid() );
|
||||
mLayerCompoundCurve = new QgsVectorLayer( QStringLiteral( "CompoundCurve?crs=27700" ), QStringLiteral( "layer compound curve" ), QStringLiteral( "memory" ) );
|
||||
mLayerLineZ->setCrs( mFake27700 );
|
||||
mLayerCompoundCurve = new QgsVectorLayer( QStringLiteral( "CompoundCurve?" ), QStringLiteral( "layer compound curve" ), QStringLiteral( "memory" ) );
|
||||
QVERIFY( mLayerCompoundCurve->isValid() );
|
||||
mLayerCompoundCurve->setCrs( mFake27700 );
|
||||
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayerLine << mLayerMultiLine << mLayerPolygon << mLayerMultiPolygon << mLayerPoint << mLayerPointZ << mLayerLineZ << mLayerCompoundCurve );
|
||||
|
||||
|
||||
QgsFeature lineF1;
|
||||
lineF1.setGeometry( QgsGeometry::fromWkt( "LineString (2 1, 1 1, 1 3)" ) );
|
||||
|
||||
@ -268,7 +288,8 @@ void TestQgsVertexTool::initTestCase()
|
||||
|
||||
mLayerLineReprojected->startEditing();
|
||||
mLayerLineReprojected->addFeature( lineF13857 );
|
||||
mFidLineF13857 = lineF13857.id();
|
||||
mLayerLineReprojected->commitChanges();
|
||||
mFidLineF13857 = *( mLayerLineReprojected->allFeatureIds().begin() );
|
||||
QCOMPARE( mLayerLineReprojected->featureCount(), ( long ) 1 );
|
||||
|
||||
mLayerPolygon->startEditing();
|
||||
@ -318,6 +339,14 @@ void TestQgsVertexTool::initTestCase()
|
||||
QCOMPARE( mLayerLineZ->undoStack()->index(), 3 );
|
||||
QCOMPARE( mLayerCompoundCurve->undoStack()->index(), 2 );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( false );
|
||||
|
||||
mCanvas = new QgsMapCanvas();
|
||||
|
||||
mCanvas->setDestinationCrs( mFake27700 );
|
||||
|
||||
mAdvancedDigitizingDockWidget = new QgsAdvancedDigitizingDockWidget( mCanvas );
|
||||
|
||||
mCanvas->setFrameStyle( QFrame::NoFrame );
|
||||
mCanvas->resize( 512, 512 );
|
||||
mCanvas->setExtent( QgsRectangle( 0, 0, 8, 8 ) );
|
||||
@ -345,6 +374,25 @@ void TestQgsVertexTool::initTestCase()
|
||||
mVertexTool = new QgsVertexTool( mCanvas, mAdvancedDigitizingDockWidget );
|
||||
|
||||
mCanvas->setMapTool( mVertexTool );
|
||||
|
||||
QgsSnappingConfig cfg = mCanvas->snappingUtils()->config();
|
||||
cfg.setEnabled( false );
|
||||
mCanvas->snappingUtils()->setConfig( cfg );
|
||||
}
|
||||
|
||||
void TestQgsVertexTool::cleanup()
|
||||
{
|
||||
mLayerLine->rollBack();
|
||||
mLayerMultiLine->rollBack();
|
||||
mLayerLineReprojected->rollBack();
|
||||
mLayerPolygon->rollBack();
|
||||
mLayerMultiPolygon->rollBack();
|
||||
mLayerPoint->rollBack();
|
||||
mLayerPointZ->rollBack();
|
||||
mLayerLineZ->rollBack();
|
||||
mLayerCompoundCurve->rollBack();
|
||||
|
||||
QgsProject::instance()->clear();
|
||||
}
|
||||
|
||||
//runs after all tests
|
||||
@ -361,7 +409,6 @@ void TestQgsVertexTool::testTopologicalEditingMoveVertexZ()
|
||||
QCOMPARE( mLayerLineZ->undoStack()->index(), 3 );
|
||||
QCOMPARE( mLayerLineZ->featureCount(), ( long ) 3 );
|
||||
|
||||
const bool topologicalEditing = QgsProject::instance()->topologicalEditing();
|
||||
QgsProject::instance()->setTopologicalEditing( true );
|
||||
QgsSnappingConfig cfg = mCanvas->snappingUtils()->config();
|
||||
cfg.setMode( Qgis::SnappingMode::AllLayers );
|
||||
@ -376,7 +423,6 @@ void TestQgsVertexTool::testTopologicalEditingMoveVertexZ()
|
||||
QCOMPARE( mLayerLineZ->getFeature( mFidLineZF1 ).geometry().asWkt(), QString( "LineString Z (5 5 1, 5 7 5, 7 5 1)" ) );
|
||||
QCOMPARE( mLayerLineZ->getFeature( mFidLineZF2 ).geometry().asWkt(), QString( "LineString Z (5 7 5, 7 7 10)" ) );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( topologicalEditing );
|
||||
mLayerLineZ->undoStack()->undo();
|
||||
cfg.setEnabled( false );
|
||||
mCanvas->snappingUtils()->setConfig( cfg );
|
||||
@ -392,7 +438,6 @@ void TestQgsVertexTool::testTopologicalEditingMoveVertexOnSegmentZ()
|
||||
|
||||
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue->setValue( 333 );
|
||||
|
||||
const bool topologicalEditing = QgsProject::instance()->topologicalEditing();
|
||||
QgsProject::instance()->setTopologicalEditing( true );
|
||||
QgsSnappingConfig cfg = mCanvas->snappingUtils()->config();
|
||||
cfg.setMode( Qgis::SnappingMode::AllLayers );
|
||||
@ -407,7 +452,6 @@ void TestQgsVertexTool::testTopologicalEditingMoveVertexOnSegmentZ()
|
||||
QCOMPARE( mLayerLineZ->getFeature( mFidLineZF1 ).geometry().asWkt(), QString( "LineString Z (5 5 1, 6 7 7.5, 7 5 1)" ) );
|
||||
QCOMPARE( mLayerLineZ->getFeature( mFidLineZF2 ).geometry().asWkt(), QString( "LineString Z (5 7 5, 6 7 7.5, 7 7 10)" ) );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( topologicalEditing );
|
||||
// Two undo steps, one for the vertex move, one for the topological point
|
||||
mLayerLineZ->undoStack()->undo();
|
||||
mLayerLineZ->undoStack()->undo();
|
||||
@ -422,7 +466,6 @@ void TestQgsVertexTool::testTopologicalEditingMoveVertexOnIntersectionZ()
|
||||
{
|
||||
QgsSettingsRegistryCore::settingsDigitizingDefaultZValue->setValue( 333 );
|
||||
|
||||
const bool topologicalEditing = QgsProject::instance()->topologicalEditing();
|
||||
QgsProject::instance()->setTopologicalEditing( true );
|
||||
QgsSnappingConfig cfg = mCanvas->snappingUtils()->config();
|
||||
cfg.setMode( Qgis::SnappingMode::AllLayers );
|
||||
@ -440,7 +483,6 @@ void TestQgsVertexTool::testTopologicalEditingMoveVertexOnIntersectionZ()
|
||||
QCOMPARE( mLayerLineZ->getFeature( mFidLineZF1 ).geometry().asWkt(), QString( "LineString Z (5 5 1, 5.5 5.5 5, 6 6 1, 7 5 1)" ) );
|
||||
QCOMPARE( mLayerLineZ->getFeature( mFidLineZF3 ).geometry().asWkt(), QString( "LineString Z (5.5 5.5 5, 7 5.5 10)" ) );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( topologicalEditing );
|
||||
// Two undo steps, one for the vertex move, one for the topological point
|
||||
mLayerLineZ->undoStack()->undo();
|
||||
mLayerLineZ->undoStack()->undo();
|
||||
@ -462,7 +504,6 @@ void TestQgsVertexTool::testTopologicalEditingMoveVerticesOnSegmentZ()
|
||||
QCOMPARE( mLayerLineZ->featureCount(), ( long ) 4 );
|
||||
|
||||
// Activates topological editing
|
||||
const bool topologicalEditing = QgsProject::instance()->topologicalEditing();
|
||||
QgsProject::instance()->setTopologicalEditing( true );
|
||||
|
||||
// And snapping
|
||||
@ -489,7 +530,6 @@ void TestQgsVertexTool::testTopologicalEditingMoveVerticesOnSegmentZ()
|
||||
// Undo changes
|
||||
mLayerLineZ->deleteFeature( linez.id() );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( topologicalEditing );
|
||||
mLayerLineZ->undoStack()->undo();
|
||||
mLayerLineZ->undoStack()->undo();
|
||||
mLayerLineZ->undoStack()->undo();
|
||||
@ -509,10 +549,17 @@ void TestQgsVertexTool::testMoveVertex()
|
||||
// move vertex of linestring
|
||||
|
||||
mouseClick( 2, 1, Qt::LeftButton );
|
||||
QCOMPARE( mVertexTool->mDraggingVertexType, QgsVertexTool::DraggingVertexType::MovingVertex );
|
||||
QCOMPARE( mVertexTool->mDraggingVertex->layer->id(), mLayerLine->id() );
|
||||
QCOMPARE( mVertexTool->mDraggingVertex->fid, mFidLineF1 );
|
||||
QCOMPARE( mVertexTool->mDraggingVertex->vertexId, 0 );
|
||||
mouseClick( 2, 2, Qt::LeftButton );
|
||||
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry().asWkt( 0 ), "LineString (2 2, 1 1, 1 3)" );
|
||||
|
||||
QCOMPARE( mLayerLine->undoStack()->count(), 2 );
|
||||
|
||||
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 2, 1 1, 1 3)" ) );
|
||||
|
||||
mLayerLine->undoStack()->undo();
|
||||
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
|
||||
@ -968,6 +1015,12 @@ void TestQgsVertexTool::testConvertVertex()
|
||||
|
||||
void TestQgsVertexTool::testMoveMultipleVertices()
|
||||
{
|
||||
mLayerLineReprojected->startEditing();
|
||||
QCOMPARE( mLayerLineReprojected->undoStack()->index(), 0 );
|
||||
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry().asWkt( 0 ), QStringLiteral( "LineString (2 1, 1 1, 1 3)" ) );
|
||||
QCOMPARE( mLayerLineReprojected->getFeature( mFidLineF13857 ).geometry().asWkt( 0 ), QStringLiteral( "LineString (-228837 6428900, -228838 6428900, -228838 6428903)" ) );
|
||||
|
||||
// select two vertices
|
||||
mousePress( 0.5, 0.5, Qt::LeftButton );
|
||||
mouseMove( 1.5, 3.5 );
|
||||
@ -981,16 +1034,20 @@ void TestQgsVertexTool::testMoveMultipleVertices()
|
||||
mouseClick( 8, 8, Qt::LeftButton );
|
||||
|
||||
QCOMPARE( mLayerLine->undoStack()->index(), 2 );
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 0 0, 0 2)" ) );
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry().asWkt( 0 ), QStringLiteral( "LineString (2 1, 0 0, 0 2)" ) );
|
||||
QCOMPARE( mLayerLineReprojected->getFeature( mFidLineF13857 ).geometry().asWkt( 0 ), QStringLiteral( "LineString (-228837 6428900, -228840 6428899, -228840 6428902)" ) );
|
||||
|
||||
mLayerLine->undoStack()->undo();
|
||||
QCOMPARE( mLayerLine->undoStack()->index(), 1 );
|
||||
QCOMPARE( mLayerLineReprojected->undoStack()->index(), 1 );
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry().asWkt( 0 ), QStringLiteral( "LineString (2 1, 1 1, 1 3)" ) );
|
||||
QCOMPARE( mLayerLineReprojected->getFeature( mFidLineF13857 ).geometry().asWkt( 0 ), QStringLiteral( "LineString (-228837 6428900, -228840 6428899, -228840 6428902)" ) );
|
||||
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
|
||||
|
||||
QCOMPARE( mLayerLineReprojected->getFeature( mFidLineF13857 ).geometry().asWkt( 0 ), QStringLiteral( "LineString (-841256 6405990, -841259 6405988)" ) );
|
||||
mLayerLineReprojected->undoStack()->undo();
|
||||
QCOMPARE( mLayerLineReprojected->getFeature( mFidLineF13857 ).geometry().asWkt( 0 ), QStringLiteral( "LineString (-841256 6405990, -841258 6405990)" ) );
|
||||
QCOMPARE( mLayerLineReprojected->getFeature( mFidLineF13857 ).geometry().asWkt( 0 ), QStringLiteral( "LineString (-228837 6428900, -228838 6428900, -228838 6428903)" ) );
|
||||
}
|
||||
|
||||
void TestQgsVertexTool::testMoveMultipleVertices2()
|
||||
@ -1037,8 +1094,6 @@ void TestQgsVertexTool::testMoveVertexTopo()
|
||||
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
|
||||
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( false );
|
||||
}
|
||||
|
||||
void TestQgsVertexTool::testDeleteVertexTopo()
|
||||
@ -1066,8 +1121,6 @@ void TestQgsVertexTool::testDeleteVertexTopo()
|
||||
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
|
||||
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( false );
|
||||
}
|
||||
|
||||
void TestQgsVertexTool::testAddVertexTopo()
|
||||
@ -1097,8 +1150,6 @@ void TestQgsVertexTool::testAddVertexTopo()
|
||||
mLayerPolygon->undoStack()->undo();
|
||||
|
||||
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( false );
|
||||
}
|
||||
|
||||
void TestQgsVertexTool::testMoveEdgeTopo()
|
||||
@ -1154,8 +1205,6 @@ void TestQgsVertexTool::testMoveEdgeTopo()
|
||||
mLayerPolygon->undoStack()->undo();
|
||||
|
||||
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( false );
|
||||
}
|
||||
|
||||
void TestQgsVertexTool::testAddVertexTopoFirstSegment()
|
||||
@ -1175,8 +1224,6 @@ void TestQgsVertexTool::testAddVertexTopoFirstSegment()
|
||||
mLayerPolygon->undoStack()->undo();
|
||||
|
||||
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( false );
|
||||
}
|
||||
|
||||
void TestQgsVertexTool::testAddVertexTopoMultipleLayers()
|
||||
@ -1190,7 +1237,6 @@ void TestQgsVertexTool::testAddVertexTopoMultipleLayers()
|
||||
QVERIFY( resAdd );
|
||||
const QgsFeatureId fTmpId = fTmp.id();
|
||||
|
||||
const bool topologicalEditing = QgsProject::instance()->topologicalEditing();
|
||||
QgsProject::instance()->setTopologicalEditing( true );
|
||||
QgsSnappingConfig cfg = mCanvas->snappingUtils()->config();
|
||||
cfg.setMode( Qgis::SnappingMode::AllLayers );
|
||||
@ -1231,7 +1277,6 @@ void TestQgsVertexTool::testAddVertexTopoMultipleLayers()
|
||||
|
||||
QCOMPARE( mLayerPolygon->undoStack()->index(), 1 );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( topologicalEditing );
|
||||
cfg.setEnabled( false );
|
||||
mCanvas->snappingUtils()->setConfig( cfg );
|
||||
}
|
||||
@ -1383,7 +1428,6 @@ void TestQgsVertexTool::testAvoidIntersections()
|
||||
|
||||
QCOMPARE( mLayerPolygon->featureCount(), ( long ) 1 );
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( false );
|
||||
QgsProject::instance()->setAvoidIntersectionsMode( mode );
|
||||
}
|
||||
|
||||
@ -1434,7 +1478,8 @@ void TestQgsVertexTool::testActiveLayerPriority()
|
||||
// check that features from current layer get priority when picking points
|
||||
|
||||
// create a temporary line layer that has a common vertex with existing line layer at (1, 1)
|
||||
QgsVectorLayer *layerLine2 = new QgsVectorLayer( QStringLiteral( "LineString?crs=EPSG:27700" ), QStringLiteral( "layer line 2" ), QStringLiteral( "memory" ) );
|
||||
QgsVectorLayer *layerLine2 = new QgsVectorLayer( QStringLiteral( "LineString?" ), QStringLiteral( "layer line 2" ), QStringLiteral( "memory" ) );
|
||||
layerLine2->setCrs( mFake27700 );
|
||||
QVERIFY( layerLine2->isValid() );
|
||||
QgsPolylineXY line1;
|
||||
line1 << QgsPointXY( 0, 1 ) << QgsPointXY( 1, 1 ) << QgsPointXY( 1, 0 );
|
||||
@ -1445,7 +1490,6 @@ void TestQgsVertexTool::testActiveLayerPriority()
|
||||
const QgsFeatureId fidLineF1 = lineF1.id();
|
||||
QCOMPARE( layerLine2->featureCount(), ( long ) 1 );
|
||||
QgsProject::instance()->addMapLayer( layerLine2 );
|
||||
QList<QgsMapLayer *> oldMapLayers = mCanvas->layers();
|
||||
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayerLine << mLayerPolygon << mLayerPoint << mLayerCompoundCurve << layerLine2 );
|
||||
|
||||
// make one layer active and check its vertex is used
|
||||
@ -1475,7 +1519,6 @@ void TestQgsVertexTool::testActiveLayerPriority()
|
||||
mCanvas->setCurrentLayer( nullptr );
|
||||
|
||||
// get rid of the temporary layer
|
||||
mCanvas->setLayers( oldMapLayers );
|
||||
QgsProject::instance()->removeMapLayer( layerLine2 );
|
||||
}
|
||||
|
||||
@ -1643,18 +1686,19 @@ void TestQgsVertexTool::testSelectVerticesByPolygon()
|
||||
|
||||
void TestQgsVertexTool::testMoveVertexTopoOtherMapCrs()
|
||||
{
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry().asWkt( 2 ), "LineString (2 1, 1 1, 1 3)" );
|
||||
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry().asWkt( 2 ), "Polygon ((4 1, 7 1, 7 4, 4 4, 4 1))" );
|
||||
|
||||
// test moving of vertices of two features at once
|
||||
|
||||
QgsProject::instance()->setTopologicalEditing( true );
|
||||
QgsCoordinateReferenceSystem prevCrs = QgsProject::instance()->crs();
|
||||
QgsCoordinateReferenceSystem tmpCrs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) );
|
||||
|
||||
// move linestring vertex to connect with polygon at point (7, 1)
|
||||
mouseClick( 2, 1, Qt::LeftButton );
|
||||
mouseClick( 7, 1, Qt::LeftButton );
|
||||
|
||||
// change CRS so that the map canvas and the layers CRSs are different
|
||||
mCanvas->setDestinationCrs( tmpCrs );
|
||||
mCanvas->setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ) );
|
||||
mCanvas->snappingUtils()->locatorForLayer( mLayerLine )->init();
|
||||
mCanvas->snappingUtils()->locatorForLayer( mLayerPolygon )->init();
|
||||
|
||||
@ -1679,8 +1723,6 @@ void TestQgsVertexTool::testMoveVertexTopoOtherMapCrs()
|
||||
// back to the original state
|
||||
QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(2 1, 1 1, 1 3)" ) );
|
||||
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );
|
||||
mCanvas->setDestinationCrs( prevCrs );
|
||||
QgsProject::instance()->setTopologicalEditing( false );
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsVertexTool )
|
||||
|
Loading…
x
Reference in New Issue
Block a user