QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsprojectstylealgorithms.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprojectstylealgorithms.h
3  ---------------------
4  begin : July 2019
5  copyright : (C) 2019 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 QGSPROJECTSTYLESALGORITHMS_H
19 #define QGSPROJECTSTYLESALGORITHMS_H
20 
21 #define SIP_NO_FILE
22 
23 #include "qgis_sip.h"
24 #include "qgis_analysis.h"
25 #include "qgsprocessingalgorithm.h"
26 #include "qgsstyle.h"
27 #include "qgsstyleentityvisitor.h"
28 
30 
37 class ANALYSIS_EXPORT QgsSaveToStyleVisitor : public QgsStyleEntityVisitorInterface
38 {
39  public:
40 
48  QgsSaveToStyleVisitor( QgsStyle *style, const QList< QgsStyle::StyleEntity > &objects = QList< QgsStyle::StyleEntity >() );
49 
50  bool visit( const QgsStyleEntityVisitorInterface::StyleLeaf &entity ) override;
51  bool visitEnter( const QgsStyleEntityVisitorInterface::Node &node ) override;
52  bool visitExit( const QgsStyleEntityVisitorInterface::Node &node ) override;
53 
54  private:
55 
56  QgsStyle *mStyle = nullptr;
57  QList< QgsStyle::StyleEntity > mObjects;
58  QStringList mParentNames;
59 
60 };
61 
65 class QgsStyleFromProjectAlgorithm : public QgsProcessingAlgorithm
66 {
67 
68  public:
69 
70  QgsStyleFromProjectAlgorithm();
71  ~QgsStyleFromProjectAlgorithm() override;
72  void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
73  QString name() const override;
74  QString displayName() const override;
75  QStringList tags() const override;
76  QString group() const override;
77  QString groupId() const override;
78  QString shortHelpString() const override;
79  QString shortDescription() const override;
80  QgsStyleFromProjectAlgorithm *createInstance() const override SIP_FACTORY;
81 
82  protected:
83 
84  bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
85  QVariantMap processAlgorithm( const QVariantMap &parameters,
86  QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
87 
88  private:
89 
90  QString mProjectPath;
91  QList< QgsStyle::StyleEntity > mObjects;
92  std::unique_ptr< QgsStyle > mStyle;
93 };
94 
96 
97 #endif // QGSPROJECTSTYLESALGORITHMS_H
98 
99 
QgsProcessingAlgorithm::shortDescription
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
Definition: qgsprocessingalgorithm.cpp:58
QgsProcessingAlgorithm::displayName
virtual QString displayName() const =0
Returns the translated algorithm name, which should be used for any user-visible display of the algor...
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition: qgsprocessingfeedback.h:38
QgsProcessingAlgorithm::groupId
virtual QString groupId() const
Returns the unique ID of the group this algorithm belongs to.
Definition: qgsprocessingalgorithm.h:233
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
QgsProcessingAlgorithm::createInstance
virtual QgsProcessingAlgorithm * createInstance() const =0
Creates a new instance of the algorithm class.
QgsStyleEntityVisitorInterface::visitExit
virtual bool visitExit(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor stops visiting a node.
Definition: qgsstyleentityvisitor.h:183
QgsStyleEntityVisitorInterface::StyleLeaf
Contains information relating to the style entity currently being visited.
Definition: qgsstyleentityvisitor.h:61
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsProcessingAlgorithm::name
virtual QString name() const =0
Returns the algorithm name, used for identifying the algorithm.
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:44
qgsprocessingalgorithm.h
qgis_sip.h
QgsProcessingAlgorithm::shortHelpString
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
Definition: qgsprocessingalgorithm.cpp:63
QgsStyleEntityVisitorInterface::Node
Contains information relating to a node (i.e.
Definition: qgsstyleentityvisitor.h:111
qgsstyle.h
QgsStyleEntityVisitorInterface::visitEnter
virtual bool visitEnter(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor starts visiting a node.
Definition: qgsstyleentityvisitor.h:169
QgsProcessingAlgorithm
Abstract base class for processing algorithms.
Definition: qgsprocessingalgorithm.h:52
QgsStyle
Definition: qgsstyle.h:160
QgsStyleEntityVisitorInterface::visit
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
Definition: qgsstyleentityvisitor.h:153
QgsProcessingAlgorithm::group
virtual QString group() const
Returns the name of the group this algorithm belongs to.
Definition: qgsprocessingalgorithm.h:224
QgsProcessingAlgorithm::tags
virtual QStringList tags() const
Returns a list of tags which relate to the algorithm, and are used to assist users in searching for s...
Definition: qgsprocessingalgorithm.h:180
qgsstyleentityvisitor.h
QgsProcessingAlgorithm::initAlgorithm
virtual void initAlgorithm(const QVariantMap &configuration=QVariantMap())=0
Initializes the algorithm using the specified configuration.