Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] Add an algorithm which transfers all items from the
main annotation layer in a project to a secondary annotation layer Useful for moving items created in the main layer to a secondary layer, so that the item placement can be adjusted within the layer stack
- Loading branch information
1 parent
c2c0f25
commit 5234442
Showing
5 changed files
with
178 additions
and
0 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,92 @@ | |||
/*************************************************************************** | |||
qgsalgorithmannotations.cpp | |||
------------------------------ | |||
begin : September 2021 | |||
copyright : (C) 2021 by Nyall Dawson | |||
email : nyall dot dawson at gmail dot com | |||
***************************************************************************/ | |||
|
|||
/*************************************************************************** | |||
* * | |||
* 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 "qgsalgorithmannotations.h" | |||
#include "qgsannotationlayer.h" | |||
|
|||
///@cond PRIVATE | |||
|
|||
QString QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::name() const | |||
{ | |||
return QStringLiteral( "transferannotationsfrommain" ); | |||
} | |||
|
|||
QString QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::displayName() const | |||
{ | |||
return QObject::tr( "Transfer annotations from main layer" ); | |||
} | |||
|
|||
QStringList QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::tags() const | |||
{ | |||
return QObject::tr( "annotations,drawing,cosmetic,objects" ).split( ',' ); | |||
} | |||
|
|||
QString QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::group() const | |||
{ | |||
return QObject::tr( "Cartography" ); | |||
} | |||
|
|||
QString QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::groupId() const | |||
{ | |||
return QStringLiteral( "cartography" ); | |||
} | |||
|
|||
QgsProcessingAlgorithm::Flags QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::flags() const | |||
{ | |||
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagNoThreading | QgsProcessingAlgorithm::FlagRequiresProject; | |||
} | |||
|
|||
|
|||
QString QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::shortHelpString() const | |||
{ | |||
return QObject::tr( "Transfer all annotations from the main annotation layer in a project to a new annotation layer." ); | |||
} | |||
|
|||
QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm *QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::createInstance() const | |||
{ | |||
return new QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm(); | |||
} | |||
|
|||
void QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::initAlgorithm( const QVariantMap & ) | |||
{ | |||
addParameter( new QgsProcessingParameterString( QStringLiteral( "LAYER_NAME" ), QObject::tr( "New layer name" ), QObject::tr( "Annotations" ) ) ); | |||
|
|||
addOutput( new QgsProcessingOutputMapLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "New annotation layer" ) ) ); | |||
} | |||
|
|||
QVariantMap QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback * ) | |||
{ | |||
if ( !context.project() ) | |||
throw QgsProcessingException( QObject::tr( "No project available." ) ); | |||
|
|||
QgsAnnotationLayer *main = context.project()->mainAnnotationLayer(); | |||
if ( !main ) | |||
throw QgsProcessingException( QObject::tr( "Could not load main annotation layer for project." ) ); | |||
|
|||
std::unique_ptr< QgsAnnotationLayer > newLayer( main->clone() ); | |||
newLayer->setName( parameterAsString( parameters, QStringLiteral( "LAYER_NAME" ), context ) ); | |||
main->clear(); | |||
|
|||
QVariantMap outputs; | |||
outputs.insert( QStringLiteral( "OUTPUT" ), newLayer->id() ); | |||
|
|||
context.project()->addMapLayer( newLayer.release() ); | |||
|
|||
return outputs; | |||
} | |||
|
|||
///@endcond |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
/*************************************************************************** | |||
qgsalgorithmannotations.h | |||
------------------------------ | |||
begin : September 2021 | |||
copyright : (C) 2021 by Nyall Dawson | |||
email : nyall dot dawson at gmail dot com | |||
***************************************************************************/ | |||
|
|||
/*************************************************************************** | |||
* * | |||
* 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 QGSALGORITHMANNOTATIONS_H | |||
#define QGSALGORITHMANNOTATIONS_H | |||
|
|||
#define SIP_NO_FILE | |||
|
|||
#include "qgis_sip.h" | |||
#include "qgsprocessingalgorithm.h" | |||
|
|||
///@cond PRIVATE | |||
|
|||
/** | |||
* Native transfer annotations from main annotation layer algorithm | |||
*/ | |||
class QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm : public QgsProcessingAlgorithm | |||
{ | |||
|
|||
public: | |||
|
|||
QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm() = default; | |||
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override; | |||
QString name() const override; | |||
QString displayName() const override; | |||
QStringList tags() const override; | |||
QString group() const override; | |||
QString groupId() const override; | |||
Flags flags() const override; | |||
QString shortHelpString() const override; | |||
QgsTransferAnnotationsFromMainAnnotationLayerAlgorithm *createInstance() const override SIP_FACTORY; | |||
|
|||
protected: | |||
|
|||
QVariantMap processAlgorithm( const QVariantMap ¶meters, | |||
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override; | |||
}; | |||
|
|||
///@endcond PRIVATE | |||
|
|||
#endif // QGSALGORITHMANNOTATIONS_H |
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