QGIS API Documentation  2.13.0-Master
qgsfield.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfield.h - Describes a field in a layer or table
3  --------------------------------------
4  Date : 01-Jan-2004
5  Copyright : (C) 2004 by Gary E.Sherman
6  email : sherman at mrcc.com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSFIELD_H
17 #define QGSFIELD_H
18 
19 #include <QString>
20 #include <QVariant>
21 #include <QVector>
22 #include <QSharedDataPointer>
23 
25 
26 class QgsExpression;
27 class QgsFieldPrivate;
28 class QgsFieldsPrivate;
29 
30 /***************************************************************************
31  * This class is considered CRITICAL and any change MUST be accompanied with
32  * full unit tests in testqgsfield.cpp.
33  * See details in QEP #17
34  ****************************************************************************/
35 
44 class CORE_EXPORT QgsField
45 {
46  public:
59  QgsField( const QString& name = QString(),
60  QVariant::Type type = QVariant::Invalid,
61  const QString& typeName = QString(),
62  int len = 0,
63  int prec = 0,
64  const QString& comment = QString() );
65 
68  QgsField( const QgsField& other );
69 
72  QgsField& operator =( const QgsField &other );
73 
75  virtual ~QgsField();
76 
77  bool operator==( const QgsField& other ) const;
78  bool operator!=( const QgsField& other ) const;
79 
81  QString name() const;
82 
84  QVariant::Type type() const;
85 
92  QString typeName() const;
93 
98  int length() const;
99 
104  int precision() const;
105 
109  QString comment() const;
110 
115  void setName( const QString& name );
116 
120  void setType( QVariant::Type type );
121 
126  void setTypeName( const QString& typeName );
127 
132  void setLength( int len );
133 
138  void setPrecision( int precision );
139 
143  void setComment( const QString& comment );
144 
146  QString displayString( const QVariant& v ) const;
147 
155  bool convertCompatible( QVariant& v ) const;
156 
157 
158  private:
159 
161 
162 
163 }; // class QgsField
164 
165 Q_DECLARE_METATYPE( QgsField )
166 
167 
168 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsField& field );
170 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsField& field );
171 
172 
173 
174 /***************************************************************************
175  * This class is considered CRITICAL and any change MUST be accompanied with
176  * full unit tests in testqgsfields.cpp.
177  * See details in QEP #17
178  ****************************************************************************/
179 
189 class CORE_EXPORT QgsFields
190 {
191  public:
192 
194  {
199  OriginExpression
200  };
201 
202  typedef struct Field
203  {
204  Field(): origin( OriginUnknown ), originIndex( -1 ) {}
205  Field( const QgsField& f, FieldOrigin o, int oi ): field( f ), origin( o ), originIndex( oi ) {}
206 
208  bool operator==( const Field& other ) const { return field == other.field && origin == other.origin && originIndex == other.originIndex; }
210  bool operator!=( const Field& other ) const { return !( *this == other ); }
211 
215  } Field;
216 
219  QgsFields();
220 
223  QgsFields( const QgsFields& other );
224 
227  QgsFields& operator =( const QgsFields &other );
228 
229  virtual ~QgsFields();
230 
232  void clear();
234  bool append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
236  bool appendExpressionField( const QgsField& field, int originIndex );
238  void remove( int fieldIdx );
240  void extend( const QgsFields& other );
241 
243  bool isEmpty() const;
245  int count() const;
247  int size() const;
251  bool exists( int i ) const;
252 
254  const QgsField& operator[]( int i ) const;
256  QgsField& operator[]( int i );
258  const QgsField& at( int i ) const;
260  const QgsField& field( int fieldIdx ) const;
262  const QgsField& field( const QString& name ) const;
263 
265  FieldOrigin fieldOrigin( int fieldIdx ) const;
267  int fieldOriginIndex( int fieldIdx ) const;
268 
270  int indexFromName( const QString& name ) const;
271 
275  int fieldNameIndex( const QString& fieldName ) const;
276 
279  QgsAttributeList allAttributesList() const;
280 
282  QList<QgsField> toList() const;
283 
285  bool operator==( const QgsFields& other ) const;
287  bool operator!=( const QgsFields& other ) const { return !( *this == other ); }
288 
289  private:
290 
292 
293 };
294 
295 Q_DECLARE_METATYPE( QgsFields )
296 
297 
298 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFields& fields );
300 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFields& fields );
301 
302 #endif
Class for parsing and evaluation of expressions (formerly called "search strings").
field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
Definition: qgsfield.h:197
field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
Definition: qgsfield.h:198
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsField field
field
Definition: qgsfield.h:212
Container of fields for a vector layer.
Definition: qgsfield.h:189
field comes from the underlying data provider of the vector layer (originIndex = index in provider&#39;s ...
Definition: qgsfield.h:196
it has not been specified where the field comes from
Definition: qgsfield.h:195
bool operator==(const Field &other) const
Definition: qgsfield.h:208
Field(const QgsField &f, FieldOrigin o, int oi)
Definition: qgsfield.h:205
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsField &field)
Writes the field to stream out.
Definition: qgsfield.cpp:240
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
bool operator!=(const Field &other) const
Definition: qgsfield.h:210
QList< int > QgsAttributeList
Definition: qgsfield.h:24
int originIndex
index specific to the origin
Definition: qgsfield.h:214
bool operator!=(const QgsFields &other) const
Definition: qgsfield.h:287
FieldOrigin origin
origin of the field
Definition: qgsfield.h:213
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsField &field)
Reads a field from stream in into field.
Definition: qgsfield.cpp:251