QGIS API Documentation  2.99.0-Master (8ec3eaf)
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 
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 
36 #include "qgseditorwidgetsetup.h"
37 #include "qgsfieldconstraints.h"
38 
47 class CORE_EXPORT QgsField
48 {
49  Q_GADGET
50 
51  Q_PROPERTY( bool isNumeric READ isNumeric )
52  Q_PROPERTY( int length READ length WRITE setLength )
53  Q_PROPERTY( int precision READ precision WRITE setPrecision )
54  Q_PROPERTY( QString comment READ comment WRITE setComment )
55  Q_PROPERTY( QString name READ name WRITE setName )
56  Q_PROPERTY( QString alias READ alias WRITE setAlias )
57  Q_PROPERTY( QString defaultValueExpression READ defaultValueExpression WRITE setDefaultValueExpression )
58  Q_PROPERTY( QgsFieldConstraints constraints READ constraints WRITE setConstraints )
59 
60  public:
61 
76  QgsField( const QString& name = QString(),
77  QVariant::Type type = QVariant::Invalid,
78  const QString& typeName = QString(),
79  int len = 0,
80  int prec = 0,
81  const QString& comment = QString(),
82  QVariant::Type subType = QVariant::Invalid );
83 
86  QgsField( const QgsField& other );
87 
90  QgsField& operator =( const QgsField &other );
91 
93  virtual ~QgsField();
94 
95  bool operator==( const QgsField& other ) const;
96  bool operator!=( const QgsField& other ) const;
97 
102  QString name() const;
103 
110  QString displayName() const;
111 
113  QVariant::Type type() const;
114 
121  QVariant::Type subType() const;
122 
129  QString typeName() const;
130 
135  int length() const;
136 
141  int precision() const;
142 
146  QString comment() const;
147 
154  bool isNumeric() const;
155 
160  void setName( const QString& name );
161 
165  void setType( QVariant::Type type );
166 
173  void setSubType( QVariant::Type subType );
174 
179  void setTypeName( const QString& typeName );
180 
185  void setLength( int len );
186 
191  void setPrecision( int precision );
192 
196  void setComment( const QString& comment );
197 
204  QString defaultValueExpression() const;
205 
212  void setDefaultValueExpression( const QString& expression );
213 
219  const QgsFieldConstraints& constraints() const;
220 
226  void setConstraints( const QgsFieldConstraints& constraints );
227 
233  QString alias() const;
234 
240  void setAlias( const QString& alias );
241 
243  QString displayString( const QVariant& v ) const;
244 
252  bool convertCompatible( QVariant& v ) const;
253 
255  operator QVariant() const
256  {
257  return QVariant::fromValue( *this );
258  }
259 
265  void setEditorWidgetSetup( const QgsEditorWidgetSetup& v );
266 
272  const QgsEditorWidgetSetup& editorWidgetSetup() const;
273 
274  private:
275 
276  QSharedDataPointer<QgsFieldPrivate> d;
277 
278 
279 }; // class QgsField
280 
282 
283 CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsField& field );
286 CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsField& field );
287 
288 
289 #endif
Class for parsing and evaluation of expressions (formerly called "search strings").
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
Stores information about constraints which may be present on a field.
CORE_EXPORT QDataStream & operator<<(QDataStream &out, const QgsField &field)
Writes the field to stream out. QGIS version compatibility is not guaranteed.
Definition: qgsfield.cpp:306
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:47
Holder for the widget type and its configuration for a field.
QList< int > QgsAttributeList
Definition: qgsfield.h:24
CORE_EXPORT QDataStream & operator>>(QDataStream &in, QgsField &field)
Reads a field from stream in into field. QGIS version compatibility is not guaranteed.
Definition: qgsfield.cpp:329