QGIS API Documentation  2.99.0-Master (cb63e82)
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 #include "qgsfield_p.h"
24 #include "qgis_core.h"
25 
26 typedef QList<int> QgsAttributeList;
27 
28 /***************************************************************************
29  * This class is considered CRITICAL and any change MUST be accompanied with
30  * full unit tests in testqgsfield.cpp.
31  * See details in QEP #17
32  ****************************************************************************/
33 
34 #include "qgseditorwidgetsetup.h"
35 #include "qgsfieldconstraints.h"
36 
45 class CORE_EXPORT QgsField
46 {
47  Q_GADGET
48 
49  Q_PROPERTY( bool isNumeric READ isNumeric )
50  Q_PROPERTY( int length READ length WRITE setLength )
51  Q_PROPERTY( int precision READ precision WRITE setPrecision )
52  Q_PROPERTY( QString comment READ comment WRITE setComment )
53  Q_PROPERTY( QString name READ name WRITE setName )
54  Q_PROPERTY( QString alias READ alias WRITE setAlias )
55  Q_PROPERTY( QString defaultValueExpression READ defaultValueExpression WRITE setDefaultValueExpression )
56  Q_PROPERTY( QgsFieldConstraints constraints READ constraints WRITE setConstraints )
57 
58  public:
59 
74  QgsField( const QString &name = QString(),
75  QVariant::Type type = QVariant::Invalid,
76  const QString &typeName = QString(),
77  int len = 0,
78  int prec = 0,
79  const QString &comment = QString(),
80  QVariant::Type subType = QVariant::Invalid );
81 
84  QgsField( const QgsField &other );
85 
88  QgsField &operator =( const QgsField &other );
89 
90  virtual ~QgsField() = default;
91 
92  bool operator==( const QgsField &other ) const;
93  bool operator!=( const QgsField &other ) const;
94 
99  QString name() const;
100 
107  QString displayName() const;
108 
110  QVariant::Type type() const;
111 
118  QVariant::Type subType() const;
119 
126  QString typeName() const;
127 
132  int length() const;
133 
138  int precision() const;
139 
143  QString comment() const;
144 
151  bool isNumeric() const;
152 
157  void setName( const QString &name );
158 
162  void setType( QVariant::Type type );
163 
170  void setSubType( QVariant::Type subType );
171 
176  void setTypeName( const QString &typeName );
177 
182  void setLength( int len );
183 
188  void setPrecision( int precision );
189 
193  void setComment( const QString &comment );
194 
201  QString defaultValueExpression() const;
202 
209  void setDefaultValueExpression( const QString &expression );
210 
216  const QgsFieldConstraints &constraints() const;
217 
223  void setConstraints( const QgsFieldConstraints &constraints );
224 
230  QString alias() const;
231 
237  void setAlias( const QString &alias );
238 
240  QString displayString( const QVariant &v ) const;
241 
249  bool convertCompatible( QVariant &v ) const;
250 
252  operator QVariant() const
253  {
254  return QVariant::fromValue( *this );
255  }
256 
262  void setEditorWidgetSetup( const QgsEditorWidgetSetup &v );
263 
272  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
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:302
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:45
Holder for the widget type and its configuration for a field.
QList< int > QgsAttributeList
Definition: qgsfield.h:26
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:325