QGIS API Documentation 3.41.0-Master (af5edcb665c)
|
Encapsulate a field in an attribute table or data source. More...
#include <qgsfield.h>
Public Member Functions | |
QgsField (const QgsField &other) | |
Q_DECL_DEPRECATED | QgsField (const QString &name, QVariant::Type type, const QString &typeName=QString(), int len=0, int prec=0, const QString &comment=QString(), QVariant::Type subType=QVariant::Invalid) |
Constructor. | |
QgsField (const QString &name=QString(), QMetaType::Type type=QMetaType::Type::UnknownType, const QString &typeName=QString(), int len=0, int prec=0, const QString &comment=QString(), QMetaType::Type subType=QMetaType::Type::UnknownType) | |
Constructor. | |
virtual | ~QgsField () |
QString | alias () const |
Returns the alias for the field (the friendly displayed name of the field ), or an empty string if there is no alias. | |
QString | comment () const |
Returns the field comment. | |
Qgis::FieldConfigurationFlags | configurationFlags () const |
Returns the Flags for the field (searchable, …). | |
const QgsFieldConstraints & | constraints () const |
Returns constraints which are present for the field. | |
bool | convertCompatible (QVariant &v, QString *errorMessage=nullptr) const |
Converts the provided variant to a compatible format. | |
QgsDefaultValue | defaultValueDefinition () const |
Returns the expression used when calculating the default value for the field. | |
QString | displayName () const |
Returns the name to use when displaying this field. | |
QString | displayNameWithAlias () const |
Returns the name to use when displaying this field and adds the alias in parenthesis if it is defined. | |
QString | displayString (const QVariant &v) const |
Formats string for display. | |
QString | displayType (bool showConstraints=false) const |
Returns the type to use when displaying this field, including the length and precision of the datatype if applicable. | |
Qgis::FieldDuplicatePolicy | duplicatePolicy () const |
Returns the field's duplicate policy, which indicates how field values should be handled during a duplicate operation. | |
QgsEditorWidgetSetup | editorWidgetSetup () const |
Gets the editor widget setup for the field. | |
QString | friendlyTypeString () const |
Returns a user friendly, translated representation of the field type. | |
bool | isDateOrTime () const |
Returns if this field is a date and/or time type. | |
bool | isNumeric () const |
Returns if this field is numeric. | |
bool | isReadOnly () const |
Returns true if this field is a read-only field. | |
int | length () const |
Gets the length of the field. | |
QMap< int, QVariant > | metadata () const |
Returns the map of field metadata. | |
QVariant | metadata (int property) const |
Returns a specific metadata property. | |
QVariant | metadata (Qgis::FieldMetadataProperty property) const |
Returns a specific metadata property. | |
QString | name () const |
Returns the name of the field. | |
operator QVariant () const | |
Allows direct construction of QVariants from fields. | |
bool | operator!= (const QgsField &other) const |
QgsField & | operator= (const QgsField &other) |
bool | operator== (const QgsField &other) const |
int | precision () const |
Gets the precision of the field. | |
void | setAlias (const QString &alias) |
Sets the alias for the field (the friendly displayed name of the field ). | |
void | setComment (const QString &comment) |
Set the field comment. | |
void | setConfigurationFlags (Qgis::FieldConfigurationFlags flags) |
Sets the Flags for the field (searchable, …). | |
void | setConstraints (const QgsFieldConstraints &constraints) |
Sets constraints which are present for the field. | |
void | setDefaultValueDefinition (const QgsDefaultValue &defaultValueDefinition) |
Sets an expression to use when calculating the default value for the field. | |
void | setDuplicatePolicy (Qgis::FieldDuplicatePolicy policy) |
Sets the field's duplicate policy, which indicates how field values should be handled during a duplicate operation. | |
void | setEditorWidgetSetup (const QgsEditorWidgetSetup &v) |
Set the editor widget setup for the field. | |
void | setLength (int len) |
Set the field length. | |
void | setMetadata (const QMap< int, QVariant > metadata) |
Sets the map of field metadata. | |
void | setMetadata (int property, const QVariant &value) |
Sets a metadata property to value. | |
void | setMetadata (Qgis::FieldMetadataProperty property, const QVariant &value) |
Sets a metadata property to value. | |
void | setName (const QString &name) |
Set the field name. | |
void | setPrecision (int precision) |
Set the field precision. | |
void | setReadOnly (bool readOnly) |
Make field read-only if readOnly is set to true. | |
void | setSplitPolicy (Qgis::FieldDomainSplitPolicy policy) |
Sets the field's split policy, which indicates how field values should be handled during a split operation. | |
void | setSubType (QMetaType::Type subType) |
If the field is a collection, set its element's type. | |
Q_DECL_DEPRECATED void | setSubType (QVariant::Type subType) |
If the field is a collection, set its element's type. | |
void | setType (QMetaType::Type type) |
Set variant type. | |
Q_DECL_DEPRECATED void | setType (QVariant::Type type) |
Set variant type. | |
void | setTypeName (const QString &typeName) |
Set the field type. | |
Qgis::FieldDomainSplitPolicy | splitPolicy () const |
Returns the field's split policy, which indicates how field values should be handled during a split operation. | |
QMetaType::Type | subType () const |
If the field is a collection, gets its element's type. | |
QMetaType::Type | type () const |
Gets variant type of the field as it will be retrieved from data source. | |
QString | typeName () const |
Gets the field type. | |
Static Public Member Functions | |
static QString | readableConfigurationFlag (Qgis::FieldConfigurationFlag flag) |
Returns the readable and translated value of the configuration flag. | |
Static Public Attributes | |
static constexpr int | MAX_WKT_LENGTH = 999 |
Properties | |
QString | alias |
QString | comment |
Qgis::FieldConfigurationFlags | configurationFlags |
QgsFieldConstraints | constraints |
QgsDefaultValue | defaultValueDefinition |
bool | isDateOrTime |
bool | isNumeric |
bool | isReadOnly |
int | length |
QString | name |
int | precision |
QMetaType::Type | type |
Encapsulate a field in an attribute table or data source.
QgsField stores metadata about an attribute field, including name, type length, and if applicable, precision.
Definition at line 52 of file qgsfield.h.
QgsField::QgsField | ( | const QString & | name = QString() , |
QMetaType::Type | type = QMetaType::Type::UnknownType , |
||
const QString & | typeName = QString() , |
||
int | len = 0 , |
||
int | prec = 0 , |
||
const QString & | comment = QString() , |
||
QMetaType::Type | subType = QMetaType::Type::UnknownType |
||
) |
Constructor.
Constructs a new QgsField object.
name | Field name |
type | Field variant type, currently supported: String / Int / Double |
typeName | Field type (e.g., char, varchar, text, int, serial, double). Field types are usually unique to the source and are stored exactly as returned from the data store. |
len | Field length |
prec | Field precision. Usually decimal places but may also be used in conjunction with other fields types (e.g., variable character fields) |
comment | Comment for the field |
subType | If the field is a collection, its element's type. When all the elements don't need to have the same type, leave this to QVariant::Invalid. |
Definition at line 48 of file qgsfield.cpp.
QgsField::QgsField | ( | const QString & | name, |
QVariant::Type | type, | ||
const QString & | typeName = QString() , |
||
int | len = 0 , |
||
int | prec = 0 , |
||
const QString & | comment = QString() , |
||
QVariant::Type | subType = QVariant::Invalid |
||
) |
Constructor.
Constructs a new QgsField object.
name | Field name |
type | Field variant type, currently supported: String / Int / Double |
typeName | Field type (e.g., char, varchar, text, int, serial, double). Field types are usually unique to the source and are stored exactly as returned from the data store. |
len | Field length |
prec | Field precision. Usually decimal places but may also be used in conjunction with other fields types (e.g., variable character fields) |
comment | Comment for the field |
subType | If the field is a collection, its element's type. When all the elements don't need to have the same type, leave this to QVariant::Invalid. |
Definition at line 54 of file qgsfield.cpp.
QgsField::QgsField | ( | const QgsField & | other | ) |
Definition at line 60 of file qgsfield.cpp.
|
virtualdefault |
QString QgsField::alias | ( | ) | const |
Returns the alias for the field (the friendly displayed name of the field ), or an empty string if there is no alias.
Definition at line 291 of file qgsfield.cpp.
QString QgsField::comment | ( | ) | const |
Returns the field comment.
Definition at line 176 of file qgsfield.cpp.
Qgis::FieldConfigurationFlags QgsField::configurationFlags | ( | ) | const |
Returns the Flags for the field (searchable, …).
Definition at line 301 of file qgsfield.cpp.
const QgsFieldConstraints & QgsField::constraints | ( | ) | const |
Returns constraints which are present for the field.
Definition at line 286 of file qgsfield.cpp.
bool QgsField::convertCompatible | ( | QVariant & | v, |
QString * | errorMessage = nullptr |
||
) | const |
Converts the provided variant to a compatible format.
v | The value to convert |
errorMessage | if specified, will be set to a descriptive error when a conversion failure occurs |
true
if the conversion was successful Definition at line 473 of file qgsfield.cpp.
QgsDefaultValue QgsField::defaultValueDefinition | ( | ) | const |
Returns the expression used when calculating the default value for the field.
Definition at line 271 of file qgsfield.cpp.
QString QgsField::displayName | ( | ) | const |
Returns the name to use when displaying this field.
This will be the field alias if set, otherwise the field name.
Definition at line 95 of file qgsfield.cpp.
QString QgsField::displayNameWithAlias | ( | ) | const |
Returns the name to use when displaying this field and adds the alias in parenthesis if it is defined.
This will be used when working close to the data structure (i.e. building expressions and queries), when the real field name must be shown but the alias is also useful to understand what the field represents.
Definition at line 103 of file qgsfield.cpp.
QString QgsField::displayString | ( | const QVariant & | v | ) | const |
Formats string for display.
Definition at line 317 of file qgsfield.cpp.
QString QgsField::displayType | ( | bool | showConstraints = false | ) | const |
Returns the type to use when displaying this field, including the length and precision of the datatype if applicable.
This will be used when the full datatype with details has to displayed to the user.
Definition at line 112 of file qgsfield.cpp.
Qgis::FieldDuplicatePolicy QgsField::duplicatePolicy | ( | ) | const |
Returns the field's duplicate policy, which indicates how field values should be handled during a duplicate operation.
Definition at line 765 of file qgsfield.cpp.
QgsEditorWidgetSetup QgsField::editorWidgetSetup | ( | ) | const |
Gets the editor widget setup for the field.
Defaults may be set by the provider and can be overridden by manual field configuration.
Definition at line 740 of file qgsfield.cpp.
QString QgsField::friendlyTypeString | ( | ) | const |
Returns a user friendly, translated representation of the field type.
Unlike displayType(), this method only returns strings representing the field type and does not include length, precision or constraint information.
Definition at line 139 of file qgsfield.cpp.
bool QgsField::isDateOrTime | ( | ) | const |
Returns if this field is a date and/or time type.
Definition at line 216 of file qgsfield.cpp.
bool QgsField::isNumeric | ( | ) | const |
Returns if this field is numeric.
Any integer or floating point type will return true
for this.
Definition at line 211 of file qgsfield.cpp.
bool QgsField::isReadOnly | ( | ) | const |
Returns true
if this field is a read-only field.
This is the case for providers which support generated fields for instance.
Definition at line 750 of file qgsfield.cpp.
int QgsField::length | ( | ) | const |
Gets the length of the field.
Definition at line 166 of file qgsfield.cpp.
QMap< int, QVariant > QgsField::metadata | ( | ) | const |
Returns the map of field metadata.
Map keys should match values from the Qgis::FieldMetadataProperty enum.
Definition at line 186 of file qgsfield.cpp.
QVariant QgsField::metadata | ( | int | property | ) | const |
Returns a specific metadata property.
Definition at line 181 of file qgsfield.cpp.
QVariant QgsField::metadata | ( | Qgis::FieldMetadataProperty | property | ) | const |
Returns a specific metadata property.
Definition at line 191 of file qgsfield.cpp.
QString QgsField::name | ( | ) | const |
Returns the name of the field.
Definition at line 90 of file qgsfield.cpp.
QgsField::operator QVariant | ( | ) | const |
Allows direct construction of QVariants from fields.
Definition at line 730 of file qgsfield.cpp.
bool QgsField::operator!= | ( | const QgsField & | other | ) | const |
Definition at line 85 of file qgsfield.cpp.
Definition at line 74 of file qgsfield.cpp.
bool QgsField::operator== | ( | const QgsField & | other | ) | const |
Definition at line 80 of file qgsfield.cpp.
int QgsField::precision | ( | ) | const |
Gets the precision of the field.
Not all field types have a related precision.
Definition at line 171 of file qgsfield.cpp.
|
static |
Returns the readable and translated value of the configuration flag.
Definition at line 451 of file qgsfield.cpp.
void QgsField::setAlias | ( | const QString & | alias | ) |
Sets the alias for the field (the friendly displayed name of the field ).
alias | field alias, or empty string to remove an existing alias |
Definition at line 296 of file qgsfield.cpp.
void QgsField::setComment | ( | const QString & | comment | ) |
Set the field comment.
Definition at line 266 of file qgsfield.cpp.
void QgsField::setConfigurationFlags | ( | Qgis::FieldConfigurationFlags | flags | ) |
Sets the Flags for the field (searchable, …).
Definition at line 306 of file qgsfield.cpp.
void QgsField::setConstraints | ( | const QgsFieldConstraints & | constraints | ) |
Sets constraints which are present for the field.
Definition at line 281 of file qgsfield.cpp.
void QgsField::setDefaultValueDefinition | ( | const QgsDefaultValue & | defaultValueDefinition | ) |
Sets an expression to use when calculating the default value for the field.
defaultValueDefinition | expression to evaluate when calculating default values for field. Pass a default constructed QgsDefaultValue to reset. |
Definition at line 276 of file qgsfield.cpp.
void QgsField::setDuplicatePolicy | ( | Qgis::FieldDuplicatePolicy | policy | ) |
Sets the field's duplicate policy, which indicates how field values should be handled during a duplicate operation.
Definition at line 770 of file qgsfield.cpp.
void QgsField::setEditorWidgetSetup | ( | const QgsEditorWidgetSetup & | v | ) |
Set the editor widget setup for the field.
v | The value to set |
Definition at line 735 of file qgsfield.cpp.
void QgsField::setLength | ( | int | len | ) |
Set the field length.
len | Length of the field |
Definition at line 257 of file qgsfield.cpp.
void QgsField::setMetadata | ( | const QMap< int, QVariant > | metadata | ) |
Sets the map of field metadata.
Map keys should match values from the Qgis::FieldMetadataProperty enum.
Definition at line 196 of file qgsfield.cpp.
void QgsField::setMetadata | ( | int | property, |
const QVariant & | value | ||
) |
Sets a metadata property to value.
Definition at line 206 of file qgsfield.cpp.
void QgsField::setMetadata | ( | Qgis::FieldMetadataProperty | property, |
const QVariant & | value | ||
) |
Sets a metadata property to value.
Definition at line 201 of file qgsfield.cpp.
void QgsField::setName | ( | const QString & | name | ) |
void QgsField::setPrecision | ( | int | precision | ) |
Set the field precision.
precision | Precision of the field |
Definition at line 261 of file qgsfield.cpp.
void QgsField::setReadOnly | ( | bool | readOnly | ) |
Make field read-only if readOnly is set to true.
This is the case for providers which support generated fields for instance.
Definition at line 745 of file qgsfield.cpp.
void QgsField::setSplitPolicy | ( | Qgis::FieldDomainSplitPolicy | policy | ) |
Sets the field's split policy, which indicates how field values should be handled during a split operation.
Definition at line 760 of file qgsfield.cpp.
void QgsField::setSubType | ( | QMetaType::Type | subType | ) |
If the field is a collection, set its element's type.
When all the elements don't need to have the same type, set this to QVariant::Invalid.
Definition at line 242 of file qgsfield.cpp.
void QgsField::setSubType | ( | QVariant::Type | subType | ) |
If the field is a collection, set its element's type.
When all the elements don't need to have the same type, set this to QVariant::Invalid.
Definition at line 247 of file qgsfield.cpp.
void QgsField::setType | ( | QMetaType::Type | type | ) |
Set variant type.
Definition at line 232 of file qgsfield.cpp.
void QgsField::setType | ( | QVariant::Type | type | ) |
Set variant type.
Definition at line 237 of file qgsfield.cpp.
void QgsField::setTypeName | ( | const QString & | typeName | ) |
Qgis::FieldDomainSplitPolicy QgsField::splitPolicy | ( | ) | const |
Returns the field's split policy, which indicates how field values should be handled during a split operation.
Definition at line 755 of file qgsfield.cpp.
QMetaType::Type QgsField::subType | ( | ) | const |
If the field is a collection, gets its element's type.
When all the elements don't need to have the same type, this returns QVariant::Invalid.
Definition at line 156 of file qgsfield.cpp.
QMetaType::Type QgsField::type | ( | ) | const |
Gets variant type of the field as it will be retrieved from data source.
Definition at line 151 of file qgsfield.cpp.
QString QgsField::typeName | ( | ) | const |
Gets the field type.
Field types vary depending on the data source. Examples are char, int, double, blob, geometry, etc. The type is stored exactly as the data store reports it, with no attempt to standardize the value.
Definition at line 161 of file qgsfield.cpp.
|
staticconstexpr |
Definition at line 557 of file qgsfield.h.
|
readwrite |
Definition at line 63 of file qgsfield.h.
|
readwrite |
Definition at line 61 of file qgsfield.h.
|
readwrite |
Definition at line 66 of file qgsfield.h.
|
readwrite |
Definition at line 65 of file qgsfield.h.
|
readwrite |
Definition at line 64 of file qgsfield.h.
|
read |
Definition at line 57 of file qgsfield.h.
|
read |
Definition at line 56 of file qgsfield.h.
|
readwrite |
Definition at line 67 of file qgsfield.h.
|
readwrite |
Definition at line 58 of file qgsfield.h.
|
readwrite |
Definition at line 62 of file qgsfield.h.
|
readwrite |
Definition at line 59 of file qgsfield.h.
|
readwrite |
Definition at line 60 of file qgsfield.h.