12
12
* (at your option) any later version. *
14
14
***************************************************************************/
15
/* $Id: qgsfield.h 4502 2006-01-08 01:18:20Z timlinux $ */
24
\brief Class to encapsulate a field in an attribute table or data source.
26
QgsField stores metadata about an attribute field, including name, type
27
length, and if applicable, precision.
24
* Encapsulate a field in an attribute table or data source.
25
* QgsField stores metadata about an attribute field, including name, type
26
* length, and if applicable, precision.
29
class CORE_EXPORT QgsField
33
32
/** Constructor. Constructs a new QgsField object.
34
33
* @param nam Field name
35
* @param typ Field type (eg. char, varchar, text, int, serial, double).
34
* @param type Field variant type, currently supported: String / Int / Double
35
* @param typeName Field type (eg. char, varchar, text, int, serial, double).
36
36
Field types are usually unique to the source and are stored exactly
37
37
as returned from the data store.
38
38
* @param len Field length
39
39
* @param prec Field precision. Usually decimal places but may also be
40
40
* used in conjunction with other fields types (eg. variable character fields)
41
* @param num Has to be true if field contains numeric values.
41
* @param comment Comment for the field
43
QgsField(QString nam = "", QString typ = "", int len = 0, int prec = 0, bool num = false);
48
bool operator==(const QgsField other) const;
49
bool operator!=(const QgsField other) const;
51
//! Gets the name of the field
52
QString const & name() const;
44
QgsField( QString name = QString(),
45
QVariant::Type type = QVariant::Invalid,
46
QString typeName = QString(),
49
QString comment = QString() );
54
bool operator==( const QgsField& other ) const;
56
//! Gets the name of the field
57
const QString & name() const;
59
//! Gets variant type of the field as it will be retrieved from data source
60
QVariant::Type type() const;
56
63
Gets the field type. Field types vary depending on the data source. Examples
57
64
are char, int, double, blob, geometry, etc. The type is stored exactly as
58
65
the data store reports it, with no attenpt to standardize the value.
59
66
@return QString containing the field type
61
QString const & type() const;
68
const QString & typeName() const;
65
72
Gets the length of the field.
66
73
@return int containing the length of the field
72
79
Gets the precision of the field. Not all field types have a related precision.
73
80
@return int containing the precision or zero if not applicable to the field type.
75
int precision() const;
82
int precision() const;
78
Returns true if field contains numeric values. This information is set by provider.
80
bool isNumeric() const;
85
Returns the field comment
87
const QString & comment() const;
84
90
Set the field name.
85
91
@param nam Name of the field
87
void setName(QString const & nam);
93
void setName( const QString & nam );
98
void setType( QVariant::Type type );
90
101
Set the field type.
91
102
@param typ Field type
93
void setType(QString const & typ);
104
void setTypeName( const QString & typ );
96
107
Set the field length.
97
108
@param len Length of the field
99
void setLength(int len);
110
void setLength( int len );
102
113
Set the field precision.
103
114
@param prec Precision of the field
105
void setPrecision(int prec);
116
void setPrecision( int prec );
108
Set whether field is numeric
120
Set the field comment
110
void setNumeric(bool num);
122
void setComment( const QString & comment );
130
QVariant::Type mType;
132
//! Type name from provider
129
144
}; // class QgsField
146
// key = field index, value=field data
147
typedef QMap<int, QgsField> QgsFieldMap;