From 21a2599d0db592f4d3082375160d30b14b6e4d8d Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 21 Oct 2019 07:45:13 +1000 Subject: [PATCH] Move annotation layer renderer to own file --- python/core/auto_additions/qgsmaplayer.py | 4 +- .../annotations/qgsannotationlayer.sip.in | 17 ------ python/core/auto_generated/qgsmaplayer.sip.in | 2 +- src/core/CMakeLists.txt | 4 ++ src/core/annotations/qgsannotationlayer.cpp | 43 +------------ src/core/annotations/qgsannotationlayer.h | 15 ----- .../qgsannotationlayerrenderer.cpp | 60 +++++++++++++++++++ .../annotations/qgsannotationlayerrenderer.h | 44 ++++++++++++++ 8 files changed, 112 insertions(+), 77 deletions(-) create mode 100644 src/core/annotations/qgsannotationlayerrenderer.cpp create mode 100644 src/core/annotations/qgsannotationlayerrenderer.h diff --git a/python/core/auto_additions/qgsmaplayer.py b/python/core/auto_additions/qgsmaplayer.py index f4ce6de4553..62c5055c493 100644 --- a/python/core/auto_additions/qgsmaplayer.py +++ b/python/core/auto_additions/qgsmaplayer.py @@ -12,8 +12,8 @@ QgsMapLayer.MeshLayer.__doc__ = "Added in 3.2" QgsMapLayer.VectorTileLayer = QgsMapLayerType.VectorTileLayer QgsMapLayer.VectorTileLayer.__doc__ = "Added in 3.14" QgsMapLayer.AnnotationLayer = QgsMapLayerType.AnnotationLayer -QgsMapLayer.AnnotationLayer.__doc__ = "Contains freeform, georeferenced annotations. Added in QGIS 3.10" -QgsMapLayerType.__doc__ = 'Types of layers that can be added to a map\n\n.. versionadded:: 3.8\n\n' + '* ``VectorLayer``: ' + QgsMapLayerType.VectorLayer.__doc__ + '\n' + '* ``RasterLayer``: ' + QgsMapLayerType.RasterLayer.__doc__ + '\n' + '* ``PluginLayer``: ' + QgsMapLayerType.PluginLayer.__doc__ + '\n' + '* ``MeshLayer``: ' + QgsMapLayerType.MeshLayer.__doc__ + '\n' + '* ``VectorTileLayer``: ' + QgsMapLayerType.VectorTileLayer.__doc__ +QgsMapLayer.AnnotationLayer.__doc__ = "Contains freeform, georeferenced annotations. Added in QGIS 3.16" +QgsMapLayerType.__doc__ = 'Types of layers that can be added to a map\n\n.. versionadded:: 3.8\n\n' + '* ``VectorLayer``: ' + QgsMapLayerType.VectorLayer.__doc__ + '\n' + '* ``RasterLayer``: ' + QgsMapLayerType.RasterLayer.__doc__ + '\n' + '* ``PluginLayer``: ' + QgsMapLayerType.PluginLayer.__doc__ + '\n' + '* ``MeshLayer``: ' + QgsMapLayerType.MeshLayer.__doc__ + '\n' + '* ``VectorTileLayer``: ' + QgsMapLayerType.VectorTileLayer.__doc__ + '\n' + '* ``AnnotationLayer``: ' + QgsMapLayerType.AnnotationLayer.__doc__ # -- QgsMapLayer.LayerFlag.baseClass = QgsMapLayer QgsMapLayer.LayerFlags.baseClass = QgsMapLayer diff --git a/python/core/auto_generated/annotations/qgsannotationlayer.sip.in b/python/core/auto_generated/annotations/qgsannotationlayer.sip.in index 2b642f34e67..f11c70cf315 100644 --- a/python/core/auto_generated/annotations/qgsannotationlayer.sip.in +++ b/python/core/auto_generated/annotations/qgsannotationlayer.sip.in @@ -88,23 +88,6 @@ Constructor for LayerOptions. }; -class QgsAnnotationLayerRenderer : QgsMapLayerRenderer -{ - -%TypeHeaderCode -#include "qgsannotationlayer.h" -%End - public: - - QgsAnnotationLayerRenderer( QgsAnnotationLayer *layer, QgsRenderContext &context ); - ~QgsAnnotationLayerRenderer(); - virtual QgsFeedback *feedback() const; - - virtual bool render(); - - -}; - /************************************************************************ * This file has been generated automatically from * * * diff --git a/python/core/auto_generated/qgsmaplayer.sip.in b/python/core/auto_generated/qgsmaplayer.sip.in index 6b613bcff8a..5b10be183b3 100644 --- a/python/core/auto_generated/qgsmaplayer.sip.in +++ b/python/core/auto_generated/qgsmaplayer.sip.in @@ -20,7 +20,7 @@ enum class QgsMapLayerType RasterLayer, PluginLayer, MeshLayer, - VectorTileLayer, + VectorTileLayer AnnotationLayer, }; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index a692351b9ae..e2bf6266fd5 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -125,6 +125,8 @@ SET(QGIS_CORE_SRCS auth/qgsauthmethodregistry.cpp annotations/qgsannotation.cpp + annotations/qgsannotationlayer.cpp + annotations/qgsannotationlayerrenderer.cpp annotations/qgsannotationmanager.cpp annotations/qgshtmlannotation.cpp annotations/qgssvgannotation.cpp @@ -1045,6 +1047,8 @@ SET(QGIS_CORE_HDRS 3d/qgsabstract3drenderer.h annotations/qgsannotation.h + annotations/qgsannotationlayer.h + annotations/qgsannotationlayerrenderer.h annotations/qgsannotationmanager.h annotations/qgsannotationregistry.h annotations/qgshtmlannotation.h diff --git a/src/core/annotations/qgsannotationlayer.cpp b/src/core/annotations/qgsannotationlayer.cpp index f5696d63e56..4ddebaf7a92 100644 --- a/src/core/annotations/qgsannotationlayer.cpp +++ b/src/core/annotations/qgsannotationlayer.cpp @@ -15,7 +15,7 @@ ***************************************************************************/ #include "qgsannotationlayer.h" -#include "qgsfeedback.h" +#include "qgsannotationlayerrenderer.h" #include QgsAnnotationLayer::QgsAnnotationLayer( const QString &name, const LayerOptions &options ) @@ -130,44 +130,3 @@ QRectF QgsAnnotationLayer::margin() const } #endif -QgsAnnotationLayerRenderer::QgsAnnotationLayerRenderer( QgsAnnotationLayer *layer, QgsRenderContext &context ) - : QgsMapLayerRenderer( layer->id(), &context ) - , mFeedback( qgis::make_unique< QgsFeedback >() ) -{ - // clone items from layer - const QMap< QString, QgsAnnotationItem * > items = layer->items(); - mItems.reserve( items.size() ); - for ( auto it = items.constBegin(); it != items.constEnd(); ++it ) - { - if ( it.value() ) - mItems << ( *it )->clone(); - } - - // std::sort( mItems.begin(), mItems.end(), []( QgsAnnotationItem * a, QgsAnnotationItem * b ) { return a->zIndex() < b->zIndex(); } ); -} - -QgsAnnotationLayerRenderer::~QgsAnnotationLayerRenderer() -{ - qDeleteAll( mItems ); -} - -QgsFeedback *QgsAnnotationLayerRenderer::feedback() const -{ - return mFeedback.get(); -} - -bool QgsAnnotationLayerRenderer::render() -{ - QgsRenderContext &context = *renderContext(); - - for ( QgsAnnotationItem *item : qgis::as_const( mItems ) ) - { - if ( mFeedback->isCanceled() ) - break; - - - renderContext()->setCoordinateTransform( QgsCoordinateTransform( item->crs(), context.coordinateTransform().destinationCrs(), context.transformContext() ) ); - item->render( context, mFeedback.get() ); - } - return true; -} diff --git a/src/core/annotations/qgsannotationlayer.h b/src/core/annotations/qgsannotationlayer.h index dc59f0383af..cea89ca07d9 100644 --- a/src/core/annotations/qgsannotationlayer.h +++ b/src/core/annotations/qgsannotationlayer.h @@ -100,19 +100,4 @@ class CORE_EXPORT QgsAnnotationLayer : public QgsMapLayer double mOpacity = 100; }; -class CORE_EXPORT QgsAnnotationLayerRenderer : public QgsMapLayerRenderer -{ - public: - - QgsAnnotationLayerRenderer( QgsAnnotationLayer *layer, QgsRenderContext &context ); - ~QgsAnnotationLayerRenderer() override; - QgsFeedback *feedback() const override; - bool render() override; - - private: - QVector< QgsAnnotationItem *> mItems; - std::unique_ptr< QgsFeedback > mFeedback; - -}; - #endif // QGSANNOTATIONLAYER_H diff --git a/src/core/annotations/qgsannotationlayerrenderer.cpp b/src/core/annotations/qgsannotationlayerrenderer.cpp new file mode 100644 index 00000000000..64043ef26db --- /dev/null +++ b/src/core/annotations/qgsannotationlayerrenderer.cpp @@ -0,0 +1,60 @@ +/*************************************************************************** + qgsannotationlayerrenderer.cpp + ------------------ + copyright : (C) 2019 by Sandro Mani + email : smani at sourcepole dot ch + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 "qgsannotationlayerrenderer.h" +#include "qgsannotationlayer.h" +#include "qgsfeedback.h" + +QgsAnnotationLayerRenderer::QgsAnnotationLayerRenderer( QgsAnnotationLayer *layer, QgsRenderContext &context ) + : QgsMapLayerRenderer( layer->id(), &context ) + , mFeedback( qgis::make_unique< QgsFeedback >() ) +{ + // clone items from layer + const QMap< QString, QgsAnnotationItem * > items = layer->items(); + mItems.reserve( items.size() ); + for ( auto it = items.constBegin(); it != items.constEnd(); ++it ) + { + if ( it.value() ) + mItems << ( *it )->clone(); + } + + // std::sort( mItems.begin(), mItems.end(), []( QgsAnnotationItem * a, QgsAnnotationItem * b ) { return a->zIndex() < b->zIndex(); } ); +} + +QgsAnnotationLayerRenderer::~QgsAnnotationLayerRenderer() +{ + qDeleteAll( mItems ); +} + +QgsFeedback *QgsAnnotationLayerRenderer::feedback() const +{ + return mFeedback.get(); +} + +bool QgsAnnotationLayerRenderer::render() +{ + QgsRenderContext &context = *renderContext(); + + for ( QgsAnnotationItem *item : qgis::as_const( mItems ) ) + { + if ( mFeedback->isCanceled() ) + break; + + renderContext()->setCoordinateTransform( QgsCoordinateTransform( item->crs(), context.coordinateTransform().destinationCrs(), context.transformContext() ) ); + item->render( context, mFeedback.get() ); + } + return true; +} diff --git a/src/core/annotations/qgsannotationlayerrenderer.h b/src/core/annotations/qgsannotationlayerrenderer.h new file mode 100644 index 00000000000..5045d355a65 --- /dev/null +++ b/src/core/annotations/qgsannotationlayerrenderer.h @@ -0,0 +1,44 @@ +/*************************************************************************** + qgsannotationlayerrenderer.h + ---------------- + copyright : (C) 2019 by Sandro Mani + email : smani at sourcepole dot ch + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 QGSANNOTATIONLAYERRENDERER_H +#define QGSANNOTATIONLAYERRENDERER_H + +#define SIP_NO_FILE + +#include "qgis_core.h" +#include "qgis_sip.h" +#include "qgsmaplayerrenderer.h" + +class QgsAnnotationItem; +class QgsAnnotationLayer; + +class CORE_EXPORT QgsAnnotationLayerRenderer : public QgsMapLayerRenderer +{ + public: + + QgsAnnotationLayerRenderer( QgsAnnotationLayer *layer, QgsRenderContext &context ); + ~QgsAnnotationLayerRenderer() override; + QgsFeedback *feedback() const override; + bool render() override; + + private: + QVector< QgsAnnotationItem *> mItems; + std::unique_ptr< QgsFeedback > mFeedback; + +}; + +#endif // QGSANNOTATIONLAYERRENDERER_H