Skip to content

Commit

Permalink
Merge pull request #7822 from m-kuhn/constCorrectQgsGeometryError
Browse files Browse the repository at this point in the history
Const correctness for QgsGeometry::Error
  • Loading branch information
m-kuhn committed Sep 7, 2018
2 parents e611756 + e637fd5 commit 7f63d41
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
18 changes: 15 additions & 3 deletions python/core/auto_generated/geometry/qgsgeometry.sip.in
Expand Up @@ -1481,9 +1481,21 @@ by calling `error()` on the returned geometry.
explicit Error( const QString &m );

Error( const QString &m, const QgsPointXY &p );
QString what();
QgsPointXY where();
bool hasWhere();
QString what() const;
%Docstring
A human readable error message containing details about the error.
%End

QgsPointXY where() const;
%Docstring
The coordinates at which the error is located and should be visualized.
%End

bool hasWhere() const;
%Docstring
True if the location available from :py:func:`where` is valid.
%End

};

enum ValidationMethod
Expand Down
15 changes: 15 additions & 0 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -3288,3 +3288,18 @@ QDataStream &operator>>( QDataStream &in, QgsGeometry &geometry )
return in;
}


QString QgsGeometry::Error::what() const
{
return mMessage;
}

QgsPointXY QgsGeometry::Error::where() const
{
return mLocation;
}

bool QgsGeometry::Error::hasWhere() const
{
return mHasLocation;
}
38 changes: 25 additions & 13 deletions src/core/geometry/qgsgeometry.h
Expand Up @@ -1418,27 +1418,39 @@ class CORE_EXPORT QgsGeometry
*/
class CORE_EXPORT Error
{
QString message;
QgsPointXY location;
bool hasLocation = false;

public:
Error()
: message( QStringLiteral( "none" ) )
: mMessage( QStringLiteral( "none" ) )
{}

explicit Error( const QString &m )
: message( m )
: mMessage( m )
{}

Error( const QString &m, const QgsPointXY &p )
: message( m )
, location( p )
, hasLocation( true ) {}

QString what() { return message; }
QgsPointXY where() { return location; }
bool hasWhere() { return hasLocation; }
: mMessage( m )
, mLocation( p )
, mHasLocation( true ) {}

/**
* A human readable error message containing details about the error.
*/
QString what() const;

/**
* The coordinates at which the error is located and should be visualized.
*/
QgsPointXY where() const;

/**
* True if the location available from \see where is valid.
*/
bool hasWhere() const;

private:
QString mMessage;
QgsPointXY mLocation;
bool mHasLocation = false;
};

/**
Expand Down

0 comments on commit 7f63d41

Please sign in to comment.