22 QgsProcessingAlgorithm::Flags QgsDropTableFieldsAlgorithm::flags()
const
27 QString QgsDropTableFieldsAlgorithm::name()
const
29 return QStringLiteral(
"deletecolumn" );
32 QString QgsDropTableFieldsAlgorithm::displayName()
const
34 return QObject::tr(
"Drop field(s)" );
37 QString 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." );
42 QString QgsDropTableFieldsAlgorithm::shortDescription()
const
44 return QObject::tr(
"Deletes fields from a vector layer." );
47 QStringList QgsDropTableFieldsAlgorithm::tags()
const
49 return QObject::tr(
"drop,delete,remove,fields,columns,attributes" ).split(
',' );
52 QString QgsDropTableFieldsAlgorithm::group()
const
54 return QObject::tr(
"Vector table" );
57 QString QgsDropTableFieldsAlgorithm::groupId()
const
59 return QStringLiteral(
"vectortable" );
62 QString QgsDropTableFieldsAlgorithm::outputName()
const
64 return QObject::tr(
"Remaining fields" );
67 QList<int> QgsDropTableFieldsAlgorithm::inputLayerTypes()
const
77 QgsDropTableFieldsAlgorithm *QgsDropTableFieldsAlgorithm::createInstance()
const
79 return new QgsDropTableFieldsAlgorithm();
82 void QgsDropTableFieldsAlgorithm::initParameters(
const QVariantMap & )
87 QgsFields 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 = parameterAsFields( 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 );
144 bool QgsDropTableFieldsAlgorithm::supportInPlaceEdit(
const QgsMapLayer *layer )
const
156 QgsProcessingAlgorithm::Flags QgsRetainTableFieldsAlgorithm::flags()
const
161 QString QgsRetainTableFieldsAlgorithm::name()
const
163 return QStringLiteral(
"retainfields" );
166 QString QgsRetainTableFieldsAlgorithm::displayName()
const
168 return QObject::tr(
"Retain fields" );
171 QString 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." );
176 QString QgsRetainTableFieldsAlgorithm::shortDescription()
const
178 return QObject::tr(
"Retains selected fields from a vector layer." );
181 QStringList QgsRetainTableFieldsAlgorithm::tags()
const
183 return QObject::tr(
"drop,delete,remove,retain,keep,other,fields,columns,attributes" ).split(
',' );
186 QString QgsRetainTableFieldsAlgorithm::group()
const
188 return QObject::tr(
"Vector table" );
191 QString QgsRetainTableFieldsAlgorithm::groupId()
const
193 return QStringLiteral(
"vectortable" );
196 QString QgsRetainTableFieldsAlgorithm::outputName()
const
198 return QObject::tr(
"Retained fields" );
201 QList<int> QgsRetainTableFieldsAlgorithm::inputLayerTypes()
const
211 QgsRetainTableFieldsAlgorithm *QgsRetainTableFieldsAlgorithm::createInstance()
const
213 return new QgsRetainTableFieldsAlgorithm();
216 void QgsRetainTableFieldsAlgorithm::initParameters(
const QVariantMap & )
221 QgsFields QgsRetainTableFieldsAlgorithm::outputFields(
const QgsFields &inputFields )
const
224 for (
const QString &
field : mFieldsToRetain )
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 = parameterAsFields( 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 ) );
279 bool 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