22QgsProcessingAlgorithm::Flags QgsDropTableFieldsAlgorithm::flags()
const
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
156QgsProcessingAlgorithm::Flags QgsRetainTableFieldsAlgorithm::flags()
const
161QString QgsRetainTableFieldsAlgorithm::name()
const
163 return QStringLiteral(
"retainfields" );
166QString QgsRetainTableFieldsAlgorithm::displayName()
const
168 return QObject::tr(
"Retain fields" );
171QString QgsRetainTableFieldsAlgorithm::shortHelpString()
const
173 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." );
176QString QgsRetainTableFieldsAlgorithm::shortDescription()
const
178 return QObject::tr(
"Retains selected fields from a vector layer." );
181QStringList QgsRetainTableFieldsAlgorithm::tags()
const
183 return QObject::tr(
"drop,delete,remove,retain,keep,other,fields,columns,attributes" ).split(
',' );
186QString QgsRetainTableFieldsAlgorithm::group()
const
188 return QObject::tr(
"Vector table" );
191QString QgsRetainTableFieldsAlgorithm::groupId()
const
193 return QStringLiteral(
"vectortable" );
196QString QgsRetainTableFieldsAlgorithm::outputName()
const
198 return QObject::tr(
"Retained fields" );
201QList<int> QgsRetainTableFieldsAlgorithm::inputLayerTypes()
const
211QgsRetainTableFieldsAlgorithm *QgsRetainTableFieldsAlgorithm::createInstance()
const
213 return new QgsRetainTableFieldsAlgorithm();
216void QgsRetainTableFieldsAlgorithm::initParameters(
const QVariantMap & )
221QgsFields QgsRetainTableFieldsAlgorithm::outputFields(
const QgsFields &inputFields )
const
224 for (
const QString &field : mFieldsToRetain )
226 const int index = inputFields.
lookupField( field );
228 mFieldIndices.append( index );
231 std::sort( mFieldIndices.begin(), mFieldIndices.end() );
235 for (
const int index : std::as_const( mFieldIndices ) )
237 outFields.
append( inputFields.
at( index ) );
244 mFieldsToRetain = parameterAsStrings( parameters, QStringLiteral(
"FIELDS" ), context );
248 std::unique_ptr< QgsProcessingFeatureSource> source( parameterAsSource( parameters, QStringLiteral(
"INPUT" ), context ) );
251 for (
const QString &field : std::as_const( mFieldsToRetain ) )
253 const int index = source->fields().lookupField( field );
256 feedback->
pushInfo( QObject::tr(
"Field “%1” does not exist in input layer " ).arg( field ) );
270 outputAttributes.reserve( mFieldIndices.count() );
271 for (
const int index : mFieldIndices )
273 outputAttributes.append( inputAttributes.at( index ) );
279bool QgsRetainTableFieldsAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const
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, FieldOrigin origin=OriginProvider, int originIndex=-1)
Appends a field. The field must have unique name, otherwise it is rejected (returns false)
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).
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Base class for all map layer types.
Abstract base class for processing algorithms.
Contains information about the context in which a processing algorithm is executed.
QgsProcessingAlgorithm::Flags flags() const override
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
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.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
QList< QgsFeature > QgsFeatureList