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