Skip to content

Commit

Permalink
wip test not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Djedouas committed Aug 9, 2024
1 parent 120fef1 commit 5bf20df
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/app/vertextool/qgsvertextool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class MatchCollectingFilter : public QgsPointLocator::MatchFilter

bool acceptMatch( const QgsPointLocator::Match &match ) override
{
std::cout << "filtering match from layer " << match.layer()->name().toStdString() << ", vertexNr " << match.vertexIndex() << std::endl;
if ( match.layer()->geometryType() != Qgis::GeometryType::Polygon )
return true;

Expand Down Expand Up @@ -213,6 +214,7 @@ class SelectedMatchFilter : public QgsPointLocator::MatchFilter

bool acceptMatch( const QgsPointLocator::Match &match ) override
{
std::cout << "SelectedMatchFilter: selecting best match, currently on match layer " << match.layer()->name().toStdString() << ", feature " << match.featureId() << ", match distance " << match.distance() << std::endl;
if ( match.distance() <= mTolerance && match.layer() )
{
// option 1: we have "locked" feature - we consider just a match from that feature
Expand Down Expand Up @@ -1659,6 +1661,8 @@ void QgsVertexTool::deleteVertexEditorSelection()
void QgsVertexTool::startDragging( QgsMapMouseEvent *e )
{
QgsPointXY mapPoint = toMapCoordinates( e->pos() );
std::cout << "start dragging, event map point : " << mapPoint << std::endl;

if ( isNearEndpointMarker( mapPoint ) )
{
startDraggingAddVertexAtEndpoint( mapPoint );
Expand All @@ -1667,10 +1671,15 @@ void QgsVertexTool::startDragging( QgsMapMouseEvent *e )

QgsPointLocator::Match m = snapToEditableLayer( e );
if ( !m.isValid() )
{
std::cout << "no valid match found" << std::endl << std::endl;
return;
}
if ( mLockedFeature && ( mLockedFeature->featureId() != m.featureId() || mLockedFeature->layer() != m.layer() ) )
return; // when a feature is bound to the vertex editor, only process actions for that feature

std::cout << "VALID match found" << std::endl << std::endl;

// activate advanced digitizing dock
setAdvancedDigitizingAllowed( true );

Expand Down Expand Up @@ -1708,22 +1717,30 @@ QSet<Vertex> QgsVertexTool::findCoincidentVertices( const QSet<Vertex> &vertices
{
QSet<Vertex> topoVertices;
const auto editableLayers = editableVectorLayers();
std::cout << "-----------------" << std::endl;
std::cout << "looping vertices" << std::endl;

for ( const Vertex &v : std::as_const( vertices ) )
{
QgsPointXY origPointV = cachedGeometryForVertex( v ).vertexAt( v.vertexId );
QgsPointXY mapPointV = toMapCoordinates( v.layer, origPointV );
std::cout << "\tlooping editable layers" << std::endl;
for ( QgsVectorLayer *vlayer : editableLayers )
{
const auto snappedVertices = layerVerticesSnappedToPoint( vlayer, mapPointV );
std::cout << "\t\tlooping matches in layer " << vlayer->name().toStdString() << std::endl;
for ( const QgsPointLocator::Match &otherMatch : snappedVertices )
{
std::cout << "\t\t\tfound match: layer: " << otherMatch.layer()->name().toStdString() << ", featureId: " << otherMatch.featureId() << std::endl;
std::cout << "\t\t\tfeature: " << otherMatch.layer()->getFeature( otherMatch.featureId() ).geometry().asWkt().toStdString() << std::endl;
std::cout << "\t\t\tvertexIndex: " << otherMatch.vertexIndex() << std::endl;
Vertex otherVertex( otherMatch.layer(), otherMatch.featureId(), otherMatch.vertexIndex() );
if ( !vertices.contains( otherVertex ) )
topoVertices << otherVertex;
}
}
}
std::cout << "-----------------" << std::endl;
return topoVertices;
}

Expand Down Expand Up @@ -1753,6 +1770,7 @@ void QgsVertexTool::buildExtraVertices( const QSet<Vertex> &vertices, const QgsP
void QgsVertexTool::startDraggingMoveVertex( const QgsPointLocator::Match &m )
{
Q_ASSERT( m.hasVertex() );
std::cout << "startDraggingMoveVertex" << std::endl;

QgsGeometry geom = cachedGeometry( m.layer(), m.featureId() );

Expand All @@ -1771,6 +1789,7 @@ void QgsVertexTool::startDraggingMoveVertex( const QgsPointLocator::Match &m )

if ( QgsProject::instance()->topologicalEditing() )
{
std::cout << "findCoincidentVertices" << std::endl;
movingVertices.unite( findCoincidentVertices( movingVertices ) );
}

Expand Down
56 changes: 56 additions & 0 deletions tests/src/app/testqgsvertextool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class TestQgsVertexTool : public QObject
void testActiveLayerPriority();
void testSelectedFeaturesPriority();
void testVertexToolCompoundCurve();
void testMoveVertexTopoOtherMapCrs();

private:
QPoint mapToScreen( double mapX, double mapY )
Expand Down Expand Up @@ -1589,5 +1590,60 @@ void TestQgsVertexTool::testSelectVerticesByPolygon()
QCOMPARE( mLayerMultiPolygon->getFeature( mFidMultiPolygonF1 ).geometry(), QgsGeometry::fromWkt( "MultiPolygon (((1 5, 2 5, 2 6.5, 2 8, 1 8, 1 6.5, 1 5),(1.25 5.5, 1.25 6, 1.75 6, 1.75 5.5, 1.25 5.5),(1.25 7, 1.75 7, 1.75 7.5, 1.25 7.5, 1.25 7)),((3 5, 3 6.5, 3 8, 4 8, 4 6.5, 4 5, 3 5),(3.25 5.5, 3.75 5.5, 3.75 6, 3.25 6, 3.25 5.5),(3.25 7, 3.75 7, 3.75 7.5, 3.25 7.5, 3.25 7)))" ) );
}

void TestQgsVertexTool::testMoveVertexTopoOtherMapCrs()
{
// test moving of vertices of two features at once

QgsProject::instance()->setTopologicalEditing( true );
QgsCoordinateReferenceSystem prevCrs = QgsProject::instance()->crs();
QgsCoordinateReferenceSystem tmpCrs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4126" ) );

// connect linestring with polygon at point (7, 1)
mouseClick( 2, 1, Qt::LeftButton );
mouseClick( 7, 1, Qt::LeftButton );

QgsProject::instance()->setCrs( tmpCrs );
mCanvas->setDestinationCrs( tmpCrs );
mCanvas->refreshAllLayers();

QgsPointXY mapPointStart = mCanvas->mapSettings().layerToMapCoordinates( mLayerPolygon, QgsPointXY( 7, 1 ) );
QgsPointXY mapPointEnd = mCanvas->mapSettings().layerToMapCoordinates( mLayerPolygon, QgsPointXY( 3, 3 ) );

auto it = mLayerPolygon->getFeature( mFidPolygonF1 ).geometry().constGet()->vertices();
while ( it.hasNext() )
{
auto pt = it.next();
std::cout << pt << std::endl;
auto mapPt = mCanvas->mapSettings().layerToMapCoordinates( mLayerPolygon, pt );
std::cout << mapPt << std::endl;
std::cout << mapToScreen( mapPt.x(), mapPt.y() ) << std::endl;
}
std::cout << "-----" << std::endl;
std::cout << "pt start: " << mapPointStart << std::endl;
std::cout << "pt end : " << mapPointEnd << std::endl;
std::cout << "screen pt start: " << mapToScreen( mapPointStart.x(), mapPointStart.y() ) << std::endl;
std::cout << "-----" << std::endl;

// move shared vertex of linestring and polygon
mouseClick( mapPointStart.x(), mapPointStart.y(), Qt::LeftButton );
mouseClick( mapPointEnd.x(), mapPointEnd.y(), Qt::LeftButton );

QCOMPARE( mLayerLine->getFeature( mFidLineF1 ).geometry(), QgsGeometry::fromWkt( "LINESTRING(3 3, 1 1, 1 3)" ) );
QCOMPARE( mLayerPolygon->getFeature( mFidPolygonF1 ).geometry(), QgsGeometry::fromWkt( "POLYGON((4 1, 7 1, 7 4, 4 4, 4 1))" ) );

QCOMPARE( mLayerLine->undoStack()->index(), 2 );
QCOMPARE( mLayerPolygon->undoStack()->index(), 3 ); // one more move of vertex from earlier
mLayerLine->undoStack()->undo();
mLayerPolygon->undoStack()->undo();
mLayerPolygon->undoStack()->undo();

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()->setCrs( prevCrs );
QgsProject::instance()->setTopologicalEditing( false );
}

QGSTEST_MAIN( TestQgsVertexTool )
#include "testqgsvertextool.moc"

0 comments on commit 5bf20df

Please sign in to comment.