Skip to content

Commit

Permalink
No more QgsGeometry pointers in the public API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
m-kuhn committed Jun 11, 2017
1 parent 6896548 commit cc877c3
Show file tree
Hide file tree
Showing 32 changed files with 127 additions and 188 deletions.
7 changes: 0 additions & 7 deletions python/core/geometry/qgsgeometry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,6 @@ not disjoint with existing polygons of the feature
:rtype: int
%End

int makeDifference( const QgsGeometry *other );
%Docstring
Changes this geometry such that it does not intersect the other geometry
\param other geometry that should not be intersect
:return: 0 in case of success
:rtype: int
%End

QgsGeometry makeDifference( const QgsGeometry &other ) const;
%Docstring
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsgeometryvalidator.sip
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class QgsGeometryValidator : QThread
%End
public:

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

void stop();

static void validateGeometry( const QgsGeometry *g, QList<QgsGeometry::Error> &errors /Out/, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
static void validateGeometry( const QgsGeometry &geometry, QList<QgsGeometry::Error> &errors /Out/, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
%Docstring
Validate geometry and produce a list of geometry errors
%End
Expand Down
6 changes: 3 additions & 3 deletions python/core/qgsogcutils.sip
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Read rectangle from GML3 Envelope
:rtype: QgsRectangle
%End

static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc,
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
QgsOgcUtils::GMLVersion gmlVersion,
const QString &srsName,
bool invertAxisOrientation,
Expand All @@ -72,14 +72,14 @@ Read rectangle from GML3 Envelope
:rtype: QDomElement
%End

static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, const QString &format, int precision = 17 );
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );
%Docstring
Exports the geometry to GML2 or GML3
:return: QDomElement
:rtype: QDomElement
%End

static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, int precision = 17 );
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );
%Docstring
Exports the geometry to GML2
:return: QDomElement
Expand Down
49 changes: 3 additions & 46 deletions python/core/qgspallabeling.sip
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ Z-Index of label, where labels with a higher z-index are rendered on top of labe

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

void registerFeature( QgsFeature &f, QgsRenderContext &context );
void registerFeature( QgsFeature &f, QgsRenderContext &context );

%Docstring
Register a feature for labeling.
Expand Down Expand Up @@ -553,7 +553,7 @@ class QgsPalLabeling
%End


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

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

protected:
static void dataDefinedTextStyle( QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
%Docstring
Update temporary QgsPalLayerSettings with any data defined text style values
%End

static void dataDefinedTextFormatting( QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
%Docstring
Update temporary QgsPalLayerSettings with any data defined text formatting values
%End

static void dataDefinedTextBuffer( QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
%Docstring
Update temporary QgsPalLayerSettings with any data defined text buffer values
%End

static void dataDefinedShapeBackground( QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
%Docstring
Update temporary QgsPalLayerSettings with any data defined shape background values
%End

static void dataDefinedDropShadow( QgsPalLayerSettings &tmpLyr,
const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
%Docstring
Update temporary QgsPalLayerSettings with any data defined drop shadow values
%End


static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry *geom, double minSize );
%Docstring
Checks whether a geometry exceeds the minimum required size for a geometry to be labeled.
\param context render context
\param geom geometry
\param minSize minimum size for geometry
:return: true if geometry exceeds minimum size
.. versionadded:: 2.9
:rtype: bool
%End

};

/************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectordataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ Returns a list of available encodings
.. versionadded:: 3.0
%End

QgsGeometry *convertToProviderType( const QgsGeometry &geom ) const /Factory/;
QgsGeometry convertToProviderType( const QgsGeometry &geom ) const;
%Docstring
Converts the geometry to the provider type if possible / necessary
:return: the converted geometry or None if no conversion was necessary or possible
Expand Down
2 changes: 1 addition & 1 deletion src/app/nodetool/qgsnodetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ void QgsNodeTool::GeometryValidation::start( QgsGeometry &geom, QgsNodeTool *t,
if ( settings.value( QStringLiteral( "qgis/digitizing/validate_geometries" ), 1 ).toInt() == 2 )
method = QgsGeometry::ValidatorGeos;

validator = new QgsGeometryValidator( &geom, nullptr, method );
validator = new QgsGeometryValidator( geom, nullptr, method );
connect( validator, &QgsGeometryValidator::errorFound, tool, &QgsNodeTool::validationErrorFound );
connect( validator, &QThread::finished, tool, &QgsNodeTool::validationFinished );
validator->start();
Expand Down
2 changes: 1 addition & 1 deletion src/app/nodetool/qgsselectedfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void QgsSelectedFeature::validateGeometry( QgsGeometry *g )
QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal;
if ( settings.value( QStringLiteral( "qgis/digitizing/validate_geometries" ), 1 ).toInt() == 2 )
method = QgsGeometry::ValidatorGeos;
mValidator = new QgsGeometryValidator( g, nullptr, method );
mValidator = new QgsGeometryValidator( *g, nullptr, method );
connect( mValidator, &QgsGeometryValidator::errorFound, this, &QgsSelectedFeature::addError );
connect( mValidator, &QThread::finished, this, &QgsSelectedFeature::validationFinished );
mValidator->start();
Expand Down
6 changes: 0 additions & 6 deletions src/app/qgsmaptooloffsetcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,3 @@ QgsGeometry QgsMapToolOffsetCurve::convertToSingleLine( const QgsGeometry &geom,
}
return QgsGeometry();
}

QgsGeometry *QgsMapToolOffsetCurve::convertToMultiLine( QgsGeometry *geom )
{
Q_UNUSED( geom );
return nullptr;
}
2 changes: 0 additions & 2 deletions src/app/qgsmaptooloffsetcurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ class APP_EXPORT QgsMapToolOffsetCurve: public QgsMapToolEdit
QgsGeometry linestringFromPolygon( const QgsGeometry &featureGeom, int vertex );
//! Returns a single line from a multiline (or does nothing if geometry is already a single line). Deletes the input geometry
QgsGeometry convertToSingleLine( const QgsGeometry &geom, int vertex, bool &isMulti );
//! Converts offset line back to a multiline if necessary
QgsGeometry *convertToMultiLine( QgsGeometry *geom );
};

#endif // QGSMAPTOOLOFFSETCURVE_H
8 changes: 4 additions & 4 deletions src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,16 +836,16 @@ int QgsGeometry::reshapeGeometry( const QgsLineString &reshapeLineString )
return errorCode;
}

int QgsGeometry::makeDifference( const QgsGeometry *other )
int QgsGeometry::makeDifferenceInPlace( const QgsGeometry &other )
{
if ( !d->geometry || !other->d->geometry )
if ( !d->geometry || !other.d->geometry )
{
return 0;
}

QgsGeos geos( d->geometry );

QgsAbstractGeometry *diffGeom = geos.intersection( *( other->geometry() ) );
QgsAbstractGeometry *diffGeom = geos.intersection( *other.geometry() );
if ( !diffGeom )
{
return 1;
Expand Down Expand Up @@ -1964,7 +1964,7 @@ QgsGeometry QgsGeometry::makeValid()

void QgsGeometry::validateGeometry( QList<QgsGeometry::Error> &errors, ValidationMethod method )
{
QgsGeometryValidator::validateGeometry( this, errors, method );
QgsGeometryValidator::validateGeometry( *this, errors, method );
}

bool QgsGeometry::isGeosValid() const
Expand Down
3 changes: 2 additions & 1 deletion src/core/geometry/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,9 @@ class CORE_EXPORT QgsGeometry
/** Changes this geometry such that it does not intersect the other geometry
* \param other geometry that should not be intersect
* \returns 0 in case of success
* \note Not available in Python
*/
int makeDifference( const QgsGeometry *other );
int makeDifferenceInPlace( const QgsGeometry &other ) SIP_SKIP;

/** Returns the geometry formed by modifying this geometry such that it does not
* intersect the other geometry.
Expand Down
10 changes: 4 additions & 6 deletions src/core/qgsgeometryvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ email : jef at norbit dot de
#include "qgsgeometry.h"
#include "qgslogger.h"

QgsGeometryValidator::QgsGeometryValidator( const QgsGeometry *g, QList<QgsGeometry::Error> *errors, QgsGeometry::ValidationMethod method )
QgsGeometryValidator::QgsGeometryValidator( const QgsGeometry &geometry, QList<QgsGeometry::Error> *errors, QgsGeometry::ValidationMethod method )
: QThread()
, mGeometry( geometry )
, mErrors( errors )
, mStop( false )
, mErrorCount( 0 )
, mMethod( method )
{
Q_ASSERT( g );
if ( g )
mG = *g;
}

QgsGeometryValidator::~QgsGeometryValidator()
Expand Down Expand Up @@ -357,9 +355,9 @@ void QgsGeometryValidator::addError( const QgsGeometry::Error &e )
*mErrors << e;
}

void QgsGeometryValidator::validateGeometry( const QgsGeometry *g, QList<QgsGeometry::Error> &errors, QgsGeometry::ValidationMethod method )
void QgsGeometryValidator::validateGeometry( const QgsGeometry &geometry, QList<QgsGeometry::Error> &errors, QgsGeometry::ValidationMethod method )
{
QgsGeometryValidator *gv = new QgsGeometryValidator( g, &errors, method );
QgsGeometryValidator *gv = new QgsGeometryValidator( geometry, &errors, method );
connect( gv, &QgsGeometryValidator::errorFound, gv, &QgsGeometryValidator::addError );
gv->run();
gv->wait();
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsgeometryvalidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class CORE_EXPORT QgsGeometryValidator : public QThread
/**
* Constructor for QgsGeometryValidator.
*/
QgsGeometryValidator( const QgsGeometry *g, QList<QgsGeometry::Error> *errors = nullptr, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
QgsGeometryValidator( const QgsGeometry &geoemtry, QList<QgsGeometry::Error> *errors = nullptr, QgsGeometry::ValidationMethod method = QgsGeometry::ValidatorQgisInternal );
~QgsGeometryValidator();

void run() override;
void stop();

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

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

QgsGeometry mG;
QgsGeometry mGeometry;
QList<QgsGeometry::Error> *mErrors;
bool mStop;
int mErrorCount;
Expand Down
16 changes: 8 additions & 8 deletions src/core/qgsogcutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,12 +1122,12 @@ QDomElement QgsOgcUtils::rectangleToGMLEnvelope( QgsRectangle *env, QDomDocument
return envElem;
}

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

QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocument &doc,
QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
GMLVersion gmlVersion,
const QString &srsName,
bool invertAxisOrientation,
Expand All @@ -1146,7 +1146,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocumen

bool hasZValue = false;

QByteArray wkb( geometry->exportToWkb() );
QByteArray wkb( geometry.exportToWkb() );
QgsConstWkbPtr wkbPtr( wkb );
try
{
Expand All @@ -1161,7 +1161,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocumen

if ( gmlVersion != GML_2_1_2 )
{
switch ( geometry->wkbType() )
switch ( geometry.wkbType() )
{
case QgsWkbTypes::Point25D:
case QgsWkbTypes::Point:
Expand All @@ -1185,7 +1185,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocumen

try
{
switch ( geometry->wkbType() )
switch ( geometry.wkbType() )
{
case QgsWkbTypes::Point25D:
case QgsWkbTypes::Point:
Expand Down Expand Up @@ -1501,7 +1501,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocumen
}
}

QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, int precision )
QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision )
{
return geometryToGML( geometry, doc, QStringLiteral( "GML2" ), precision );
}
Expand Down Expand Up @@ -2572,7 +2572,7 @@ QDomElement QgsOgcUtilsExprToFilter::expressionFunctionToOgcFilter( const QgsExp
}
QString wkt = static_cast<const QgsExpressionNodeLiteral *>( firstFnArg )->value().toString();
QgsGeometry geom = QgsGeometry::fromWkt( wkt );
otherGeomElem = QgsOgcUtils::geometryToGML( &geom, mDoc, mGMLVersion, mSrsName, mInvertAxisOrientation,
otherGeomElem = QgsOgcUtils::geometryToGML( geom, mDoc, mGMLVersion, mSrsName, mInvertAxisOrientation,
QStringLiteral( "qgis_id_geom_%1" ).arg( mGeomId ) );
mGeomId ++;
}
Expand Down Expand Up @@ -3043,7 +3043,7 @@ QDomElement QgsOgcUtilsSQLStatementToFilter::toOgcFilter( const QgsSQLStatement:

QString wkt = static_cast<const QgsSQLStatement::NodeLiteral *>( firstFnArg )->value().toString();
QgsGeometry geom = QgsGeometry::fromWkt( wkt );
QDomElement geomElem = QgsOgcUtils::geometryToGML( &geom, mDoc, mGMLVersion, srsName, axisInversion,
QDomElement geomElem = QgsOgcUtils::geometryToGML( geom, mDoc, mGMLVersion, srsName, axisInversion,
QStringLiteral( "qgis_id_geom_%1" ).arg( mGeomId ) );
mGeomId ++;
if ( geomElem.isNull() )
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsogcutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CORE_EXPORT QgsOgcUtils
\returns QDomElement
\since QGIS 2.16
*/
static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc,
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc,
QgsOgcUtils::GMLVersion gmlVersion,
const QString &srsName,
bool invertAxisOrientation,
Expand All @@ -90,12 +90,12 @@ class CORE_EXPORT QgsOgcUtils
/** Exports the geometry to GML2 or GML3
\returns QDomElement
*/
static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, const QString &format, int precision = 17 );
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, const QString &format, int precision = 17 );

/** Exports the geometry to GML2
\returns QDomElement
*/
static QDomElement geometryToGML( const QgsGeometry *geometry, QDomDocument &doc, int precision = 17 );
static QDomElement geometryToGML( const QgsGeometry &geometry, QDomDocument &doc, int precision = 17 );

/** Exports the rectangle to GML2 Box
\returns QDomElement
Expand Down
Loading

0 comments on commit cc877c3

Please sign in to comment.