QGIS API Documentation 3.99.0-Master (09f76ad7019)
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
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27
28QString QgsTransferAnnotationsFromMainAlgorithm::name() const
29{
30 return u"transferannotationsfrommain"_s;
31}
32
33QString QgsTransferAnnotationsFromMainAlgorithm::displayName() const
34{
35 return QObject::tr( "Transfer annotations from main layer" );
36}
37
38QStringList QgsTransferAnnotationsFromMainAlgorithm::tags() const
39{
40 return QObject::tr( "annotations,drawing,cosmetic,objects" ).split( ',' );
41}
42
43QString QgsTransferAnnotationsFromMainAlgorithm::group() const
44{
45 return QObject::tr( "Cartography" );
46}
47
48QString QgsTransferAnnotationsFromMainAlgorithm::groupId() const
49{
50 return u"cartography"_s;
51}
52
53Qgis::ProcessingAlgorithmFlags QgsTransferAnnotationsFromMainAlgorithm::flags() const
54{
56}
57
58QString QgsTransferAnnotationsFromMainAlgorithm::shortHelpString() const
59{
60 return QObject::tr( "This algorithm transfers all annotations from the main annotation layer in a project to a new annotation layer." );
61}
62
63QString QgsTransferAnnotationsFromMainAlgorithm::shortDescription() const
64{
65 return QObject::tr( "Transfers all annotations from the main annotation layer in a project to a new annotation layer." );
66}
67
68QgsTransferAnnotationsFromMainAlgorithm *QgsTransferAnnotationsFromMainAlgorithm::createInstance() const
69{
70 return new QgsTransferAnnotationsFromMainAlgorithm();
71}
72
73void QgsTransferAnnotationsFromMainAlgorithm::initAlgorithm( const QVariantMap & )
74{
75 addParameter( new QgsProcessingParameterString( u"LAYER_NAME"_s, QObject::tr( "New layer name" ), QObject::tr( "Annotations" ) ) );
76
77 addOutput( new QgsProcessingOutputMapLayer( u"OUTPUT"_s, QObject::tr( "New annotation layer" ) ) );
78}
79
80QVariantMap QgsTransferAnnotationsFromMainAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
81{
82 if ( !context.project() )
83 throw QgsProcessingException( QObject::tr( "No project available." ) );
84
86 if ( !main )
87 throw QgsProcessingException( QObject::tr( "Could not load main annotation layer for project." ) );
88
89 std::unique_ptr<QgsAnnotationLayer> newLayer( main->clone() );
90 newLayer->setName( parameterAsString( parameters, u"LAYER_NAME"_s, context ) );
91 main->clear();
92
93 QVariantMap outputs;
94 outputs.insert( u"OUTPUT"_s, newLayer->id() );
95
96 context.project()->addMapLayer( newLayer.release() );
97
98 return outputs;
99}
100
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
Definition qgis.h:3680
@ NoThreading
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
Definition qgis.h:3659
@ RequiresProject
The algorithm requires that a valid QgsProject is available from the processing context in order to e...
Definition qgis.h:3667
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[])