27QString QgsDropTableFieldsAlgorithm::name()
const
29 return QStringLiteral(
"deletecolumn" );
32QString QgsDropTableFieldsAlgorithm::displayName()
const
34 return QObject::tr(
"Drop field(s)" );
37QString QgsDropTableFieldsAlgorithm::shortHelpString()
const
39 return QObject::tr(
"This algorithm takes a vector layer and generates a new one that has the exact same content but without the selected columns." );
42QString QgsDropTableFieldsAlgorithm::shortDescription()
const
44 return QObject::tr(
"Deletes fields from a vector layer." );
47QStringList QgsDropTableFieldsAlgorithm::tags()
const
49 return QObject::tr(
"drop,delete,remove,fields,columns,attributes" ).split(
',' );
52QString QgsDropTableFieldsAlgorithm::group()
const
54 return QObject::tr(
"Vector table" );
57QString QgsDropTableFieldsAlgorithm::groupId()
const
59 return QStringLiteral(
"vectortable" );
62QString QgsDropTableFieldsAlgorithm::outputName()
const
64 return QObject::tr(
"Remaining fields" );
67QList<int> QgsDropTableFieldsAlgorithm::inputLayerTypes()
const
77QgsDropTableFieldsAlgorithm *QgsDropTableFieldsAlgorithm::createInstance()
const
79 return new QgsDropTableFieldsAlgorithm();
82void QgsDropTableFieldsAlgorithm::initParameters(
const QVariantMap & )
87QgsFields QgsDropTableFieldsAlgorithm::outputFields(
const QgsFields &inputFields )
const
91 for (
const QString &field : mFieldsToDelete )
95 mFieldIndices.append( index );
99 std::sort( mFieldIndices.begin(), mFieldIndices.end(), std::greater<int>() );
102 for (
const int index : std::as_const( mFieldIndices ) )
104 outFields.
remove( index );
111 mFieldsToDelete = parameterAsStrings( parameters, QStringLiteral(
"COLUMN" ), context );
115 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
118 for (
const QString &field : std::as_const( mFieldsToDelete ) )
120 const int index = source->fields().lookupField( field );
123 feedback->
pushInfo( QObject::tr(
"Field “%1” does not exist in input layer " ).arg( field ) );
136 for (
const int index : mFieldIndices )
138 attributes.remove( index );
144bool QgsDropTableFieldsAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const
160QString QgsRetainTableFieldsAlgorithm::name()
const
162 return QStringLiteral(
"retainfields" );
165QString QgsRetainTableFieldsAlgorithm::displayName()
const
167 return QObject::tr(
"Retain fields" );
170QString QgsRetainTableFieldsAlgorithm::shortHelpString()
const
172 return QObject::tr(
"This algorithm takes a vector layer and generates a new one that retains only the selected fields. All other fields will be dropped." );
175QString QgsRetainTableFieldsAlgorithm::shortDescription()
const
177 return QObject::tr(
"Retains selected fields from a vector layer." );
180QStringList QgsRetainTableFieldsAlgorithm::tags()
const
182 return QObject::tr(
"drop,delete,remove,retain,keep,other,fields,columns,attributes" ).split(
',' );
185QString QgsRetainTableFieldsAlgorithm::group()
const
187 return QObject::tr(
"Vector table" );
190QString QgsRetainTableFieldsAlgorithm::groupId()
const
192 return QStringLiteral(
"vectortable" );
195QString QgsRetainTableFieldsAlgorithm::outputName()
const
197 return QObject::tr(
"Retained fields" );
200QList<int> QgsRetainTableFieldsAlgorithm::inputLayerTypes()
const
210QgsRetainTableFieldsAlgorithm *QgsRetainTableFieldsAlgorithm::createInstance()
const
212 return new QgsRetainTableFieldsAlgorithm();
215void QgsRetainTableFieldsAlgorithm::initParameters(
const QVariantMap & )
220QgsFields QgsRetainTableFieldsAlgorithm::outputFields(
const QgsFields &inputFields )
const
223 for (
const QString &field : mFieldsToRetain )
225 const int index = inputFields.
lookupField( field );
227 mFieldIndices.append( index );
230 std::sort( mFieldIndices.begin(), mFieldIndices.end() );
234 for (
const int index : std::as_const( mFieldIndices ) )
236 outFields.
append( inputFields.
at( index ) );
243 mFieldsToRetain = parameterAsStrings( parameters, QStringLiteral(
"FIELDS" ), context );
247 std::unique_ptr<QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
250 for (
const QString &field : std::as_const( mFieldsToRetain ) )
252 const int index = source->fields().lookupField( field );
255 feedback->
pushInfo( QObject::tr(
"Field “%1” does not exist in input layer " ).arg( field ) );
269 outputAttributes.reserve( mFieldIndices.count() );
270 for (
const int index : mFieldIndices )
272 outputAttributes.append( inputAttributes.at( index ) );
278bool QgsRetainTableFieldsAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const
@ Vector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
QFlags< ProcessingAlgorithmFlag > ProcessingAlgorithmFlags
Flags indicating how and when an algorithm operates and should be exposed to users.
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
@ SupportsInPlaceEdits
Algorithm supports in-place editing.
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
void remove(int fieldIdx)
Removes the field with the given index.
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.
Base class for all map layer types.
Contains information about the context in which a processing algorithm is executed.
Qgis::ProcessingAlgorithmFlags flags() const override
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Base class for providing feedback from a processing algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
A vector layer or feature source field parameter for processing algorithms.
QList< QgsFeature > QgsFeatureList