QGIS API Documentation  3.17.0-Master (a035f434f4)
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 
Base class for providing feedback from a processing algorithm.
An interface for classes which can visit style entity (e.g.
Abstract base class for processing algorithms.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
virtual bool visitExit(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor stops visiting a node.
Contains information relating to a node (i.e.
#define SIP_FACTORY
Definition: qgis_sip.h:76
virtual bool visitEnter(const QgsStyleEntityVisitorInterface::Node &node)
Called when the visitor starts visiting a node.
Contains information about the context in which a processing algorithm is executed.
Contains information relating to the style entity currently being visited.