22 QString QgsAddIncrementalFieldAlgorithm::name()
const 24 return QStringLiteral(
"addautoincrementalfield" );
27 QString QgsAddIncrementalFieldAlgorithm::displayName()
const 29 return QObject::tr(
"Add autoincremental field" );
32 QString QgsAddIncrementalFieldAlgorithm::shortHelpString()
const 34 return QObject::tr(
"This algorithm adds a new integer field to a vector layer, with a sequential value for each feature.\n\n" 35 "This field can be used as a unique ID for features in the layer. The new attribute " 36 "is not added to the input layer but a new layer is generated instead.\n\n" 37 "The initial starting value for the incremental series can be specified.\n\n" 38 "Optionally, grouping fields can be specified. If group fields are present, then the field value will " 39 "be reset for each combination of these group field values." );
42 QStringList QgsAddIncrementalFieldAlgorithm::tags()
const 44 return QObject::tr(
"add,create,serial,primary,key,unique,fields" ).split(
',' );
47 QString QgsAddIncrementalFieldAlgorithm::group()
const 49 return QObject::tr(
"Vector table" );
52 QString QgsAddIncrementalFieldAlgorithm::groupId()
const 54 return QStringLiteral(
"vectortable" );
57 QString QgsAddIncrementalFieldAlgorithm::outputName()
const 59 return QObject::tr(
"Incremented" );
62 QList<int> QgsAddIncrementalFieldAlgorithm::inputLayerTypes()
const 67 QgsAddIncrementalFieldAlgorithm *QgsAddIncrementalFieldAlgorithm::createInstance()
const 69 return new QgsAddIncrementalFieldAlgorithm();
77 void QgsAddIncrementalFieldAlgorithm::initParameters(
const QVariantMap & )
79 addParameter(
new QgsProcessingParameterString( QStringLiteral(
"FIELD_NAME" ), QObject::tr(
"Field name" ), QStringLiteral(
"AUTO" ) ) );
86 QgsFields QgsAddIncrementalFieldAlgorithm::outputFields(
const QgsFields &inputFields )
const 96 mStartValue = parameterAsInt( parameters, QStringLiteral(
"START" ), context );
98 mFieldName = parameterAsString( parameters, QStringLiteral(
"FIELD_NAME" ), context );
99 mGroupedFieldNames = parameterAsFields( parameters, QStringLiteral(
"GROUP_FIELDS" ), context );
105 if ( !mGroupedFieldNames.empty() && mGroupedFields.empty() )
107 for (
const QString &field : qgis::as_const( mGroupedFieldNames ) )
109 int idx = mFields.lookupField( field );
111 mGroupedFields << idx;
117 if ( mGroupedFields.empty() )
119 attributes.append( mValue );
125 for (
int index : qgis::as_const( mGroupedFields ) )
129 long long value = mGroupedValues.value( groupAttributes, mStartValue );
130 attributes.append( value );
132 mGroupedValues[ groupAttributes ] = value;
Base class for providing feedback from a processing algorithm.
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
A vector layer or feature source field parameter for processing algorithms.
QList< QgsFeature > QgsFeatureList
Container of fields for a vector layer.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Append a field. The field must have unique name, otherwise it is rejected (returns false) ...
Encapsulate a field in an attribute table or data source.
A numeric parameter for processing algorithms.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Contains information about the context in which a processing algorithm is executed.
A string parameter for processing algorithms.