Move annotation layer renderer to own file

This commit is contained in:
Nyall Dawson 2019-10-21 07:45:13 +10:00
parent 35d9a657c8
commit 21a2599d0d
8 changed files with 112 additions and 77 deletions

View File

@ -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

View File

@ -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 *
* *

View File

@ -20,7 +20,7 @@ enum class QgsMapLayerType
RasterLayer,
PluginLayer,
MeshLayer,
VectorTileLayer,
VectorTileLayer
AnnotationLayer,
};

View File

@ -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

View File

@ -15,7 +15,7 @@
***************************************************************************/
#include "qgsannotationlayer.h"
#include "qgsfeedback.h"
#include "qgsannotationlayerrenderer.h"
#include <QUuid>
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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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