QGIS API Documentation
3.4.15-Madeira (e83d02e274)
|
Encapsulate a field in an attribute table or data source. More...
#include <qgsfield.h>
Public Member Functions | |
QgsField (const QString &name=QString(), QVariant::Type type=QVariant::Invalid, const QString &typeName=QString(), int len=0, int prec=0, const QString &comment=QString(), QVariant::Type subType=QVariant::Invalid) | |
Constructor. More... | |
QgsField (const QgsField &other) | |
Copy constructor. More... | |
virtual | ~QgsField ()=default |
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. More... | |
QString | comment () const |
Returns the field comment. More... | |
const QgsFieldConstraints & | constraints () const |
Returns constraints which are present for the field. More... | |
bool | convertCompatible (QVariant &v) const |
Converts the provided variant to a compatible format. More... | |
QgsDefaultValue | defaultValueDefinition () const |
Returns the expression used when calculating the default value for the field. More... | |
QString | displayName () const |
Returns the name to use when displaying this field. More... | |
QString | displayString (const QVariant &v) const |
Formats string for display. More... | |
QgsEditorWidgetSetup | editorWidgetSetup () const |
Gets the editor widget setup for the field. More... | |
bool | isNumeric () const |
Returns if this field is numeric. More... | |
int | length () const |
Gets the length of the field. More... | |
QString | name () const |
Returns the name of the field. More... | |
operator QVariant () const | |
Allows direct construction of QVariants from fields. More... | |
bool | operator!= (const QgsField &other) const |
QgsField & | operator= (const QgsField &other) |
Assignment operator. More... | |
bool | operator== (const QgsField &other) const |
int | precision () const |
Gets the precision of the field. More... | |
void | setAlias (const QString &alias) |
Sets the alias for the field (the friendly displayed name of the field ). More... | |
void | setComment (const QString &comment) |
Set the field comment. More... | |
void | setConstraints (const QgsFieldConstraints &constraints) |
Sets constraints which are present for the field. More... | |
void | setDefaultValueDefinition (const QgsDefaultValue &defaultValueDefinition) |
Sets an expression to use when calculating the default value for the field. More... | |
void | setEditorWidgetSetup (const QgsEditorWidgetSetup &v) |
Set the editor widget setup for the field. More... | |
void | setLength (int len) |
Set the field length. More... | |
void | setName (const QString &name) |
Set the field name. More... | |
void | setPrecision (int precision) |
Set the field precision. More... | |
void | setSubType (QVariant::Type subType) |
If the field is a collection, set its element's type. More... | |
void | setType (QVariant::Type type) |
Set variant type. More... | |
void | setTypeName (const QString &typeName) |
Set the field type. More... | |
QVariant::Type | subType () const |
If the field is a collection, gets its element's type. More... | |
QVariant::Type | type () const |
Gets variant type of the field as it will be retrieved from data source. More... | |
QString | typeName () const |
Gets the field type. More... | |
Properties | |
QString | alias |
QString | comment |
QgsFieldConstraints | constraints |
QgsDefaultValue | defaultValueDefinition |
bool | isNumeric |
int | length |
QString | name |
int | precision |
QVariant::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 48 of file qgsfield.h.
QgsField::QgsField | ( | const QString & | name = QString() , |
QVariant::Type | type = QVariant::Invalid , |
||
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 47 of file qgsfield.cpp.
QgsField::QgsField | ( | const QgsField & | other | ) |
Copy constructor.
Definition at line 54 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.
QString QgsField::comment | ( | ) | const |
Returns the field comment.
const QgsFieldConstraints& QgsField::constraints | ( | ) | const |
bool QgsField::convertCompatible | ( | QVariant & | v | ) | const |
Converts the provided variant to a compatible format.
v | The value to convert |
Definition at line 272 of file qgsfield.cpp.
QgsDefaultValue QgsField::defaultValueDefinition | ( | ) | const |
Returns the expression used when calculating the default value for the field.
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 87 of file qgsfield.cpp.
QString QgsField::displayString | ( | const QVariant & | v | ) | const |
Formats string for display.
Definition at line 206 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 429 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.
int QgsField::length | ( | ) | const |
Gets the length of the field.
QString QgsField::name | ( | ) | const |
Returns the name of the field.
|
inline |
Allows direct construction of QVariants from fields.
Definition at line 316 of file qgsfield.h.
bool QgsField::operator!= | ( | const QgsField & | other | ) | const |
Definition at line 77 of file qgsfield.cpp.
Assignment operator.
Definition at line 66 of file qgsfield.cpp.
bool QgsField::operator== | ( | const QgsField & | other | ) | const |
Definition at line 72 of file qgsfield.cpp.
int QgsField::precision | ( | ) | const |
Gets the precision of the field.
Not all field types have a related precision.
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 195 of file qgsfield.cpp.
void QgsField::setComment | ( | const QString & | comment | ) |
Set the field comment.
Definition at line 165 of file qgsfield.cpp.
void QgsField::setConstraints | ( | const QgsFieldConstraints & | constraints | ) |
Sets constraints which are present for the field.
Definition at line 180 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 175 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 424 of file qgsfield.cpp.
void QgsField::setLength | ( | int | len | ) |
Set the field length.
len | Length of the field |
Definition at line 156 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 160 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 146 of file qgsfield.cpp.
void QgsField::setType | ( | QVariant::Type | type | ) |
Set variant type.
Definition at line 141 of file qgsfield.cpp.
void QgsField::setTypeName | ( | const QString & | typeName | ) |
QVariant::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 100 of file qgsfield.cpp.
QVariant::Type QgsField::type | ( | ) | const |
Gets variant type of the field as it will be retrieved from data source.
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 105 of file qgsfield.cpp.
|
readwrite |
Definition at line 58 of file qgsfield.h.
|
readwrite |
Definition at line 56 of file qgsfield.h.
|
readwrite |
Definition at line 60 of file qgsfield.h.
|
readwrite |
Definition at line 59 of file qgsfield.h.
|
read |
Definition at line 52 of file qgsfield.h.
|
readwrite |
Definition at line 53 of file qgsfield.h.
|
readwrite |
Definition at line 57 of file qgsfield.h.
|
readwrite |
Definition at line 54 of file qgsfield.h.
|
readwrite |
Definition at line 55 of file qgsfield.h.