Skip to content

Commit cc877c3

Browse files
committedJun 11, 2017
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

+127
-188
lines changed
 

‎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

‎src/core/geometry/qgsgeometry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,9 @@ class CORE_EXPORT QgsGeometry
496496
/** Changes this geometry such that it does not intersect the other geometry
497497
* \param other geometry that should not be intersect
498498
* \returns 0 in case of success
499+
* \note Not available in Python
499500
*/
500-
int makeDifference( const QgsGeometry *other );
501+
int makeDifferenceInPlace( const QgsGeometry &other ) SIP_SKIP;
501502

502503
/** Returns the geometry formed by modifying this geometry such that it does not
503504
* intersect the other geometry.

‎src/core/qgsgeometryvalidator.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ email : jef at norbit dot de
1818
#include "qgsgeometry.h"
1919
#include "qgslogger.h"
2020

21-
QgsGeometryValidator::QgsGeometryValidator( const QgsGeometry *g, QList<QgsGeometry::Error> *errors, QgsGeometry::ValidationMethod method )
21+
QgsGeometryValidator::QgsGeometryValidator( const QgsGeometry &geometry, QList<QgsGeometry::Error> *errors, QgsGeometry::ValidationMethod method )
2222
: QThread()
23+
, mGeometry( geometry )
2324
, mErrors( errors )
2425
, mStop( false )
2526
, mErrorCount( 0 )
2627
, mMethod( method )
2728
{
28-
Q_ASSERT( g );
29-
if ( g )
30-
mG = *g;
3129
}
3230

3331
QgsGeometryValidator::~QgsGeometryValidator()
@@ -357,9 +355,9 @@ void QgsGeometryValidator::addError( const QgsGeometry::Error &e )
357355
*mErrors << e;
358356
}
359357

360-
void QgsGeometryValidator::validateGeometry( const QgsGeometry *g, QList<QgsGeometry::Error> &errors, QgsGeometry::ValidationMethod method )
358+
void QgsGeometryValidator::validateGeometry( const QgsGeometry &geometry, QList<QgsGeometry::Error> &errors, QgsGeometry::ValidationMethod method )
361359
{
362-
QgsGeometryValidator *gv = new QgsGeometryValidator( g, &errors, method );
360+
QgsGeometryValidator *gv = new QgsGeometryValidator( geometry, &errors, method );
363361
connect( gv, &QgsGeometryValidator::errorFound, gv, &QgsGeometryValidator::addError );
364362
gv->run();
365363
gv->wait();

‎src/core/qgsgeometryvalidator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class CORE_EXPORT QgsGeometryValidator : public QThread
3333
/**
3434
* Constructor for QgsGeometryValidator.
3535
*/
36-
QgsGeometryValidator( const QgsGeometry *g, QList<QgsGeometry::Error> *errors = nullptr, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
36+
QgsGeometryValidator( const QgsGeometry &geoemtry, QList<QgsGeometry::Error> *errors = nullptr, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
3737
~QgsGeometryValidator();
3838

3939
void run() override;
4040
void stop();
4141

4242
//! Validate geometry and produce a list of geometry errors
43-
static void validateGeometry( const QgsGeometry *g, QList<QgsGeometry::Error> &errors SIP_OUT, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
43+
static void validateGeometry( const QgsGeometry &geometry, QList<QgsGeometry::Error> &errors SIP_OUT, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
4444

4545
signals:
4646
void errorFound( const QgsGeometry::Error & );
@@ -57,7 +57,7 @@ class CORE_EXPORT QgsGeometryValidator : public QThread
5757
bool ringInRing( const QgsPolyline &inside, const QgsPolyline &outside );
5858
bool pointInRing( const QgsPolyline &ring, const QgsPointXY &p );
5959

60-
QgsGeometry mG;
60+
QgsGeometry mGeometry;
6161
QList<QgsGeometry::Error> *mErrors;
6262
bool mStop;
6363
int mErrorCount;

‎src/core/qgsogcutils.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,12 +1122,12 @@ QDomElement QgsOgcUtils::rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument
11221122
return envElem;
11231123
}
11241124

1125-
QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, const QString &format, int precision )
1125+
QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision )
11261126
{
11271127
return geometryToGML( geometry, doc, ( format == QLatin1String( "GML2" ) ) ? GML_2_1_2 : GML_3_2_1, QString(), false, QString(), precision );
11281128
}
11291129

1130-
QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocument &doc,
1130+
QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
11311131
GMLVersion gmlVersion,
11321132
const QString &srsName,
11331133
bool invertAxisOrientation,
@@ -1146,7 +1146,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocumen
11461146

11471147
bool hasZValue = false;
11481148

1149-
QByteArray wkb( geometry->exportToWkb() );
1149+
QByteArray wkb( geometry.exportToWkb() );
11501150
QgsConstWkbPtr wkbPtr( wkb );
11511151
try
11521152
{
@@ -1161,7 +1161,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocumen
11611161

11621162
if ( gmlVersion != GML_2_1_2 )
11631163
{
1164-
switch ( geometry->wkbType() )
1164+
switch ( geometry.wkbType() )
11651165
{
11661166
case QgsWkbTypes::Point25D:
11671167
case QgsWkbTypes::Point:
@@ -1185,7 +1185,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocumen
11851185

11861186
try
11871187
{
1188-
switch ( geometry->wkbType() )
1188+
switch ( geometry.wkbType() )
11891189
{
11901190
case QgsWkbTypes::Point25D:
11911191
case QgsWkbTypes::Point:
@@ -1501,7 +1501,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocumen
15011501
}
15021502
}
15031503

1504-
QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, int precision )
1504+
QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision )
15051505
{
15061506
return geometryToGML( geometry, doc, QStringLiteral( "GML2" ), precision );
15071507
}
@@ -2572,7 +2572,7 @@ QDomElement QgsOgcUtilsExprToFilter::expressionFunctionToOgcFilter( const QgsExp
25722572
}
25732573
QString wkt = static_cast<const QgsExpressionNodeLiteral *>( firstFnArg )->value().toString();
25742574
QgsGeometry geom = QgsGeometry::fromWkt( wkt );
2575-
otherGeomElem = QgsOgcUtils::geometryToGML( &geom, mDoc, mGMLVersion, mSrsName, mInvertAxisOrientation,
2575+
otherGeomElem = QgsOgcUtils::geometryToGML( geom, mDoc, mGMLVersion, mSrsName, mInvertAxisOrientation,
25762576
QStringLiteral( "qgis_id_geom_%1" ).arg( mGeomId ) );
25772577
mGeomId ++;
25782578
}
@@ -3043,7 +3043,7 @@ QDomElement QgsOgcUtilsSQLStatementToFilter::toOgcFilter( const QgsSQLStatement:
30433043

30443044
QString wkt = static_cast<const QgsSQLStatement::NodeLiteral *>( firstFnArg )->value().toString();
30453045
QgsGeometry geom = QgsGeometry::fromWkt( wkt );
3046-
QDomElement geomElem = QgsOgcUtils::geometryToGML( &geom, mDoc, mGMLVersion, srsName, axisInversion,
3046+
QDomElement geomElem = QgsOgcUtils::geometryToGML( geom, mDoc, mGMLVersion, srsName, axisInversion,
30473047
QStringLiteral( "qgis_id_geom_%1" ).arg( mGeomId ) );
30483048
mGeomId ++;
30493049
if ( geomElem.isNull() )

‎src/core/qgsogcutils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CORE_EXPORT QgsOgcUtils
8080
\returns QDomElement
8181
\since QGIS 2.16
8282
*/
83-
static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc,
83+
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
8484
QgsOgcUtils::GMLVersion gmlVersion,
8585
const QString &srsName,
8686
bool invertAxisOrientation,
@@ -90,12 +90,12 @@ class CORE_EXPORT QgsOgcUtils
9090
/** Exports the geometry to GML2 or GML3
9191
\returns QDomElement
9292
*/
93-
static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, const QString &format, int precision = 17 );
93+
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
9494

9595
/** Exports the geometry to GML2
9696
\returns QDomElement
9797
*/
98-
static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, int precision = 17 );
98+
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
9999

100100
/** Exports the rectangle to GML2 Box
101101
\returns QDomElement

0 commit comments

Comments
 (0)
Please sign in to comment.