QGIS API Documentation  2.9.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 
24 typedef QList<int> QgsAttributeList;
25 
26 class QgsExpression;
27 class QgsFieldPrivate;
28 class QgsFieldsPrivate;
29 
38 class CORE_EXPORT QgsField
39 {
40  public:
53  QgsField( QString name = QString(),
54  QVariant::Type type = QVariant::Invalid,
55  QString typeName = QString(),
56  int len = 0,
57  int prec = 0,
58  QString comment = QString() );
59 
62  QgsField( const QgsField& other );
63 
66  QgsField& operator =( const QgsField &other );
67 
69  virtual ~QgsField();
70 
71  bool operator==( const QgsField& other ) const;
72  bool operator!=( const QgsField& other ) const;
73 
75  const QString& name() const;
76 
78  QVariant::Type type() const;
79 
86  const QString& typeName() const;
87 
92  int length() const;
93 
98  int precision() const;
99 
103  const QString& comment() const;
104 
109  void setName( const QString& name );
110 
114  void setType( QVariant::Type type );
115 
120  void setTypeName( const QString& typeName );
121 
126  void setLength( int len );
127 
132  void setPrecision( int precision );
133 
137  void setComment( const QString& comment );
138 
140  QString displayString( const QVariant& v ) const;
141 
149  bool convertCompatible( QVariant& v ) const;
150 
151  private:
152 
153  QSharedDataPointer<QgsFieldPrivate> d;
154 
155 }; // class QgsField
156 
158 
160 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsField& field );
162 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsField& field );
163 
173 class CORE_EXPORT QgsFields
174 {
175  public:
176 
178  {
183  OriginExpression
184  };
185 
186  typedef struct Field
187  {
188  Field(): origin( OriginUnknown ), originIndex( -1 ) {}
189  Field( const QgsField& f, FieldOrigin o, int oi ): field( f ), origin( o ), originIndex( oi ) {}
190 
192  bool operator==( const Field& other ) const { return field == other.field && origin == other.origin && originIndex == other.originIndex; }
194  bool operator!=( const Field& other ) const { return !( *this == other ); }
195 
199  } Field;
200 
203  QgsFields();
204 
207  QgsFields( const QgsFields& other );
208 
211  QgsFields& operator =( const QgsFields &other );
212 
213  virtual ~QgsFields();
214 
216  void clear();
218  bool append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
220  bool appendExpressionField( const QgsField& field, int originIndex );
222  void remove( int fieldIdx );
224  void extend( const QgsFields& other );
225 
227  bool isEmpty() const;
229  int count() const;
231  int size() const;
235  bool exists( int i ) const;
236 
238  const QgsField& operator[]( int i ) const;
240  QgsField& operator[]( int i );
242  const QgsField& at( int i ) const;
244  const QgsField& field( int fieldIdx ) const;
246  const QgsField& field( const QString& name ) const;
247 
249  FieldOrigin fieldOrigin( int fieldIdx ) const;
251  int fieldOriginIndex( int fieldIdx ) const;
252 
254  int indexFromName( const QString& name ) const;
255 
259  int fieldNameIndex( const QString& fieldName ) const;
260 
263  QgsAttributeList allAttributesList() const;
264 
266  QList<QgsField> toList() const;
267 
269  bool operator==( const QgsFields& other ) const;
271  bool operator!=( const QgsFields& other ) const { return !( *this == other ); }
272 
273  private:
274 
275  QSharedDataPointer<QgsFieldsPrivate> d;
276 
277 };
278 
280 
282 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFields& fields );
284 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFields& fields );
285 
286 #endif
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:86
Q_DECLARE_METATYPE(QgsField)
field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
Definition: qgsfield.h:181
field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
Definition: qgsfield.h:182
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsField field
field
Definition: qgsfield.h:196
Container of fields for a vector layer.
Definition: qgsfield.h:173
field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
Definition: qgsfield.h:180
it has not been specified where the field comes from
Definition: qgsfield.h:179
bool operator==(const Field &other) const
Definition: qgsfield.h:192
Field(const QgsField &f, FieldOrigin o, int oi)
Definition: qgsfield.h:189
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsField &field)
Writes the field to stream out.
Definition: qgsfield.cpp:179
QList< int > QgsAttributeList
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:38
bool operator!=(const Field &other) const
Definition: qgsfield.h:194
QList< int > QgsAttributeList
Definition: qgsfield.h:24
int originIndex
index specific to the origin
Definition: qgsfield.h:198
bool operator!=(const QgsFields &other) const
Definition: qgsfield.h:271
FieldOrigin origin
origin of the field
Definition: qgsfield.h:197
double size
Definition: qgssvgcache.cpp:77
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsField &field)
Reads a field from stream in into field.
Definition: qgsfield.cpp:190