Skip to content

Commit

Permalink
sync vertices with matches
Browse files Browse the repository at this point in the history
  • Loading branch information
vcloarec committed Jul 29, 2020
1 parent 932151f commit 938c3ff
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions python/gui/auto_generated/qgsgeometryrubberband.sip.in
Expand Up @@ -99,6 +99,11 @@ Sets whether the vertices are drawn
QgsWkbTypes::GeometryType geometryType() const;
%Docstring
Returns which geometry is handled by the rubber band, polygon or line
%End

void setGeometryType( const QgsWkbTypes::GeometryType &geometryType );
%Docstring
Sets which geometry is handled by the rubber band, polygon or line
%End

};
Expand Down
38 changes: 34 additions & 4 deletions src/gui/qgsmaptoolcapture.cpp
Expand Up @@ -135,7 +135,7 @@ void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer )
}

if ( mTempRubberBand )
mTempRubberBand->setRubberBandGeometryType( CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );
mTempRubberBand->setRubberBandGeometryType( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );

resetRubberBand();
}
Expand Down Expand Up @@ -271,14 +271,17 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
// Move the last point of the captured curve to the first point on the trace string (necessary if there is offset)
QgsVertexId lastVertexId( 0, 0, mCaptureCurve.numPoints() - 1 );
mCaptureCurve.moveVertex( lastVertexId, layerPoints.first() );
mSnappingMatches.removeLast();
mSnappingMatches.append( QgsPointLocator::Match() );

int pointBefore = mCaptureCurve.numPoints();
mCaptureCurve.addCurve( new QgsLineString( layerPoints ) );

resetRubberBand();

// Curves de-approximation
QgsSettings settings;
//if ( settings.value( QStringLiteral( "/qgis/digitizing/convert_to_curve" ), false ).toBool() )
if ( settings.value( QStringLiteral( "/qgis/digitizing/convert_to_curve" ), false ).toBool() )
{
// If the tool and the layer support curves
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
Expand All @@ -293,6 +296,11 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
}
}

// sync the snapping matches list
int pointAfter = mCaptureCurve.numPoints();
for ( ; pointBefore < pointAfter; ++pointBefore )
mSnappingMatches.append( QgsPointLocator::Match() );

tracer->reportError( QgsTracer::ErrNone, true ); // clear messagebar if there was any error
return true;
}
Expand Down Expand Up @@ -556,6 +564,12 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
if ( match.isValid() && mSnappingMatches.count() > 0 && !mSnappingMatches.last().isValid() )
{
mSnappingMatches.removeLast();
if ( mTempRubberBand->stringType() == QgsWkbTypes::CircularString )
{
// for circular string two points are added and match for intermediate point is stored
mSnappingMatches.removeLast();
mSnappingMatches.append( mCircularIntermediateMatch );
}
mSnappingMatches.append( match );
}
}
Expand All @@ -567,6 +581,13 @@ int QgsMapToolCapture::addVertex( const QgsPointXY &point, const QgsPointLocator
mCaptureCurve.addVertex( layerPoint );
mSnappingMatches.append( match );
}
else
{
if ( mTempRubberBand->stringType() == QgsWkbTypes::CircularString )
{
mCircularIntermediateMatch = match;
}
}

mTempRubberBand->addPoint( mapPoint );

Expand Down Expand Up @@ -667,12 +688,19 @@ void QgsMapToolCapture::undo()
mCaptureCurve.addVertex( fp );
}
else
{
int pointsCountBefore = mCaptureCurve.numPoints();
mCaptureCurve.deleteVertex( vertexToRemove );
int pointsCountAfter = mCaptureCurve.numPoints();
for ( ; pointsCountAfter < pointsCountBefore; pointsCountAfter++ )
mSnappingMatches.removeLast();
}

mCaptureCurve.deleteVertex( vertexToRemove );
mSnappingMatches.removeAt( vertexToRemove.vertex );
updateExtraSnapLayer();

std::cout << "*************************** remaining vertices " << mCaptureCurve.numPoints() << std::endl;
std::cout << "*************************** remaining matches " << mSnappingMatches.count() << std::endl;

resetRubberBand();

mTempRubberBand->reset( mCaptureMode == CapturePolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry, mDigitizingType, firstCapturedMapPoint() );
Expand Down Expand Up @@ -855,6 +883,7 @@ void QgsMapToolCapture::setPoints( const QVector<QgsPointXY> &pointList )
mSnappingMatches.clear();
for ( int i = 0; i < line->length(); ++i )
mSnappingMatches.append( QgsPointLocator::Match() );
resetRubberBand();
}

void QgsMapToolCapture::setPoints( const QgsPointSequence &pointList )
Expand All @@ -866,6 +895,7 @@ void QgsMapToolCapture::setPoints( const QgsPointSequence &pointList )
mSnappingMatches.clear();
for ( int i = 0; i < line->length(); ++i )
mSnappingMatches.append( QgsPointLocator::Match() );
resetRubberBand();
}

QgsPoint QgsMapToolCapture::mapPoint( const QgsPointXY &point ) const
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsmaptoolcapture.h
Expand Up @@ -404,6 +404,7 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
QgsCompoundCurve mCaptureCurve;

QList<QgsPointLocator::Match> mSnappingMatches;
QgsPointLocator::Match mCircularIntermediateMatch = QgsPointLocator::Match();

void validateGeometry();
QgsGeometryValidator *mValidator = nullptr;
Expand Down

0 comments on commit 938c3ff

Please sign in to comment.