Skip to content
Permalink
Browse files

Merge pull request #4720 from nyalldawson/ref_geom

Template based referenced geometry class
  • Loading branch information
nyalldawson committed Sep 6, 2017
2 parents 9502022 + f1313af commit 2e20b6f69bfa0b66937d31f68be0641baf82ed24
@@ -268,6 +268,7 @@
%Include geometry/qgsmultisurface.sip
%Include geometry/qgspolygon.sip
%Include geometry/qgsrectangle.sip
%Include geometry/qgsreferencedgeometry.sip
%Include geometry/qgsregularpolygon.sip
%Include geometry/qgstriangle.sip
%Include geometry/qgssurface.sip
@@ -42,6 +42,8 @@ Construct a rectangle from a QRectF. The rectangle is normalized after construct
Copy constructor
%End

~QgsRectangle();

void set( const QgsPointXY &p1, const QgsPointXY &p2 );
%Docstring
Sets the rectangle from two QgsPoints. The rectangle is
@@ -315,9 +317,15 @@ Copy constructor
:rtype: QgsBox3d
%End

operator QVariant() const;
%Docstring
Allows direct construction of QVariants from rectangles.
%End

};



/************************************************************************
* This file has been generated automatically from *
* *
@@ -0,0 +1,120 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/geometry/qgsreferencedgeometry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsReferencedGeometryBase
{
%Docstring
A base class for geometry primitives which are stored with an associated reference system.

QgsReferencedGeometryBase classes represent some form of geometry primitive
(such as rectangles) which have an optional coordinate reference system
associated with them.

.. versionadded:: 3.0
.. seealso:: QgsReferencedRectangle
%End

%TypeHeaderCode
#include "qgsreferencedgeometry.h"
%End
public:

QgsReferencedGeometryBase( const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
%Docstring
Constructor for QgsReferencedGeometryBase, with the specified ``crs``.
%End

QgsCoordinateReferenceSystem crs() const;
%Docstring
Returns the associated coordinate reference system, or an invalid CRS if
no reference system is set.
.. seealso:: setCrs()
:rtype: QgsCoordinateReferenceSystem
%End

void setCrs( const QgsCoordinateReferenceSystem &crs );
%Docstring
Sets the associated ``crs``. Set to an invalid CRS if
no reference system is required.
.. seealso:: crs()
%End

};

class QgsReferencedRectangle : QgsRectangle, QgsReferencedGeometryBase
{
%Docstring
A QgsRectangle with associated coordinate reference system.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsreferencedgeometry.h"
%End
public:

QgsReferencedRectangle( const QgsRectangle &rectangle, const QgsCoordinateReferenceSystem &crs );
%Docstring
Constructor for QgsReferencedRectangle, with the specified initial ``rectangle``
and ``crs``.
%End

QgsReferencedRectangle();
%Docstring
Constructor for QgsReferencedRectangle.
%End

operator QVariant() const;
%Docstring
Allows direct construction of QVariants from rectangle.
%End

};


class QgsReferencedPointXY : QgsPointXY, QgsReferencedGeometryBase
{
%Docstring
A QgsPointXY with associated coordinate reference system.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsreferencedgeometry.h"
%End
public:

QgsReferencedPointXY( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs );
%Docstring
Constructor for QgsReferencedPointXY, with the specified initial ``point``
and ``crs``.
%End

QgsReferencedPointXY();
%Docstring
Constructor for QgsReferencedPointXY.
%End

operator QVariant() const;
%Docstring
Allows direct construction of QVariants from point.
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
* src/core/geometry/qgsreferencedgeometry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -285,6 +285,11 @@ Divides the coordinates in this point by a scalar quantity in place
:rtype: QgsPointXY
%End

operator QVariant() const;
%Docstring
Allows direct construction of QVariants from points.
%End

SIP_PYOBJECT __repr__();
%MethodCode
QString str = "(" + QString::number( sipCpp->x() ) + "," + QString::number( sipCpp->y() ) + ")";
@@ -447,6 +447,7 @@ SET(QGIS_CORE_SRCS
geometry/qgspoint.cpp
geometry/qgspolygon.cpp
geometry/qgsrectangle.cpp
geometry/qgsreferencedgeometry.cpp
geometry/qgsregularpolygon.cpp
geometry/qgstriangle.cpp
geometry/qgswkbptr.cpp
@@ -1059,6 +1060,7 @@ SET(QGIS_CORE_HDRS
geometry/qgsmultisurface.h
geometry/qgspolygon.h
geometry/qgsrectangle.h
geometry/qgsreferencedgeometry.h
geometry/qgsregularpolygon.h
geometry/qgstriangle.h
geometry/qgssurface.h
@@ -47,6 +47,11 @@ class CORE_EXPORT QgsRectangle
//! Copy constructor
QgsRectangle( const QgsRectangle &other );

// IMPORTANT - while QgsRectangle is inherited by QgsReferencedRectangle, we do NOT want a virtual destructor here
// because this class MUST be lightweight and we don't want the cost of the vtable here.
// see https://github.com/qgis/QGIS/pull/4720#issuecomment-308652392
~QgsRectangle() = default;

/**
* Sets the rectangle from two QgsPoints. The rectangle is
* normalised after construction.
@@ -301,6 +306,12 @@ class CORE_EXPORT QgsRectangle
*/
QgsBox3d toBox3d( double zMin, double zMax ) const;

//! Allows direct construction of QVariants from rectangles.
operator QVariant() const
{
return QVariant::fromValue( *this );
}

private:

double mXmin;
@@ -310,6 +321,8 @@ class CORE_EXPORT QgsRectangle

};

Q_DECLARE_METATYPE( QgsRectangle )

#ifndef SIP_RUN

/**
@@ -0,0 +1,32 @@
/***************************************************************************
qgsreferencedgeometry.cpp
------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsreferencedgeometry.h"

QgsReferencedGeometryBase::QgsReferencedGeometryBase( const QgsCoordinateReferenceSystem &crs )
: mCrs( crs )
{}

QgsReferencedRectangle::QgsReferencedRectangle( const QgsRectangle &rect, const QgsCoordinateReferenceSystem &crs )
: QgsRectangle( rect )
, QgsReferencedGeometryBase( crs )
{}

QgsReferencedPointXY::QgsReferencedPointXY( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs )
: QgsPointXY( point )
, QgsReferencedGeometryBase( crs )
{}
@@ -0,0 +1,128 @@
/***************************************************************************
qgsreferencedgeometry.h
----------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSREFERENCEDGEOMETRY_H
#define QGSREFERENCEDGEOMETRY_H

#include "qgis.h"
#include "qgis_sip.h"
#include "qgis_core.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsrectangle.h"

/**
* \class QgsReferencedGeometryBase
* \ingroup core
* A base class for geometry primitives which are stored with an associated reference system.
*
* QgsReferencedGeometryBase classes represent some form of geometry primitive
* (such as rectangles) which have an optional coordinate reference system
* associated with them.
*
* \since QGIS 3.0
* \see QgsReferencedRectangle
*/
class CORE_EXPORT QgsReferencedGeometryBase
{
public:

/**
* Constructor for QgsReferencedGeometryBase, with the specified \a crs.
*/
QgsReferencedGeometryBase( const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );

/**
* Returns the associated coordinate reference system, or an invalid CRS if
* no reference system is set.
* \see setCrs()
*/
QgsCoordinateReferenceSystem crs() const { return mCrs; }

/**
* Sets the associated \a crs. Set to an invalid CRS if
* no reference system is required.
* \see crs()
*/
void setCrs( const QgsCoordinateReferenceSystem &crs ) { mCrs = crs; }

private:

QgsCoordinateReferenceSystem mCrs;

};

/**
* \ingroup core
* A QgsRectangle with associated coordinate reference system.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsReferencedRectangle : public QgsRectangle, public QgsReferencedGeometryBase
{
public:

/**
* Constructor for QgsReferencedRectangle, with the specified initial \a rectangle
* and \a crs.
*/
QgsReferencedRectangle( const QgsRectangle &rectangle, const QgsCoordinateReferenceSystem &crs );

/**
* Constructor for QgsReferencedRectangle.
*/
QgsReferencedRectangle() = default;

//! Allows direct construction of QVariants from rectangle.
operator QVariant() const
{
return QVariant::fromValue( *this );
}

};

Q_DECLARE_METATYPE( QgsReferencedRectangle )

/**
* \ingroup core
* A QgsPointXY with associated coordinate reference system.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsReferencedPointXY : public QgsPointXY, public QgsReferencedGeometryBase
{
public:

/**
* Constructor for QgsReferencedPointXY, with the specified initial \a point
* and \a crs.
*/
QgsReferencedPointXY( const QgsPointXY &point, const QgsCoordinateReferenceSystem &crs );

/**
* Constructor for QgsReferencedPointXY.
*/
QgsReferencedPointXY() = default;

//! Allows direct construction of QVariants from point.
operator QVariant() const
{
return QVariant::fromValue( *this );
}

};

Q_DECLARE_METATYPE( QgsReferencedPointXY )

#endif // QGSREFERENCEDGEOMETRY_H

0 comments on commit 2e20b6f

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