QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
40 class CORE_EXPORT QgsField
41 {
42  public:
55  QgsField( QString name = QString(),
56  QVariant::Type type = QVariant::Invalid,
57  QString typeName = QString(),
58  int len = 0,
59  int prec = 0,
60  QString comment = QString() );
61 
64  QgsField( const QgsField& other );
65 
68  QgsField& operator =( const QgsField &other );
69 
71  virtual ~QgsField();
72 
73  bool operator==( const QgsField& other ) const;
74  bool operator!=( const QgsField& other ) const;
75 
77  const QString& name() const;
78 
80  QVariant::Type type() const;
81 
88  const QString& typeName() const;
89 
94  int length() const;
95 
100  int precision() const;
101 
105  const QString& comment() const;
106 
111  void setName( const QString& name );
112 
116  void setType( QVariant::Type type );
117 
122  void setTypeName( const QString& typeName );
123 
128  void setLength( int len );
129 
134  void setPrecision( int precision );
135 
139  void setComment( const QString& comment );
140 
142  QString displayString( const QVariant& v ) const;
143 
151  bool convertCompatible( QVariant& v ) const;
152 
153 
154  private:
155 
157 
158 
159 }; // class QgsField
160 
162 
164 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsField& field );
166 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsField& field );
167 
177 class CORE_EXPORT QgsFields
178 {
179  public:
180 
182  {
187  OriginExpression
188  };
189 
190  typedef struct Field
191  {
192  Field(): origin( OriginUnknown ), originIndex( -1 ) {}
193  Field( const QgsField& f, FieldOrigin o, int oi ): field( f ), origin( o ), originIndex( oi ) {}
194 
196  bool operator==( const Field& other ) const { return field == other.field && origin == other.origin && originIndex == other.originIndex; }
198  bool operator!=( const Field& other ) const { return !( *this == other ); }
199 
203  } Field;
204 
207  QgsFields();
208 
211  QgsFields( const QgsFields& other );
212 
215  QgsFields& operator =( const QgsFields &other );
216 
217  virtual ~QgsFields();
218 
220  void clear();
222  bool append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
224  bool appendExpressionField( const QgsField& field, int originIndex );
226  void remove( int fieldIdx );
228  void extend( const QgsFields& other );
229 
231  bool isEmpty() const;
233  int count() const;
235  int size() const;
239  bool exists( int i ) const;
240 
242  const QgsField& operator[]( int i ) const;
244  QgsField& operator[]( int i );
246  const QgsField& at( int i ) const;
248  const QgsField& field( int fieldIdx ) const;
250  const QgsField& field( const QString& name ) const;
251 
253  FieldOrigin fieldOrigin( int fieldIdx ) const;
255  int fieldOriginIndex( int fieldIdx ) const;
256 
258  int indexFromName( const QString& name ) const;
259 
263  int fieldNameIndex( const QString& fieldName ) const;
264 
267  QgsAttributeList allAttributesList() const;
268 
270  QList<QgsField> toList() const;
271 
273  bool operator==( const QgsFields& other ) const;
275  bool operator!=( const QgsFields& other ) const { return !( *this == other ); }
276 
277  private:
278 
280 
281 };
282 
284 
286 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFields& fields );
288 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFields& fields );
289 
290 #endif
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:88
Q_DECLARE_METATYPE(QgsField)
field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
Definition: qgsfield.h:185
field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
Definition: qgsfield.h:186
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsField field
field
Definition: qgsfield.h:200
Container of fields for a vector layer.
Definition: qgsfield.h:177
field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
Definition: qgsfield.h:184
it has not been specified where the field comes from
Definition: qgsfield.h:183
bool operator==(const Field &other) const
Definition: qgsfield.h:196
Field(const QgsField &f, FieldOrigin o, int oi)
Definition: qgsfield.h:193
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsField &field)
Writes the field to stream out.
Definition: qgsfield.cpp:181
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:40
bool operator!=(const Field &other) const
Definition: qgsfield.h:198
QList< int > QgsAttributeList
Definition: qgsfield.h:24
int originIndex
index specific to the origin
Definition: qgsfield.h:202
bool operator!=(const QgsFields &other) const
Definition: qgsfield.h:275
FieldOrigin origin
origin of the field
Definition: qgsfield.h:201
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsField &field)
Reads a field from stream in into field.
Definition: qgsfield.cpp:192