Skip to content
Permalink
Browse files

[tracing curves] add supports curve flag

  • Loading branch information
olivierdalang committed May 11, 2020
1 parent ac9752c commit 5d2e79e31dc81c3807e3c141b8710580145f8342
@@ -35,6 +35,11 @@ QgsMapToolAddPart::QgsMapToolAddPart( QgsMapCanvas *canvas )
connect( QgisApp::instance(), &QgisApp::projectRead, this, &QgsMapToolAddPart::stopCapturing );
}

QgsMapToolCapture::Capabilities QgsMapToolAddPart::capabilities() const
{
return QgsMapToolCapture::SupportsCurves;
}

void QgsMapToolAddPart::canvasReleaseEvent( QgsMapMouseEvent *e )
{
if ( checkSelection() )
@@ -23,6 +23,8 @@ class APP_EXPORT QgsMapToolAddPart : public QgsMapToolCapture
public:
QgsMapToolAddPart( QgsMapCanvas *canvas );

QgsMapToolCapture::Capabilities capabilities() const override;

void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;

@@ -66,6 +66,11 @@ QgsMapToolCapture::~QgsMapToolCapture()
}
}

QgsMapToolCapture::Capabilities QgsMapToolCapture::capabilities() const
{
return QgsMapToolCapture::NoCapabilities;
}

void QgsMapToolCapture::activate()
{
if ( mTempRubberBand )
@@ -289,14 +294,18 @@ bool QgsMapToolCapture::tracingAddVertex( const QgsPointXY &point )
mSnappingMatches.append( QgsPointLocator::Match() );
}

// If the layer supports curves, we de-approximate curves
// Curves de-approximation
QgsSettings settings;
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( vlayer->dataProvider()->capabilities().testFlag( QgsVectorDataProvider::Capability::CircularGeometries ) && settings.value( QStringLiteral( "/qgis/digitizing/convert_to_curve" ), false ).toBool() )
if ( settings.value( QStringLiteral( "/qgis/digitizing/convert_to_curve" ), false ).toBool() )
{
QgsGeometry linear = QgsGeometry( mCaptureCurve.segmentize() );
QgsGeometry curved = linear.convertToCurves();
mCaptureCurve = *qgsgeometry_cast<QgsCompoundCurve *>( curved.constGet() );
// If the tool and the layer support curves
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( capabilities().testFlag( QgsMapToolCapture::Capability::SupportsCurves ) && vlayer->dataProvider()->capabilities().testFlag( QgsVectorDataProvider::Capability::CircularGeometries ) )
{
QgsGeometry linear = QgsGeometry( mCaptureCurve.segmentize() );
QgsGeometry curved = linear.convertToCurves();
mCaptureCurve = *qgsgeometry_cast<QgsCompoundCurve *>( curved.constGet() );
}
}

tracer->reportError( QgsTracer::ErrNone, true ); // clear messagebar if there was any error
@@ -52,11 +52,24 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing
CapturePolygon //!< Capture polygons
};

enum Capability
{
NoCapabilities = 0, //!< Tool has no capabilities
SupportsCurves = 1, //!< Supports curved geometries input;
};

Q_DECLARE_FLAGS( Capabilities, Capability )

//! constructor
QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );

~QgsMapToolCapture() override;

/**
* Returns flags containing the supported capabilities
*/
virtual QgsMapToolCapture::Capabilities capabilities() const;

void activate() override;
void deactivate() override;

@@ -314,4 +327,6 @@ class GUI_EXPORT QgsMapToolCapture : public QgsMapToolAdvancedDigitizing

};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapToolCapture::Capabilities )

#endif
@@ -43,6 +43,11 @@ QgsMapToolDigitizeFeature::QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, QgsA
connect( QgsProject::instance(), &QgsProject::readProject, this, &QgsMapToolDigitizeFeature::stopCapturing );
}

QgsMapToolCapture::Capabilities QgsMapToolDigitizeFeature::capabilities() const
{
return QgsMapToolCapture::SupportsCurves;
}

void QgsMapToolDigitizeFeature::digitized( const QgsFeature &f )
{
emit digitizingCompleted( f );
@@ -42,6 +42,8 @@ class GUI_EXPORT QgsMapToolDigitizeFeature : public QgsMapToolCapture
*/
QgsMapToolDigitizeFeature( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode = QgsMapToolCapture::CaptureNone );

QgsMapToolCapture::Capabilities capabilities() const override;

void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;

/**

0 comments on commit 5d2e79e

Please sign in to comment.
You can’t perform that action at this time.