Skip to content

Commit

Permalink
new string concatenation algorithm in processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry authored and nyalldawson committed Oct 24, 2017
1 parent 89a31e5 commit 386eef2
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/plugins/processing/gui/wrappers.py
Expand Up @@ -1030,7 +1030,8 @@ def createWidget(self):
# strings, numbers, files and table fields are all allowed input types
strings = self.dialog.getAvailableValuesOfType(
[QgsProcessingParameterString, QgsProcessingParameterNumber, QgsProcessingParameterFile,
QgsProcessingParameterField, QgsProcessingParameterExpression], [QgsProcessingOutputString])
QgsProcessingParameterField, QgsProcessingParameterExpression],
[QgsProcessingOutputString, QgsProcessingOutputFile])
options = [(self.dialog.resolveValueDescription(s), s) for s in strings]
if self.param.multiLine():
widget = MultilineTextPanel(options)
Expand Down
1 change: 1 addition & 0 deletions src/analysis/CMakeLists.txt
Expand Up @@ -54,6 +54,7 @@ SET(QGIS_ANALYSIS_SRCS
processing/qgsalgorithmsimplify.cpp
processing/qgsalgorithmsmooth.cpp
processing/qgsalgorithmsplitwithlines.cpp
processing/qgsalgorithmstringconcatenation.cpp
processing/qgsalgorithmsubdivide.cpp
processing/qgsalgorithmtransect.cpp
processing/qgsalgorithmtransform.cpp
Expand Down
74 changes: 74 additions & 0 deletions src/analysis/processing/qgsalgorithmstringconcatenation.cpp
@@ -0,0 +1,74 @@
/***************************************************************************
qgsalgorithmstringconcatenation.cpp
---------------------
begin : October 2017
copyright : (C) 2017 by Etienne Trimaille
email : etienne at kartoza 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 "qgsalgorithmstringconcatenation.h"

///@cond PRIVATE

QString QgsStringConcatenationAlgorithm::name() const
{
return QStringLiteral( "stringconcatenation" );
}

QgsProcessingAlgorithm::Flags QgsStringConcatenationAlgorithm::flags() const
{
return FlagHideFromToolbox;
}

QString QgsStringConcatenationAlgorithm::displayName() const
{
return QObject::tr( "String concatenation" );
}

QStringList QgsStringConcatenationAlgorithm::tags() const
{
return QObject::tr( "string,concatenation,merge" ).split( ',' );
}

QString QgsStringConcatenationAlgorithm::group() const
{
return QObject::tr( "Modeler tool" );
}

QString QgsStringConcatenationAlgorithm::shortHelpString() const
{
return QObject::tr( "This algorithm concatenates two strings together." );
}

QgsStringConcatenationAlgorithm *QgsStringConcatenationAlgorithm::createInstance() const
{
return new QgsStringConcatenationAlgorithm();
}

void QgsStringConcatenationAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterString( QStringLiteral( "INPUT_1" ), QObject::tr( "Input 1" ), QVariant(), false, false ) );
addParameter( new QgsProcessingParameterString( QStringLiteral( "INPUT_2" ), QObject::tr( "Input 2" ), QVariant(), false, false ) );
addOutput( new QgsProcessingOutputString( QStringLiteral( "CONCATENATION" ), QObject::tr( "Concatenation" ) ) );
}

QVariantMap QgsStringConcatenationAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
QString input_1 = parameterAsString( parameters, QStringLiteral( "INPUT_1" ), context );
QString input_2 = parameterAsString( parameters, QStringLiteral( "INPUT_2" ), context );

QVariantMap outputs;
outputs.insert( QStringLiteral( "CONCATENATION" ), input_1 + input_2 );
return outputs;
}

///@endcond
53 changes: 53 additions & 0 deletions src/analysis/processing/qgsalgorithmstringconcatenation.h
@@ -0,0 +1,53 @@
/***************************************************************************
qgsalgorithmstringconcatenation.h
---------------------
begin : October 2017
copyright : (C) 2017 by Etienne Trimaille
email : etienne at kartoza 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 QGSALGORITHMSTRINGCONCATENATION_H
#define QGSALGORITHMSTRINGCONCATENATION_H

#define SIP_NO_FILE

#include "qgis.h"
#include "qgsprocessingalgorithm.h"

///@cond PRIVATE

/**
* Native string concatenation algorithm.
*/
class QgsStringConcatenationAlgorithm : public QgsProcessingAlgorithm
{
public:
QgsStringConcatenationAlgorithm() = default;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
Flags flags() const override;
QString name() const override;
QString displayName() const override;
virtual QStringList tags() const override;
QString group() const override;
QString shortHelpString() const override;
QgsStringConcatenationAlgorithm *createInstance() const override SIP_FACTORY;

protected:

virtual QVariantMap processAlgorithm( const QVariantMap &parameters,
QgsProcessingContext &context, QgsProcessingFeedback * ) override;

};

///@endcond PRIVATE

#endif // QGSALGORITHMSTRINGCONCATENATION_H
2 changes: 2 additions & 0 deletions src/analysis/processing/qgsnativealgorithms.cpp
Expand Up @@ -49,6 +49,7 @@
#include "qgsalgorithmsimplify.h"
#include "qgsalgorithmsmooth.h"
#include "qgsalgorithmsplitwithlines.h"
#include "qgsalgorithmstringconcatenation.h"
#include "qgsalgorithmsubdivide.h"
#include "qgsalgorithmtransect.h"
#include "qgsalgorithmtransform.h"
Expand Down Expand Up @@ -122,6 +123,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsSimplifyAlgorithm() );
addAlgorithm( new QgsSmoothAlgorithm() );
addAlgorithm( new QgsSplitWithLinesAlgorithm() );
addAlgorithm( new QgsStringConcatenationAlgorithm() );
addAlgorithm( new QgsSubdivideAlgorithm() );
addAlgorithm( new QgsTransectAlgorithm() );
addAlgorithm( new QgsTransformAlgorithm() );
Expand Down

0 comments on commit 386eef2

Please sign in to comment.