26#include <QRegularExpression>
29using namespace Qt::StringLiterals;
33QString QgsSplitFeaturesByAttributeCharacterAlgorithm::name()
const
35 return u
"splitfeaturesbycharacter"_s;
38QString QgsSplitFeaturesByAttributeCharacterAlgorithm::displayName()
const
40 return QObject::tr(
"Split features by character" );
43QStringList QgsSplitFeaturesByAttributeCharacterAlgorithm::tags()
const
45 return QObject::tr(
"separate,attribute,value,string" ).split(
',' );
48QString QgsSplitFeaturesByAttributeCharacterAlgorithm::group()
const
50 return QObject::tr(
"Vector general" );
53QString QgsSplitFeaturesByAttributeCharacterAlgorithm::groupId()
const
55 return u
"vectorgeneral"_s;
58QString QgsSplitFeaturesByAttributeCharacterAlgorithm::shortHelpString()
const
60 return QObject::tr(
"This algorithm splits features into multiple output features by splitting a field's value with a specified character.\n\n"
61 "For instance, if a layer contains features with multiple comma separated values contained in a single field, this "
62 "algorithm can be used to split these values up across multiple output features.\n\n"
63 "Geometries and other attributes remain unchanged in the output.\n\n"
64 "Optionally, the separator string can be a regular expression for added flexibility." );
67QString QgsSplitFeaturesByAttributeCharacterAlgorithm::shortDescription()
const
69 return QObject::tr(
"Splits features into multiple output features by splitting a field by a character." );
77QList<int> QgsSplitFeaturesByAttributeCharacterAlgorithm::inputLayerTypes()
const
82void QgsSplitFeaturesByAttributeCharacterAlgorithm::initParameters(
const QVariantMap & )
84 addParameter(
new QgsProcessingParameterField( u
"FIELD"_s, QObject::tr(
"Split using values in field" ), QVariant(), u
"INPUT"_s ) );
86 std::unique_ptr<QgsProcessingParameterDefinition> regexParam = std::make_unique<QgsProcessingParameterBoolean>( u
"REGEX"_s, QObject::tr(
"Use regular expression separator" ) );
88 addParameter( regexParam.release() );
96QgsSplitFeaturesByAttributeCharacterAlgorithm *QgsSplitFeaturesByAttributeCharacterAlgorithm::createInstance()
const
98 return new QgsSplitFeaturesByAttributeCharacterAlgorithm();
101QgsFields QgsSplitFeaturesByAttributeCharacterAlgorithm::outputFields(
const QgsFields &inputFields )
const
103 mFieldIndex = inputFields.
lookupField( mFieldName );
105 for (
int i = 0; i < inputFields.
count(); ++i )
107 if ( i != mFieldIndex )
109 outputFields.
append( inputFields.
at( i ) );
120QString QgsSplitFeaturesByAttributeCharacterAlgorithm::outputName()
const
122 return QObject::tr(
"Split" );
127 mChar = parameterAsString( parameters, u
"CHAR"_s, context );
128 mFieldName = parameterAsString( parameters, u
"FIELD"_s, context );
129 mUseRegex = parameterAsBoolean( parameters, u
"REGEX"_s, context );
131 mRegex = QRegularExpression( mChar );
138 const QString val = f.
attribute( mFieldIndex ).toString();
139 const QStringList parts = mUseRegex ? val.split( mRegex ) : val.split( mChar );
140 res.reserve( parts.size() );
141 for (
const QString &p : parts )
ProcessingSourceType
Processing data source types.
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
QFlags< SinkFlag > SinkFlags
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
A vector layer or feature source field parameter for processing algorithms.
A string parameter for processing algorithms.
QList< QgsFeature > QgsFeatureList