QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
QgsFields Class Reference

Container of fields for a vector layer. More...

#include <qgsfield.h>

Classes

struct  Field

Public Types

typedef struct QgsFields::Field Field
enum  FieldOrigin {
  OriginUnknown, OriginProvider, OriginJoin, OriginEdit,
  OriginExpression
}

Public Member Functions

QgsAttributeList allAttributesList () const
 Utility function to get list of attribute indexes.
bool append (const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
 Append a field. The field must have unique name, otherwise it is rejected (returns false)
bool appendExpressionField (const QgsField &field, int originIndex)
 Append an expression field. The field must have unique name, otherwise it is rejected (returns false)
const QgsFieldat (int i) const
 Get field at particular index (must be in range 0..N-1)
void clear ()
 Remove all fields.
int count () const
 Return number of items.
bool exists (int i) const
 Return if a field index is valid.
void extend (const QgsFields &other)
 Extend with fields from another QgsFields container.
const QgsFieldfield (int fieldIdx) const
 Get field at particular index (must be in range 0..N-1)
const QgsFieldfield (const QString &name) const
 Get field at particular index (must be in range 0..N-1)
int fieldNameIndex (const QString &fieldName) const
 Look up field's index from name - case insensitive TODO: sort out case sensitive (indexFromName()) vs insensitive (fieldNameIndex()) calls.
FieldOrigin fieldOrigin (int fieldIdx) const
 Get field's origin (value from an enumeration)
int fieldOriginIndex (int fieldIdx) const
 Get field's origin index (its meaning is specific to each type of origin)
int indexFromName (const QString &name) const
 Look up field's index from name. Returns -1 on error.
bool isEmpty () const
 Check whether the container is empty.
bool operator!= (const QgsFields &other) const
bool operator== (const QgsFields &other) const
const QgsFieldoperator[] (int i) const
 Get field at particular index (must be in range 0..N-1)
QgsFieldoperator[] (int i)
 Get field at particular index (must be in range 0..N-1)
void remove (int fieldIdx)
 Remove a field with the given index.
int size () const
 Return number of items.
QList< QgsFieldtoList () const
 Utility function to return a list of QgsField instances.

Protected Attributes

QVector< FieldmFields
 internal storage of the container
QHash< QString, int > mNameToIndex
 map for quick resolution of name to index

Detailed Description

Container of fields for a vector layer.

In addition to storing a list of QgsField instances, it also:

Definition at line 172 of file qgsfield.h.

Member Typedef Documentation

Member Enumeration Documentation

Enumerator:
OriginUnknown 

it has not been specified where the field comes from

OriginProvider 

field comes from the underlying data provider of the vector layer (originIndex = index in provider's fields)

OriginJoin 

field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index within the join)

OriginEdit 

field has been temporarily added in editing mode (originIndex = index in the list of added attributes)

OriginExpression 

field is calculated from an expression

Definition at line 176 of file qgsfield.h.

Member Function Documentation

QgsAttributeList QgsFields::allAttributesList ( ) const

Utility function to get list of attribute indexes.

Note
added in 2.4

Definition at line 246 of file qgsfield.cpp.

bool QgsFields::append ( const QgsField field,
FieldOrigin  origin = OriginProvider,
int  originIndex = -1 
)

Append a field. The field must have unique name, otherwise it is rejected (returns false)

Definition at line 177 of file qgsfield.cpp.

bool QgsFields::appendExpressionField ( const QgsField field,
int  originIndex 
)

Append an expression field. The field must have unique name, otherwise it is rejected (returns false)

Definition at line 190 of file qgsfield.cpp.

const QgsField& QgsFields::at ( int  i) const
inline

Get field at particular index (must be in range 0..N-1)

Definition at line 227 of file qgsfield.h.

void QgsFields::clear ( )

Remove all fields.

Definition at line 171 of file qgsfield.cpp.

int QgsFields::count ( ) const
inline

Return number of items.

Definition at line 214 of file qgsfield.h.

bool QgsFields::exists ( int  i) const
inline

Return if a field index is valid.

Parameters
iIndex of the field which needs to be checked
Returns
True if the field exists

Definition at line 220 of file qgsfield.h.

void QgsFields::extend ( const QgsFields other)

Extend with fields from another QgsFields container.

Definition at line 210 of file qgsfield.cpp.

const QgsField& QgsFields::field ( int  fieldIdx) const
inline

Get field at particular index (must be in range 0..N-1)

Definition at line 229 of file qgsfield.h.

const QgsField& QgsFields::field ( const QString &  name) const
inline

Get field at particular index (must be in range 0..N-1)

Definition at line 231 of file qgsfield.h.

int QgsFields::fieldNameIndex ( const QString &  fieldName) const

Look up field's index from name - case insensitive TODO: sort out case sensitive (indexFromName()) vs insensitive (fieldNameIndex()) calls.

Note
added in 2.4

Definition at line 234 of file qgsfield.cpp.

QgsFields::FieldOrigin QgsFields::fieldOrigin ( int  fieldIdx) const

Get field's origin (value from an enumeration)

Definition at line 218 of file qgsfield.cpp.

int QgsFields::fieldOriginIndex ( int  fieldIdx) const
inline

Get field's origin index (its meaning is specific to each type of origin)

Definition at line 236 of file qgsfield.h.

int QgsFields::indexFromName ( const QString &  name) const
inline

Look up field's index from name. Returns -1 on error.

Definition at line 239 of file qgsfield.h.

bool QgsFields::isEmpty ( ) const
inline

Check whether the container is empty.

Definition at line 212 of file qgsfield.h.

bool QgsFields::operator!= ( const QgsFields other) const
inline
Note
added in 2.6

Definition at line 256 of file qgsfield.h.

bool QgsFields::operator== ( const QgsFields other) const
inline
Note
added in 2.6

Definition at line 254 of file qgsfield.h.

const QgsField& QgsFields::operator[] ( int  i) const
inline

Get field at particular index (must be in range 0..N-1)

Definition at line 223 of file qgsfield.h.

QgsField& QgsFields::operator[] ( int  i)
inline

Get field at particular index (must be in range 0..N-1)

Definition at line 225 of file qgsfield.h.

void QgsFields::remove ( int  fieldIdx)

Remove a field with the given index.

Definition at line 201 of file qgsfield.cpp.

int QgsFields::size ( ) const
inline

Return number of items.

Definition at line 216 of file qgsfield.h.

QList< QgsField > QgsFields::toList ( ) const

Utility function to return a list of QgsField instances.

Definition at line 226 of file qgsfield.cpp.

Member Data Documentation

QVector<Field> QgsFields::mFields
protected

internal storage of the container

Definition at line 260 of file qgsfield.h.

QHash<QString, int> QgsFields::mNameToIndex
protected

map for quick resolution of name to index

Definition at line 263 of file qgsfield.h.


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