From d2076a1400c8ac0d897a9f634de0410178602b15 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Sun, 13 Aug 2017 12:29:05 +0200 Subject: [PATCH] Convert more dynamic_casts to qgsgeometry_casts --- src/core/geometry/qgscompoundcurve.cpp | 2 +- src/core/geometry/qgscurvepolygon.cpp | 4 ++-- src/core/geometry/qgsgeometryeditutils.cpp | 4 ++-- src/core/geometry/qgsgeometryutils.cpp | 6 +++--- src/core/geometry/qgsgeos.cpp | 8 ++++---- src/core/geometry/qgsinternalgeometryengine.cpp | 2 +- src/core/geometry/qgslinestring.cpp | 2 +- src/core/geometry/qgsmulticurve.cpp | 2 +- src/core/geometry/qgsmultipoint.cpp | 2 +- src/core/geometry/qgsmultipolygon.cpp | 6 +++--- src/core/geometry/qgspolygon.cpp | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/core/geometry/qgscompoundcurve.cpp b/src/core/geometry/qgscompoundcurve.cpp index 258e6dbc579..3a7be6bf7dc 100644 --- a/src/core/geometry/qgscompoundcurve.cpp +++ b/src/core/geometry/qgscompoundcurve.cpp @@ -222,7 +222,7 @@ QString QgsCompoundCurve::asWkt( int precision ) const Q_FOREACH ( const QgsCurve *curve, mCurves ) { QString childWkt = curve->asWkt( precision ); - if ( dynamic_cast( curve ) ) + if ( qgsgeometry_cast( curve ) ) { // Type names of linear geometries are omitted childWkt = childWkt.mid( childWkt.indexOf( '(' ) ); diff --git a/src/core/geometry/qgscurvepolygon.cpp b/src/core/geometry/qgscurvepolygon.cpp index b10280f856c..00f26ec8bcc 100644 --- a/src/core/geometry/qgscurvepolygon.cpp +++ b/src/core/geometry/qgscurvepolygon.cpp @@ -255,7 +255,7 @@ QString QgsCurvePolygon::asWkt( int precision ) const if ( mExteriorRing ) { QString childWkt = mExteriorRing->asWkt( precision ); - if ( dynamic_cast( mExteriorRing ) ) + if ( qgsgeometry_cast( mExteriorRing ) ) { // Type names of linear geometries are omitted childWkt = childWkt.mid( childWkt.indexOf( '(' ) ); @@ -265,7 +265,7 @@ QString QgsCurvePolygon::asWkt( int precision ) const Q_FOREACH ( const QgsCurve *curve, mInteriorRings ) { QString childWkt = curve->asWkt( precision ); - if ( dynamic_cast( curve ) ) + if ( qgsgeometry_cast( curve ) ) { // Type names of linear geometries are omitted childWkt = childWkt.mid( childWkt.indexOf( '(' ) ); diff --git a/src/core/geometry/qgsgeometryeditutils.cpp b/src/core/geometry/qgsgeometryeditutils.cpp index 7e5c08dcac7..87993463609 100644 --- a/src/core/geometry/qgsgeometryeditutils.cpp +++ b/src/core/geometry/qgsgeometryeditutils.cpp @@ -123,7 +123,7 @@ int QgsGeometryEditUtils::addPart( QgsAbstractGeometry *geom, QgsAbstractGeometr if ( QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::MultiSurface || QgsWkbTypes::flatType( geom->wkbType() ) == QgsWkbTypes::MultiPolygon ) { - QgsCurve *curve = dynamic_cast( part ); + QgsCurve *curve = qgsgeometry_cast( part ); if ( curve && curve->isClosed() && curve->numPoints() >= 4 ) { QgsCurvePolygon *poly = nullptr; @@ -199,7 +199,7 @@ bool QgsGeometryEditUtils::deleteRing( QgsAbstractGeometry *geom, int ringNum, i return false; } - QgsCurvePolygon *cpoly = dynamic_cast( g ); + QgsCurvePolygon *cpoly = qgsgeometry_cast( g ); if ( !cpoly ) { return false; diff --git a/src/core/geometry/qgsgeometryutils.cpp b/src/core/geometry/qgsgeometryutils.cpp index 01e48cd8dd6..41f78739346 100644 --- a/src/core/geometry/qgsgeometryutils.cpp +++ b/src/core/geometry/qgsgeometryutils.cpp @@ -37,18 +37,18 @@ QList QgsGeometryUtils::extractLineStrings( const QgsAbstractGe while ( ! geometries.isEmpty() ) { const QgsAbstractGeometry *g = geometries.takeFirst(); - if ( const QgsCurve *curve = dynamic_cast< const QgsCurve * >( g ) ) + if ( const QgsCurve *curve = qgsgeometry_cast< const QgsCurve * >( g ) ) { linestrings << static_cast< QgsLineString * >( curve->segmentize() ); } - else if ( const QgsGeometryCollection *collection = dynamic_cast< const QgsGeometryCollection * >( g ) ) + else if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( g ) ) { for ( int i = 0; i < collection->numGeometries(); ++i ) { geometries.append( collection->geometryN( i ) ); } } - else if ( const QgsCurvePolygon *curvePolygon = dynamic_cast< const QgsCurvePolygon * >( g ) ) + else if ( const QgsCurvePolygon *curvePolygon = qgsgeometry_cast< const QgsCurvePolygon * >( g ) ) { if ( curvePolygon->exteriorRing() ) linestrings << static_cast< QgsLineString * >( curvePolygon->exteriorRing()->segmentize() ); diff --git a/src/core/geometry/qgsgeos.cpp b/src/core/geometry/qgsgeos.cpp index 3b52aba6a23..1f61766a8c3 100644 --- a/src/core/geometry/qgsgeos.cpp +++ b/src/core/geometry/qgsgeos.cpp @@ -1656,7 +1656,7 @@ bool QgsGeos::isSimple( QString *errorMsg ) const GEOSCoordSequence *QgsGeos::createCoordinateSequence( const QgsCurve *curve, double precision, bool forceClose ) { bool segmentize = false; - const QgsLineString *line = dynamic_cast( curve ); + const QgsLineString *line = qgsgeometry_cast( curve ); if ( !line ) { @@ -1742,7 +1742,7 @@ GEOSCoordSequence *QgsGeos::createCoordinateSequence( const QgsCurve *curve, dou GEOSGeometry *QgsGeos::createGeosPoint( const QgsAbstractGeometry *point, int coordDims, double precision ) { - const QgsPoint *pt = dynamic_cast( point ); + const QgsPoint *pt = qgsgeometry_cast( point ); if ( !pt ) return nullptr; @@ -1796,7 +1796,7 @@ GEOSGeometry *QgsGeos::createGeosPointXY( double x, double y, bool hasZ, double GEOSGeometry *QgsGeos::createGeosLinestring( const QgsAbstractGeometry *curve, double precision ) { - const QgsCurve *c = dynamic_cast( curve ); + const QgsCurve *c = qgsgeometry_cast( curve ); if ( !c ) return nullptr; @@ -1815,7 +1815,7 @@ GEOSGeometry *QgsGeos::createGeosLinestring( const QgsAbstractGeometry *curve, d GEOSGeometry *QgsGeos::createGeosPolygon( const QgsAbstractGeometry *poly, double precision ) { - const QgsCurvePolygon *polygon = dynamic_cast( poly ); + const QgsCurvePolygon *polygon = qgsgeometry_cast( poly ); if ( !polygon ) return nullptr; diff --git a/src/core/geometry/qgsinternalgeometryengine.cpp b/src/core/geometry/qgsinternalgeometryengine.cpp index 772aa419760..0769253dafd 100644 --- a/src/core/geometry/qgsinternalgeometryengine.cpp +++ b/src/core/geometry/qgsinternalgeometryengine.cpp @@ -158,7 +158,7 @@ Cell *getCentroidCell( const QgsPolygonV2 *polygon ) QgsPoint surfacePoleOfInaccessibility( const QgsSurface *surface, double precision, double &distanceFromBoundary ) { std::unique_ptr< QgsPolygonV2 > segmentizedPoly; - const QgsPolygonV2 *polygon = dynamic_cast< const QgsPolygonV2 * >( surface ); + const QgsPolygonV2 *polygon = qgsgeometry_cast< const QgsPolygonV2 * >( surface ); if ( !polygon ) { segmentizedPoly.reset( static_cast< QgsPolygonV2 *>( surface->segmentize() ) ); diff --git a/src/core/geometry/qgslinestring.cpp b/src/core/geometry/qgslinestring.cpp index 66a72d34358..f7c45747f13 100644 --- a/src/core/geometry/qgslinestring.cpp +++ b/src/core/geometry/qgslinestring.cpp @@ -137,7 +137,7 @@ QgsLineString::QgsLineString( const QList &points ) bool QgsLineString::operator==( const QgsCurve &other ) const { - const QgsLineString *otherLine = dynamic_cast< const QgsLineString * >( &other ); + const QgsLineString *otherLine = qgsgeometry_cast< const QgsLineString * >( &other ); if ( !otherLine ) return false; diff --git a/src/core/geometry/qgsmulticurve.cpp b/src/core/geometry/qgsmulticurve.cpp index f94b9cdde06..115bbeccc61 100644 --- a/src/core/geometry/qgsmulticurve.cpp +++ b/src/core/geometry/qgsmulticurve.cpp @@ -104,7 +104,7 @@ QString QgsMultiCurve::asJSON( int precision ) const bool QgsMultiCurve::addGeometry( QgsAbstractGeometry *g ) { - if ( !dynamic_cast( g ) ) + if ( !qgsgeometry_cast( g ) ) { delete g; return false; diff --git a/src/core/geometry/qgsmultipoint.cpp b/src/core/geometry/qgsmultipoint.cpp index ec68f069d77..4fa53180592 100644 --- a/src/core/geometry/qgsmultipoint.cpp +++ b/src/core/geometry/qgsmultipoint.cpp @@ -97,7 +97,7 @@ QString QgsMultiPointV2::asJSON( int precision ) const bool QgsMultiPointV2::addGeometry( QgsAbstractGeometry *g ) { - if ( !dynamic_cast( g ) ) + if ( !qgsgeometry_cast( g ) ) { delete g; return false; diff --git a/src/core/geometry/qgsmultipolygon.cpp b/src/core/geometry/qgsmultipolygon.cpp index 26cb4d87ffc..c0787bb6de6 100644 --- a/src/core/geometry/qgsmultipolygon.cpp +++ b/src/core/geometry/qgsmultipolygon.cpp @@ -115,7 +115,7 @@ QString QgsMultiPolygonV2::asJSON( int precision ) const bool QgsMultiPolygonV2::addGeometry( QgsAbstractGeometry *g ) { - if ( !dynamic_cast( g ) ) + if ( !qgsgeometry_cast( g ) ) { delete g; return false; @@ -144,11 +144,11 @@ QgsAbstractGeometry *QgsMultiPolygonV2::boundary() const { QgsAbstractGeometry *polygonBoundary = polygon->boundary(); - if ( QgsLineString *lineStringBoundary = dynamic_cast< QgsLineString * >( polygonBoundary ) ) + if ( QgsLineString *lineStringBoundary = qgsgeometry_cast< QgsLineString * >( polygonBoundary ) ) { multiLine->addGeometry( lineStringBoundary ); } - else if ( QgsMultiLineString *multiLineStringBoundary = dynamic_cast< QgsMultiLineString * >( polygonBoundary ) ) + else if ( QgsMultiLineString *multiLineStringBoundary = qgsgeometry_cast< QgsMultiLineString * >( polygonBoundary ) ) { for ( int j = 0; j < multiLineStringBoundary->numGeometries(); ++j ) { diff --git a/src/core/geometry/qgspolygon.cpp b/src/core/geometry/qgspolygon.cpp index c19acdd7a77..d388d1cf253 100644 --- a/src/core/geometry/qgspolygon.cpp +++ b/src/core/geometry/qgspolygon.cpp @@ -185,7 +185,7 @@ void QgsPolygonV2::addInteriorRing( QgsCurve *ring ) ring = segmented; } - QgsLineString *lineString = dynamic_cast< QgsLineString *>( ring ); + QgsLineString *lineString = qgsgeometry_cast< QgsLineString *>( ring ); if ( lineString && !lineString->isClosed() ) { lineString->close(); @@ -219,7 +219,7 @@ void QgsPolygonV2::setExteriorRing( QgsCurve *ring ) ring = line; } - QgsLineString *lineString = dynamic_cast< QgsLineString *>( ring ); + QgsLineString *lineString = qgsgeometry_cast< QgsLineString *>( ring ); if ( lineString && !lineString->isClosed() ) { lineString->close();