Skip to content

Commit cc877c3

Browse files
committed
No more QgsGeometry pointers in the public API
Geometries are passed as const reference and returned by value. This make using the API easier and reduces the risk of ownership problems. The overhead is minimal due to implicit sharing. Fix qgis/qgis4.0_api#68
1 parent 6896548 commit cc877c3

32 files changed

Lines changed: 127 additions & 188 deletions

‎python/core/geometry/qgsgeometry.sip‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,13 +496,6 @@ not disjoint with existing polygons of the feature
496496
:rtype: int
497497
%End
498498

499-
int makeDifference( const QgsGeometry *other );
500-
%Docstring
501-
Changes this geometry such that it does not intersect the other geometry
502-
\param other geometry that should not be intersect
503-
:return: 0 in case of success
504-
:rtype: int
505-
%End
506499

507500
QgsGeometry makeDifference( const QgsGeometry &other ) const;
508501
%Docstring

‎python/core/qgsgeometryvalidator.sip‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class QgsGeometryValidator : QThread
1616
%End
1717
public:
1818

19-
QgsGeometryValidator( const QgsGeometry *g, QList<QgsGeometry::Error> *errors = 0, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
19+
QgsGeometryValidator( const QgsGeometry &geoemtry, QList<QgsGeometry::Error> *errors = 0, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
2020
%Docstring
2121
Constructor for QgsGeometryValidator.
2222
%End
@@ -26,7 +26,7 @@ class QgsGeometryValidator : QThread
2626

2727
void stop();
2828

29-
static void validateGeometry( const QgsGeometry *g, QList<QgsGeometry::Error> &errors /Out/, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
29+
static void validateGeometry( const QgsGeometry &geometry, QList<QgsGeometry::Error> &errors /Out/, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
3030
%Docstring
3131
Validate geometry and produce a list of geometry errors
3232
%End

‎python/core/qgsogcutils.sip‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Read rectangle from GML3 Envelope
5959
:rtype: QgsRectangle
6060
%End
6161

62-
static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc,
62+
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
6363
QgsOgcUtils::GMLVersion gmlVersion,
6464
const QString &srsName,
6565
bool invertAxisOrientation,
@@ -72,14 +72,14 @@ Read rectangle from GML3 Envelope
7272
:rtype: QDomElement
7373
%End
7474

75-
static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, const QString &format, int precision = 17 );
75+
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
7676
%Docstring
7777
Exports the geometry to GML2 or GML3
7878
:return: QDomElement
7979
:rtype: QDomElement
8080
%End
8181

82-
static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, int precision = 17 );
82+
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
8383
%Docstring
8484
Exports the geometry to GML2
8585
:return: QDomElement

‎python/core/qgspallabeling.sip‎

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ Z-Index of label, where labels with a higher z-index are rendered on top of labe
415415

416416
void calculateLabelSize( const QFontMetricsF *fm, QString text, double &labelX, double &labelY, QgsFeature *f = 0, QgsRenderContext *context = 0 );
417417

418-
void registerFeature( QgsFeature &f, QgsRenderContext &context );
418+
void registerFeature( QgsFeature &f, QgsRenderContext &context );
419419

420420
%Docstring
421421
Register a feature for labeling.
@@ -553,7 +553,7 @@ class QgsPalLabeling
553553
%End
554554

555555

556-
static QgsGeometry prepareGeometry( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, QgsGeometry *clipGeometry = 0 ) /Factory/;
556+
static QgsGeometry prepareGeometry( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry() ) /Factory/;
557557
%Docstring
558558
Prepares a geometry for registration with PAL. Handles reprojection, rotation, clipping, etc.
559559
\param geometry geometry to prepare
@@ -565,7 +565,7 @@ class QgsPalLabeling
565565
:rtype: QgsGeometry
566566
%End
567567

568-
static bool geometryRequiresPreparation( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, QgsGeometry *clipGeometry = 0 );
568+
static bool geometryRequiresPreparation( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry() );
569569
%Docstring
570570
Checks whether a geometry requires preparation before registration with PAL
571571
\param geometry geometry to prepare
@@ -599,49 +599,6 @@ class QgsPalLabeling
599599
:rtype: list of str
600600
%End
601601

602-
protected:
603-
static void dataDefinedTextStyle( QgsPalLayerSettings &tmpLyr,
604-
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
605-
%Docstring
606-
Update temporary QgsPalLayerSettings with any data defined text style values
607-
%End
608-
609-
static void dataDefinedTextFormatting( QgsPalLayerSettings &tmpLyr,
610-
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
611-
%Docstring
612-
Update temporary QgsPalLayerSettings with any data defined text formatting values
613-
%End
614-
615-
static void dataDefinedTextBuffer( QgsPalLayerSettings &tmpLyr,
616-
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
617-
%Docstring
618-
Update temporary QgsPalLayerSettings with any data defined text buffer values
619-
%End
620-
621-
static void dataDefinedShapeBackground( QgsPalLayerSettings &tmpLyr,
622-
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
623-
%Docstring
624-
Update temporary QgsPalLayerSettings with any data defined shape background values
625-
%End
626-
627-
static void dataDefinedDropShadow( QgsPalLayerSettings &tmpLyr,
628-
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
629-
%Docstring
630-
Update temporary QgsPalLayerSettings with any data defined drop shadow values
631-
%End
632-
633-
634-
static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry *geom, double minSize );
635-
%Docstring
636-
Checks whether a geometry exceeds the minimum required size for a geometry to be labeled.
637-
\param context render context
638-
\param geom geometry
639-
\param minSize minimum size for geometry
640-
:return: true if geometry exceeds minimum size
641-
.. versionadded:: 2.9
642-
:rtype: bool
643-
%End
644-
645602
};
646603

647604
/************************************************************************

‎python/core/qgsvectordataprovider.sip‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ Returns a list of available encodings
556556
.. versionadded:: 3.0
557557
%End
558558
559-
QgsGeometry *convertToProviderType( const QgsGeometry &geom ) const /Factory/;
559+
QgsGeometry convertToProviderType( const QgsGeometry &geom ) const;
560560
%Docstring
561561
Converts the geometry to the provider type if possible / necessary
562562
:return: the converted geometry or None if no conversion was necessary or possible

‎src/app/nodetool/qgsnodetool.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ void QgsNodeTool::GeometryValidation::start( QgsGeometry &geom, QgsNodeTool *t,
18281828
if ( settings.value( QStringLiteral( "qgis/digitizing/validate_geometries" ), 1 ).toInt() == 2 )
18291829
method = QgsGeometry::ValidatorGeos;
18301830

1831-
validator = new QgsGeometryValidator( &geom, nullptr, method );
1831+
validator = new QgsGeometryValidator( geom, nullptr, method );
18321832
connect( validator, &QgsGeometryValidator::errorFound, tool, &QgsNodeTool::validationErrorFound );
18331833
connect( validator, &QThread::finished, tool, &QgsNodeTool::validationFinished );
18341834
validator->start();

‎src/app/nodetool/qgsselectedfeature.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void QgsSelectedFeature::validateGeometry( QgsGeometry *g )
188188
QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal;
189189
if ( settings.value( QStringLiteral( "qgis/digitizing/validate_geometries" ), 1 ).toInt() == 2 )
190190
method = QgsGeometry::ValidatorGeos;
191-
mValidator = new QgsGeometryValidator( g, nullptr, method );
191+
mValidator = new QgsGeometryValidator( *g, nullptr, method );
192192
connect( mValidator, &QgsGeometryValidator::errorFound, this, &QgsSelectedFeature::addError );
193193
connect( mValidator, &QThread::finished, this, &QgsSelectedFeature::validationFinished );
194194
mValidator->start();

‎src/app/qgsmaptooloffsetcurve.cpp‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,3 @@ QgsGeometry QgsMapToolOffsetCurve::convertToSingleLine( const QgsGeometry &geom,
477477
}
478478
return QgsGeometry();
479479
}
480-
481-
QgsGeometry *QgsMapToolOffsetCurve::convertToMultiLine( QgsGeometry *geom )
482-
{
483-
Q_UNUSED( geom );
484-
return nullptr;
485-
}

‎src/app/qgsmaptooloffsetcurve.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ class APP_EXPORT QgsMapToolOffsetCurve: public QgsMapToolEdit
7272
QgsGeometry linestringFromPolygon( const QgsGeometry &featureGeom, int vertex );
7373
//! Returns a single line from a multiline (or does nothing if geometry is already a single line). Deletes the input geometry
7474
QgsGeometry convertToSingleLine( const QgsGeometry &geom, int vertex, bool &isMulti );
75-
//! Converts offset line back to a multiline if necessary
76-
QgsGeometry *convertToMultiLine( QgsGeometry *geom );
7775
};
7876

7977
#endif // QGSMAPTOOLOFFSETCURVE_H

‎src/core/geometry/qgsgeometry.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,16 +836,16 @@ int QgsGeometry::reshapeGeometry( const QgsLineString &reshapeLineString )
836836
return errorCode;
837837
}
838838

839-
int QgsGeometry::makeDifference( const QgsGeometry *other )
839+
int QgsGeometry::makeDifferenceInPlace( const QgsGeometry &other )
840840
{
841-
if ( !d->geometry || !other->d->geometry )
841+
if ( !d->geometry || !other.d->geometry )
842842
{
843843
return 0;
844844
}
845845

846846
QgsGeos geos( d->geometry );
847847

848-
QgsAbstractGeometry *diffGeom = geos.intersection( *( other->geometry() ) );
848+
QgsAbstractGeometry *diffGeom = geos.intersection( *other.geometry() );
849849
if ( !diffGeom )
850850
{
851851
return 1;
@@ -1964,7 +1964,7 @@ QgsGeometry QgsGeometry::makeValid()
19641964

19651965
void QgsGeometry::validateGeometry( QList<QgsGeometry::Error> &errors, ValidationMethod method )
19661966
{
1967-
QgsGeometryValidator::validateGeometry( this, errors, method );
1967+
QgsGeometryValidator::validateGeometry( *this, errors, method );
19681968
}
19691969

19701970
bool QgsGeometry::isGeosValid() const

0 commit comments

Comments
 (0)