2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
\class QgsField
|
|
|
|
\brief Class to 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class QgsField
|
|
|
|
{
|
|
|
|
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsfield.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** Constructor. Constructs a new QgsField object.
|
2012-09-24 02:28:15 +02:00
|
|
|
* @param name Field name
|
2007-03-24 22:40:10 +00:00
|
|
|
* @param type Field variant type, currently supported: String / Int / Double
|
2012-09-24 02:28:15 +02:00
|
|
|
* @param typeName Field type (eg. char, varchar, text, int, serial, double).
|
2007-01-09 02:39:15 +00:00
|
|
|
Field types are usually unique to the source and are stored exactly
|
|
|
|
as returned from the data store.
|
|
|
|
* @param len Field length
|
|
|
|
* @param prec Field precision. Usually decimal places but may also be
|
|
|
|
* used in conjunction with other fields types (eg. variable character fields)
|
2007-03-24 22:40:10 +00:00
|
|
|
* @param comment Comment for the field
|
2007-01-09 02:39:15 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
QgsField( QString name = QString(),
|
|
|
|
QVariant::Type type = QVariant::Invalid,
|
|
|
|
QString typeName = QString(),
|
|
|
|
int len = 0,
|
|
|
|
int prec = 0,
|
|
|
|
QString comment = QString() );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Destructor
|
|
|
|
~QgsField();
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
bool operator==( const QgsField& other ) const;
|
2012-12-17 21:22:42 +01:00
|
|
|
bool operator!=( const QgsField& other ) const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Gets the name of the field
|
|
|
|
const QString & name() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
//! Gets variant type of the field as it will be retrieved from data source
|
|
|
|
QVariant::Type type() const;
|
|
|
|
|
|
|
|
/**
|
2007-01-09 02:39:15 +00:00
|
|
|
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 attenpt to standardize the value.
|
|
|
|
@return QString containing the field type
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
const QString & typeName() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the length of the field.
|
|
|
|
@return int containing the length of the field
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
int length() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the precision of the field. Not all field types have a related precision.
|
|
|
|
@return int containing the precision or zero if not applicable to the field type.
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
int precision() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
/**
|
2007-03-24 22:40:10 +00:00
|
|
|
Returns the field comment
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
const QString & comment() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set the field name.
|
|
|
|
@param nam Name of the field
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setName( const QString & nam );
|
|
|
|
|
2007-03-24 22:40:10 +00:00
|
|
|
/**
|
|
|
|
Set variant type.
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setType( QVariant::Type type );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set the field type.
|
|
|
|
@param typ Field type
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setTypeName( const QString & typ );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set the field length.
|
|
|
|
@param len Length of the field
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setLength( int len );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set the field precision.
|
|
|
|
@param prec Precision of the field
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setPrecision( int prec );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2007-03-24 22:40:10 +00:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
/**
|
2007-03-24 22:40:10 +00:00
|
|
|
Set the field comment
|
2007-01-09 02:39:15 +00:00
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setComment( const QString & comment );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2013-06-23 16:00:16 +02:00
|
|
|
/**Formats string for display*/
|
|
|
|
QString displayString( const QVariant& v ) const;
|
2007-01-09 02:39:15 +00:00
|
|
|
}; // class QgsField
|
2012-12-17 21:22:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class QgsFields
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsfield.h>
|
|
|
|
%End
|
2013-06-23 16:00:16 +02:00
|
|
|
public:
|
2012-12-17 21:22:42 +01:00
|
|
|
|
2014-01-18 23:05:32 +01:00
|
|
|
enum FieldOrigin
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Remove all fields
|
2013-06-23 16:00:16 +02:00
|
|
|
void clear();
|
2014-01-18 23:05:32 +01:00
|
|
|
//! Append a field. The field must have unique name, otherwise it is rejected (returns false)
|
|
|
|
bool append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
|
|
|
|
//! Remove a field with the given index
|
2013-06-23 16:00:16 +02:00
|
|
|
void remove( int fieldIdx );
|
2014-01-18 23:05:32 +01:00
|
|
|
//! Extend with fields from another QgsFields container
|
|
|
|
void extend( const QgsFields& other );
|
2012-12-17 21:22:42 +01:00
|
|
|
|
2014-01-18 23:05:32 +01:00
|
|
|
//! Check whether the container is empty
|
2013-06-23 16:00:16 +02:00
|
|
|
bool isEmpty() const;
|
2014-01-18 23:05:32 +01:00
|
|
|
//! Return number of items
|
|
|
|
int count() const;
|
2013-06-23 16:00:16 +02:00
|
|
|
// __len__ annotation since sip 4.10.3
|
|
|
|
//int count() const /__len__/;
|
|
|
|
int __len__() const;
|
2013-04-20 11:19:10 +02:00
|
|
|
%MethodCode
|
|
|
|
sipRes = sipCpp->count();
|
|
|
|
%End
|
2014-01-18 23:05:32 +01:00
|
|
|
//! Return number of items
|
2013-06-23 16:00:16 +02:00
|
|
|
int size() const;
|
2014-01-18 23:05:32 +01:00
|
|
|
//! Return if a field index is valid
|
|
|
|
//! @param i Index of the field which needs to be checked
|
|
|
|
//! @return True if the field exists
|
|
|
|
bool exists( int i ) const;
|
|
|
|
|
|
|
|
//! Get field at particular index (must be in range 0..N-1)
|
|
|
|
//inline const QgsField& operator[]( int i ) const;
|
|
|
|
//! Get field at particular index (must be in range 0..N-1)
|
2013-06-23 16:00:16 +02:00
|
|
|
QgsField& operator[](int i) /Factory/;
|
2012-12-17 21:22:42 +01:00
|
|
|
%MethodCode
|
2013-06-16 14:46:43 +02:00
|
|
|
SIP_SSIZE_T idx = sipConvertFromSequenceIndex(a0, sipCpp->count());
|
2012-12-17 21:22:42 +01:00
|
|
|
if (idx < 0)
|
|
|
|
sipIsErr = 1;
|
|
|
|
else
|
|
|
|
sipRes = new QgsField(sipCpp->operator[](idx));
|
2013-06-15 15:00:39 +02:00
|
|
|
|
2012-12-17 21:22:42 +01:00
|
|
|
%End
|
2014-01-18 23:05:32 +01:00
|
|
|
//! Get field at particular index (must be in range 0..N-1)
|
|
|
|
const QgsField& at( int i ) const;
|
|
|
|
//! Get field at particular index (must be in range 0..N-1)
|
|
|
|
const QgsField& field( int fieldIdx ) const;
|
|
|
|
//! Get field at particular index (must be in range 0..N-1)
|
|
|
|
const QgsField& field( const QString& name ) const;
|
|
|
|
|
|
|
|
//! Get field's origin (value from an enumeration)
|
|
|
|
FieldOrigin fieldOrigin( int fieldIdx ) const;
|
|
|
|
//! Get field's origin index (its meaning is specific to each type of origin)
|
|
|
|
int fieldOriginIndex( int fieldIdx ) const;
|
|
|
|
|
|
|
|
//! Look up field's index from name. Returns -1 on error
|
|
|
|
int indexFromName( const QString& name ) const;
|
|
|
|
|
|
|
|
//! Utility function to return a list of QgsField instances
|
|
|
|
QList<QgsField> toList() const;
|
2012-12-17 21:22:42 +01:00
|
|
|
|
|
|
|
/* SIP_PYOBJECT __getitem__(int key);
|
|
|
|
%MethodCode
|
|
|
|
if (a0 = sipConvertFromSequenceIndex(a0, sipCpp->count()) < 0)
|
|
|
|
sipIsErr = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("__getitem__ %d", a0);
|
|
|
|
QgsField* fld = new QgsField(sipCpp->at(a0));
|
2013-08-13 12:32:56 +02:00
|
|
|
sipRes = sipConvertFromType(fld, sipType_QgsField, Py_None);
|
2012-12-17 21:22:42 +01:00
|
|
|
}
|
|
|
|
%End*/
|
|
|
|
|
|
|
|
void __setitem__(int key, const QgsField& field);
|
|
|
|
%MethodCode
|
|
|
|
int idx = (int)sipConvertFromSequenceIndex(a0, sipCpp->count());
|
|
|
|
if (idx < 0)
|
|
|
|
sipIsErr = 1;
|
|
|
|
else
|
|
|
|
(*sipCpp)[idx] = *a1;
|
|
|
|
%End
|
|
|
|
|
|
|
|
};
|
|
|
|
|