QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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, QVariant::Type subType )
49 {
50  d = new QgsFieldPrivate( name, type, subType, typeName, len, prec, comment );
51 }
52 
53 QgsField::QgsField( const QgsField &other ) //NOLINT
54  : d( other.d )
55 {
56 
57 }
58 
59 QgsField::~QgsField() = default;
60 
61 /***************************************************************************
62  * This class is considered CRITICAL and any change MUST be accompanied with
63  * full unit tests in testqgsfield.cpp.
64  * See details in QEP #17
65  ****************************************************************************/
66 
67 QgsField &QgsField::operator =( const QgsField &other ) //NOLINT
68 {
69  d = other.d;
70  return *this;
71 }
72 
73 bool QgsField::operator==( const QgsField &other ) const
74 {
75  return *( other.d ) == *d;
76 }
77 
78 bool QgsField::operator!=( const QgsField &other ) const
79 {
80  return !( *this == other );
81 }
82 
83 QString QgsField::name() const
84 {
85  return d->name;
86 }
87 
88 QString QgsField::displayName() const
89 {
90  if ( !d->alias.isEmpty() )
91  return d->alias;
92  else
93  return d->name;
94 }
95 
97 {
98  if ( alias().isEmpty() )
99  {
100  return name();
101  }
102  return QStringLiteral( "%1 (%2)" ).arg( name() ).arg( alias() );
103 }
104 
105 QString QgsField::displayType( const bool showConstraints ) const
106 {
107  QString typeStr = typeName();
108 
109  if ( length() > 0 && precision() > 0 )
110  typeStr += QStringLiteral( "(%1, %2)" ).arg( length() ).arg( precision() );
111  else if ( length() > 0 )
112  typeStr += QStringLiteral( "(%1)" ).arg( length() );
113 
114  if ( showConstraints )
115  {
117  ? QStringLiteral( " NOT NULL" )
118  : QStringLiteral( " NULL" );
119 
121  ? QStringLiteral( " UNIQUE" )
122  : QString();
123  }
124 
125  return typeStr;
126 }
127 
128 QVariant::Type QgsField::type() const
129 {
130  return d->type;
131 }
132 
133 QVariant::Type QgsField::subType() const
134 {
135  return d->subType;
136 }
137 
138 QString QgsField::typeName() const
139 {
140  return d->typeName;
141 }
142 
143 int QgsField::length() const
144 {
145  return d->length;
146 }
147 
149 {
150  return d->precision;
151 }
152 
153 QString QgsField::comment() const
154 {
155  return d->comment;
156 }
157 
159 {
160  return d->type == QVariant::Double || d->type == QVariant::Int || d->type == QVariant::UInt || d->type == QVariant::LongLong || d->type == QVariant::ULongLong;
161 }
162 
164 {
165  return d->type == QVariant::Date || d->type == QVariant::Time || d->type == QVariant::DateTime;
166 }
167 
168 /***************************************************************************
169  * This class is considered CRITICAL and any change MUST be accompanied with
170  * full unit tests in testqgsfield.cpp.
171  * See details in QEP #17
172  ****************************************************************************/
173 
174 void QgsField::setName( const QString &name )
175 {
176  d->name = name;
177 }
178 
179 void QgsField::setType( QVariant::Type type )
180 {
181  d->type = type;
182 }
183 
184 void QgsField::setSubType( QVariant::Type subType )
185 {
186  d->subType = subType;
187 }
188 
189 void QgsField::setTypeName( const QString &typeName )
190 {
191  d->typeName = typeName;
192 }
193 
194 void QgsField::setLength( int len )
195 {
196  d->length = len;
197 }
199 {
200  d->precision = precision;
201 }
202 
203 void QgsField::setComment( const QString &comment )
204 {
205  d->comment = comment;
206 }
207 
209 {
210  return d->defaultValueDefinition;
211 }
212 
213 void QgsField::setDefaultValueDefinition( const QgsDefaultValue &defaultValueDefinition )
214 {
215  d->defaultValueDefinition = defaultValueDefinition;
216 }
217 
219 {
220  d->constraints = constraints;
221 }
222 
224 {
225  return d->constraints;
226 }
227 
228 QString QgsField::alias() const
229 {
230  return d->alias;
231 }
232 
233 void QgsField::setAlias( const QString &alias )
234 {
235  d->alias = alias;
236 }
237 
238 QgsField::ConfigurationFlags QgsField::configurationFlags() const
239 {
240  return d->flags;
241 }
242 
243 void QgsField::setConfigurationFlags( QgsField::ConfigurationFlags flags )
244 {
245  d->flags = flags;
246 }
247 
248 /***************************************************************************
249  * This class is considered CRITICAL and any change MUST be accompanied with
250  * full unit tests in testqgsfield.cpp.
251  * See details in QEP #17
252  ****************************************************************************/
253 
254 QString QgsField::displayString( const QVariant &v ) const
255 {
256  if ( v.isNull() )
257  {
259  }
260 
261  // Special treatment for numeric types if group separator is set or decimalPoint is not a dot
262  if ( d->type == QVariant::Double )
263  {
264  // if value doesn't contain a double (a default value expression for instance),
265  // apply no transformation
266  bool ok;
267  v.toDouble( &ok );
268  if ( !ok )
269  return v.toString();
270 
271  // Locales with decimal point != '.' or that require group separator: use QLocale
272  if ( QLocale().decimalPoint() != '.' ||
273  !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
274  {
275  if ( d->precision > 0 )
276  {
277  if ( -1 < v.toDouble() && v.toDouble() < 1 )
278  {
279  return QLocale().toString( v.toDouble(), 'g', d->precision );
280  }
281  else
282  {
283  return QLocale().toString( v.toDouble(), 'f', d->precision );
284  }
285  }
286  else
287  {
288  // Precision is not set, let's guess it from the
289  // standard conversion to string
290  QString s( v.toString() );
291  int dotPosition( s.indexOf( '.' ) );
292  int precision;
293  if ( dotPosition < 0 && s.indexOf( 'e' ) < 0 )
294  {
295  precision = 0;
296  return QLocale().toString( v.toDouble(), 'f', precision );
297  }
298  else
299  {
300  if ( dotPosition < 0 ) precision = 0;
301  else precision = s.length() - dotPosition - 1;
302 
303  if ( -1 < v.toDouble() && v.toDouble() < 1 )
304  {
305  return QLocale().toString( v.toDouble(), 'g', precision );
306  }
307  else
308  {
309  return QLocale().toString( v.toDouble(), 'f', precision );
310  }
311  }
312  }
313  }
314  // Default for doubles with precision
315  else if ( d->type == QVariant::Double && d->precision > 0 )
316  {
317  if ( -1 < v.toDouble() && v.toDouble() < 1 )
318  {
319  return QString::number( v.toDouble(), 'g', d->precision );
320  }
321  else
322  {
323  return QString::number( v.toDouble(), 'f', d->precision );
324  }
325  }
326  }
327  // Other numeric types than doubles
328  else if ( isNumeric() &&
329  !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
330  {
331  bool ok;
332  qlonglong converted( v.toLongLong( &ok ) );
333  if ( ok )
334  return QLocale().toString( converted );
335  }
336  else if ( d->typeName.compare( QLatin1String( "json" ), Qt::CaseInsensitive ) == 0 || d->typeName == QLatin1String( "jsonb" ) )
337  {
338  QJsonDocument doc = QJsonDocument::fromVariant( v );
339  return QString::fromUtf8( doc.toJson().data() );
340  }
341  else if ( d->type == QVariant::ByteArray )
342  {
343  return QObject::tr( "BLOB" );
344  }
345  // Fallback if special rules do not apply
346  return v.toString();
347 }
348 
350 {
351  switch ( flag )
352  {
354  return QObject::tr( "None" );
356  return QObject::tr( "Not searchable" );
358  return QStringLiteral( "Do not expose via WMS" );
360  return QStringLiteral( "Do not expose via WFS" );
361  }
362  return QString();
363 }
364 
365 /***************************************************************************
366  * This class is considered CRITICAL and any change MUST be accompanied with
367  * full unit tests in testqgsfield.cpp.
368  * See details in QEP #17
369  ****************************************************************************/
370 
371 bool QgsField::convertCompatible( QVariant &v, QString *errorMessage ) const
372 {
373  const QVariant original = v;
374  if ( errorMessage )
375  errorMessage->clear();
376 
377  if ( v.isNull() )
378  {
379  v.convert( d->type );
380  return true;
381  }
382 
383  if ( d->type == QVariant::Int && v.toInt() != v.toLongLong() )
384  {
385  v = QVariant( d->type );
386  if ( errorMessage )
387  *errorMessage = QObject::tr( "Value \"%1\" is too large for integer field" ).arg( original.toLongLong() );
388  return false;
389  }
390 
391  // Give it a chance to convert to double since for not '.' locales
392  // we accept both comma and dot as decimal point
393  if ( d->type == QVariant::Double && v.type() == QVariant::String )
394  {
395  QVariant tmp( v );
396  if ( !tmp.convert( d->type ) )
397  {
398  // This might be a string with thousand separator: use locale to convert
399  bool ok = false;
400  double d = qgsPermissiveToDouble( v.toString(), ok );
401  if ( ok )
402  {
403  v = QVariant( d );
404  return true;
405  }
406  // For not 'dot' locales, we also want to accept '.'
407  if ( QLocale().decimalPoint() != '.' )
408  {
409  d = QLocale( QLocale::C ).toDouble( v.toString(), &ok );
410  if ( ok )
411  {
412  v = QVariant( d );
413  return true;
414  }
415  }
416  }
417  }
418 
419  // For string representation of an int we also might have thousand separator
420  if ( d->type == QVariant::Int && v.type() == QVariant::String )
421  {
422  QVariant tmp( v );
423  if ( !tmp.convert( d->type ) )
424  {
425  // This might be a string with thousand separator: use locale to convert
426  bool ok;
427  int i = qgsPermissiveToInt( v.toString(), ok );
428  if ( ok )
429  {
430  v = QVariant( i );
431  return true;
432  }
433  }
434  }
435 
436  // For string representation of a long we also might have thousand separator
437  if ( d->type == QVariant::LongLong && v.type() == QVariant::String )
438  {
439  QVariant tmp( v );
440  if ( !tmp.convert( d->type ) )
441  {
442  // This might be a string with thousand separator: use locale to convert
443  bool ok;
444  qlonglong l = qgsPermissiveToLongLong( v.toString(), ok );
445  if ( ok )
446  {
447  v = QVariant( l );
448  return true;
449  }
450  }
451  }
452 
453  //String representations of doubles in QVariant will return false to convert( QVariant::Int )
454  //work around this by first converting to double, and then checking whether the double is convertible to int
455  if ( d->type == QVariant::Int && v.canConvert( QVariant::Double ) )
456  {
457  bool ok = false;
458  double dbl = v.toDouble( &ok );
459  if ( !ok )
460  {
461  //couldn't convert to number
462  v = QVariant( d->type );
463 
464  if ( errorMessage )
465  *errorMessage = QObject::tr( "Value \"%1\" is not a number" ).arg( original.toString() );
466 
467  return false;
468  }
469 
470  double round = std::round( dbl );
471  if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
472  {
473  //double too large to fit in int
474  v = QVariant( d->type );
475 
476  if ( errorMessage )
477  *errorMessage = QObject::tr( "Value \"%1\" is too large for integer field" ).arg( original.toDouble() );
478 
479  return false;
480  }
481  v = QVariant( static_cast< int >( std::round( dbl ) ) );
482  return true;
483  }
484 
485  //String representations of doubles in QVariant will return false to convert( QVariant::LongLong )
486  //work around this by first converting to double, and then checking whether the double is convertible to longlong
487  if ( d->type == QVariant::LongLong && v.canConvert( QVariant::Double ) )
488  {
489  //firstly test the conversion to longlong because conversion to double will rounded the value
490  QVariant tmp( v );
491  if ( !tmp.convert( d->type ) )
492  {
493  bool ok = false;
494  double dbl = v.toDouble( &ok );
495  if ( !ok )
496  {
497  //couldn't convert to number
498  v = QVariant( d->type );
499 
500  if ( errorMessage )
501  *errorMessage = QObject::tr( "Value \"%1\" is not a number" ).arg( original.toString() );
502 
503  return false;
504  }
505 
506  double round = std::round( dbl );
507  if ( round > static_cast<double>( std::numeric_limits<long long>::max() ) || round < static_cast<double>( -std::numeric_limits<long long>::max() ) )
508  {
509  //double too large to fit in longlong
510  v = QVariant( d->type );
511 
512  if ( errorMessage )
513  *errorMessage = QObject::tr( "Value \"%1\" is too large for long long field" ).arg( original.toDouble() );
514 
515  return false;
516  }
517  v = QVariant( static_cast< long long >( std::round( dbl ) ) );
518  return true;
519  }
520  }
521 
522  if ( !v.convert( d->type ) )
523  {
524  v = QVariant( d->type );
525 
526  if ( errorMessage )
527  *errorMessage = QObject::tr( "Could not convert value \"%1\" to target type" ).arg( original.toString() );
528 
529  return false;
530  }
531 
532  if ( d->type == QVariant::Double && d->precision > 0 )
533  {
534  double s = std::pow( 10, d->precision );
535  double d = v.toDouble() * s;
536  v = QVariant( ( d < 0 ? std::ceil( d - 0.5 ) : std::floor( d + 0.5 ) ) / s );
537  return true;
538  }
539 
540  if ( d->type == QVariant::String && d->length > 0 && v.toString().length() > d->length )
541  {
542  const int length = v.toString().length();
543  v = v.toString().left( d->length );
544 
545  if ( errorMessage )
546  *errorMessage = QObject::tr( "String of length %1 exceeds maximum field length (%2)" ).arg( length ).arg( d->length );
547 
548  return false;
549  }
550 
551  return true;
552 }
553 
555 {
556  d->editorWidgetSetup = v;
557 }
558 
560 {
561  return d->editorWidgetSetup;
562 }
563 
564 /***************************************************************************
565  * This class is considered CRITICAL and any change MUST be accompanied with
566  * full unit tests in testqgsfield.cpp.
567  * See details in QEP #17
568  ****************************************************************************/
569 
570 QDataStream &operator<<( QDataStream &out, const QgsField &field )
571 {
572  out << field.name();
573  out << static_cast< quint32 >( field.type() );
574  out << field.typeName();
575  out << field.length();
576  out << field.precision();
577  out << field.comment();
578  out << field.alias();
581  out << field.constraints().constraints();
582  out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintNotNull ) );
583  out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintUnique ) );
584  out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintExpression ) );
585  out << static_cast< quint32 >( field.constraints().constraintStrength( QgsFieldConstraints::ConstraintNotNull ) );
586  out << static_cast< quint32 >( field.constraints().constraintStrength( QgsFieldConstraints::ConstraintUnique ) );
590  out << static_cast< quint32 >( field.subType() );
591  return out;
592 }
593 
594 QDataStream &operator>>( QDataStream &in, QgsField &field )
595 {
596  quint32 type;
597  quint32 subType;
598  quint32 length;
599  quint32 precision;
600  quint32 constraints;
601  quint32 originNotNull;
602  quint32 originUnique;
603  quint32 originExpression;
604  quint32 strengthNotNull;
605  quint32 strengthUnique;
606  quint32 strengthExpression;
607 
608  bool applyOnUpdate;
609 
610  QString name;
611  QString typeName;
612  QString comment;
613  QString alias;
614  QString defaultValueExpression;
615  QString constraintExpression;
616  QString constraintDescription;
617 
618  in >> name >> type >> typeName >> length >> precision >> comment >> alias
619  >> defaultValueExpression >> applyOnUpdate >> constraints >> originNotNull >> originUnique >> originExpression >> strengthNotNull >> strengthUnique >> strengthExpression >>
620  constraintExpression >> constraintDescription >> subType;
621  field.setName( name );
622  field.setType( static_cast< QVariant::Type >( type ) );
624  field.setLength( static_cast< int >( length ) );
625  field.setPrecision( static_cast< int >( precision ) );
626  field.setComment( comment );
627  field.setAlias( alias );
628  field.setDefaultValueDefinition( QgsDefaultValue( defaultValueExpression, applyOnUpdate ) );
629  QgsFieldConstraints fieldConstraints;
630  if ( constraints & QgsFieldConstraints::ConstraintNotNull )
631  {
632  fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintNotNull, static_cast< QgsFieldConstraints::ConstraintOrigin>( originNotNull ) );
634  }
635  else
637  if ( constraints & QgsFieldConstraints::ConstraintUnique )
638  {
639  fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintUnique, static_cast< QgsFieldConstraints::ConstraintOrigin>( originUnique ) );
641  }
642  else
644  if ( constraints & QgsFieldConstraints::ConstraintExpression )
645  {
646  fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintExpression, static_cast< QgsFieldConstraints::ConstraintOrigin>( originExpression ) );
648  }
649  else
651  fieldConstraints.setConstraintExpression( constraintExpression, constraintDescription );
652  field.setConstraints( fieldConstraints );
653  field.setSubType( static_cast< QVariant::Type >( subType ) );
654  return in;
655 }
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_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:49
QgsField::setSubType
void setSubType(QVariant::Type subType)
If the field is a collection, set its element's type.
Definition: qgsfield.cpp:184
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:233
QgsField::displayString
QString displayString(const QVariant &v) const
Formats string for display.
Definition: qgsfield.cpp:254
QgsEditorWidgetSetup
Holder for the widget type and its configuration for a field.
Definition: qgseditorwidgetsetup.h:29
QgsField::ConfigurationFlag
ConfigurationFlag
Configuration flags for fields These flags are meant to be user-configurable and are not describing a...
Definition: qgsfield.h:82
QgsField::length
int length
Definition: qgsfield.h:55
QgsField::operator==
bool operator==(const QgsField &other) const
Definition: qgsfield.cpp:73
QgsField::isDateOrTime
bool isDateOrTime
Definition: qgsfield.h:54
QgsFieldConstraints
Stores information about constraints which may be present on a field.
Definition: qgsfieldconstraints.h:33
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:96
QgsField::ConfigurationFlag::None
@ None
No flag is defined.
QgsField::isNumeric
Q_GADGET bool isNumeric
Definition: qgsfield.h:53
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:138
QgsField::operator=
QgsField & operator=(const QgsField &other)
Assignment operator.
Definition: qgsfield.cpp:67
field
const QgsField & field
Definition: qgsfield.h:456
QgsField::setConstraints
void setConstraints(const QgsFieldConstraints &constraints)
Sets constraints which are present for the field.
Definition: qgsfield.cpp:218
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:554
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
QgsField::setConfigurationFlags
void setConfigurationFlags(QgsField::ConfigurationFlags configurationFlags)
Sets the Flags for the field (searchable, …)
Definition: qgsfield.cpp:243
operator>>
QDataStream & operator>>(QDataStream &in, QgsField &field)
Reads a field from stream in into field. QGIS version compatibility is not guaranteed.
Definition: qgsfield.cpp:594
QgsField::operator!=
bool operator!=(const QgsField &other) const
Definition: qgsfield.cpp:78
precision
int precision
Definition: qgswfsgetfeature.cpp:49
QgsField::setTypeName
void setTypeName(const QString &typeName)
Set the field type.
Definition: qgsfield.cpp:189
QgsField::~QgsField
virtual ~QgsField()
QgsApplication::nullRepresentation
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
Definition: qgsapplication.cpp:1851
QgsFieldConstraints::removeConstraint
void removeConstraint(Constraint constraint)
Removes a constraint from the field.
Definition: qgsfieldconstraints.h:117
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:55
QgsField::readableConfigurationFlag
static QString readableConfigurationFlag(QgsField::ConfigurationFlag flag)
Returns the reabable and translated value of the configuration flag.
Definition: qgsfield.cpp:349
QgsField::defaultValueDefinition
QgsDefaultValue defaultValueDefinition
Definition: qgsfield.h:61
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:194
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
QgsDefaultValue::expression
Q_GADGET QString expression
Definition: qgsdefaultvalue.h:52
typeName
const QString & typeName
Definition: qgswfsgetfeature.cpp:55
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:133
QgsField::ConfigurationFlag::NotSearchable
@ NotSearchable
Defines if the field is searchable (used in the locator search for instance)
QgsField::configurationFlags
ConfigurationFlags configurationFlags
Definition: qgsfield.h:63
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:105
QgsField::setPrecision
void setPrecision(int precision)
Set the field precision.
Definition: qgsfield.cpp:198
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)
Definition: qgsfield.cpp:570
QgsField::setDefaultValueDefinition
void setDefaultValueDefinition(const QgsDefaultValue &defaultValueDefinition)
Sets an expression to use when calculating the default value for the field.
Definition: qgsfield.cpp:213
QgsField::setComment
void setComment(const QString &comment)
Set the field comment.
Definition: qgsfield.cpp:203
QgsField::displayName
QString displayName() const
Returns the name to use when displaying this field.
Definition: qgsfield.cpp:88
QgsField::setType
void setType(QVariant::Type type)
Set variant type.
Definition: qgsfield.cpp:179
QgsFieldConstraints::constraints
Q_GADGET Constraints constraints
Definition: qgsfieldconstraints.h:36
QgsFieldConstraints::ConstraintStrength
ConstraintStrength
Strength of constraints.
Definition: qgsfieldconstraints.h:65
QgsDefaultValue::applyOnUpdate
bool applyOnUpdate
Definition: qgsdefaultvalue.h:53
QgsField::editorWidgetSetup
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Definition: qgsfield.cpp:559
QgsField::ConfigurationFlag::HideFromWfs
@ HideFromWfs
Fields is available if layer is served as WFS from QGIS server.
QgsField::convertCompatible
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Definition: qgsfield.cpp:371
QgsField::ConfigurationFlag::HideFromWms
@ HideFromWms
Fields is available if layer is served as WMS from QGIS server.
QgsField::type
QVariant::Type type
Definition: qgsfield.h:57
QgsField::setName
void setName(const QString &name)
Set the field name.
Definition: qgsfield.cpp:174
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
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50