Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing][needs-docs] replace set raster style and set vector style
Python algorithms with generics set layer style C++ algorithm
- Loading branch information
Showing
6 changed files
with
149 additions
and
2 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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*************************************************************************** | ||
qgsalgorithmapplylayerstyle.cpp | ||
--------------------- | ||
begin : December 2019 | ||
copyright : (C) 2017 by Alexander Bruy | ||
email : alexander dot bruy 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 "qgsalgorithmapplylayerstyle.h" | ||
|
||
///@cond PRIVATE | ||
|
||
QString QgsApplyLayerStyleAlgorithm::name() const | ||
{ | ||
return QStringLiteral( "setlayerstyle" ); | ||
} | ||
|
||
QString QgsApplyLayerStyleAlgorithm::displayName() const | ||
{ | ||
return QObject::tr( "Set layer style" ); | ||
} | ||
|
||
QStringList QgsApplyLayerStyleAlgorithm::tags() const | ||
{ | ||
return QObject::tr( "change,layer,style,qml" ).split( ',' ); | ||
} | ||
|
||
QString QgsApplyLayerStyleAlgorithm::group() const | ||
{ | ||
return QObject::tr( "Cartography" ); | ||
} | ||
|
||
QString QgsApplyLayerStyleAlgorithm::groupId() const | ||
{ | ||
return QStringLiteral( "cartography" ); | ||
} | ||
|
||
QString QgsApplyLayerStyleAlgorithm::shortHelpString() const | ||
{ | ||
return QObject::tr( "This algorithm renames a layer." ); | ||
} | ||
|
||
QgsProcessingAlgorithm::Flags QgsApplyLayerStyleAlgorithm::flags() const | ||
{ | ||
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagNoThreading; | ||
} | ||
|
||
QgsApplyLayerStyleAlgorithm *QgsApplyLayerStyleAlgorithm::createInstance() const | ||
{ | ||
return new QgsApplyLayerStyleAlgorithm(); | ||
} | ||
|
||
void QgsApplyLayerStyleAlgorithm::initAlgorithm( const QVariantMap & ) | ||
{ | ||
addParameter( new QgsProcessingParameterMapLayer( QStringLiteral( "INPUT" ), QObject::tr( "Layer" ) ) ); | ||
addParameter( new QgsProcessingParameterFile( QStringLiteral( "STYLE" ), QObject::tr( "Style file" ), QgsProcessingParameterFile::File, QStringLiteral( "qml" ) ) ); | ||
addOutput( new QgsProcessingOutputMapLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Styled" ) ) ); | ||
} | ||
|
||
QVariantMap QgsApplyLayerStyleAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback * ) | ||
{ | ||
QgsMapLayer *layer = parameterAsLayer( parameters, QStringLiteral( "INPUT" ), context ); | ||
QString style = parameterAsFile( parameters, QStringLiteral( "STYLE" ), context ); | ||
|
||
if ( !layer ) | ||
throw QgsProcessingException( QObject::tr( "Invalid input layer" ) ); | ||
|
||
bool ok = false; | ||
QString msg = layer->loadNamedStyle( style, ok ); | ||
if ( !ok ) | ||
{ | ||
throw QgsProcessingException( QObject::tr( "Failed to apply style. Error: %1" ).arg( msg ) ); | ||
} | ||
layer->triggerRepaint(); | ||
|
||
QVariantMap results; | ||
results.insert( QStringLiteral( "OUTPUT" ), layer->id() ); | ||
return results; | ||
} | ||
|
||
///@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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*************************************************************************** | ||
qgsalgorithmapplylayerstyle.h | ||
--------------------- | ||
begin : December 2019 | ||
copyright : (C) 2019 by Alexander Bruy | ||
email : alexander dot bruy 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 QGSALGORITHMAPPLYLAYERSTYLE_H | ||
#define QGSALGORITHMAPPLYLAYERSTYLE_H | ||
|
||
#define SIP_NO_FILE | ||
|
||
#include "qgis_sip.h" | ||
#include "qgsprocessingalgorithm.h" | ||
|
||
///@cond PRIVATE | ||
|
||
/** | ||
* Native apply layer style algorithm. | ||
*/ | ||
class QgsApplyLayerStyleAlgorithm : public QgsProcessingAlgorithm | ||
{ | ||
public: | ||
QgsApplyLayerStyleAlgorithm() = default; | ||
Flags flags() const override; | ||
QString name() const override; | ||
QString displayName() const override; | ||
QStringList tags() const override; | ||
QString group() const override; | ||
QString groupId() const override; | ||
QString shortHelpString() const override; | ||
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override; | ||
QgsApplyLayerStyleAlgorithm *createInstance() const override SIP_FACTORY; | ||
|
||
protected: | ||
|
||
QVariantMap processAlgorithm( const QVariantMap ¶meters, | ||
QgsProcessingContext &context, QgsProcessingFeedback * ) override; | ||
|
||
}; | ||
|
||
///@endcond PRIVATE | ||
|
||
#endif // QGSALGORITHMAPPLYLAYERSTYLE_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