23QString QgsAddTableFieldAlgorithm::name()
const
25 return QStringLiteral(
"addfieldtoattributestable" );
28QString QgsAddTableFieldAlgorithm::displayName()
const
30 return QObject::tr(
"Add field to attributes table" );
33QString QgsAddTableFieldAlgorithm::shortHelpString()
const
35 return QObject::tr(
"This algorithm adds a new attribute to a vector layer.\n\n"
36 "The name and characteristics of the attribute are defined as parameters. The new attribute "
37 "is not added to the input layer but a new layer is generated instead.\n\n" );
40QStringList QgsAddTableFieldAlgorithm::tags()
const
42 return QObject::tr(
"add,create,new,attribute,fields" ).split(
',' );
45QString QgsAddTableFieldAlgorithm::group()
const
47 return QObject::tr(
"Vector table" );
50QString QgsAddTableFieldAlgorithm::groupId()
const
52 return QStringLiteral(
"vectortable" );
55QString QgsAddTableFieldAlgorithm::outputName()
const
57 return QObject::tr(
"Added" );
60QList<int> QgsAddTableFieldAlgorithm::inputLayerTypes()
const
70QgsAddTableFieldAlgorithm *QgsAddTableFieldAlgorithm::createInstance()
const
72 return new QgsAddTableFieldAlgorithm();
75void QgsAddTableFieldAlgorithm::initParameters(
const QVariantMap & )
79 QStringList typeStrings;
81 typeStrings.reserve( 11 );
83 for (
const auto &type :
84 std::vector < std::pair< QVariant::Type, QVariant::Type > >
86 {QVariant::Int, QVariant::Invalid },
87 {QVariant::Double, QVariant::Invalid },
88 {QVariant::String, QVariant::Invalid },
89 {QVariant::Bool, QVariant::Invalid },
90 {QVariant::Date, QVariant::Invalid },
91 {QVariant::Time, QVariant::Invalid },
92 {QVariant::DateTime, QVariant::Invalid },
93 {QVariant::ByteArray, QVariant::Invalid },
94 {QVariant::StringList, QVariant::Invalid },
95 {QVariant::List, QVariant::Int },
96 {QVariant::List, QVariant::Double }
103 std::unique_ptr< QgsProcessingParameterEnum> fieldTypes = std::make_unique< QgsProcessingParameterEnum> ( QStringLiteral(
"FIELD_TYPE" ), QObject::tr(
"Field type" ),
104 typeStrings,
false, 0 );
105 fieldTypes->setMetadata(
108 QStringLiteral(
"widget_wrapper" ),
111 QStringLiteral(
"icons" ), icons
116 addParameter( fieldTypes.release() );
123QgsFields QgsAddTableFieldAlgorithm::outputFields(
const QgsFields &inputFields )
const
132 const QString name = parameterAsString( parameters, QStringLiteral(
"FIELD_NAME" ), context );
133 const int type = parameterAsInt( parameters, QStringLiteral(
"FIELD_TYPE" ), context );
134 const int length = parameterAsInt( parameters, QStringLiteral(
"FIELD_LENGTH" ), context );
135 const int precision = parameterAsInt( parameters, QStringLiteral(
"FIELD_PRECISION" ), context );
137 mField.setName( name );
138 mField.setLength( length );
144 mField.setType( QVariant::Int );
147 mField.setType( QVariant::Double );
150 mField.setType( QVariant::String );
153 mField.setType( QVariant::Bool );
156 mField.setType( QVariant::Date );
159 mField.setType( QVariant::Time );
162 mField.setType( QVariant::DateTime );
165 mField.setType( QVariant::ByteArray );
168 mField.setType( QVariant::StringList );
169 mField.setSubType( QVariant::String );
172 mField.setType( QVariant::List );
173 mField.setSubType( QVariant::Int );
176 mField.setType( QVariant::List );
177 mField.setSubType( QVariant::Double );
188 attributes.append( QVariant() );
193bool QgsAddTableFieldAlgorithm::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.
Encapsulate a field in an attribute table or data source.
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)
static QIcon iconForFieldType(QVariant::Type type, QVariant::Type subType=QVariant::Type::Invalid)
Returns an icon corresponding to a field type.
Base class for all map layer types.
Contains information about the context in which a processing algorithm is executed.
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.
A numeric parameter for processing algorithms.
A string parameter for processing algorithms.
@ TypeVector
Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink ha...
static QString typeToDisplayString(QVariant::Type type, QVariant::Type subType=QVariant::Type::Invalid)
Returns a user-friendly translated string representing a QVariant type.
QList< QgsFeature > QgsFeatureList