QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsalgorithmannotations.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmannotations.cpp
3 ------------------------------
4 begin : September 2021
5 copyright : (C) 2021 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include "qgsannotationlayer.h"
21
23
24QString QgsTransferAnnotationsFromMainAlgorithm::name() const
25{
26 return QStringLiteral( "transferannotationsfrommain" );
27}
28
29QString QgsTransferAnnotationsFromMainAlgorithm::displayName() const
30{
31 return QObject::tr( "Transfer annotations from main layer" );
32}
33
34QStringList QgsTransferAnnotationsFromMainAlgorithm::tags() const
35{
36 return QObject::tr( "annotations,drawing,cosmetic,objects" ).split( ',' );
37}
38
39QString QgsTransferAnnotationsFromMainAlgorithm::group() const
40{
41 return QObject::tr( "Cartography" );
42}
43
44QString QgsTransferAnnotationsFromMainAlgorithm::groupId() const
45{
46 return QStringLiteral( "cartography" );
47}
48
49Qgis::ProcessingAlgorithmFlags QgsTransferAnnotationsFromMainAlgorithm::flags() const
50{
52}
53
54QString QgsTransferAnnotationsFromMainAlgorithm::shortHelpString() const
55{
56 return QObject::tr( "This algorithm transfers all annotations from the main annotation layer in a project to a new annotation layer." );
57}
58
59QString QgsTransferAnnotationsFromMainAlgorithm::shortDescription() const
60{
61 return QObject::tr( "Transfers all annotations from the main annotation layer in a project to a new annotation layer." );
62}
63
64QgsTransferAnnotationsFromMainAlgorithm *QgsTransferAnnotationsFromMainAlgorithm::createInstance() const
65{
66 return new QgsTransferAnnotationsFromMainAlgorithm();
67}
68
69void QgsTransferAnnotationsFromMainAlgorithm::initAlgorithm( const QVariantMap & )
70{
71 addParameter( new QgsProcessingParameterString( QStringLiteral( "LAYER_NAME" ), QObject::tr( "New layer name" ), QObject::tr( "Annotations" ) ) );
72
73 addOutput( new QgsProcessingOutputMapLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "New annotation layer" ) ) );
74}
75
76QVariantMap QgsTransferAnnotationsFromMainAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
77{
78 if ( !context.project() )
79 throw QgsProcessingException( QObject::tr( "No project available." ) );
80
82 if ( !main )
83 throw QgsProcessingException( QObject::tr( "Could not load main annotation layer for project." ) );
84
85 std::unique_ptr<QgsAnnotationLayer> newLayer( main->clone() );
86 newLayer->setName( parameterAsString( parameters, QStringLiteral( "LAYER_NAME" ), context ) );
87 main->clear();
88
89 QVariantMap outputs;
90 outputs.insert( QStringLiteral( "OUTPUT" ), newLayer->id() );
91
92 context.project()->addMapLayer( newLayer.release() );
93
94 return outputs;
95}
96
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3609
@ NoThreading
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
Definition qgis.h:3588
@ RequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
Definition qgis.h:3596
Represents a map layer containing a set of georeferenced annotations, e.g.
virtual Qgis::ProcessingAlgorithmFlags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Contains information about the context in which a processing algorithm is executed.
QgsProject * project() const
Returns the project in which the algorithm is being executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
A map layer output for processing algorithms, where layers may be either vector or raster.
A string parameter for processing algorithms.
QgsAnnotationLayer * mainAnnotationLayer()
Returns the main annotation layer associated with the project.
QgsMapLayer * addMapLayer(QgsMapLayer *mapLayer, bool addToLegend=true, bool takeOwnership=true)
Add a layer to the map of loaded layers.
int main(int argc, char *argv[])