QGIS API Documentation 3.27.0-Master (0a97e3138f)
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"
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
36QgsField::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
48QgsField::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
54QgsField::QgsField( const QgsField &other ) //NOLINT
55 : d( other.d )
56{
57
58}
59
60QgsField::~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
68QgsField &QgsField::operator =( const QgsField &other ) //NOLINT
69{
70 d = other.d;
71 return *this;
72}
73
74bool QgsField::operator==( const QgsField &other ) const
75{
76 return *( other.d ) == *d;
77}
78
79bool QgsField::operator!=( const QgsField &other ) const
80{
81 return !( *this == other );
82}
83
84QString QgsField::name() const
85{
86 return d->name;
87}
88
89QString 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
106QString 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
129QVariant::Type QgsField::type() const
130{
131 return d->type;
132}
133
134QVariant::Type QgsField::subType() const
135{
136 return d->subType;
137}
138
139QString QgsField::typeName() const
140{
141 return d->typeName;
142}
143
145{
146 return d->length;
147}
148
150{
151 return d->precision;
152}
153
154QString 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
175void QgsField::setName( const QString &name )
176{
177 d->name = name;
178}
179
180void QgsField::setType( QVariant::Type type )
181{
182 d->type = type;
183}
184
185void QgsField::setSubType( QVariant::Type subType )
186{
187 d->subType = subType;
188}
189
190void QgsField::setTypeName( const QString &typeName )
191{
192 d->typeName = typeName;
193}
194
195void QgsField::setLength( int len )
196{
197 d->length = len;
198}
200{
201 d->precision = precision;
202}
203
204void QgsField::setComment( const QString &comment )
205{
206 d->comment = comment;
207}
208
210{
211 return d->defaultValueDefinition;
212}
213
214void 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
229QString QgsField::alias() const
230{
231 return d->alias;
232}
233
234void QgsField::setAlias( const QString &alias )
235{
236 d->alias = alias;
237}
238
239QgsField::ConfigurationFlags QgsField::configurationFlags() const
240{
241 return d->flags;
242}
243
244void 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
255QString 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
402bool 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 ( d->type == QVariant::String && ( d->typeName.compare( QLatin1String( "json" ), Qt::CaseInsensitive ) == 0 || d->typeName == QLatin1String( "jsonb" ) ) )
554 {
555 const QJsonDocument doc = QJsonDocument::fromVariant( v );
556 if ( !doc.isNull() )
557 {
558 v = QString::fromUtf8( doc.toJson( QJsonDocument::Compact ).constData() );
559 return true;
560 }
561 v = QVariant( d->type );
562 return false;
563 }
564
565 if ( !v.convert( d->type ) )
566 {
567 v = QVariant( d->type );
568
569 if ( errorMessage )
570 *errorMessage = QObject::tr( "Could not convert value \"%1\" to target type" ).arg( original.toString() );
571
572 return false;
573 }
574
575 if ( d->type == QVariant::Double && d->precision > 0 )
576 {
577 const double s = std::pow( 10, d->precision );
578 const double d = v.toDouble() * s;
579 v = QVariant( ( d < 0 ? std::ceil( d - 0.5 ) : std::floor( d + 0.5 ) ) / s );
580 return true;
581 }
582
583 if ( d->type == QVariant::String && d->length > 0 && v.toString().length() > d->length )
584 {
585 const int length = v.toString().length();
586 v = v.toString().left( d->length );
587
588 if ( errorMessage )
589 *errorMessage = QObject::tr( "String of length %1 exceeds maximum field length (%2)" ).arg( length ).arg( d->length );
590
591 return false;
592 }
593
594 return true;
595}
596
598{
599 d->editorWidgetSetup = v;
600}
601
603{
604 return d->editorWidgetSetup;
605}
606
607void QgsField::setReadOnly( bool readOnly )
608{
609 d->isReadOnly = readOnly;
610}
611
613{
614 return d->isReadOnly;
615}
616
617
618/***************************************************************************
619 * This class is considered CRITICAL and any change MUST be accompanied with
620 * full unit tests in testqgsfield.cpp.
621 * See details in QEP #17
622 ****************************************************************************/
623
624QDataStream &operator<<( QDataStream &out, const QgsField &field )
625{
626 out << field.name();
627 out << static_cast< quint32 >( field.type() );
628 out << field.typeName();
629 out << field.length();
630 out << field.precision();
631 out << field.comment();
632 out << field.alias();
635 out << field.constraints().constraints();
636 out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintNotNull ) );
637 out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintUnique ) );
644 out << static_cast< quint32 >( field.subType() );
645 return out;
646}
647
648QDataStream &operator>>( QDataStream &in, QgsField &field )
649{
650 quint32 type;
651 quint32 subType;
652 quint32 length;
653 quint32 precision;
654 quint32 constraints;
655 quint32 originNotNull;
656 quint32 originUnique;
657 quint32 originExpression;
658 quint32 strengthNotNull;
659 quint32 strengthUnique;
660 quint32 strengthExpression;
661
662 bool applyOnUpdate;
663
664 QString name;
665 QString typeName;
666 QString comment;
667 QString alias;
668 QString defaultValueExpression;
669 QString constraintExpression;
670 QString constraintDescription;
671
672 in >> name >> type >> typeName >> length >> precision >> comment >> alias
673 >> defaultValueExpression >> applyOnUpdate >> constraints >> originNotNull >> originUnique >> originExpression >> strengthNotNull >> strengthUnique >> strengthExpression >>
674 constraintExpression >> constraintDescription >> subType;
675 field.setName( name );
676 field.setType( static_cast< QVariant::Type >( type ) );
678 field.setLength( static_cast< int >( length ) );
679 field.setPrecision( static_cast< int >( precision ) );
680 field.setComment( comment );
681 field.setAlias( alias );
682 field.setDefaultValueDefinition( QgsDefaultValue( defaultValueExpression, applyOnUpdate ) );
683 QgsFieldConstraints fieldConstraints;
684 if ( constraints & QgsFieldConstraints::ConstraintNotNull )
685 {
686 fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintNotNull, static_cast< QgsFieldConstraints::ConstraintOrigin>( originNotNull ) );
688 }
689 else
691 if ( constraints & QgsFieldConstraints::ConstraintUnique )
692 {
693 fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintUnique, static_cast< QgsFieldConstraints::ConstraintOrigin>( originUnique ) );
695 }
696 else
699 {
700 fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintExpression, static_cast< QgsFieldConstraints::ConstraintOrigin>( originExpression ) );
702 }
703 else
705 fieldConstraints.setConstraintExpression( constraintExpression, constraintDescription );
706 field.setConstraints( fieldConstraints );
707 field.setSubType( static_cast< QVariant::Type >( subType ) );
708 return in;
709}
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:597
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:607
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:602
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:648
QDataStream & operator<<(QDataStream &out, const QgsField &field)
Definition: qgsfield.cpp:624
const QgsField & field
Definition: qgsfield.h:463
const QString & typeName
int precision