Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move annotation layer renderer to own file
- Loading branch information
1 parent
35d9a65
commit 21a2599
Showing
8 changed files
with
112 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |