QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 (const QgsField &other)
 Copy constructor. More...
 
virtual ~QgsField ()
 Destructor. More...
 
const QStringcomment () const
 Returns the field comment. More...
 
bool convertCompatible (QVariant &v) const
 Converts the provided variant to a compatible format. More...
 
QString displayString (const QVariant &v) const
 Formats string for display. More...
 
int length () const
 Gets the length of the field. More...
 
const QStringname () const
 Gets the name of the field. 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 setComment (const QString &comment)
 Set the field comment. 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 setType (QVariant::Type type)
 Set variant type. More...
 
void setTypeName (const QString &typeName)
 Set the field type. More...
 
QVariant::Type type () const
 Gets variant type of the field as it will be retrieved from data source. More...
 
const QStringtypeName () const
 Gets the field type. 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.

Note
QgsField objects are implicitly shared.

Definition at line 38 of file qgsfield.h.

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

Definition at line 37 of file qgsfield.cpp.

QgsField::QgsField ( const QgsField other)

Copy constructor.

Definition at line 42 of file qgsfield.cpp.

QgsField::~QgsField ( )
virtual

Destructor.

Definition at line 55 of file qgsfield.cpp.

Member Function Documentation

const QString & QgsField::comment ( ) const

Returns the field comment.

Definition at line 94 of file qgsfield.cpp.

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 142 of file qgsfield.cpp.

QString QgsField::displayString ( const QVariant v) const

Formats string for display.

Definition at line 128 of file qgsfield.cpp.

int QgsField::length ( ) const

Gets the length of the field.

Returns
int containing the length of the field

Definition at line 84 of file qgsfield.cpp.

const QString & QgsField::name ( ) const

Gets the name of the field.

Definition at line 69 of file qgsfield.cpp.

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

Definition at line 64 of file qgsfield.cpp.

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

Assignment operator.

Definition at line 48 of file qgsfield.cpp.

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

Definition at line 59 of file qgsfield.cpp.

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.

Definition at line 89 of file qgsfield.cpp.

void QgsField::setComment ( const QString comment)

Set the field comment.

Definition at line 123 of file qgsfield.cpp.

void QgsField::setLength ( int  len)

Set the field length.

Parameters
lenLength of the field

Definition at line 114 of file qgsfield.cpp.

void QgsField::setName ( const QString name)

Set the field name.

Parameters
nameName of the field

Definition at line 99 of file qgsfield.cpp.

void QgsField::setPrecision ( int  precision)

Set the field precision.

Parameters
precisionPrecision of the field

Definition at line 118 of file qgsfield.cpp.

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

Set variant type.

Definition at line 104 of file qgsfield.cpp.

void QgsField::setTypeName ( const QString typeName)

Set the field type.

Parameters
typeNameField type

Definition at line 109 of file qgsfield.cpp.

QVariant::Type QgsField::type ( ) const

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

Definition at line 74 of file qgsfield.cpp.

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

Definition at line 79 of file qgsfield.cpp.


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