QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Private Attributes | 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...
 

Private Attributes

QString mName
 Name. More...
 
QVariant::Type mType
 Variant type. More...
 
QString mTypeName
 Type name from provider. More...
 
int mLength
 Length. More...
 
int mPrecision
 Precision. More...
 
QString mComment
 Comment. 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.

Definition at line 33 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 35 of file qgsfield.cpp.

QgsField::~QgsField ( )

Destructor.

Definition at line 42 of file qgsfield.cpp.

Member Function Documentation

const QString & QgsField::comment ( ) const

Returns the field comment.

Definition at line 83 of file qgsfield.cpp.

References mComment.

Referenced by QgsOfflineEditing::committedAttributesAdded(), QgsVectorLayer::metadata(), setComment(), and QgsExpressionFieldBuffer::writeXml().

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

Formats string for display.

Definition at line 117 of file qgsfield.cpp.

References mPrecision, and mType.

Referenced by QgsEditorWidgetFactory::representValue().

int QgsField::length ( ) const
const QString & QgsField::name ( ) const
bool QgsField::operator!= ( const QgsField other) const

Definition at line 52 of file qgsfield.cpp.

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

Definition at line 46 of file qgsfield.cpp.

References mLength, mName, mPrecision, and mType.

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

References mPrecision.

Referenced by QgsVectorLayerEditBuffer::commitChanges(), QgsOfflineEditing::committedAttributesAdded(), QgsVectorLayer::metadata(), QgsFieldValidator::QgsFieldValidator(), QgsVectorFileWriter::QgsVectorFileWriter(), QgsVectorDataProvider::supportedType(), and QgsExpressionFieldBuffer::writeXml().

void QgsField::setComment ( const QString &  comment)

Set the field comment.

Definition at line 112 of file qgsfield.cpp.

References comment(), and mComment.

void QgsField::setLength ( int  len)

Set the field length.

Parameters
lenLength of the field

Definition at line 103 of file qgsfield.cpp.

References mLength.

void QgsField::setName ( const QString &  nam)

Set the field name.

Parameters
namName of the field

Definition at line 88 of file qgsfield.cpp.

References mName.

Referenced by QgsVectorLayerJoinBuffer::updateFields().

void QgsField::setPrecision ( int  prec)

Set the field precision.

Parameters
precPrecision of the field

Definition at line 107 of file qgsfield.cpp.

References mPrecision.

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

Set variant type.

Definition at line 93 of file qgsfield.cpp.

References mType, and type().

Referenced by QgsGmlSchema::addAttribute().

void QgsField::setTypeName ( const QString &  typ)

Set the field type.

Parameters
typField type

Definition at line 98 of file qgsfield.cpp.

References mTypeName, and typeName().

Referenced by QgsOfflineEditing::applyAttributesAdded().

QVariant::Type QgsField::type ( ) const
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 68 of file qgsfield.cpp.

References mTypeName.

Referenced by QgsVectorLayerEditBuffer::commitChanges(), QgsVectorLayer::metadata(), setTypeName(), and QgsExpressionFieldBuffer::writeXml().

Member Data Documentation

QString QgsField::mComment
private

Comment.

Definition at line 150 of file qgsfield.h.

Referenced by comment(), and setComment().

int QgsField::mLength
private

Length.

Definition at line 144 of file qgsfield.h.

Referenced by length(), operator==(), and setLength().

QString QgsField::mName
private

Name.

Definition at line 135 of file qgsfield.h.

Referenced by name(), operator==(), and setName().

int QgsField::mPrecision
private

Precision.

Definition at line 147 of file qgsfield.h.

Referenced by displayString(), operator==(), precision(), and setPrecision().

QVariant::Type QgsField::mType
private

Variant type.

Definition at line 138 of file qgsfield.h.

Referenced by displayString(), operator==(), setType(), and type().

QString QgsField::mTypeName
private

Type name from provider.

Definition at line 141 of file qgsfield.h.

Referenced by setTypeName(), and typeName().


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