Skip to content

Commit

Permalink
Template based referenced geometry class
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 6, 2017
1 parent 9502022 commit 1a961e8
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 0 deletions.
108 changes: 108 additions & 0 deletions python/core/geometry/qgsreferencedgeometry.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/geometry/qgsreferencedgeometry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




template<T>
class QgsReferencedGeometryPrimitive
{
%Docstring
A template based class for storing geometry primitives with an associated reference system.

QgsReferencedGeometryPrimitive 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
.. note::

Not available in Python bindings (although SIP file is present for specific implementations).
%End

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

QgsReferencedGeometryPrimitive( T primitive, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() );
%Docstring
Constructor for QgsReferencedGeometryPrimitive, for the specified ``primitive`` and ``crs``.
%End

T primitive() const;
%Docstring
Returns the geometry primitive.
:rtype: T
%End

T &primitive();
%Docstring
Returns the geometry primitive.
:rtype: T
%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

};


typedef QgsReferencedGeometryPrimitive<QgsRectangle> QgsReferencedGeometryPrimitiveQgsRectangleBase;

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

%TypeHeaderCode
#include "qgsreferencedgeometry.h"
typedef QgsReferencedGeometryPrimitive<QgsRectangle> QgsReferencedGeometryPrimitiveQgsRectangleBase;
%End
public:

QgsReferencedRectangle();
%Docstring
Construct a default optional expression.
It will be disabled and with an empty expression.
%End

QgsRectangle &rect();
%Docstring
:rtype: QgsRectangle
%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 *
************************************************************************/
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,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
Expand Down
107 changes: 107 additions & 0 deletions src/core/geometry/qgsreferencedgeometry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/***************************************************************************
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 QgsReferencedGeometryPrimitive
* \ingroup core
* A template based class for storing geometry primitives with an associated reference system.
*
* QgsReferencedGeometryPrimitive 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
* \note Not available in Python bindings (although SIP file is present for specific implementations).
*/
template<typename T>
class CORE_EXPORT QgsReferencedGeometryPrimitive
{
public:

/**
* Constructor for QgsReferencedGeometryPrimitive, for the specified \a primitive and \a crs.
*/
QgsReferencedGeometryPrimitive( T primitive, const QgsCoordinateReferenceSystem &crs = QgsCoordinateReferenceSystem() )
: mPrimitive( primitive )
, mCrs( crs )
{}

/**
* Returns the geometry primitive.
*/
T primitive() const { return mPrimitive; }

/**
* Returns the geometry primitive.
*/
T &primitive() { return mPrimitive; }

/**
* 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:

T mPrimitive;
QgsCoordinateReferenceSystem mCrs;

};

/**
* A QgsRectangle with associated coordinate reference system.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsReferencedRectangle : public QgsReferencedGeometryPrimitive< QgsRectangle >
{
public:

/**
* Construct a default optional expression.
* It will be disabled and with an empty expression.
*/
QgsReferencedRectangle();

QgsRectangle &rect() { return primitive(); }


};

#endif // QGSREFERENCEDGEOMETRY_H




0 comments on commit 1a961e8

Please sign in to comment.