Skip to content
Permalink
Browse files

new string concatenation algorithm in processing

  • Loading branch information
Gustry authored and nyalldawson committed Oct 24, 2017
1 parent 89a31e5 commit 386eef2e6c7faec47a9cb6656683407416c31848
@@ -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)
@@ -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
@@ -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
@@ -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
@@ -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"
@@ -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() );

0 comments on commit 386eef2

Please sign in to comment.
You can’t perform that action at this time.