QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | 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 (QString name=QString(), QVariant::Type type=QVariant::Invalid, QString typeName=QString(), int len=0, int prec=0, QString comment=QString())
 Constructor. More...
 
 ~QgsField ()
 Destructor. More...
 
bool operator== (const QgsField &other) const
 
bool operator!= (const QgsField &other) const
 
const QString & name () const
 Gets the name of the field. More...
 
QVariant::Type type () const
 Gets variant type of the field as it will be retrieved from data source. More...
 
const QString & typeName () const
 Gets the field type. More...
 
int length () const
 Gets the length of the field. More...
 
int precision () const
 Gets the precision of the field. More...
 
const QString & comment () const
 Returns the field comment. More...
 
void setName (const QString &nam)
 Set the field name. More...
 
void setType (QVariant::Type type)
 Set variant type. More...
 
void setTypeName (const QString &typ)
 Set the field type. More...
 
void setLength (int len)
 Set the field length. More...
 
void setPrecision (int prec)
 Set the field precision. More...
 
void setComment (const QString &comment)
 Set the field comment. More...
 
QString displayString (const QVariant &v) const
 Formats string for display. More...
 
bool convertCompatible (QVariant &v) const
 Converts the provided variant to a compatible format. More...
 

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.

Constructor & Destructor Documentation

QgsField::QgsField ( QString  name = QString(),
QVariant::Type  type = QVariant::Invalid,
QString  typeName = QString(),
int  len = 0,
int  prec = 0,
QString  comment = QString() 
)

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
QgsField::~QgsField ( )

Destructor.

Member Function Documentation

const QString & QgsField::comment ( ) const

Returns the field comment.

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
QString QgsField::displayString ( const QVariant &  v) const

Formats string for display.

int QgsField::length ( ) const

Gets the length of the field.

Returns
int containing the length of the field
const QString & QgsField::name ( ) const

Gets the name of the field.

bool QgsField::operator!= ( const QgsField other) const
bool QgsField::operator== ( const QgsField other) const
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.
void QgsField::setComment ( const QString &  comment)

Set the field comment.

void QgsField::setLength ( int  len)

Set the field length.

Parameters
lenLength of the field
void QgsField::setName ( const QString &  nam)

Set the field name.

Parameters
namName of the field
void QgsField::setPrecision ( int  prec)

Set the field precision.

Parameters
precPrecision of the field
void QgsField::setType ( QVariant::Type  type)

Set variant type.

void QgsField::setTypeName ( const QString &  typ)

Set the field type.

Parameters
typField type
QVariant::Type QgsField::type ( ) const

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

const 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

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