Skip to content

Commit

Permalink
Treat item crs as matching annotation layer CRS
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 5, 2020
1 parent ce40245 commit 50d4bf0
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 183 deletions.
23 changes: 3 additions & 20 deletions python/core/auto_generated/annotations/qgsannotationitem.sip.in
Expand Up @@ -41,10 +41,9 @@ Abstract base class for annotation items which are drawn with QgsAnnotationLayer
%End
public:

QgsAnnotationItem( const QgsCoordinateReferenceSystem &crs );
QgsAnnotationItem();
%Docstring
Constructor for an annotation item, with the specified ``crs`` for storing
its geographic location.
Constructor for an annotation item.
%End


Expand All @@ -62,23 +61,7 @@ Returns a unique (untranslated) string identifying the type of item.

virtual QgsRectangle boundingBox() const = 0;
%Docstring
Returns the bounding box of the item's geographic location.

The coordinate reference system for the bounding box is retrieved via :py:func:`~QgsAnnotationItem.crs`.
%End

QgsCoordinateReferenceSystem crs() const;
%Docstring
Returns the CRS used for storing the location of the item.

.. seealso:: :py:func:`setCrs`
%End

void setCrs( const QgsCoordinateReferenceSystem &crs );
%Docstring
Sets the ``crs`` used for storing the location of the item.

.. seealso:: :py:func:`crs`
Returns the bounding box of the item's geographic location, in the parent layer's coordinate reference system.
%End

virtual void render( QgsRenderContext &context, QgsFeedback *feedback ) = 0;
Expand Down
Expand Up @@ -23,9 +23,9 @@ An annotation item which renders a line symbol along a linestring geometry.
%End
public:

QgsAnnotationLineStringItem( const QgsLineString &linestring, const QgsCoordinateReferenceSystem &crs );
QgsAnnotationLineStringItem( const QgsLineString &linestring );
%Docstring
Constructor for QgsAnnotationLineStringItem, with the specified ``linestring`` in the given ``crs``.
Constructor for QgsAnnotationLineStringItem, with the specified ``linestring``.
%End
~QgsAnnotationLineStringItem();

Expand Down Expand Up @@ -53,7 +53,7 @@ Creates a new linestring annotation item.
%Docstring
Returns the line string geometry of the item.

The coordinate reference system for the line can be retrieved through :py:func:`~QgsAnnotationLineStringItem.crs`.
The coordinate reference system for the line will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

.. seealso:: :py:func:`setLineString`
%End
Expand All @@ -62,7 +62,7 @@ The coordinate reference system for the line can be retrieved through :py:func:`
%Docstring
Sets the ``lineString`` geometry of the item.

The coordinate reference system for the line can be set through :py:func:`~QgsAnnotationLineStringItem.setCrs`.
The coordinate reference system for the line will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

.. seealso:: :py:func:`lineString`
%End
Expand Down
Expand Up @@ -23,9 +23,9 @@ An annotation item which renders a marker symbol at a point location.
%End
public:

QgsAnnotationMarkerItem( QgsPointXY point, const QgsCoordinateReferenceSystem &crs );
QgsAnnotationMarkerItem( QgsPointXY point );
%Docstring
Constructor for QgsAnnotationMarkerItem, at the specified ``point`` in the given ``crs``.
Constructor for QgsAnnotationMarkerItem, at the specified ``point``.
%End
~QgsAnnotationMarkerItem();

Expand All @@ -52,7 +52,7 @@ Creates a new marker annotation item.
%Docstring
Returns the point location of the marker.

The coordinate reference system for the point can be retrieved through :py:func:`~QgsAnnotationMarkerItem.crs`.
The coordinate reference system for the point will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

.. seealso:: :py:func:`setPoint`
%End
Expand All @@ -61,7 +61,7 @@ The coordinate reference system for the point can be retrieved through :py:func:
%Docstring
Sets the ``point`` location of the marker.

The coordinate reference system for the point can be set through :py:func:`~QgsAnnotationMarkerItem.setCrs`.
The coordinate reference system for the point will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

.. seealso:: :py:func:`point`
%End
Expand Down
Expand Up @@ -23,9 +23,9 @@ An annotation item which renders a fill symbol for a polygon geometry.
%End
public:

QgsAnnotationPolygonItem( const QgsPolygon &polygon, const QgsCoordinateReferenceSystem &crs );
QgsAnnotationPolygonItem( const QgsPolygon &polygon );
%Docstring
Constructor for QgsAnnotationPolygonItem, with the specified ``polygon`` in the given ``crs``.
Constructor for QgsAnnotationPolygonItem, with the specified ``polygon`` geometry.
%End
~QgsAnnotationPolygonItem();

Expand All @@ -52,7 +52,7 @@ Creates a new polygon annotation item.
%Docstring
Returns the polygon geometry of the item.

The coordinate reference system for the polygon can be retrieved through :py:func:`~QgsAnnotationPolygonItem.crs`.
The coordinate reference system for the polygon will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

.. seealso:: :py:func:`setPolygon`
%End
Expand All @@ -61,7 +61,7 @@ The coordinate reference system for the polygon can be retrieved through :py:fun
%Docstring
Sets the ``polygon`` geometry of the item.

The coordinate reference system for the polygon can be set through :py:func:`~QgsAnnotationPolygonItem.setCrs`.
The coordinate reference system for the polygon will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

.. seealso:: :py:func:`polygon`
%End
Expand Down
10 changes: 0 additions & 10 deletions src/core/annotations/qgsannotationitem.cpp
Expand Up @@ -19,13 +19,3 @@
#include "qgssymbollayerutils.h"


QgsAnnotationItem::QgsAnnotationItem( const QgsCoordinateReferenceSystem &crs )
: mCrs( crs )
{

}

void QgsAnnotationItem::setCrs( const QgsCoordinateReferenceSystem &crs )
{
mCrs = crs;
}
24 changes: 3 additions & 21 deletions src/core/annotations/qgsannotationitem.h
Expand Up @@ -62,10 +62,9 @@ class CORE_EXPORT QgsAnnotationItem
public:

/**
* Constructor for an annotation item, with the specified \a crs for storing
* its geographic location.
* Constructor for an annotation item.
*/
QgsAnnotationItem( const QgsCoordinateReferenceSystem &crs );
QgsAnnotationItem() = default;

#ifndef SIP_RUN
//! QgsAnnotationItem cannot be copied
Expand All @@ -87,26 +86,10 @@ class CORE_EXPORT QgsAnnotationItem
virtual QString type() const = 0;

/**
* Returns the bounding box of the item's geographic location.
*
* The coordinate reference system for the bounding box is retrieved via crs().
* Returns the bounding box of the item's geographic location, in the parent layer's coordinate reference system.
*/
virtual QgsRectangle boundingBox() const = 0;

/**
* Returns the CRS used for storing the location of the item.
*
* \see setCrs()
*/
QgsCoordinateReferenceSystem crs() const { return mCrs; }

/**
* Sets the \a crs used for storing the location of the item.
*
* \see crs()
*/
void setCrs( const QgsCoordinateReferenceSystem &crs );

/**
* Renders the item to the specified render \a context.
*
Expand Down Expand Up @@ -143,7 +126,6 @@ class CORE_EXPORT QgsAnnotationItem

private:

QgsCoordinateReferenceSystem mCrs;
int mZIndex = 0;

#ifdef SIP_RUN
Expand Down
5 changes: 2 additions & 3 deletions src/core/annotations/qgsannotationlayer.cpp
Expand Up @@ -77,14 +77,13 @@ QgsRectangle QgsAnnotationLayer::extent() const
QgsRectangle rect;
for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
{
QgsCoordinateTransform trans( it.value()->crs(), crs(), mTransformContext );
if ( rect.isNull() )
{
rect = trans.transform( it.value()->boundingBox() );
rect = it.value()->boundingBox();
}
else
{
rect.combineExtentWith( trans.transform( it.value()->boundingBox() ) );
rect.combineExtentWith( it.value()->boundingBox() );
}
}
return rect;
Expand Down
1 change: 0 additions & 1 deletion src/core/annotations/qgsannotationlayerrenderer.cpp
Expand Up @@ -53,7 +53,6 @@ bool QgsAnnotationLayerRenderer::render()
if ( mFeedback->isCanceled() )
break;

renderContext()->setCoordinateTransform( QgsCoordinateTransform( item->crs(), context.coordinateTransform().destinationCrs(), context.transformContext() ) );
item->render( context, mFeedback.get() );
}
return true;
Expand Down
12 changes: 4 additions & 8 deletions src/core/annotations/qgsannotationlinestringitem.cpp
Expand Up @@ -19,8 +19,8 @@
#include "qgssymbol.h"
#include "qgssymbollayerutils.h"

QgsAnnotationLineStringItem::QgsAnnotationLineStringItem( const QgsLineString &linestring, const QgsCoordinateReferenceSystem &crs )
: QgsAnnotationItem( crs )
QgsAnnotationLineStringItem::QgsAnnotationLineStringItem( const QgsLineString &linestring )
: QgsAnnotationItem()
, mLineString( linestring )
, mSymbol( qgis::make_unique< QgsLineSymbol >() )
{
Expand Down Expand Up @@ -72,7 +72,6 @@ void QgsAnnotationLineStringItem::render( QgsRenderContext &context, QgsFeedback
bool QgsAnnotationLineStringItem::writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const
{
element.setAttribute( QStringLiteral( "wkt" ), mLineString.asWkt() );
crs().writeXml( element, document );
element.setAttribute( QStringLiteral( "zIndex" ), zIndex() );

element.appendChild( QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "lineSymbol" ), mSymbol.get(), document, context ) );
Expand All @@ -82,7 +81,7 @@ bool QgsAnnotationLineStringItem::writeXml( QDomElement &element, QDomDocument &

QgsAnnotationLineStringItem *QgsAnnotationLineStringItem::create()
{
return new QgsAnnotationLineStringItem( QgsLineString(), QgsCoordinateReferenceSystem() );
return new QgsAnnotationLineStringItem( QgsLineString() );
}

bool QgsAnnotationLineStringItem::readXml( const QDomElement &element, const QgsReadWriteContext &context )
Expand All @@ -91,9 +90,6 @@ bool QgsAnnotationLineStringItem::readXml( const QDomElement &element, const Qgs
QgsLineString ls;
mLineString.fromWkt( wkt );

QgsCoordinateReferenceSystem crs;
crs.readXml( element );
setCrs( crs );
setZIndex( element.attribute( QStringLiteral( "zIndex" ) ).toInt() );

const QDomElement symbolElem = element.firstChildElement( QStringLiteral( "symbol" ) );
Expand All @@ -110,7 +106,7 @@ QgsRectangle QgsAnnotationLineStringItem::boundingBox() const

QgsAnnotationLineStringItem *QgsAnnotationLineStringItem::clone()
{
std::unique_ptr< QgsAnnotationLineStringItem > item = qgis::make_unique< QgsAnnotationLineStringItem >( mLineString, crs() );
std::unique_ptr< QgsAnnotationLineStringItem > item = qgis::make_unique< QgsAnnotationLineStringItem >( mLineString );
item->setSymbol( mSymbol->clone() );
item->setZIndex( zIndex() );
return item.release();
Expand Down
8 changes: 4 additions & 4 deletions src/core/annotations/qgsannotationlinestringitem.h
Expand Up @@ -34,9 +34,9 @@ class CORE_EXPORT QgsAnnotationLineStringItem : public QgsAnnotationItem
public:

/**
* Constructor for QgsAnnotationLineStringItem, with the specified \a linestring in the given \a crs.
* Constructor for QgsAnnotationLineStringItem, with the specified \a linestring.
*/
QgsAnnotationLineStringItem( const QgsLineString &linestring, const QgsCoordinateReferenceSystem &crs );
QgsAnnotationLineStringItem( const QgsLineString &linestring );
~QgsAnnotationLineStringItem() override;

QString type() const override;
Expand All @@ -56,7 +56,7 @@ class CORE_EXPORT QgsAnnotationLineStringItem : public QgsAnnotationItem
/**
* Returns the line string geometry of the item.
*
* The coordinate reference system for the line can be retrieved through crs().
* The coordinate reference system for the line will be the parent layer's QgsAnnotationLayer::crs().
*
* \see setLineString()
*/
Expand All @@ -65,7 +65,7 @@ class CORE_EXPORT QgsAnnotationLineStringItem : public QgsAnnotationItem
/**
* Sets the \a lineString geometry of the item.
*
* The coordinate reference system for the line can be set through setCrs().
* The coordinate reference system for the line will be the parent layer's QgsAnnotationLayer::crs().
*
* \see lineString()
*/
Expand Down
12 changes: 4 additions & 8 deletions src/core/annotations/qgsannotationmarkeritem.cpp
Expand Up @@ -19,8 +19,8 @@
#include "qgssymbol.h"
#include "qgssymbollayerutils.h"

QgsAnnotationMarkerItem::QgsAnnotationMarkerItem( QgsPointXY point, const QgsCoordinateReferenceSystem &crs )
: QgsAnnotationItem( crs )
QgsAnnotationMarkerItem::QgsAnnotationMarkerItem( QgsPointXY point )
: QgsAnnotationItem()
, mPoint( point )
, mSymbol( qgis::make_unique< QgsMarkerSymbol >() )
{
Expand Down Expand Up @@ -60,7 +60,6 @@ bool QgsAnnotationMarkerItem::writeXml( QDomElement &element, QDomDocument &docu
element.setAttribute( QStringLiteral( "x" ), qgsDoubleToString( mPoint.x() ) );
element.setAttribute( QStringLiteral( "y" ), qgsDoubleToString( mPoint.y() ) );
element.setAttribute( QStringLiteral( "zIndex" ), zIndex() );
crs().writeXml( element, document );

element.appendChild( QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "markerSymbol" ), mSymbol.get(), document, context ) );

Expand All @@ -69,7 +68,7 @@ bool QgsAnnotationMarkerItem::writeXml( QDomElement &element, QDomDocument &docu

QgsAnnotationMarkerItem *QgsAnnotationMarkerItem::create()
{
return new QgsAnnotationMarkerItem( QgsPointXY(), QgsCoordinateReferenceSystem() );
return new QgsAnnotationMarkerItem( QgsPointXY() );
}

bool QgsAnnotationMarkerItem::readXml( const QDomElement &element, const QgsReadWriteContext &context )
Expand All @@ -78,9 +77,6 @@ bool QgsAnnotationMarkerItem::readXml( const QDomElement &element, const QgsRead
const double y = element.attribute( QStringLiteral( "y" ) ).toDouble();
mPoint = QgsPointXY( x, y );

QgsCoordinateReferenceSystem crs;
crs.readXml( element );
setCrs( crs );
setZIndex( element.attribute( QStringLiteral( "zIndex" ) ).toInt() );

const QDomElement symbolElem = element.firstChildElement( QStringLiteral( "symbol" ) );
Expand All @@ -92,7 +88,7 @@ bool QgsAnnotationMarkerItem::readXml( const QDomElement &element, const QgsRead

QgsAnnotationMarkerItem *QgsAnnotationMarkerItem::clone()
{
std::unique_ptr< QgsAnnotationMarkerItem > item = qgis::make_unique< QgsAnnotationMarkerItem >( mPoint, crs() );
std::unique_ptr< QgsAnnotationMarkerItem > item = qgis::make_unique< QgsAnnotationMarkerItem >( mPoint );
item->setSymbol( mSymbol->clone() );
item->setZIndex( zIndex() );
return item.release();
Expand Down
8 changes: 4 additions & 4 deletions src/core/annotations/qgsannotationmarkeritem.h
Expand Up @@ -34,9 +34,9 @@ class CORE_EXPORT QgsAnnotationMarkerItem : public QgsAnnotationItem
public:

/**
* Constructor for QgsAnnotationMarkerItem, at the specified \a point in the given \a crs.
* Constructor for QgsAnnotationMarkerItem, at the specified \a point.
*/
QgsAnnotationMarkerItem( QgsPointXY point, const QgsCoordinateReferenceSystem &crs );
QgsAnnotationMarkerItem( QgsPointXY point );
~QgsAnnotationMarkerItem() override;

QString type() const override;
Expand All @@ -55,7 +55,7 @@ class CORE_EXPORT QgsAnnotationMarkerItem : public QgsAnnotationItem
/**
* Returns the point location of the marker.
*
* The coordinate reference system for the point can be retrieved through crs().
* The coordinate reference system for the point will be the parent layer's QgsAnnotationLayer::crs().
*
* \see setPoint()
*/
Expand All @@ -64,7 +64,7 @@ class CORE_EXPORT QgsAnnotationMarkerItem : public QgsAnnotationItem
/**
* Sets the \a point location of the marker.
*
* The coordinate reference system for the point can be set through setCrs().
* The coordinate reference system for the point will be the parent layer's QgsAnnotationLayer::crs().
*
* \see point()
*/
Expand Down

0 comments on commit 50d4bf0

Please sign in to comment.