QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsfield.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfield.cpp - 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  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "qgsfields.h"
18 #include "qgsfield_p.h"
19 #include "qgis.h"
20 #include "qgsapplication.h"
21 #include "qgssettings.h"
22 
23 #include <QDataStream>
24 #include <QIcon>
25 #include <QLocale>
26 #include <QJsonDocument>
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 #if 0
35 QgsField::QgsField( QString nam, QString typ, int len, int prec, bool num,
36  QString comment )
37  : mName( nam ), mType( typ ), mLength( len ), mPrecision( prec ), mNumeric( num )
38  , mComment( comment )
39 {
40  // This function used to lower case the field name since some stores
41  // use upper case (e.g., shapefiles), but that caused problems with
42  // attribute actions getting confused between uppercase and
43  // lowercase versions of the attribute names, so just leave the
44  // names how they are now.
45 }
46 #endif
47 QgsField::QgsField( const QString &name, QVariant::Type type,
48  const QString &typeName, int len, int prec, const QString &comment,
49  QVariant::Type subType )
50 {
51  d = new QgsFieldPrivate( name, type, subType, typeName, len, prec, comment );
52 }
53 
54 QgsField::QgsField( const QgsField &other ) //NOLINT
55  : d( other.d )
56 {
57 
58 }
59 
60 QgsField::~QgsField() = default;
61 
62 /***************************************************************************
63  * This class is considered CRITICAL and any change MUST be accompanied with
64  * full unit tests in testqgsfield.cpp.
65  * See details in QEP #17
66  ****************************************************************************/
67 
68 QgsField &QgsField::operator =( const QgsField &other ) //NOLINT
69 {
70  d = other.d;
71  return *this;
72 }
73 
74 bool QgsField::operator==( const QgsField &other ) const
75 {
76  return *( other.d ) == *d;
77 }
78 
79 bool QgsField::operator!=( const QgsField &other ) const
80 {
81  return !( *this == other );
82 }
83 
84 QString QgsField::name() const
85 {
86  return d->name;
87 }
88 
89 QString QgsField::displayName() const
90 {
91  if ( !d->alias.isEmpty() )
92  return d->alias;
93  else
94  return d->name;
95 }
96 
98 {
99  if ( alias().isEmpty() )
100  {
101  return name();
102  }
103  return QStringLiteral( "%1 (%2)" ).arg( name() ).arg( alias() );
104 }
105 
106 QString QgsField::displayType( const bool showConstraints ) const
107 {
108  QString typeStr = typeName();
109 
110  if ( length() > 0 && precision() > 0 )
111  typeStr += QStringLiteral( "(%1, %2)" ).arg( length() ).arg( precision() );
112  else if ( length() > 0 )
113  typeStr += QStringLiteral( "(%1)" ).arg( length() );
114 
115  if ( showConstraints )
116  {
118  ? QStringLiteral( " NOT NULL" )
119  : QStringLiteral( " NULL" );
120 
122  ? QStringLiteral( " UNIQUE" )
123  : QString();
124  }
125 
126  return typeStr;
127 }
128 
129 QVariant::Type QgsField::type() const
130 {
131  return d->type;
132 }
133 
134 QVariant::Type QgsField::subType() const
135 {
136  return d->subType;
137 }
138 
139 QString QgsField::typeName() const
140 {
141  return d->typeName;
142 }
143 
144 int QgsField::length() const
145 {
146  return d->length;
147 }
148 
149 int QgsField::precision() const
150 {
151  return d->precision;
152 }
153 
154 QString QgsField::comment() const
155 {
156  return d->comment;
157 }
158 
159 bool QgsField::isNumeric() const
160 {
161  return d->type == QVariant::Double || d->type == QVariant::Int || d->type == QVariant::UInt || d->type == QVariant::LongLong || d->type == QVariant::ULongLong;
162 }
163 
164 bool QgsField::isDateOrTime() const
165 {
166  return d->type == QVariant::Date || d->type == QVariant::Time || d->type == QVariant::DateTime;
167 }
168 
169 /***************************************************************************
170  * This class is considered CRITICAL and any change MUST be accompanied with
171  * full unit tests in testqgsfield.cpp.
172  * See details in QEP #17
173  ****************************************************************************/
174 
175 void QgsField::setName( const QString &name )
176 {
177  d->name = name;
178 }
179 
180 void QgsField::setType( QVariant::Type type )
181 {
182  d->type = type;
183 }
184 
185 void QgsField::setSubType( QVariant::Type subType )
186 {
187  d->subType = subType;
188 }
189 
190 void QgsField::setTypeName( const QString &typeName )
191 {
192  d->typeName = typeName;
193 }
194 
195 void QgsField::setLength( int len )
196 {
197  d->length = len;
198 }
200 {
201  d->precision = precision;
202 }
203 
204 void QgsField::setComment( const QString &comment )
205 {
206  d->comment = comment;
207 }
208 
210 {
211  return d->defaultValueDefinition;
212 }
213 
214 void QgsField::setDefaultValueDefinition( const QgsDefaultValue &defaultValueDefinition )
215 {
216  d->defaultValueDefinition = defaultValueDefinition;
217 }
218 
220 {
221  d->constraints = constraints;
222 }
223 
225 {
226  return d->constraints;
227 }
228 
229 QString QgsField::alias() const
230 {
231  return d->alias;
232 }
233 
234 void QgsField::setAlias( const QString &alias )
235 {
236  d->alias = alias;
237 }
238 
239 /***************************************************************************
240  * This class is considered CRITICAL and any change MUST be accompanied with
241  * full unit tests in testqgsfield.cpp.
242  * See details in QEP #17
243  ****************************************************************************/
244 
245 QString QgsField::displayString( const QVariant &v ) const
246 {
247  if ( v.isNull() )
248  {
250  }
251 
252  // Special treatment for numeric types if group separator is set or decimalPoint is not a dot
253  if ( d->type == QVariant::Double )
254  {
255  // Locales with decimal point != '.' or that require group separator: use QLocale
256  if ( QLocale().decimalPoint() != '.' ||
257  !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
258  {
259  if ( d->precision > 0 )
260  {
261  if ( -1 < v.toDouble() && v.toDouble() < 1 )
262  {
263  return QLocale().toString( v.toDouble(), 'g', d->precision );
264  }
265  else
266  {
267  return QLocale().toString( v.toDouble(), 'f', d->precision );
268  }
269  }
270  else
271  {
272  // Precision is not set, let's guess it from the
273  // standard conversion to string
274  QString s( v.toString() );
275  int dotPosition( s.indexOf( '.' ) );
276  int precision;
277  if ( dotPosition < 0 && s.indexOf( 'e' ) < 0 )
278  {
279  precision = 0;
280  return QLocale().toString( v.toDouble(), 'f', precision );
281  }
282  else
283  {
284  if ( dotPosition < 0 ) precision = 0;
285  else precision = s.length() - dotPosition - 1;
286 
287  if ( -1 < v.toDouble() && v.toDouble() < 1 )
288  {
289  return QLocale().toString( v.toDouble(), 'g', precision );
290  }
291  else
292  {
293  return QLocale().toString( v.toDouble(), 'f', precision );
294  }
295  }
296  }
297  }
298  // Default for doubles with precision
299  else if ( d->type == QVariant::Double && d->precision > 0 )
300  {
301  if ( -1 < v.toDouble() && v.toDouble() < 1 )
302  {
303  return QString::number( v.toDouble(), 'g', d->precision );
304  }
305  else
306  {
307  return QString::number( v.toDouble(), 'f', d->precision );
308  }
309  }
310  }
311  // Other numeric types than doubles
312  else if ( isNumeric() &&
313  !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
314  {
315  bool ok;
316  qlonglong converted( v.toLongLong( &ok ) );
317  if ( ok )
318  return QLocale().toString( converted );
319  }
320  else if ( d->typeName.compare( QLatin1String( "json" ), Qt::CaseInsensitive ) == 0 || d->typeName == QLatin1String( "jsonb" ) )
321  {
322  QJsonDocument doc = QJsonDocument::fromVariant( v );
323  return QString::fromUtf8( doc.toJson().data() );
324  }
325  else if ( d->type == QVariant::ByteArray )
326  {
327  return QObject::tr( "BLOB" );
328  }
329  // Fallback if special rules do not apply
330  return v.toString();
331 }
332 
333 /***************************************************************************
334  * This class is considered CRITICAL and any change MUST be accompanied with
335  * full unit tests in testqgsfield.cpp.
336  * See details in QEP #17
337  ****************************************************************************/
338 
339 bool QgsField::convertCompatible( QVariant &v ) const
340 {
341  if ( v.isNull() )
342  {
343  v.convert( d->type );
344  return true;
345  }
346 
347  if ( d->type == QVariant::Int && v.toInt() != v.toLongLong() )
348  {
349  v = QVariant( d->type );
350  return false;
351  }
352 
353  // Give it a chance to convert to double since for not '.' locales
354  // we accept both comma and dot as decimal point
355  if ( d->type == QVariant::Double && v.type() == QVariant::String )
356  {
357  QVariant tmp( v );
358  if ( !tmp.convert( d->type ) )
359  {
360  // This might be a string with thousand separator: use locale to convert
361  bool ok = false;
362  double d = qgsPermissiveToDouble( v.toString(), ok );
363  if ( ok )
364  {
365  v = QVariant( d );
366  return true;
367  }
368  // For not 'dot' locales, we also want to accept '.'
369  if ( QLocale().decimalPoint() != '.' )
370  {
371  d = QLocale( QLocale::C ).toDouble( v.toString(), &ok );
372  if ( ok )
373  {
374  v = QVariant( d );
375  return true;
376  }
377  }
378  }
379  }
380 
381  // For string representation of an int we also might have thousand separator
382  if ( d->type == QVariant::Int && v.type() == QVariant::String )
383  {
384  QVariant tmp( v );
385  if ( !tmp.convert( d->type ) )
386  {
387  // This might be a string with thousand separator: use locale to convert
388  bool ok;
389  int i = qgsPermissiveToInt( v.toString(), ok );
390  if ( ok )
391  {
392  v = QVariant( i );
393  return true;
394  }
395  }
396  }
397 
398  // For string representation of a long we also might have thousand separator
399  if ( d->type == QVariant::LongLong && v.type() == QVariant::String )
400  {
401  QVariant tmp( v );
402  if ( !tmp.convert( d->type ) )
403  {
404  // This might be a string with thousand separator: use locale to convert
405  bool ok;
406  qlonglong l = qgsPermissiveToLongLong( v.toString(), ok );
407  if ( ok )
408  {
409  v = QVariant( l );
410  return true;
411  }
412  }
413  }
414 
415  //String representations of doubles in QVariant will return false to convert( QVariant::Int )
416  //work around this by first converting to double, and then checking whether the double is convertible to int
417  if ( d->type == QVariant::Int && v.canConvert( QVariant::Double ) )
418  {
419  bool ok = false;
420  double dbl = v.toDouble( &ok );
421  if ( !ok )
422  {
423  //couldn't convert to number
424  v = QVariant( d->type );
425  return false;
426  }
427 
428  double round = std::round( dbl );
429  if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
430  {
431  //double too large to fit in int
432  v = QVariant( d->type );
433  return false;
434  }
435  v = QVariant( static_cast< int >( std::round( dbl ) ) );
436  return true;
437  }
438 
439  //String representations of doubles in QVariant will return false to convert( QVariant::LongLong )
440  //work around this by first converting to double, and then checking whether the double is convertible to longlong
441  if ( d->type == QVariant::LongLong && v.canConvert( QVariant::Double ) )
442  {
443  //firstly test the conversion to longlong because conversion to double will rounded the value
444  QVariant tmp( v );
445  if ( !tmp.convert( d->type ) )
446  {
447  bool ok = false;
448  double dbl = v.toDouble( &ok );
449  if ( !ok )
450  {
451  //couldn't convert to number
452  v = QVariant( d->type );
453  return false;
454  }
455 
456  double round = std::round( dbl );
457  if ( round > std::numeric_limits<long long>::max() || round < -std::numeric_limits<long long>::max() )
458  {
459  //double too large to fit in longlong
460  v = QVariant( d->type );
461  return false;
462  }
463  v = QVariant( static_cast< long long >( std::round( dbl ) ) );
464  return true;
465  }
466  }
467 
468  if ( !v.convert( d->type ) )
469  {
470  v = QVariant( d->type );
471  return false;
472  }
473 
474  if ( d->type == QVariant::Double && d->precision > 0 )
475  {
476  double s = std::pow( 10, d->precision );
477  double d = v.toDouble() * s;
478  v = QVariant( ( d < 0 ? std::ceil( d - 0.5 ) : std::floor( d + 0.5 ) ) / s );
479  return true;
480  }
481 
482  if ( d->type == QVariant::String && d->length > 0 && v.toString().length() > d->length )
483  {
484  v = v.toString().left( d->length );
485  return false;
486  }
487 
488  return true;
489 }
490 
492 {
493  d->editorWidgetSetup = v;
494 }
495 
497 {
498  return d->editorWidgetSetup;
499 }
500 
501 /***************************************************************************
502  * This class is considered CRITICAL and any change MUST be accompanied with
503  * full unit tests in testqgsfield.cpp.
504  * See details in QEP #17
505  ****************************************************************************/
506 
507 QDataStream &operator<<( QDataStream &out, const QgsField &field )
508 {
509  out << field.name();
510  out << static_cast< quint32 >( field.type() );
511  out << field.typeName();
512  out << field.length();
513  out << field.precision();
514  out << field.comment();
515  out << field.alias();
516  out << field.defaultValueDefinition().expression();
517  out << field.defaultValueDefinition().applyOnUpdate();
518  out << field.constraints().constraints();
519  out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintNotNull ) );
520  out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintUnique ) );
521  out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintExpression ) );
522  out << static_cast< quint32 >( field.constraints().constraintStrength( QgsFieldConstraints::ConstraintNotNull ) );
523  out << static_cast< quint32 >( field.constraints().constraintStrength( QgsFieldConstraints::ConstraintUnique ) );
524  out << static_cast< quint32 >( field.constraints().constraintStrength( QgsFieldConstraints::ConstraintExpression ) );
525  out << field.constraints().constraintExpression();
526  out << field.constraints().constraintDescription();
527  out << static_cast< quint32 >( field.subType() );
528  return out;
529 }
530 
531 QDataStream &operator>>( QDataStream &in, QgsField &field )
532 {
533  quint32 type;
534  quint32 subType;
535  quint32 length;
536  quint32 precision;
537  quint32 constraints;
538  quint32 originNotNull;
539  quint32 originUnique;
540  quint32 originExpression;
541  quint32 strengthNotNull;
542  quint32 strengthUnique;
543  quint32 strengthExpression;
544 
545  bool applyOnUpdate;
546 
547  QString name;
548  QString typeName;
549  QString comment;
550  QString alias;
551  QString defaultValueExpression;
552  QString constraintExpression;
553  QString constraintDescription;
554 
555  in >> name >> type >> typeName >> length >> precision >> comment >> alias
556  >> defaultValueExpression >> applyOnUpdate >> constraints >> originNotNull >> originUnique >> originExpression >> strengthNotNull >> strengthUnique >> strengthExpression >>
557  constraintExpression >> constraintDescription >> subType;
558  field.setName( name );
559  field.setType( static_cast< QVariant::Type >( type ) );
560  field.setTypeName( typeName );
561  field.setLength( static_cast< int >( length ) );
562  field.setPrecision( static_cast< int >( precision ) );
563  field.setComment( comment );
564  field.setAlias( alias );
565  field.setDefaultValueDefinition( QgsDefaultValue( defaultValueExpression, applyOnUpdate ) );
566  QgsFieldConstraints fieldConstraints;
567  if ( constraints & QgsFieldConstraints::ConstraintNotNull )
568  {
569  fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintNotNull, static_cast< QgsFieldConstraints::ConstraintOrigin>( originNotNull ) );
571  }
572  else
574  if ( constraints & QgsFieldConstraints::ConstraintUnique )
575  {
576  fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintUnique, static_cast< QgsFieldConstraints::ConstraintOrigin>( originUnique ) );
578  }
579  else
581  if ( constraints & QgsFieldConstraints::ConstraintExpression )
582  {
583  fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintExpression, static_cast< QgsFieldConstraints::ConstraintOrigin>( originExpression ) );
585  }
586  else
588  fieldConstraints.setConstraintExpression( constraintExpression, constraintDescription );
589  field.setConstraints( fieldConstraints );
590  field.setSubType( static_cast< QVariant::Type >( subType ) );
591  return in;
592 }
qgsPermissiveToDouble
double qgsPermissiveToDouble(QString string, bool &ok)
Converts a string to a double in a permissive way, e.g., allowing for incorrect numbers of digits bet...
Definition: qgis.cpp:65
qgsfields.h
QgsField::isNumeric
bool isNumeric
Definition: qgsfield.h:53
qgsfield_p.h
QgsFieldConstraints::setConstraintExpression
void setConstraintExpression(const QString &expression, const QString &description=QString())
Set the constraint expression for the field.
Definition: qgsfieldconstraints.cpp:72
QgsDefaultValue
The QgsDefaultValue class provides a container for managing client side default values for fields.
Definition: qgsdefaultvalue.h:48
QgsField::setSubType
void setSubType(QVariant::Type subType)
If the field is a collection, set its element's type.
Definition: qgsfield.cpp:185
QgsFieldConstraints::setConstraint
void setConstraint(Constraint constraint, ConstraintOrigin origin=ConstraintOriginLayer)
Sets a constraint on the field.
Definition: qgsfieldconstraints.cpp:48
QgsField::setAlias
void setAlias(const QString &alias)
Sets the alias for the field (the friendly displayed name of the field ).
Definition: qgsfield.cpp:234
QgsField::displayString
QString displayString(const QVariant &v) const
Formats string for display.
Definition: qgsfield.cpp:245
QgsEditorWidgetSetup
Definition: qgseditorwidgetsetup.h:28
QgsField::length
int length
Definition: qgsfield.h:55
QgsField::operator==
bool operator==(const QgsField &other) const
Definition: qgsfield.cpp:74
QgsField::isDateOrTime
bool isDateOrTime
Definition: qgsfield.h:54
QgsFieldConstraints
Definition: qgsfieldconstraints.h:32
QgsField::displayNameWithAlias
QString displayNameWithAlias() const
Returns the name to use when displaying this field and adds the alias in parenthesis if it is defined...
Definition: qgsfield.cpp:97
QgsFieldConstraints::constraintExpression
QString constraintExpression() const
Returns the constraint expression for the field, if set.
Definition: qgsfieldconstraints.cpp:67
qgis.h
QgsField::typeName
QString typeName() const
Gets the field type.
Definition: qgsfield.cpp:139
QgsField::operator=
QgsField & operator=(const QgsField &other)
Assignment operator.
Definition: qgsfield.cpp:68
QgsField::setConstraints
void setConstraints(const QgsFieldConstraints &constraints)
Sets constraints which are present for the field.
Definition: qgsfield.cpp:219
QgsField::name
QString name
Definition: qgsfield.h:59
QgsFieldConstraints::ConstraintNotNull
@ ConstraintNotNull
Field may not be null.
Definition: qgsfieldconstraints.h:45
QgsFieldConstraints::setConstraintStrength
void setConstraintStrength(Constraint constraint, ConstraintStrength strength)
Sets the strength of a constraint.
Definition: qgsfieldconstraints.cpp:36
qgsapplication.h
QgsField::setEditorWidgetSetup
void setEditorWidgetSetup(const QgsEditorWidgetSetup &v)
Set the editor widget setup for the field.
Definition: qgsfield.cpp:491
qgsPermissiveToInt
int qgsPermissiveToInt(QString string, bool &ok)
Converts a string to an integer in a permissive way, e.g., allowing for incorrect numbers of digits b...
Definition: qgis.cpp:72
QgsField::precision
int precision
Definition: qgsfield.h:56
operator>>
QDataStream & operator>>(QDataStream &in, QgsField &field)
Reads a field from stream in into field. QGIS version compatibility is not guaranteed.
Definition: qgsfield.cpp:531
QgsField::operator!=
bool operator!=(const QgsField &other) const
Definition: qgsfield.cpp:79
precision
int precision
Definition: qgswfsgetfeature.cpp:103
QgsField::setTypeName
void setTypeName(const QString &typeName)
Set the field type.
Definition: qgsfield.cpp:190
QgsField::~QgsField
virtual ~QgsField()
QgsApplication::nullRepresentation
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
Definition: qgsapplication.cpp:1802
QgsFieldConstraints::removeConstraint
void removeConstraint(Constraint constraint)
Removes a constraint from the field.
Definition: qgsfieldconstraints.h:117
QgsFieldConstraints::constraints
Constraints constraints
Definition: qgsfieldconstraints.h:36
QgsField::QgsField
QgsField(const QString &name=QString(), QVariant::Type type=QVariant::Invalid, const QString &typeName=QString(), int len=0, int prec=0, const QString &comment=QString(), QVariant::Type subType=QVariant::Invalid)
Constructor.
Definition: qgsfield.cpp:47
QgsFieldConstraints::ConstraintOrigin
ConstraintOrigin
Origin of constraints.
Definition: qgsfieldconstraints.h:54
QgsField::defaultValueDefinition
QgsDefaultValue defaultValueDefinition
Definition: qgsfield.h:61
QgsField::convertCompatible
bool convertCompatible(QVariant &v) const
Converts the provided variant to a compatible format.
Definition: qgsfield.cpp:339
QgsField::comment
QString comment
Definition: qgsfield.h:58
QgsFieldConstraints::ConstraintUnique
@ ConstraintUnique
Field must have a unique value.
Definition: qgsfieldconstraints.h:46
QgsField::setLength
void setLength(int len)
Set the field length.
Definition: qgsfield.cpp:195
qgsPermissiveToLongLong
qlonglong qgsPermissiveToLongLong(QString string, bool &ok)
Converts a string to an qlonglong in a permissive way, e.g., allowing for incorrect numbers of digits...
Definition: qgis.cpp:79
typeName
const QString & typeName
Definition: qgswfsgetfeature.cpp:109
QgsFieldConstraints::constraintStrength
ConstraintStrength constraintStrength(Constraint constraint) const
Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not pres...
Definition: qgsfieldconstraints.cpp:27
QgsFieldConstraints::constraintDescription
QString constraintDescription() const
Returns the descriptive name for the constraint expression.
Definition: qgsfieldconstraints.h:133
QgsField::subType
QVariant::Type subType() const
If the field is a collection, gets its element's type.
Definition: qgsfield.cpp:134
QgsField::displayType
QString displayType(bool showConstraints=false) const
Returns the type to use when displaying this field, including the length and precision of the datatyp...
Definition: qgsfield.cpp:106
QgsField::setPrecision
void setPrecision(int precision)
Set the field precision.
Definition: qgsfield.cpp:199
QgsDefaultValue::expression
QString expression
Definition: qgsdefaultvalue.h:66
qgssettings.h
QgsFieldConstraints::ConstraintExpression
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
Definition: qgsfieldconstraints.h:47
QgsField::constraints
QgsFieldConstraints constraints
Definition: qgsfield.h:62
operator<<
QDataStream & operator<<(QDataStream &out, const QgsField &field)
Writes the field to stream out. QGIS version compatibility is not guaranteed.
Definition: qgsfield.cpp:507
QgsField::setDefaultValueDefinition
void setDefaultValueDefinition(const QgsDefaultValue &defaultValueDefinition)
Sets an expression to use when calculating the default value for the field.
Definition: qgsfield.cpp:214
QgsField::setComment
void setComment(const QString &comment)
Set the field comment.
Definition: qgsfield.cpp:204
QgsField::displayName
QString displayName() const
Returns the name to use when displaying this field.
Definition: qgsfield.cpp:89
QgsField::setType
void setType(QVariant::Type type)
Set variant type.
Definition: qgsfield.cpp:180
QgsFieldConstraints::ConstraintStrength
ConstraintStrength
Strength of constraints.
Definition: qgsfieldconstraints.h:64
QgsDefaultValue::applyOnUpdate
bool applyOnUpdate
Definition: qgsdefaultvalue.h:67
QgsField::editorWidgetSetup
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Definition: qgsfield.cpp:496
QgsField::type
QVariant::Type type
Definition: qgsfield.h:57
QgsField::setName
void setName(const QString &name)
Set the field name.
Definition: qgsfield.cpp:175
QgsFieldConstraints::constraintOrigin
ConstraintOrigin constraintOrigin(Constraint constraint) const
Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present ...
Definition: qgsfieldconstraints.cpp:19
QgsField::alias
QString alias
Definition: qgsfield.h:60
QgsField
Definition: qgsfield.h:49