QGIS API Documentation 4.3.0-Master (3b7b3208a79)
Loading...
Searching...
No Matches
qgsprocessingpostprocessor.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingpostprocessor.h
3 ------------------------
4 begin : October 2026
5 copyright : (C) 2026 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
18#ifndef QGSPROCESSINGPOSTPROCESSOR_H
19#define QGSPROCESSINGPOSTPROCESSOR_H
20
21#include "qgis.h"
22#include "qgis_core.h"
24
25class QgsMapLayer;
28
39{
40 public:
42
44
51 virtual void postProcessLayer( QgsMapLayer *layer, const QString &outputName, const QgsProcessingAlgorithm *algorithm );
52};
53
54
65{
66 public:
68
70
76 class CORE_EXPORT ResultLayerDetails
77 {
78 public:
87
91 QgsMapLayer *layer = nullptr;
92
97
101 int sortKey = 0;
102
107 };
108
112 static QString determineOutputName(
113 const QString &destinationId, const QgsProcessingContext::LayerDetails &details, const QgsProcessingAlgorithm *algorithm, QgsProcessingContext &context, const QVariantMap &parameters
114 );
115
121
125 static void configureResultLayerTreeLayer( QgsLayerTreeLayer *layerTreeLayer );
126
132 static QgsMapLayer *addResultLayers( const QVector< QgsProcessingResultsHandler::ResultLayerDetails > &layers, const QgsProcessingContext &context, QgsLayerTreeNode *currentSelectedNode );
133
139 bool handleAlgorithmResults( const QgsProcessingAlgorithm *algorithm, QgsProcessingContext &context, const QVariantMap &parameters, QgsProcessingFeedback *feedback = nullptr );
140
141 protected:
142#ifndef SIP_RUN
147 {
149 bool succeeded = false;
151 QList<QgsProcessingResultsHandler::ResultLayerDetails> addedLayers;
152 };
153
158 const QgsProcessingAlgorithm *algorithm, QgsProcessingContext &context, const QVariantMap &parameters, QgsProcessingFeedback *feedback
159 );
160
165
169 virtual void setNewActiveLayer( QgsMapLayer *layer );
170#endif
171};
172
173
174#endif // QGSPROCESSINGPOSTPROCESSOR_H
Layer tree group node serves as a container for layers and further groups.
Layer tree node points to a map layer.
Base class for nodes in a layer tree.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Abstract base class for processing algorithms.
Details for layers to load into projects.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
virtual void postProcessLayer(QgsMapLayer *layer, const QString &outputName, const QgsProcessingAlgorithm *algorithm)
Post-processes a layer, e.g.
int sortKey
Sort order key for ordering output layers in the layer tree.
QgsLayerTreeGroup * targetLayerTreeGroup
Optional target layer tree group, where the layer should be placed.
ResultLayerDetails(QgsMapLayer *layer)
Constructor for ResultLayerDetails.
QgsProject * destinationProject
Destination QGIS project.
static void configureResultLayerTreeLayer(QgsLayerTreeLayer *layerTreeLayer)
Applies post-processing steps to the QgsLayerTreeLayer created for an algorithm's output.
static QgsMapLayer * addResultLayers(const QVector< QgsProcessingResultsHandler::ResultLayerDetails > &layers, const QgsProcessingContext &context, QgsLayerTreeNode *currentSelectedNode)
Responsible for adding layers created by an algorithm to a project and the project's layer tree in th...
static QgsLayerTreeGroup * layerTreeResultsGroup(const QgsProcessingContext::LayerDetails &layerDetails, const QgsProcessingContext &context)
Returns the destination layer tree group to store results in, or nullptr if there is no specific dest...
virtual QgsMapLayer * handleAddResultLayers(const QgsProcessingResultsHandler::ResultDetails &details, const QgsProcessingContext &context)
Calls addResultLayers(), allowing for extra logic to be injected in subclasses.
virtual void setNewActiveLayer(QgsMapLayer *layer)
Handles setting the new project active layer after processing the results.
static QString determineOutputName(const QString &destinationId, const QgsProcessingContext::LayerDetails &details, const QgsProcessingAlgorithm *algorithm, QgsProcessingContext &context, const QVariantMap &parameters)
Determines the desired layer name for a map layer output.
bool handleAlgorithmResults(const QgsProcessingAlgorithm *algorithm, QgsProcessingContext &context, const QVariantMap &parameters, QgsProcessingFeedback *feedback=nullptr)
Handles the results from running an algorithm.
virtual QgsProcessingResultsHandler::ResultDetails handleAlgorithmResultsProtected(const QgsProcessingAlgorithm *algorithm, QgsProcessingContext &context, const QVariantMap &parameters, QgsProcessingFeedback *feedback)
Handles the results from running an algorithm.
virtual ~QgsProcessingResultsHandler()
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:114
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
#define SIP_TRANSFER
Definition qgis_sip.h:35
Stores results of running the handleAlgorithmResultsProtected method.
bool succeeded
true if all layers could be successfully loaded
QList< QgsProcessingResultsHandler::ResultLayerDetails > addedLayers
Details of newly added layers.