Skip to content
Permalink
Browse files

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
  • Loading branch information
m-kuhn committed Jun 11, 2017
1 parent 6896548 commit cc877c39ebb5f9b74b655f896e1a513748bccba8
@@ -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
@@ -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
@@ -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
@@ -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,
@@ -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
@@ -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.
@@ -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
@@ -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
@@ -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

};

/************************************************************************
@@ -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
@@ -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();
@@ -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();
@@ -477,9 +477,3 @@ QgsGeometry QgsMapToolOffsetCurve::convertToSingleLine( const QgsGeometry &geom,
}
return QgsGeometry();
}

QgsGeometry *QgsMapToolOffsetCurve::convertToMultiLine( QgsGeometry *geom )
{
Q_UNUSED( geom );
return nullptr;
}
@@ -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
@@ -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;
@@ -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
@@ -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.
@@ -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()
@@ -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();
@@ -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 & );
@@ -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;
@@ -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,
@@ -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
{
@@ -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:
@@ -1185,7 +1185,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry *geometry, QDomDocumen

try
{
switch ( geometry->wkbType() )
switch ( geometry.wkbType() )
{
case QgsWkbTypes::Point25D:
case QgsWkbTypes::Point:
@@ -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 );
}
@@ -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 ++;
}
@@ -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() )
@@ -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,
@@ -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

0 comments on commit cc877c3

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