QGIS API Documentation 3.29.0-Master (da8bb1db43)
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#include "qgsvariantutils.h"
24
25#include <QDataStream>
26#include <QIcon>
27#include <QLocale>
28#include <QJsonDocument>
29
30/***************************************************************************
31 * This class is considered CRITICAL and any change MUST be accompanied with
32 * full unit tests in testqgsfield.cpp.
33 * See details in QEP #17
34 ****************************************************************************/
35
36#if 0
37QgsField::QgsField( QString nam, QString typ, int len, int prec, bool num,
38 QString comment )
39 : mName( nam ), mType( typ ), mLength( len ), mPrecision( prec ), mNumeric( num )
40 , mComment( comment )
41{
42 // This function used to lower case the field name since some stores
43 // use upper case (e.g., shapefiles), but that caused problems with
44 // attribute actions getting confused between uppercase and
45 // lowercase versions of the attribute names, so just leave the
46 // names how they are now.
47}
48#endif
49QgsField::QgsField( const QString &name, QVariant::Type type,
50 const QString &typeName, int len, int prec, const QString &comment, QVariant::Type subType )
51{
52 d = new QgsFieldPrivate( name, type, subType, typeName, len, prec, comment );
53}
54
55QgsField::QgsField( const QgsField &other ) //NOLINT
56 : d( other.d )
57{
58
59}
60
61QgsField::~QgsField() = default;
62
63/***************************************************************************
64 * This class is considered CRITICAL and any change MUST be accompanied with
65 * full unit tests in testqgsfield.cpp.
66 * See details in QEP #17
67 ****************************************************************************/
68
69QgsField &QgsField::operator =( const QgsField &other ) //NOLINT
70{
71 d = other.d;
72 return *this;
73}
74
75bool QgsField::operator==( const QgsField &other ) const
76{
77 return *( other.d ) == *d;
78}
79
80bool QgsField::operator!=( const QgsField &other ) const
81{
82 return !( *this == other );
83}
84
85QString QgsField::name() const
86{
87 return d->name;
88}
89
90QString QgsField::displayName() const
91{
92 if ( !d->alias.isEmpty() )
93 return d->alias;
94 else
95 return d->name;
96}
97
99{
100 if ( alias().isEmpty() )
101 {
102 return name();
103 }
104 return QStringLiteral( "%1 (%2)" ).arg( name() ).arg( alias() );
105}
106
107QString QgsField::displayType( const bool showConstraints ) const
108{
109 QString typeStr = typeName();
110
111 if ( length() > 0 && precision() > 0 )
112 typeStr += QStringLiteral( "(%1, %2)" ).arg( length() ).arg( precision() );
113 else if ( length() > 0 )
114 typeStr += QStringLiteral( "(%1)" ).arg( length() );
115
116 if ( showConstraints )
117 {
119 ? QStringLiteral( " NOT NULL" )
120 : QStringLiteral( " NULL" );
121
123 ? QStringLiteral( " UNIQUE" )
124 : QString();
125 }
126
127 return typeStr;
128}
129
130QVariant::Type QgsField::type() const
131{
132 return d->type;
133}
134
135QVariant::Type QgsField::subType() const
136{
137 return d->subType;
138}
139
140QString QgsField::typeName() const
141{
142 return d->typeName;
143}
144
146{
147 return d->length;
148}
149
151{
152 return d->precision;
153}
154
155QString QgsField::comment() const
156{
157 return d->comment;
158}
159
161{
162 return d->type == QVariant::Double || d->type == QVariant::Int || d->type == QVariant::UInt || d->type == QVariant::LongLong || d->type == QVariant::ULongLong;
163}
164
166{
167 return d->type == QVariant::Date || d->type == QVariant::Time || d->type == QVariant::DateTime;
168}
169
170/***************************************************************************
171 * This class is considered CRITICAL and any change MUST be accompanied with
172 * full unit tests in testqgsfield.cpp.
173 * See details in QEP #17
174 ****************************************************************************/
175
176void QgsField::setName( const QString &name )
177{
178 d->name = name;
179}
180
181void QgsField::setType( QVariant::Type type )
182{
183 d->type = type;
184}
185
186void QgsField::setSubType( QVariant::Type subType )
187{
188 d->subType = subType;
189}
190
191void QgsField::setTypeName( const QString &typeName )
192{
193 d->typeName = typeName;
194}
195
196void QgsField::setLength( int len )
197{
198 d->length = len;
199}
201{
202 d->precision = precision;
203}
204
205void QgsField::setComment( const QString &comment )
206{
207 d->comment = comment;
208}
209
211{
212 return d->defaultValueDefinition;
213}
214
215void QgsField::setDefaultValueDefinition( const QgsDefaultValue &defaultValueDefinition )
216{
217 d->defaultValueDefinition = defaultValueDefinition;
218}
219
221{
222 d->constraints = constraints;
223}
224
226{
227 return d->constraints;
228}
229
230QString QgsField::alias() const
231{
232 return d->alias;
233}
234
235void QgsField::setAlias( const QString &alias )
236{
237 d->alias = alias;
238}
239
240QgsField::ConfigurationFlags QgsField::configurationFlags() const
241{
242 return d->flags;
243}
244
245void QgsField::setConfigurationFlags( QgsField::ConfigurationFlags flags )
246{
247 d->flags = flags;
248}
249
250/***************************************************************************
251 * This class is considered CRITICAL and any change MUST be accompanied with
252 * full unit tests in testqgsfield.cpp.
253 * See details in QEP #17
254 ****************************************************************************/
255
256QString QgsField::displayString( const QVariant &v ) const
257{
258 if ( QgsVariantUtils::isNull( v ) )
259 {
261 }
262
263 if ( v.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
264 {
265 QgsReferencedGeometry geom = qvariant_cast<QgsReferencedGeometry>( v );
266 if ( geom.isNull() )
268 else
269 {
270 QString wkt = geom.asWkt();
271 if ( wkt.length() >= 1050 )
272 {
273 wkt = wkt.left( 999 ) + QChar( 0x2026 );
274 }
275 QString formattedText = QStringLiteral( "%1 [%2]" ).arg( wkt, geom.crs().userFriendlyIdentifier() );
276 return formattedText;
277 }
278 }
279
280 // Special treatment for numeric types if group separator is set or decimalPoint is not a dot
281 if ( d->type == QVariant::Double )
282 {
283 // if value doesn't contain a double (a default value expression for instance),
284 // apply no transformation
285 bool ok;
286 v.toDouble( &ok );
287 if ( !ok )
288 return v.toString();
289
290 // Locales with decimal point != '.' or that require group separator: use QLocale
291 if ( QLocale().decimalPoint() != '.' ||
292 !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
293 {
294 if ( d->precision > 0 )
295 {
296 if ( -1 < v.toDouble() && v.toDouble() < 1 )
297 {
298 return QLocale().toString( v.toDouble(), 'g', d->precision );
299 }
300 else
301 {
302 return QLocale().toString( v.toDouble(), 'f', d->precision );
303 }
304 }
305 else
306 {
307 // Precision is not set, let's guess it from the
308 // standard conversion to string
309 const QString s( v.toString() );
310 const int dotPosition( s.indexOf( '.' ) );
311 int precision;
312 if ( dotPosition < 0 && s.indexOf( 'e' ) < 0 )
313 {
314 precision = 0;
315 return QLocale().toString( v.toDouble(), 'f', precision );
316 }
317 else
318 {
319 if ( dotPosition < 0 ) precision = 0;
320 else precision = s.length() - dotPosition - 1;
321
322 if ( -1 < v.toDouble() && v.toDouble() < 1 )
323 {
324 return QLocale().toString( v.toDouble(), 'g', precision );
325 }
326 else
327 {
328 return QLocale().toString( v.toDouble(), 'f', precision );
329 }
330 }
331 }
332 }
333 // Default for doubles with precision
334 else if ( d->precision > 0 )
335 {
336 if ( -1 < v.toDouble() && v.toDouble() < 1 )
337 {
338 return QString::number( v.toDouble(), 'g', d->precision );
339 }
340 else
341 {
342 return QString::number( v.toDouble(), 'f', d->precision );
343 }
344 }
345 else
346 {
347 const double vDouble = v.toDouble();
348 // mimic Qt 5 handling of when to switch to exponential forms
349 if ( std::fabs( vDouble ) < 1e-04 )
350 return QString::number( vDouble, 'g', QLocale::FloatingPointShortest );
351 else
352 return QString::number( vDouble, 'f', QLocale::FloatingPointShortest );
353 }
354 }
355 // Other numeric types than doubles
356 else if ( isNumeric() &&
357 !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
358 {
359 bool ok;
360 const qlonglong converted( v.toLongLong( &ok ) );
361 if ( ok )
362 return QLocale().toString( converted );
363 }
364 else if ( d->typeName.compare( QLatin1String( "json" ), Qt::CaseInsensitive ) == 0 || d->typeName == QLatin1String( "jsonb" ) )
365 {
366 const QJsonDocument doc = QJsonDocument::fromVariant( v );
367 return QString::fromUtf8( doc.toJson().data() );
368 }
369 else if ( d->type == QVariant::ByteArray )
370 {
371 return QObject::tr( "BLOB" );
372 }
373 else if ( d->type == QVariant::StringList || d->type == QVariant::List )
374 {
375 QString result;
376 const QVariantList list = v.toList();
377 for ( const QVariant &var : list )
378 {
379 if ( !result.isEmpty() )
380 result.append( QStringLiteral( ", " ) );
381 result.append( var.toString() );
382 }
383 return result;
384 }
385
386 // Fallback if special rules do not apply
387 return v.toString();
388}
389
391{
392 switch ( flag )
393 {
395 return QObject::tr( "None" );
397 return QObject::tr( "Not searchable" );
399 return QObject::tr( "Do not expose via WMS" );
401 return QObject::tr( "Do not expose via WFS" );
402 }
403 return QString();
404}
405
406/***************************************************************************
407 * This class is considered CRITICAL and any change MUST be accompanied with
408 * full unit tests in testqgsfield.cpp.
409 * See details in QEP #17
410 ****************************************************************************/
411
412bool QgsField::convertCompatible( QVariant &v, QString *errorMessage ) const
413{
414 const QVariant original = v;
415 if ( errorMessage )
416 errorMessage->clear();
417
418 if ( QgsVariantUtils::isNull( v ) )
419 {
420 v.convert( d->type );
421 return true;
422 }
423
424 if ( d->type == QVariant::Int && v.toInt() != v.toLongLong() )
425 {
426 v = QVariant( d->type );
427 if ( errorMessage )
428 *errorMessage = QObject::tr( "Value \"%1\" is too large for integer field" ).arg( original.toLongLong() );
429 return false;
430 }
431
432 // Give it a chance to convert to double since for not '.' locales
433 // we accept both comma and dot as decimal point
434 if ( d->type == QVariant::Double && v.type() == QVariant::String )
435 {
436 QVariant tmp( v );
437 if ( !tmp.convert( d->type ) )
438 {
439 // This might be a string with thousand separator: use locale to convert
440 bool ok = false;
441 double d = qgsPermissiveToDouble( v.toString(), ok );
442 if ( ok )
443 {
444 v = QVariant( d );
445 return true;
446 }
447 // For not 'dot' locales, we also want to accept '.'
448 if ( QLocale().decimalPoint() != '.' )
449 {
450 d = QLocale( QLocale::C ).toDouble( v.toString(), &ok );
451 if ( ok )
452 {
453 v = QVariant( d );
454 return true;
455 }
456 }
457 }
458 }
459
460 // For string representation of an int we also might have thousand separator
461 if ( d->type == QVariant::Int && v.type() == QVariant::String )
462 {
463 QVariant tmp( v );
464 if ( !tmp.convert( d->type ) )
465 {
466 // This might be a string with thousand separator: use locale to convert
467 bool ok;
468 const int i = qgsPermissiveToInt( v.toString(), ok );
469 if ( ok )
470 {
471 v = QVariant( i );
472 return true;
473 }
474 }
475 }
476
477 // For string representation of a long we also might have thousand separator
478 if ( d->type == QVariant::LongLong && v.type() == QVariant::String )
479 {
480 QVariant tmp( v );
481 if ( !tmp.convert( d->type ) )
482 {
483 // This might be a string with thousand separator: use locale to convert
484 bool ok;
485 const qlonglong l = qgsPermissiveToLongLong( v.toString(), ok );
486 if ( ok )
487 {
488 v = QVariant( l );
489 return true;
490 }
491 }
492 }
493
494 //String representations of doubles in QVariant will return false to convert( QVariant::Int )
495 //work around this by first converting to double, and then checking whether the double is convertible to int
496 if ( d->type == QVariant::Int && v.canConvert( QVariant::Double ) )
497 {
498 bool ok = false;
499 const double dbl = v.toDouble( &ok );
500 if ( !ok )
501 {
502 //couldn't convert to number
503 v = QVariant( d->type );
504
505 if ( errorMessage )
506 *errorMessage = QObject::tr( "Value \"%1\" is not a number" ).arg( original.toString() );
507
508 return false;
509 }
510
511 const double round = std::round( dbl );
512 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
513 {
514 //double too large to fit in int
515 v = QVariant( d->type );
516
517 if ( errorMessage )
518 *errorMessage = QObject::tr( "Value \"%1\" is too large for integer field" ).arg( original.toDouble() );
519
520 return false;
521 }
522 v = QVariant( static_cast< int >( std::round( dbl ) ) );
523 return true;
524 }
525
526 //String representations of doubles in QVariant will return false to convert( QVariant::LongLong )
527 //work around this by first converting to double, and then checking whether the double is convertible to longlong
528 if ( d->type == QVariant::LongLong && v.canConvert( QVariant::Double ) )
529 {
530 //firstly test the conversion to longlong because conversion to double will rounded the value
531 QVariant tmp( v );
532 if ( !tmp.convert( d->type ) )
533 {
534 bool ok = false;
535 const double dbl = v.toDouble( &ok );
536 if ( !ok )
537 {
538 //couldn't convert to number
539 v = QVariant( d->type );
540
541 if ( errorMessage )
542 *errorMessage = QObject::tr( "Value \"%1\" is not a number" ).arg( original.toString() );
543
544 return false;
545 }
546
547 const double round = std::round( dbl );
548 if ( round > static_cast<double>( std::numeric_limits<long long>::max() ) || round < static_cast<double>( -std::numeric_limits<long long>::max() ) )
549 {
550 //double too large to fit in longlong
551 v = QVariant( d->type );
552
553 if ( errorMessage )
554 *errorMessage = QObject::tr( "Value \"%1\" is too large for long long field" ).arg( original.toDouble() );
555
556 return false;
557 }
558 v = QVariant( static_cast< long long >( std::round( dbl ) ) );
559 return true;
560 }
561 }
562
563 if ( d->type == QVariant::String && ( d->typeName.compare( QLatin1String( "json" ), Qt::CaseInsensitive ) == 0 || d->typeName == QLatin1String( "jsonb" ) ) )
564 {
565 const QJsonDocument doc = QJsonDocument::fromVariant( v );
566 if ( !doc.isNull() )
567 {
568 v = QString::fromUtf8( doc.toJson( QJsonDocument::Compact ).constData() );
569 return true;
570 }
571 v = QVariant( d->type );
572 return false;
573 }
574
575 if ( ( d->type == QVariant::StringList || ( d->type == QVariant::List && d->subType == QVariant::String ) )
576 && ( v.type() == QVariant::String ) )
577 {
578 v = QStringList( { v.toString() } );
579 return true;
580 }
581
582 if ( ( d->type == QVariant::StringList || d->type == QVariant::List ) && !( v.type() == QVariant::StringList || v.type() == QVariant::List ) )
583 {
584 v = QVariant( d->type );
585
586 if ( errorMessage )
587 *errorMessage = QObject::tr( "Could not convert value \"%1\" to target list type" ).arg( original.toString() );
588
589 return false;
590 }
591
592 if ( !v.convert( d->type ) )
593 {
594 v = QVariant( d->type );
595
596 if ( errorMessage )
597 *errorMessage = QObject::tr( "Could not convert value \"%1\" to target type \"%2\"" )
598 .arg( original.toString() )
599 .arg( d->typeName );
600
601 return false;
602 }
603
604 if ( d->type == QVariant::Double && d->precision > 0 )
605 {
606 const double s = std::pow( 10, d->precision );
607 const double d = v.toDouble() * s;
608 v = QVariant( ( d < 0 ? std::ceil( d - 0.5 ) : std::floor( d + 0.5 ) ) / s );
609 return true;
610 }
611
612 if ( d->type == QVariant::String && d->length > 0 && v.toString().length() > d->length )
613 {
614 const int length = v.toString().length();
615 v = v.toString().left( d->length );
616
617 if ( errorMessage )
618 *errorMessage = QObject::tr( "String of length %1 exceeds maximum field length (%2)" ).arg( length ).arg( d->length );
619
620 return false;
621 }
622
623 return true;
624}
625
627{
628 d->editorWidgetSetup = v;
629}
630
632{
633 return d->editorWidgetSetup;
634}
635
636void QgsField::setReadOnly( bool readOnly )
637{
638 d->isReadOnly = readOnly;
639}
640
642{
643 return d->isReadOnly;
644}
645
646
647/***************************************************************************
648 * This class is considered CRITICAL and any change MUST be accompanied with
649 * full unit tests in testqgsfield.cpp.
650 * See details in QEP #17
651 ****************************************************************************/
652
653QDataStream &operator<<( QDataStream &out, const QgsField &field )
654{
655 out << field.name();
656 out << static_cast< quint32 >( field.type() );
657 out << field.typeName();
658 out << field.length();
659 out << field.precision();
660 out << field.comment();
661 out << field.alias();
664 out << field.constraints().constraints();
665 out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintNotNull ) );
666 out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintUnique ) );
673 out << static_cast< quint32 >( field.subType() );
674 return out;
675}
676
677QDataStream &operator>>( QDataStream &in, QgsField &field )
678{
679 quint32 type;
680 quint32 subType;
681 quint32 length;
682 quint32 precision;
683 quint32 constraints;
684 quint32 originNotNull;
685 quint32 originUnique;
686 quint32 originExpression;
687 quint32 strengthNotNull;
688 quint32 strengthUnique;
689 quint32 strengthExpression;
690
691 bool applyOnUpdate;
692
693 QString name;
694 QString typeName;
695 QString comment;
696 QString alias;
697 QString defaultValueExpression;
698 QString constraintExpression;
699 QString constraintDescription;
700
701 in >> name >> type >> typeName >> length >> precision >> comment >> alias
702 >> defaultValueExpression >> applyOnUpdate >> constraints >> originNotNull >> originUnique >> originExpression >> strengthNotNull >> strengthUnique >> strengthExpression >>
703 constraintExpression >> constraintDescription >> subType;
704 field.setName( name );
705 field.setType( static_cast< QVariant::Type >( type ) );
707 field.setLength( static_cast< int >( length ) );
708 field.setPrecision( static_cast< int >( precision ) );
709 field.setComment( comment );
710 field.setAlias( alias );
711 field.setDefaultValueDefinition( QgsDefaultValue( defaultValueExpression, applyOnUpdate ) );
712 QgsFieldConstraints fieldConstraints;
713 if ( constraints & QgsFieldConstraints::ConstraintNotNull )
714 {
715 fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintNotNull, static_cast< QgsFieldConstraints::ConstraintOrigin>( originNotNull ) );
717 }
718 else
720 if ( constraints & QgsFieldConstraints::ConstraintUnique )
721 {
722 fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintUnique, static_cast< QgsFieldConstraints::ConstraintOrigin>( originUnique ) );
724 }
725 else
728 {
729 fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintExpression, static_cast< QgsFieldConstraints::ConstraintOrigin>( originExpression ) );
731 }
732 else
734 fieldConstraints.setConstraintExpression( constraintExpression, constraintDescription );
735 field.setConstraints( fieldConstraints );
736 field.setSubType( static_cast< QVariant::Type >( subType ) );
737 return in;
738}
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:626
QString typeName() const
Gets the field type.
Definition: qgsfield.cpp:140
void setConstraints(const QgsFieldConstraints &constraints)
Sets constraints which are present for the field.
Definition: qgsfield.cpp:220
void setAlias(const QString &alias)
Sets the alias for the field (the friendly displayed name of the field ).
Definition: qgsfield.cpp:235
QString name
Definition: qgsfield.h:60
bool operator!=(const QgsField &other) const
Definition: qgsfield.cpp:80
bool operator==(const QgsField &other) const
Definition: qgsfield.cpp:75
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:390
int length
Definition: qgsfield.h:56
QgsField & operator=(const QgsField &other)
Assignment operator.
Definition: qgsfield.cpp:69
QString displayString(const QVariant &v) const
Formats string for display.
Definition: qgsfield.cpp:256
void setPrecision(int precision)
Set the field precision.
Definition: qgsfield.cpp:200
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:98
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Definition: qgsfield.cpp:412
void setName(const QString &name)
Set the field name.
Definition: qgsfield.cpp:176
void setComment(const QString &comment)
Set the field comment.
Definition: qgsfield.cpp:205
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:107
void setLength(int len)
Set the field length.
Definition: qgsfield.cpp:196
void setConfigurationFlags(QgsField::ConfigurationFlags configurationFlags)
Sets the Flags for the field (searchable, …)
Definition: qgsfield.cpp:245
QString displayName() const
Returns the name to use when displaying this field.
Definition: qgsfield.cpp:90
void setDefaultValueDefinition(const QgsDefaultValue &defaultValueDefinition)
Sets an expression to use when calculating the default value for the field.
Definition: qgsfield.cpp:215
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:636
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:135
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:49
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:186
void setType(QVariant::Type type)
Set variant type.
Definition: qgsfield.cpp:181
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:631
bool isReadOnly
Definition: qgsfield.h:65
void setTypeName(const QString &typeName)
Set the field type.
Definition: qgsfield.cpp:191
Q_GADGET bool isNull
Definition: qgsgeometry.h:166
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.
static bool isNull(const QVariant &variant)
Returns true if the specified variant should be considered a NULL value.
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:677
QDataStream & operator<<(QDataStream &out, const QgsField &field)
Definition: qgsfield.cpp:653
const QgsField & field
Definition: qgsfield.h:463
const QString & typeName
int precision