QGIS API Documentation  2.99.0-Master (e077efd)
Public Member Functions | Properties | List of all members
QgsField Class Reference

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 ()
 Destructor. More...
 
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 QgsFieldConstraintsconstraints () const
 Returns constraints which are present for the field. More...
 
bool convertCompatible (QVariant &v) const
 Converts the provided variant to a compatible format. More...
 
QString defaultValueExpression () 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...
 
const QgsEditorWidgetSetupeditorWidgetSetup () const
 Get 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
 
QgsFieldoperator= (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 setDefaultValueExpression (const QString &expression)
 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
 
QString defaultValueExpression
 
bool isNumeric
 
int length
 
QString name
 
int precision
 

Detailed Description

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.

Note
QgsField objects are implicitly shared.

Definition at line 47 of file qgsfield.h.

Constructor & Destructor Documentation

§ QgsField() [1/2]

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.

Parameters
nameField name
typeField variant type, currently supported: String / Int / Double
typeNameField type (eg. char, varchar, text, int, serial, double). Field types are usually unique to the source and are stored exactly as returned from the data store.
lenField length
precField precision. Usually decimal places but may also be used in conjunction with other fields types (eg. variable character fields)
commentComment for the field
subTypeIf 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 46 of file qgsfield.cpp.

§ QgsField() [2/2]

QgsField::QgsField ( const QgsField other)

Copy constructor.

Definition at line 53 of file qgsfield.cpp.

§ ~QgsField()

QgsField::~QgsField ( )
virtual

Destructor.

Definition at line 71 of file qgsfield.cpp.

Member Function Documentation

§ alias()

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.

See also
setAlias()
Note
added in QGIS 3.0

§ comment()

QString QgsField::comment ( ) const

Returns the field comment.

§ constraints()

const QgsFieldConstraints& QgsField::constraints ( ) const

Returns constraints which are present for the field.

Note
added in QGIS 3.0
See also
setConstraints()

§ convertCompatible()

bool QgsField::convertCompatible ( QVariant &  v) const

Converts the provided variant to a compatible format.

Parameters
vThe value to convert
Returns
True if the conversion was successful

Definition at line 229 of file qgsfield.cpp.

§ defaultValueExpression()

QString QgsField::defaultValueExpression ( ) const

Returns the expression used when calculating the default value for the field.

Returns
expression evaluated when calculating default values for field, or an empty string if no default is set
Note
added in QGIS 3.0
See also
setDefaultValueExpression()

§ displayName()

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.

See also
name()
alias()
Note
added in QGIS 3.0

Definition at line 90 of file qgsfield.cpp.

§ displayString()

QString QgsField::displayString ( const QVariant &  v) const

Formats string for display.

Definition at line 209 of file qgsfield.cpp.

§ editorWidgetSetup()

const QgsEditorWidgetSetup & QgsField::editorWidgetSetup ( ) const

Get the editor widget setup for the field.

Returns
the value

Definition at line 295 of file qgsfield.cpp.

§ isNumeric()

bool QgsField::isNumeric ( ) const

Returns if this field is numeric.

Any integer or floating point type will return true for this.

Note
added in QGIS 2.18

§ length()

int QgsField::length ( ) const

Gets the length of the field.

Returns
int containing the length of the field

§ name()

QString QgsField::name ( ) const

Returns the name of the field.

See also
setName()
displayName()

§ operator QVariant()

QgsField::operator QVariant ( ) const
inline

Allows direct construction of QVariants from fields.

Definition at line 255 of file qgsfield.h.

§ operator!=()

bool QgsField::operator!= ( const QgsField other) const

Definition at line 80 of file qgsfield.cpp.

§ operator=()

QgsField & QgsField::operator= ( const QgsField other)

Assignment operator.

Definition at line 65 of file qgsfield.cpp.

§ operator==()

bool QgsField::operator== ( const QgsField other) const

Definition at line 75 of file qgsfield.cpp.

§ precision()

int QgsField::precision ( ) const

Gets the precision of the field.

Not all field types have a related precision.

Returns
int containing the precision or zero if not applicable to the field type.

§ setAlias()

void QgsField::setAlias ( const QString &  alias)

Sets the alias for the field (the friendly displayed name of the field ).

Parameters
aliasfield alias, or empty string to remove an existing alias
See also
alias()
Note
added in QGIS 3.0

Definition at line 198 of file qgsfield.cpp.

§ setComment()

void QgsField::setComment ( const QString &  comment)

Set the field comment.

Definition at line 168 of file qgsfield.cpp.

§ setConstraints()

void QgsField::setConstraints ( const QgsFieldConstraints constraints)

Sets constraints which are present for the field.

Note
added in QGIS 3.0
See also
constraints()

Definition at line 183 of file qgsfield.cpp.

§ setDefaultValueExpression()

void QgsField::setDefaultValueExpression ( const QString &  expression)

Sets an expression to use when calculating the default value for the field.

Parameters
expressionexpression to evaluate when calculating default values for field. Pass an empty expression to clear the default.
Note
added in QGIS 3.0
See also
defaultValueExpression()

Definition at line 178 of file qgsfield.cpp.

§ setEditorWidgetSetup()

void QgsField::setEditorWidgetSetup ( const QgsEditorWidgetSetup v)

Set the editor widget setup for the field.

Parameters
vThe value to set

Definition at line 290 of file qgsfield.cpp.

§ setLength()

void QgsField::setLength ( int  len)

Set the field length.

Parameters
lenLength of the field

Definition at line 159 of file qgsfield.cpp.

§ setName()

void QgsField::setName ( const QString &  name)

Set the field name.

Parameters
nameName of the field

Definition at line 139 of file qgsfield.cpp.

§ setPrecision()

void QgsField::setPrecision ( int  precision)

Set the field precision.

Parameters
precisionPrecision of the field

Definition at line 163 of file qgsfield.cpp.

§ setSubType()

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.

Note
added in QGIS 3.0

Definition at line 149 of file qgsfield.cpp.

§ setType()

void QgsField::setType ( QVariant::Type  type)

Set variant type.

Definition at line 144 of file qgsfield.cpp.

§ setTypeName()

void QgsField::setTypeName ( const QString &  typeName)

Set the field type.

Parameters
typeNameField type

Definition at line 154 of file qgsfield.cpp.

§ subType()

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.

Note
added in QGIS 3.0

Definition at line 103 of file qgsfield.cpp.

§ type()

QVariant::Type QgsField::type ( ) const

Gets variant type of the field as it will be retrieved from data source.

Definition at line 98 of file qgsfield.cpp.

§ typeName()

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.

Returns
QString containing the field type

Definition at line 108 of file qgsfield.cpp.

Property Documentation

§ alias

QString QgsField::alias
readwrite

Definition at line 56 of file qgsfield.h.

§ comment

QString QgsField::comment
readwrite

Definition at line 54 of file qgsfield.h.

§ constraints

const QgsFieldConstraints & QgsField::constraints
readwrite

Definition at line 58 of file qgsfield.h.

§ defaultValueExpression

QString QgsField::defaultValueExpression
readwrite

Definition at line 57 of file qgsfield.h.

§ isNumeric

bool QgsField::isNumeric
read

Definition at line 51 of file qgsfield.h.

§ length

int QgsField::length
readwrite

Definition at line 52 of file qgsfield.h.

§ name

QString QgsField::name
readwrite

Definition at line 55 of file qgsfield.h.

§ precision

int QgsField::precision
readwrite

Definition at line 53 of file qgsfield.h.


The documentation for this class was generated from the following files: