Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template based referenced geometry class #4720

Merged
merged 8 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions python/core/geometry/qgsrectangle.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 *
* *
Expand Down
120 changes: 120 additions & 0 deletions python/core/geometry/qgsreferencedgeometry.sip
Original file line number Diff line number Diff line change
@@ -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 *
************************************************************************/
5 changes: 5 additions & 0 deletions python/core/qgspointxy.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) + ")";
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/core/geometry/qgsrectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -310,6 +321,8 @@ class CORE_EXPORT QgsRectangle

};

Q_DECLARE_METATYPE( QgsRectangle )

#ifndef SIP_RUN

/**
Expand Down
32 changes: 32 additions & 0 deletions src/core/geometry/qgsreferencedgeometry.cpp
Original file line number Diff line number Diff line change
@@ -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 )
{}
128 changes: 128 additions & 0 deletions src/core/geometry/qgsreferencedgeometry.h
Original file line number Diff line number Diff line change
@@ -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
Loading