QGIS API Documentation  2.14.0-Essen
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:
58  QgsField( const QString& name = QString(),
59  QVariant::Type type = QVariant::Invalid,
60  const QString& typeName = QString(),
61  int len = 0,
62  int prec = 0,
63  const QString& comment = QString() );
64 
67  QgsField( const QgsField& other );
68 
71  QgsField& operator =( const QgsField &other );
72 
74  virtual ~QgsField();
75 
76  bool operator==( const QgsField& other ) const;
77  bool operator!=( const QgsField& other ) const;
78 
80  QString name() const;
81 
83  QVariant::Type type() const;
84 
91  QString typeName() const;
92 
97  int length() const;
98 
103  int precision() const;
104 
108  QString comment() const;
109 
114  void setName( const QString& name );
115 
119  void setType( QVariant::Type type );
120 
125  void setTypeName( const QString& typeName );
126 
131  void setLength( int len );
132 
137  void setPrecision( int precision );
138 
142  void setComment( const QString& comment );
143 
145  QString displayString( const QVariant& v ) const;
146 
154  bool convertCompatible( QVariant& v ) const;
155 
156  private:
157 
159 
160 
161 }; // class QgsField
162 
163 Q_DECLARE_METATYPE( QgsField )
164 
165 
166 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsField& field );
168 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsField& field );
169 
170 
171 
172 /***************************************************************************
173  * This class is considered CRITICAL and any change MUST be accompanied with
174  * full unit tests in testqgsfields.cpp.
175  * See details in QEP #17
176  ****************************************************************************/
177 
187 class CORE_EXPORT QgsFields
188 {
189  public:
190 
192  {
197  OriginExpression
198  };
199 
200  typedef struct Field
201  {
202  Field(): origin( OriginUnknown ), originIndex( -1 ) {}
203  Field( const QgsField& f, FieldOrigin o, int oi ): field( f ), origin( o ), originIndex( oi ) {}
204 
206  bool operator==( const Field& other ) const { return field == other.field && origin == other.origin && originIndex == other.originIndex; }
208  bool operator!=( const Field& other ) const { return !( *this == other ); }
209 
213  } Field;
214 
217  QgsFields();
218 
221  QgsFields( const QgsFields& other );
222 
225  QgsFields& operator =( const QgsFields &other );
226 
227  virtual ~QgsFields();
228 
230  void clear();
232  bool append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
234  bool appendExpressionField( const QgsField& field, int originIndex );
236  void remove( int fieldIdx );
238  void extend( const QgsFields& other );
239 
241  bool isEmpty() const;
243  int count() const;
245  int size() const;
249  bool exists( int i ) const;
250 
252  const QgsField& operator[]( int i ) const;
254  QgsField& operator[]( int i );
256  const QgsField& at( int i ) const;
258  const QgsField& field( int fieldIdx ) const;
260  const QgsField& field( const QString& name ) const;
261 
263  FieldOrigin fieldOrigin( int fieldIdx ) const;
265  int fieldOriginIndex( int fieldIdx ) const;
266 
268  int indexFromName( const QString& name ) const;
269 
273  int fieldNameIndex( const QString& fieldName ) const;
274 
277  QgsAttributeList allAttributesList() const;
278 
280  QList<QgsField> toList() const;
281 
283  bool operator==( const QgsFields& other ) const;
285  bool operator!=( const QgsFields& other ) const { return !( *this == other ); }
286 
290  QIcon iconForField( int fieldIdx ) const;
291 
292  private:
293 
295 
296 };
297 
298 Q_DECLARE_METATYPE( QgsFields )
299 
300 
301 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFields& fields );
303 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFields& fields );
304 
305 #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:195
field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
Definition: qgsfield.h:196
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsField field
field
Definition: qgsfield.h:210
Container of fields for a vector layer.
Definition: qgsfield.h:187
field comes from the underlying data provider of the vector layer (originIndex = index in provider&#39;s ...
Definition: qgsfield.h:194
it has not been specified where the field comes from
Definition: qgsfield.h:193
bool operator==(const Field &other) const
Definition: qgsfield.h:206
Field(const QgsField &f, FieldOrigin o, int oi)
Definition: qgsfield.h:203
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsField &field)
Writes the field to stream out.
Definition: qgsfield.cpp:242
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
bool operator!=(const Field &other) const
Definition: qgsfield.h:208
QList< int > QgsAttributeList
Definition: qgsfield.h:24
int originIndex
index specific to the origin
Definition: qgsfield.h:212
bool operator!=(const QgsFields &other) const
Definition: qgsfield.h:285
FieldOrigin origin
origin of the field
Definition: qgsfield.h:211
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsField &field)
Reads a field from stream in into field.
Definition: qgsfield.cpp:253