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<QMetaType::Type, QMetaType::Type>> {
85 { QMetaType::Type::Int, QMetaType::Type::UnknownType },
86 { QMetaType::Type::Double, QMetaType::Type::UnknownType },
87 { QMetaType::Type::QString, QMetaType::Type::UnknownType },
88 { QMetaType::Type::Bool, QMetaType::Type::UnknownType },
89 { QMetaType::Type::QDate, QMetaType::Type::UnknownType },
90 { QMetaType::Type::QTime, QMetaType::Type::UnknownType },
91 { QMetaType::Type::QDateTime, QMetaType::Type::UnknownType },
92 { QMetaType::Type::QByteArray, QMetaType::Type::UnknownType },
93 { QMetaType::Type::QStringList, QMetaType::Type::UnknownType },
94 { QMetaType::Type::QVariantList, QMetaType::Type::Int },
95 { QMetaType::Type::QVariantList, QMetaType::Type::Double }
102 std::unique_ptr<QgsProcessingParameterEnum> fieldTypes = std::make_unique<QgsProcessingParameterEnum>( QStringLiteral(
"FIELD_TYPE" ), QObject::tr(
"Field type" ), typeStrings,
false, 0 );
103 fieldTypes->setMetadata(
104 { QVariantMap( { { QStringLiteral(
"widget_wrapper" ), QVariantMap( { { QStringLiteral(
"icons" ), icons } } ) } } )
107 addParameter( fieldTypes.release() );
111 addParameter(
new QgsProcessingParameterString( QStringLiteral(
"FIELD_ALIAS" ), QObject::tr(
"Field alias" ), QVariant(),
false,
true ) );
112 addParameter(
new QgsProcessingParameterString( QStringLiteral(
"FIELD_COMMENT" ), QObject::tr(
"Field comment" ), QVariant(),
false,
true ) );
115QgsFields QgsAddTableFieldAlgorithm::outputFields(
const QgsFields &inputFields )
const
124 const QString name = parameterAsString( parameters, QStringLiteral(
"FIELD_NAME" ), context );
125 const int type = parameterAsInt( parameters, QStringLiteral(
"FIELD_TYPE" ), context );
126 const int length = parameterAsInt( parameters, QStringLiteral(
"FIELD_LENGTH" ), context );
127 const int precision = parameterAsInt( parameters, QStringLiteral(
"FIELD_PRECISION" ), context );
128 const QString alias = parameterAsString( parameters, QStringLiteral(
"FIELD_ALIAS" ), context );
129 const QString comment = parameterAsString( parameters, QStringLiteral(
"FIELD_COMMENT" ), context );
131 mField.setName( name );
132 mField.setLength( length );
134 mField.setAlias( alias );
135 mField.setComment( comment );
140 mField.setType( QMetaType::Type::Int );
143 mField.setType( QMetaType::Type::Double );
146 mField.setType( QMetaType::Type::QString );
149 mField.setType( QMetaType::Type::Bool );
152 mField.setType( QMetaType::Type::QDate );
155 mField.setType( QMetaType::Type::QTime );
158 mField.setType( QMetaType::Type::QDateTime );
161 mField.setType( QMetaType::Type::QByteArray );
164 mField.setType( QMetaType::Type::QStringList );
165 mField.setSubType( QMetaType::Type::QString );
168 mField.setType( QMetaType::Type::QVariantList );
169 mField.setSubType( QMetaType::Type::Int );
172 mField.setType( QMetaType::Type::QVariantList );
173 mField.setSubType( QMetaType::Type::Double );
184 attributes.append( QVariant() );
189bool QgsAddTableFieldAlgorithm::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...
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
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.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
bool append(const QgsField &field, Qgis::FieldOrigin origin=Qgis::FieldOrigin::Provider, int originIndex=-1)
Appends a field.
static QIcon iconForFieldType(QMetaType::Type type, QMetaType::Type subType=QMetaType::Type::UnknownType, const QString &typeString=QString())
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.
Base class for providing feedback from a processing algorithm.
A numeric parameter for processing algorithms.
A string parameter for processing algorithms.
static QString typeToDisplayString(QMetaType::Type type, QMetaType::Type subType=QMetaType::Type::UnknownType)
Returns a user-friendly translated string representing a QVariant type.
QList< QgsFeature > QgsFeatureList