QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 
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 
157 
167 class CORE_EXPORT QgsFields
168 {
169  public:
170 
172  {
177  OriginExpression
178  };
179 
180  typedef struct Field
181  {
182  Field(): origin( OriginUnknown ), originIndex( -1 ) {}
183  Field( const QgsField& f, FieldOrigin o, int oi ): field( f ), origin( o ), originIndex( oi ) {}
184 
186  bool operator==( const Field& other ) const { return field == other.field && origin == other.origin && originIndex == other.originIndex; }
188  bool operator!=( const Field& other ) const { return !( *this == other ); }
189 
193  } Field;
194 
197  QgsFields();
198 
201  QgsFields( const QgsFields& other );
202 
205  QgsFields& operator =( const QgsFields &other );
206 
207  virtual ~QgsFields();
208 
210  void clear();
212  bool append( const QgsField& field, FieldOrigin origin = OriginProvider, int originIndex = -1 );
214  bool appendExpressionField( const QgsField& field, int originIndex );
216  void remove( int fieldIdx );
218  void extend( const QgsFields& other );
219 
221  bool isEmpty() const;
223  int count() const;
225  int size() const;
229  bool exists( int i ) const;
230 
232  const QgsField& operator[]( int i ) const;
234  QgsField& operator[]( int i );
236  const QgsField& at( int i ) const;
238  const QgsField& field( int fieldIdx ) const;
240  const QgsField& field( const QString& name ) const;
241 
243  FieldOrigin fieldOrigin( int fieldIdx ) const;
245  int fieldOriginIndex( int fieldIdx ) const;
246 
248  int indexFromName( const QString& name ) const;
249 
253  int fieldNameIndex( const QString& fieldName ) const;
254 
257  QgsAttributeList allAttributesList() const;
258 
260  QList<QgsField> toList() const;
261 
263  bool operator==( const QgsFields& other ) const;
265  bool operator!=( const QgsFields& other ) const { return !( *this == other ); }
266 
267  private:
268 
269  QSharedDataPointer<QgsFieldsPrivate> d;
270 
271 };
272 
273 #endif
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:86
field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
Definition: qgsfield.h:175
field has been temporarily added in editing mode (originIndex = index in the list of added attributes...
Definition: qgsfield.h:176
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsField field
field
Definition: qgsfield.h:190
Container of fields for a vector layer.
Definition: qgsfield.h:167
field comes from the underlying data provider of the vector layer (originIndex = index in provider's ...
Definition: qgsfield.h:174
it has not been specified where the field comes from
Definition: qgsfield.h:173
bool operator==(const Field &other) const
Definition: qgsfield.h:186
Field(const QgsField &f, FieldOrigin o, int oi)
Definition: qgsfield.h:183
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:188
QList< int > QgsAttributeList
Definition: qgsfield.h:24
int originIndex
index specific to the origin
Definition: qgsfield.h:192
bool operator!=(const QgsFields &other) const
Definition: qgsfield.h:265
FieldOrigin origin
origin of the field
Definition: qgsfield.h:191
double size
Definition: qgssvgcache.cpp:77