QGIS API Documentation  3.23.0-Master (b5237dafc3)
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 #include "qgsreferencedgeometry.h"
23 
24 #include <QDataStream>
25 #include <QIcon>
26 #include <QLocale>
27 #include <QJsonDocument>
28 
29 /***************************************************************************
30  * This class is considered CRITICAL and any change MUST be accompanied with
31  * full unit tests in testqgsfield.cpp.
32  * See details in QEP #17
33  ****************************************************************************/
34 
35 #if 0
36 QgsField::QgsField( QString nam, QString typ, int len, int prec, bool num,
37  QString comment )
38  : mName( nam ), mType( typ ), mLength( len ), mPrecision( prec ), mNumeric( num )
39  , mComment( comment )
40 {
41  // This function used to lower case the field name since some stores
42  // use upper case (e.g., shapefiles), but that caused problems with
43  // attribute actions getting confused between uppercase and
44  // lowercase versions of the attribute names, so just leave the
45  // names how they are now.
46 }
47 #endif
48 QgsField::QgsField( const QString &name, QVariant::Type type,
49  const QString &typeName, int len, int prec, const QString &comment, 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 
150 {
151  return d->precision;
152 }
153 
154 QString QgsField::comment() const
155 {
156  return d->comment;
157 }
158 
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 
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 QgsField::ConfigurationFlags QgsField::configurationFlags() const
240 {
241  return d->flags;
242 }
243 
244 void QgsField::setConfigurationFlags( QgsField::ConfigurationFlags flags )
245 {
246  d->flags = flags;
247 }
248 
249 /***************************************************************************
250  * This class is considered CRITICAL and any change MUST be accompanied with
251  * full unit tests in testqgsfield.cpp.
252  * See details in QEP #17
253  ****************************************************************************/
254 
255 QString QgsField::displayString( const QVariant &v ) const
256 {
257  if ( v.isNull() )
258  {
260  }
261 
262  if ( v.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
263  {
264  QgsReferencedGeometry geom = qvariant_cast<QgsReferencedGeometry>( v );
265  if ( geom.isNull() )
267  else
268  {
269  QString wkt = geom.asWkt();
270  if ( wkt.length() >= 1050 )
271  {
272  wkt = wkt.left( 999 ) + QChar( 0x2026 );
273  }
274  QString formattedText = QStringLiteral( "%1 [%2]" ).arg( wkt, geom.crs().userFriendlyIdentifier() );
275  return formattedText;
276  }
277  }
278 
279  // Special treatment for numeric types if group separator is set or decimalPoint is not a dot
280  if ( d->type == QVariant::Double )
281  {
282  // if value doesn't contain a double (a default value expression for instance),
283  // apply no transformation
284  bool ok;
285  v.toDouble( &ok );
286  if ( !ok )
287  return v.toString();
288 
289  // Locales with decimal point != '.' or that require group separator: use QLocale
290  if ( QLocale().decimalPoint() != '.' ||
291  !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
292  {
293  if ( d->precision > 0 )
294  {
295  if ( -1 < v.toDouble() && v.toDouble() < 1 )
296  {
297  return QLocale().toString( v.toDouble(), 'g', d->precision );
298  }
299  else
300  {
301  return QLocale().toString( v.toDouble(), 'f', d->precision );
302  }
303  }
304  else
305  {
306  // Precision is not set, let's guess it from the
307  // standard conversion to string
308  const QString s( v.toString() );
309  const int dotPosition( s.indexOf( '.' ) );
310  int precision;
311  if ( dotPosition < 0 && s.indexOf( 'e' ) < 0 )
312  {
313  precision = 0;
314  return QLocale().toString( v.toDouble(), 'f', precision );
315  }
316  else
317  {
318  if ( dotPosition < 0 ) precision = 0;
319  else precision = s.length() - dotPosition - 1;
320 
321  if ( -1 < v.toDouble() && v.toDouble() < 1 )
322  {
323  return QLocale().toString( v.toDouble(), 'g', precision );
324  }
325  else
326  {
327  return QLocale().toString( v.toDouble(), 'f', precision );
328  }
329  }
330  }
331  }
332  // Default for doubles with precision
333  else if ( d->precision > 0 )
334  {
335  if ( -1 < v.toDouble() && v.toDouble() < 1 )
336  {
337  return QString::number( v.toDouble(), 'g', d->precision );
338  }
339  else
340  {
341  return QString::number( v.toDouble(), 'f', d->precision );
342  }
343  }
344  }
345  // Other numeric types than doubles
346  else if ( isNumeric() &&
347  !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
348  {
349  bool ok;
350  const qlonglong converted( v.toLongLong( &ok ) );
351  if ( ok )
352  return QLocale().toString( converted );
353  }
354  else if ( d->typeName.compare( QLatin1String( "json" ), Qt::CaseInsensitive ) == 0 || d->typeName == QLatin1String( "jsonb" ) )
355  {
356  const QJsonDocument doc = QJsonDocument::fromVariant( v );
357  return QString::fromUtf8( doc.toJson().data() );
358  }
359  else if ( d->type == QVariant::ByteArray )
360  {
361  return QObject::tr( "BLOB" );
362  }
363  else if ( d->type == QVariant::StringList || d->type == QVariant::List )
364  {
365  QString result;
366  const QVariantList list = v.toList();
367  for ( const QVariant &var : list )
368  {
369  if ( !result.isEmpty() )
370  result.append( QStringLiteral( ", " ) );
371  result.append( var.toString() );
372  }
373  return result;
374  }
375 
376  // Fallback if special rules do not apply
377  return v.toString();
378 }
379 
381 {
382  switch ( flag )
383  {
385  return QObject::tr( "None" );
387  return QObject::tr( "Not searchable" );
389  return QObject::tr( "Do not expose via WMS" );
391  return QObject::tr( "Do not expose via WFS" );
392  }
393  return QString();
394 }
395 
396 /***************************************************************************
397  * This class is considered CRITICAL and any change MUST be accompanied with
398  * full unit tests in testqgsfield.cpp.
399  * See details in QEP #17
400  ****************************************************************************/
401 
402 bool QgsField::convertCompatible( QVariant &v, QString *errorMessage ) const
403 {
404  const QVariant original = v;
405  if ( errorMessage )
406  errorMessage->clear();
407 
408  if ( v.isNull() )
409  {
410  v.convert( d->type );
411  return true;
412  }
413 
414  if ( d->type == QVariant::Int && v.toInt() != v.toLongLong() )
415  {
416  v = QVariant( d->type );
417  if ( errorMessage )
418  *errorMessage = QObject::tr( "Value \"%1\" is too large for integer field" ).arg( original.toLongLong() );
419  return false;
420  }
421 
422  // Give it a chance to convert to double since for not '.' locales
423  // we accept both comma and dot as decimal point
424  if ( d->type == QVariant::Double && v.type() == QVariant::String )
425  {
426  QVariant tmp( v );
427  if ( !tmp.convert( d->type ) )
428  {
429  // This might be a string with thousand separator: use locale to convert
430  bool ok = false;
431  double d = qgsPermissiveToDouble( v.toString(), ok );
432  if ( ok )
433  {
434  v = QVariant( d );
435  return true;
436  }
437  // For not 'dot' locales, we also want to accept '.'
438  if ( QLocale().decimalPoint() != '.' )
439  {
440  d = QLocale( QLocale::C ).toDouble( v.toString(), &ok );
441  if ( ok )
442  {
443  v = QVariant( d );
444  return true;
445  }
446  }
447  }
448  }
449 
450  // For string representation of an int we also might have thousand separator
451  if ( d->type == QVariant::Int && v.type() == QVariant::String )
452  {
453  QVariant tmp( v );
454  if ( !tmp.convert( d->type ) )
455  {
456  // This might be a string with thousand separator: use locale to convert
457  bool ok;
458  const int i = qgsPermissiveToInt( v.toString(), ok );
459  if ( ok )
460  {
461  v = QVariant( i );
462  return true;
463  }
464  }
465  }
466 
467  // For string representation of a long we also might have thousand separator
468  if ( d->type == QVariant::LongLong && v.type() == QVariant::String )
469  {
470  QVariant tmp( v );
471  if ( !tmp.convert( d->type ) )
472  {
473  // This might be a string with thousand separator: use locale to convert
474  bool ok;
475  const qlonglong l = qgsPermissiveToLongLong( v.toString(), ok );
476  if ( ok )
477  {
478  v = QVariant( l );
479  return true;
480  }
481  }
482  }
483 
484  //String representations of doubles in QVariant will return false to convert( QVariant::Int )
485  //work around this by first converting to double, and then checking whether the double is convertible to int
486  if ( d->type == QVariant::Int && v.canConvert( QVariant::Double ) )
487  {
488  bool ok = false;
489  const double dbl = v.toDouble( &ok );
490  if ( !ok )
491  {
492  //couldn't convert to number
493  v = QVariant( d->type );
494 
495  if ( errorMessage )
496  *errorMessage = QObject::tr( "Value \"%1\" is not a number" ).arg( original.toString() );
497 
498  return false;
499  }
500 
501  const double round = std::round( dbl );
502  if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
503  {
504  //double too large to fit in int
505  v = QVariant( d->type );
506 
507  if ( errorMessage )
508  *errorMessage = QObject::tr( "Value \"%1\" is too large for integer field" ).arg( original.toDouble() );
509 
510  return false;
511  }
512  v = QVariant( static_cast< int >( std::round( dbl ) ) );
513  return true;
514  }
515 
516  //String representations of doubles in QVariant will return false to convert( QVariant::LongLong )
517  //work around this by first converting to double, and then checking whether the double is convertible to longlong
518  if ( d->type == QVariant::LongLong && v.canConvert( QVariant::Double ) )
519  {
520  //firstly test the conversion to longlong because conversion to double will rounded the value
521  QVariant tmp( v );
522  if ( !tmp.convert( d->type ) )
523  {
524  bool ok = false;
525  const double dbl = v.toDouble( &ok );
526  if ( !ok )
527  {
528  //couldn't convert to number
529  v = QVariant( d->type );
530 
531  if ( errorMessage )
532  *errorMessage = QObject::tr( "Value \"%1\" is not a number" ).arg( original.toString() );
533 
534  return false;
535  }
536 
537  const double round = std::round( dbl );
538  if ( round > static_cast<double>( std::numeric_limits<long long>::max() ) || round < static_cast<double>( -std::numeric_limits<long long>::max() ) )
539  {
540  //double too large to fit in longlong
541  v = QVariant( d->type );
542 
543  if ( errorMessage )
544  *errorMessage = QObject::tr( "Value \"%1\" is too large for long long field" ).arg( original.toDouble() );
545 
546  return false;
547  }
548  v = QVariant( static_cast< long long >( std::round( dbl ) ) );
549  return true;
550  }
551  }
552 
553  if ( !v.convert( d->type ) )
554  {
555  v = QVariant( d->type );
556 
557  if ( errorMessage )
558  *errorMessage = QObject::tr( "Could not convert value \"%1\" to target type" ).arg( original.toString() );
559 
560  return false;
561  }
562 
563  if ( d->type == QVariant::Double && d->precision > 0 )
564  {
565  const double s = std::pow( 10, d->precision );
566  const double d = v.toDouble() * s;
567  v = QVariant( ( d < 0 ? std::ceil( d - 0.5 ) : std::floor( d + 0.5 ) ) / s );
568  return true;
569  }
570 
571  if ( d->type == QVariant::String && d->length > 0 && v.toString().length() > d->length )
572  {
573  const int length = v.toString().length();
574  v = v.toString().left( d->length );
575 
576  if ( errorMessage )
577  *errorMessage = QObject::tr( "String of length %1 exceeds maximum field length (%2)" ).arg( length ).arg( d->length );
578 
579  return false;
580  }
581 
582  return true;
583 }
584 
586 {
587  d->editorWidgetSetup = v;
588 }
589 
591 {
592  return d->editorWidgetSetup;
593 }
594 
595 void QgsField::setReadOnly( bool readOnly )
596 {
597  d->isReadOnly = readOnly;
598 }
599 
601 {
602  return d->isReadOnly;
603 }
604 
605 
606 /***************************************************************************
607  * This class is considered CRITICAL and any change MUST be accompanied with
608  * full unit tests in testqgsfield.cpp.
609  * See details in QEP #17
610  ****************************************************************************/
611 
612 QDataStream &operator<<( QDataStream &out, const QgsField &field )
613 {
614  out << field.name();
615  out << static_cast< quint32 >( field.type() );
616  out << field.typeName();
617  out << field.length();
618  out << field.precision();
619  out << field.comment();
620  out << field.alias();
623  out << field.constraints().constraints();
624  out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintNotNull ) );
625  out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintUnique ) );
626  out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintExpression ) );
627  out << static_cast< quint32 >( field.constraints().constraintStrength( QgsFieldConstraints::ConstraintNotNull ) );
628  out << static_cast< quint32 >( field.constraints().constraintStrength( QgsFieldConstraints::ConstraintUnique ) );
632  out << static_cast< quint32 >( field.subType() );
633  return out;
634 }
635 
636 QDataStream &operator>>( QDataStream &in, QgsField &field )
637 {
638  quint32 type;
639  quint32 subType;
640  quint32 length;
641  quint32 precision;
642  quint32 constraints;
643  quint32 originNotNull;
644  quint32 originUnique;
645  quint32 originExpression;
646  quint32 strengthNotNull;
647  quint32 strengthUnique;
648  quint32 strengthExpression;
649 
650  bool applyOnUpdate;
651 
652  QString name;
653  QString typeName;
654  QString comment;
655  QString alias;
656  QString defaultValueExpression;
657  QString constraintExpression;
658  QString constraintDescription;
659 
660  in >> name >> type >> typeName >> length >> precision >> comment >> alias
661  >> defaultValueExpression >> applyOnUpdate >> constraints >> originNotNull >> originUnique >> originExpression >> strengthNotNull >> strengthUnique >> strengthExpression >>
662  constraintExpression >> constraintDescription >> subType;
663  field.setName( name );
664  field.setType( static_cast< QVariant::Type >( type ) );
666  field.setLength( static_cast< int >( length ) );
667  field.setPrecision( static_cast< int >( precision ) );
668  field.setComment( comment );
669  field.setAlias( alias );
670  field.setDefaultValueDefinition( QgsDefaultValue( defaultValueExpression, applyOnUpdate ) );
671  QgsFieldConstraints fieldConstraints;
672  if ( constraints & QgsFieldConstraints::ConstraintNotNull )
673  {
674  fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintNotNull, static_cast< QgsFieldConstraints::ConstraintOrigin>( originNotNull ) );
676  }
677  else
679  if ( constraints & QgsFieldConstraints::ConstraintUnique )
680  {
681  fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintUnique, static_cast< QgsFieldConstraints::ConstraintOrigin>( originUnique ) );
683  }
684  else
686  if ( constraints & QgsFieldConstraints::ConstraintExpression )
687  {
688  fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintExpression, static_cast< QgsFieldConstraints::ConstraintOrigin>( originExpression ) );
690  }
691  else
693  fieldConstraints.setConstraintExpression( constraintExpression, constraintDescription );
694  field.setConstraints( fieldConstraints );
695  field.setSubType( static_cast< QVariant::Type >( subType ) );
696  return in;
697 }
static QString nullRepresentation()
This string is used to represent the value NULL throughout QGIS.
QString userFriendlyIdentifier(IdentifierType type=MediumString) const
Returns a user friendly identifier for the CRS.
The QgsDefaultValue class provides a container for managing client side default values for fields.
Q_GADGET QString expression
Holder for the widget type and its configuration for a field.
Stores information about constraints which may be present on a field.
ConstraintStrength
Strength of constraints.
void setConstraintStrength(Constraint constraint, ConstraintStrength strength)
Sets the strength of a constraint.
void setConstraintExpression(const QString &expression, const QString &description=QString())
Set the constraint expression for the field.
ConstraintOrigin
Origin of constraints.
ConstraintStrength constraintStrength(Constraint constraint) const
Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not pres...
ConstraintOrigin constraintOrigin(Constraint constraint) const
Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present ...
QString constraintExpression() const
Returns the constraint expression for the field, if set.
@ ConstraintNotNull
Field may not be null.
@ ConstraintUnique
Field must have a unique value.
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
void removeConstraint(Constraint constraint)
Removes a constraint from the field.
QString constraintDescription() const
Returns the descriptive name for the constraint expression.
Q_GADGET Constraints constraints
void setConstraint(Constraint constraint, ConstraintOrigin origin=ConstraintOriginLayer)
Sets a constraint on the field.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:51
bool isDateOrTime
Definition: qgsfield.h:55
void setEditorWidgetSetup(const QgsEditorWidgetSetup &v)
Set the editor widget setup for the field.
Definition: qgsfield.cpp:585
QString typeName() const
Gets the field type.
Definition: qgsfield.cpp:139
void setConstraints(const QgsFieldConstraints &constraints)
Sets constraints which are present for the field.
Definition: qgsfield.cpp:219
void setAlias(const QString &alias)
Sets the alias for the field (the friendly displayed name of the field ).
Definition: qgsfield.cpp:234
QString name
Definition: qgsfield.h:60
bool operator!=(const QgsField &other) const
Definition: qgsfield.cpp:79
bool operator==(const QgsField &other) const
Definition: qgsfield.cpp:74
int precision
Definition: qgsfield.h:57
static QString readableConfigurationFlag(QgsField::ConfigurationFlag flag)
Returns the readable and translated value of the configuration flag.
Definition: qgsfield.cpp:380
int length
Definition: qgsfield.h:56
QgsField & operator=(const QgsField &other)
Assignment operator.
Definition: qgsfield.cpp:68
QString displayString(const QVariant &v) const
Formats string for display.
Definition: qgsfield.cpp:255
void setPrecision(int precision)
Set the field precision.
Definition: qgsfield.cpp:199
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
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Definition: qgsfield.cpp:402
void setName(const QString &name)
Set the field name.
Definition: qgsfield.cpp:175
void setComment(const QString &comment)
Set the field comment.
Definition: qgsfield.cpp:204
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
void setLength(int len)
Set the field length.
Definition: qgsfield.cpp:195
void setConfigurationFlags(QgsField::ConfigurationFlags configurationFlags)
Sets the Flags for the field (searchable, …)
Definition: qgsfield.cpp:244
QString displayName() const
Returns the name to use when displaying this field.
Definition: qgsfield.cpp:89
void setDefaultValueDefinition(const QgsDefaultValue &defaultValueDefinition)
Sets an expression to use when calculating the default value for the field.
Definition: qgsfield.cpp:214
Q_GADGET bool isNumeric
Definition: qgsfield.h:54
ConfigurationFlags configurationFlags
Definition: qgsfield.h:64
void setReadOnly(bool readOnly)
Make field read-only if readOnly is set to true.
Definition: qgsfield.cpp:595
QVariant::Type type
Definition: qgsfield.h:58
QVariant::Type subType() const
If the field is a collection, gets its element's type.
Definition: qgsfield.cpp:134
QString alias
Definition: qgsfield.h:61
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:48
QgsDefaultValue defaultValueDefinition
Definition: qgsfield.h:62
void setSubType(QVariant::Type subType)
If the field is a collection, set its element's type.
Definition: qgsfield.cpp:185
void setType(QVariant::Type type)
Set variant type.
Definition: qgsfield.cpp:180
QString comment
Definition: qgsfield.h:59
virtual ~QgsField()
QgsFieldConstraints constraints
Definition: qgsfield.h:63
ConfigurationFlag
Configuration flags for fields These flags are meant to be user-configurable and are not describing a...
Definition: qgsfield.h:80
@ HideFromWfs
Field is not available if layer is served as WFS from QGIS server.
@ NotSearchable
Defines if the field is searchable (used in the locator search for instance)
@ None
No flag is defined.
@ HideFromWms
Field is not available if layer is served as WMS from QGIS server.
QgsEditorWidgetSetup editorWidgetSetup() const
Gets the editor widget setup for the field.
Definition: qgsfield.cpp:590
bool isReadOnly
Definition: qgsfield.h:65
void setTypeName(const QString &typeName)
Set the field type.
Definition: qgsfield.cpp:190
Q_GADGET bool isNull
Definition: qgsgeometry.h:127
QString asWkt(int precision=17) const
Exports the geometry to WKT.
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
A QgsGeometry with associated coordinate reference system.
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:85
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:71
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:78
QDataStream & operator>>(QDataStream &in, QgsField &field)
Reads a field from stream in into field. QGIS version compatibility is not guaranteed.
Definition: qgsfield.cpp:636
QDataStream & operator<<(QDataStream &out, const QgsField &field)
Definition: qgsfield.cpp:612
const QgsField & field
Definition: qgsfield.h:463
const QString & typeName
int precision