QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 "qgsfield_p.h"
18#include "qgis.h"
19#include "qgsapplication.h"
21#include "qgsvariantutils.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
35QgsField::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
47QgsField::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
53QgsField::QgsField( const QgsField &other ) //NOLINT
54 : d( other.d )
55{
56
57}
58
59QgsField::~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
67QgsField &QgsField::operator =( const QgsField &other ) //NOLINT
68{
69 d = other.d;
70 return *this;
71}
72
73bool QgsField::operator==( const QgsField &other ) const
74{
75 return *( other.d ) == *d;
76}
77
78bool QgsField::operator!=( const QgsField &other ) const
79{
80 return !( *this == other );
81}
82
83QString QgsField::name() const
84{
85 return d->name;
86}
87
88QString 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(), alias() );
103}
104
105QString 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
129{
130 if ( d->type == QVariant::UserType )
131 {
132 if ( d->typeName.compare( QLatin1String( "geometry" ), Qt::CaseInsensitive ) == 0 )
133 {
134 return QObject::tr( "Geometry" );
135 }
136 }
137 return QgsVariantUtils::typeToDisplayString( d->type, d->subType );
138}
139
140QVariant::Type QgsField::type() const
141{
142 return d->type;
143}
144
145QVariant::Type QgsField::subType() const
146{
147 return d->subType;
148}
149
150QString QgsField::typeName() const
151{
152 return d->typeName;
153}
154
156{
157 return d->length;
158}
159
161{
162 return d->precision;
163}
164
165QString QgsField::comment() const
166{
167 return d->comment;
168}
169
171{
172 return d->type == QVariant::Double || d->type == QVariant::Int || d->type == QVariant::UInt || d->type == QVariant::LongLong || d->type == QVariant::ULongLong;
173}
174
176{
177 return d->type == QVariant::Date || d->type == QVariant::Time || d->type == QVariant::DateTime;
178}
179
180/***************************************************************************
181 * This class is considered CRITICAL and any change MUST be accompanied with
182 * full unit tests in testqgsfield.cpp.
183 * See details in QEP #17
184 ****************************************************************************/
185
186void QgsField::setName( const QString &name )
187{
188 d->name = name;
189}
190
191void QgsField::setType( QVariant::Type type )
192{
193 d->type = type;
194}
195
196void QgsField::setSubType( QVariant::Type subType )
197{
198 d->subType = subType;
199}
200
201void QgsField::setTypeName( const QString &typeName )
202{
203 d->typeName = typeName;
204}
205
206void QgsField::setLength( int len )
207{
208 d->length = len;
209}
211{
212 d->precision = precision;
213}
214
215void QgsField::setComment( const QString &comment )
216{
217 d->comment = comment;
218}
219
221{
222 return d->defaultValueDefinition;
223}
224
225void QgsField::setDefaultValueDefinition( const QgsDefaultValue &defaultValueDefinition )
226{
227 d->defaultValueDefinition = defaultValueDefinition;
228}
229
231{
232 d->constraints = constraints;
233}
234
236{
237 return d->constraints;
238}
239
240QString QgsField::alias() const
241{
242 return d->alias;
243}
244
245void QgsField::setAlias( const QString &alias )
246{
247 d->alias = alias;
248}
249
250QgsField::ConfigurationFlags QgsField::configurationFlags() const
251{
252 return d->flags;
253}
254
255void QgsField::setConfigurationFlags( QgsField::ConfigurationFlags flags )
256{
257 d->flags = flags;
258}
259
260/***************************************************************************
261 * This class is considered CRITICAL and any change MUST be accompanied with
262 * full unit tests in testqgsfield.cpp.
263 * See details in QEP #17
264 ****************************************************************************/
265
266QString QgsField::displayString( const QVariant &v ) const
267{
268 if ( QgsVariantUtils::isNull( v ) )
269 {
271 }
272
273 if ( v.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
274 {
275 QgsReferencedGeometry geom = qvariant_cast<QgsReferencedGeometry>( v );
276 if ( geom.isNull() )
278 else
279 {
280 QString wkt = geom.asWkt();
281 if ( wkt.length() >= 1050 )
282 {
283 wkt = wkt.left( MAX_WKT_LENGTH ) + QChar( 0x2026 );
284 }
285 QString formattedText = QStringLiteral( "%1 [%2]" ).arg( wkt, geom.crs().userFriendlyIdentifier() );
286 return formattedText;
287 }
288 }
289
290 // Special treatment for numeric types if group separator is set or decimalPoint is not a dot
291 if ( d->type == QVariant::Double )
292 {
293 // if value doesn't contain a double (a default value expression for instance),
294 // apply no transformation
295 bool ok;
296 v.toDouble( &ok );
297 if ( !ok )
298 return v.toString();
299
300 // Locales with decimal point != '.' or that require group separator: use QLocale
301 if ( QLocale().decimalPoint() != '.' ||
302 !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
303 {
304 if ( d->precision > 0 )
305 {
306 if ( -1 < v.toDouble() && v.toDouble() < 1 )
307 {
308 return QLocale().toString( v.toDouble(), 'g', d->precision );
309 }
310 else
311 {
312 return QLocale().toString( v.toDouble(), 'f', d->precision );
313 }
314 }
315 else
316 {
317 // Precision is not set, let's guess it from the
318 // standard conversion to string
319 const QString s( v.toString() );
320 const int dotPosition( s.indexOf( '.' ) );
321 int precision;
322 if ( dotPosition < 0 && s.indexOf( 'e' ) < 0 )
323 {
324 precision = 0;
325 return QLocale().toString( v.toDouble(), 'f', precision );
326 }
327 else
328 {
329 if ( dotPosition < 0 ) precision = 0;
330 else precision = s.length() - dotPosition - 1;
331
332 if ( -1 < v.toDouble() && v.toDouble() < 1 )
333 {
334 return QLocale().toString( v.toDouble(), 'g', precision );
335 }
336 else
337 {
338 return QLocale().toString( v.toDouble(), 'f', precision );
339 }
340 }
341 }
342 }
343 // Default for doubles with precision
344 else if ( d->precision > 0 )
345 {
346 if ( -1 < v.toDouble() && v.toDouble() < 1 )
347 {
348 return QString::number( v.toDouble(), 'g', d->precision );
349 }
350 else
351 {
352 return QString::number( v.toDouble(), 'f', d->precision );
353 }
354 }
355 else
356 {
357 const double vDouble = v.toDouble();
358 // mimic Qt 5 handling of when to switch to exponential forms
359 if ( std::fabs( vDouble ) < 1e-04 )
360 return QString::number( vDouble, 'g', QLocale::FloatingPointShortest );
361 else
362 return QString::number( vDouble, 'f', QLocale::FloatingPointShortest );
363 }
364 }
365 // Other numeric types than doubles
366 else if ( isNumeric() &&
367 !( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
368 {
369 bool ok;
370 const qlonglong converted( v.toLongLong( &ok ) );
371 if ( ok )
372 return QLocale().toString( converted );
373 }
374 else if ( d->typeName.compare( QLatin1String( "json" ), Qt::CaseInsensitive ) == 0 || d->typeName == QLatin1String( "jsonb" ) )
375 {
376 const QJsonDocument doc = QJsonDocument::fromVariant( v );
377 return QString::fromUtf8( doc.toJson().data() );
378 }
379 else if ( d->type == QVariant::ByteArray )
380 {
381 return QObject::tr( "BLOB" );
382 }
383 else if ( d->type == QVariant::StringList || d->type == QVariant::List )
384 {
385 QString result;
386 const QVariantList list = v.toList();
387 for ( const QVariant &var : list )
388 {
389 if ( !result.isEmpty() )
390 result.append( QStringLiteral( ", " ) );
391 result.append( var.toString() );
392 }
393 return result;
394 }
395
396 // Fallback if special rules do not apply
397 return v.toString();
398}
399
401{
402 switch ( flag )
403 {
405 return QObject::tr( "None" );
407 return QObject::tr( "Not searchable" );
409 return QObject::tr( "Do not expose via WMS" );
411 return QObject::tr( "Do not expose via WFS" );
412 }
413 return QString();
414}
415
416/***************************************************************************
417 * This class is considered CRITICAL and any change MUST be accompanied with
418 * full unit tests in testqgsfield.cpp.
419 * See details in QEP #17
420 ****************************************************************************/
421
422bool QgsField::convertCompatible( QVariant &v, QString *errorMessage ) const
423{
424 const QVariant original = v;
425 if ( errorMessage )
426 errorMessage->clear();
427
428 if ( QgsVariantUtils::isNull( v ) )
429 {
430 v.convert( d->type );
431 return true;
432 }
433
434 if ( d->type == QVariant::Int && v.toInt() != v.toLongLong() )
435 {
436 v = QVariant( d->type );
437 if ( errorMessage )
438 *errorMessage = QObject::tr( "Value \"%1\" is too large for integer field" ).arg( original.toLongLong() );
439 return false;
440 }
441
442 // Give it a chance to convert to double since for not '.' locales
443 // we accept both comma and dot as decimal point
444 if ( d->type == QVariant::Double && v.type() == QVariant::String )
445 {
446 QVariant tmp( v );
447 if ( !tmp.convert( d->type ) )
448 {
449 // This might be a string with thousand separator: use locale to convert
450 bool ok = false;
451 double d = qgsPermissiveToDouble( v.toString(), ok );
452 if ( ok )
453 {
454 v = QVariant( d );
455 return true;
456 }
457 // For not 'dot' locales, we also want to accept '.'
458 if ( QLocale().decimalPoint() != '.' )
459 {
460 d = QLocale( QLocale::C ).toDouble( v.toString(), &ok );
461 if ( ok )
462 {
463 v = QVariant( d );
464 return true;
465 }
466 }
467 }
468 }
469
470 // For string representation of an int we also might have thousand separator
471 if ( d->type == QVariant::Int && v.type() == QVariant::String )
472 {
473 QVariant tmp( v );
474 if ( !tmp.convert( d->type ) )
475 {
476 // This might be a string with thousand separator: use locale to convert
477 bool ok;
478 const int i = qgsPermissiveToInt( v.toString(), ok );
479 if ( ok )
480 {
481 v = QVariant( i );
482 return true;
483 }
484 }
485 }
486
487 // For string representation of a long we also might have thousand separator
488 if ( d->type == QVariant::LongLong && v.type() == QVariant::String )
489 {
490 QVariant tmp( v );
491 if ( !tmp.convert( d->type ) )
492 {
493 // This might be a string with thousand separator: use locale to convert
494 bool ok;
495 const qlonglong l = qgsPermissiveToLongLong( v.toString(), ok );
496 if ( ok )
497 {
498 v = QVariant( l );
499 return true;
500 }
501 }
502 }
503
504 //String representations of doubles in QVariant will return false to convert( QVariant::Int )
505 //work around this by first converting to double, and then checking whether the double is convertible to int
506 if ( d->type == QVariant::Int && v.canConvert( QVariant::Double ) )
507 {
508 bool ok = false;
509 const double dbl = v.toDouble( &ok );
510 if ( !ok )
511 {
512 //couldn't convert to number
513 v = QVariant( d->type );
514
515 if ( errorMessage )
516 *errorMessage = QObject::tr( "Value \"%1\" is not a number" ).arg( original.toString() );
517
518 return false;
519 }
520
521 const double round = std::round( dbl );
522 if ( round > std::numeric_limits<int>::max() || round < -std::numeric_limits<int>::max() )
523 {
524 //double too large to fit in int
525 v = QVariant( d->type );
526
527 if ( errorMessage )
528 *errorMessage = QObject::tr( "Value \"%1\" is too large for integer field" ).arg( original.toDouble() );
529
530 return false;
531 }
532 v = QVariant( static_cast< int >( std::round( dbl ) ) );
533 return true;
534 }
535
536 //String representations of doubles in QVariant will return false to convert( QVariant::LongLong )
537 //work around this by first converting to double, and then checking whether the double is convertible to longlong
538 if ( d->type == QVariant::LongLong && v.canConvert( QVariant::Double ) )
539 {
540 //firstly test the conversion to longlong because conversion to double will rounded the value
541 QVariant tmp( v );
542 if ( !tmp.convert( d->type ) )
543 {
544 bool ok = false;
545 const double dbl = v.toDouble( &ok );
546 if ( !ok )
547 {
548 //couldn't convert to number
549 v = QVariant( d->type );
550
551 if ( errorMessage )
552 *errorMessage = QObject::tr( "Value \"%1\" is not a number" ).arg( original.toString() );
553
554 return false;
555 }
556
557 const double round = std::round( dbl );
558 if ( round > static_cast<double>( std::numeric_limits<long long>::max() ) || round < static_cast<double>( -std::numeric_limits<long long>::max() ) )
559 {
560 //double too large to fit in longlong
561 v = QVariant( d->type );
562
563 if ( errorMessage )
564 *errorMessage = QObject::tr( "Value \"%1\" is too large for long long field" ).arg( original.toDouble() );
565
566 return false;
567 }
568 v = QVariant( static_cast< long long >( std::round( dbl ) ) );
569 return true;
570 }
571 }
572
573 if ( d->type == QVariant::String && ( d->typeName.compare( QLatin1String( "json" ), Qt::CaseInsensitive ) == 0 || d->typeName == QLatin1String( "jsonb" ) ) )
574 {
575 const QJsonDocument doc = QJsonDocument::fromVariant( v );
576 if ( !doc.isNull() )
577 {
578 v = QString::fromUtf8( doc.toJson( QJsonDocument::Compact ).constData() );
579 return true;
580 }
581 v = QVariant( d->type );
582 return false;
583 }
584
585 if ( ( d->type == QVariant::StringList || ( d->type == QVariant::List && d->subType == QVariant::String ) )
586 && ( v.type() == QVariant::String ) )
587 {
588 v = QStringList( { v.toString() } );
589 return true;
590 }
591
592 if ( ( d->type == QVariant::StringList || d->type == QVariant::List ) && !( v.type() == QVariant::StringList || v.type() == QVariant::List ) )
593 {
594 v = QVariant( d->type );
595
596 if ( errorMessage )
597 *errorMessage = QObject::tr( "Could not convert value \"%1\" to target list type" ).arg( original.toString() );
598
599 return false;
600 }
601
602 // Handle referenced geometries (e.g. from additional geometry fields)
603 if ( d->type == QVariant::String && v.userType() == QMetaType::type( "QgsReferencedGeometry" ) )
604 {
605 const QgsReferencedGeometry geom { v.value<QgsReferencedGeometry>( ) };
606 if ( geom.isNull() )
607 {
608 v = QVariant( d->type );
609 }
610 else
611 {
612 v = QVariant( geom.asWkt() );
613 }
614 return true;
615 }
616 else if ( d->type == QVariant::UserType && d->typeName.compare( QLatin1String( "geometry" ), Qt::CaseInsensitive ) == 0 )
617 {
618 if ( v.userType() == QMetaType::type( "QgsReferencedGeometry" ) || v.userType() == QMetaType::type( "QgsGeometry" ) )
619 {
620 return true;
621 }
622 else if ( v.type() == QVariant::String )
623 {
624 const QgsGeometry geom = QgsGeometry::fromWkt( v.toString() );
625 if ( !geom.isNull() )
626 {
627 v = QVariant::fromValue( geom );
628 return true;
629 }
630 }
631 return false;
632 }
633 else if ( !v.convert( d->type ) )
634 {
635 v = QVariant( d->type );
636
637 if ( errorMessage )
638 *errorMessage = QObject::tr( "Could not convert value \"%1\" to target type \"%2\"" )
639 .arg( original.toString(),
640 d->typeName );
641
642 return false;
643 }
644
645 if ( d->type == QVariant::Double && d->precision > 0 )
646 {
647 const double s = std::pow( 10, d->precision );
648 const double d = v.toDouble() * s;
649 v = QVariant( ( d < 0 ? std::ceil( d - 0.5 ) : std::floor( d + 0.5 ) ) / s );
650 return true;
651 }
652
653 if ( d->type == QVariant::String && d->length > 0 && v.toString().length() > d->length )
654 {
655 const int length = v.toString().length();
656 v = v.toString().left( d->length );
657
658 if ( errorMessage )
659 *errorMessage = QObject::tr( "String of length %1 exceeds maximum field length (%2)" ).arg( length ).arg( d->length );
660
661 return false;
662 }
663
664 return true;
665}
666
668{
669 d->editorWidgetSetup = v;
670}
671
673{
674 return d->editorWidgetSetup;
675}
676
677void QgsField::setReadOnly( bool readOnly )
678{
679 d->isReadOnly = readOnly;
680}
681
683{
684 return d->isReadOnly;
685}
686
688{
689 return d->splitPolicy;
690}
691
693{
694 d->splitPolicy = policy;
695}
696
697/***************************************************************************
698 * This class is considered CRITICAL and any change MUST be accompanied with
699 * full unit tests in testqgsfield.cpp.
700 * See details in QEP #17
701 ****************************************************************************/
702
703QDataStream &operator<<( QDataStream &out, const QgsField &field )
704{
705 out << field.name();
706 out << static_cast< quint32 >( field.type() );
707 out << field.typeName();
708 out << field.length();
709 out << field.precision();
710 out << field.comment();
711 out << field.alias();
714 out << field.constraints().constraints();
715 out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintNotNull ) );
716 out << static_cast< quint32 >( field.constraints().constraintOrigin( QgsFieldConstraints::ConstraintUnique ) );
723 out << static_cast< quint32 >( field.subType() );
724 out << static_cast< int >( field.splitPolicy() );
725 return out;
726}
727
728QDataStream &operator>>( QDataStream &in, QgsField &field )
729{
730 quint32 type;
731 quint32 subType;
732 quint32 length;
733 quint32 precision;
734 quint32 constraints;
735 quint32 originNotNull;
736 quint32 originUnique;
737 quint32 originExpression;
738 quint32 strengthNotNull;
739 quint32 strengthUnique;
740 quint32 strengthExpression;
741 int splitPolicy;
742
743 bool applyOnUpdate;
744
745 QString name;
746 QString typeName;
747 QString comment;
748 QString alias;
749 QString defaultValueExpression;
750 QString constraintExpression;
751 QString constraintDescription;
752
753 in >> name >> type >> typeName >> length >> precision >> comment >> alias
754 >> defaultValueExpression >> applyOnUpdate >> constraints >> originNotNull >> originUnique >> originExpression >> strengthNotNull >> strengthUnique >> strengthExpression >>
755 constraintExpression >> constraintDescription >> subType >> splitPolicy;
756 field.setName( name );
757 field.setType( static_cast< QVariant::Type >( type ) );
759 field.setLength( static_cast< int >( length ) );
760 field.setPrecision( static_cast< int >( precision ) );
761 field.setComment( comment );
762 field.setAlias( alias );
763 field.setDefaultValueDefinition( QgsDefaultValue( defaultValueExpression, applyOnUpdate ) );
764 field.setSplitPolicy( static_cast< Qgis::FieldDomainSplitPolicy >( splitPolicy ) );
765 QgsFieldConstraints fieldConstraints;
766 if ( constraints & QgsFieldConstraints::ConstraintNotNull )
767 {
768 fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintNotNull, static_cast< QgsFieldConstraints::ConstraintOrigin>( originNotNull ) );
770 }
771 else
773 if ( constraints & QgsFieldConstraints::ConstraintUnique )
774 {
775 fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintUnique, static_cast< QgsFieldConstraints::ConstraintOrigin>( originUnique ) );
777 }
778 else
781 {
782 fieldConstraints.setConstraint( QgsFieldConstraints::ConstraintExpression, static_cast< QgsFieldConstraints::ConstraintOrigin>( originExpression ) );
784 }
785 else
787 fieldConstraints.setConstraintExpression( constraintExpression, constraintDescription );
788 field.setConstraints( fieldConstraints );
789 field.setSubType( static_cast< QVariant::Type >( subType ) );
790 return in;
791}
FieldDomainSplitPolicy
Split policy for field domains.
Definition: qgis.h:2273
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:52
void setSplitPolicy(Qgis::FieldDomainSplitPolicy policy)
Sets the field's split policy, which indicates how field values should be handled during a split oper...
Definition: qgsfield.cpp:692
bool isDateOrTime
Definition: qgsfield.h:56
void setEditorWidgetSetup(const QgsEditorWidgetSetup &v)
Set the editor widget setup for the field.
Definition: qgsfield.cpp:667
QString typeName() const
Gets the field type.
Definition: qgsfield.cpp:150
void setConstraints(const QgsFieldConstraints &constraints)
Sets constraints which are present for the field.
Definition: qgsfield.cpp:230
void setAlias(const QString &alias)
Sets the alias for the field (the friendly displayed name of the field ).
Definition: qgsfield.cpp:245
QString name
Definition: qgsfield.h:61
bool operator!=(const QgsField &other) const
Definition: qgsfield.cpp:78
bool operator==(const QgsField &other) const
Definition: qgsfield.cpp:73
int precision
Definition: qgsfield.h:58
static QString readableConfigurationFlag(QgsField::ConfigurationFlag flag)
Returns the readable and translated value of the configuration flag.
Definition: qgsfield.cpp:400
int length
Definition: qgsfield.h:57
QgsField & operator=(const QgsField &other)
Assignment operator.
Definition: qgsfield.cpp:67
QString displayString(const QVariant &v) const
Formats string for display.
Definition: qgsfield.cpp:266
void setPrecision(int precision)
Set the field precision.
Definition: qgsfield.cpp:210
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
bool convertCompatible(QVariant &v, QString *errorMessage=nullptr) const
Converts the provided variant to a compatible format.
Definition: qgsfield.cpp:422
void setName(const QString &name)
Set the field name.
Definition: qgsfield.cpp:186
void setComment(const QString &comment)
Set the field comment.
Definition: qgsfield.cpp:215
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
Qgis::FieldDomainSplitPolicy splitPolicy() const
Returns the field's split policy, which indicates how field values should be handled during a split o...
Definition: qgsfield.cpp:687
void setLength(int len)
Set the field length.
Definition: qgsfield.cpp:206
void setConfigurationFlags(QgsField::ConfigurationFlags configurationFlags)
Sets the Flags for the field (searchable, …)
Definition: qgsfield.cpp:255
QString displayName() const
Returns the name to use when displaying this field.
Definition: qgsfield.cpp:88
void setDefaultValueDefinition(const QgsDefaultValue &defaultValueDefinition)
Sets an expression to use when calculating the default value for the field.
Definition: qgsfield.cpp:225
Q_GADGET bool isNumeric
Definition: qgsfield.h:55
ConfigurationFlags configurationFlags
Definition: qgsfield.h:65
QString friendlyTypeString() const
Returns a user friendly, translated representation of the field type.
Definition: qgsfield.cpp:128
void setReadOnly(bool readOnly)
Make field read-only if readOnly is set to true.
Definition: qgsfield.cpp:677
QVariant::Type type
Definition: qgsfield.h:59
QVariant::Type subType() const
If the field is a collection, gets its element's type.
Definition: qgsfield.cpp:145
QString alias
Definition: qgsfield.h:62
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
static constexpr int MAX_WKT_LENGTH
Definition: qgsfield.h:486
QgsDefaultValue defaultValueDefinition
Definition: qgsfield.h:63
void setSubType(QVariant::Type subType)
If the field is a collection, set its element's type.
Definition: qgsfield.cpp:196
void setType(QVariant::Type type)
Set variant type.
Definition: qgsfield.cpp:191
QString comment
Definition: qgsfield.h:60
virtual ~QgsField()
QgsFieldConstraints constraints
Definition: qgsfield.h:64
ConfigurationFlag
Configuration flags for fields These flags are meant to be user-configurable and are not describing a...
Definition: qgsfield.h:81
@ 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:672
bool isReadOnly
Definition: qgsfield.h:66
void setTypeName(const QString &typeName)
Set the field type.
Definition: qgsfield.cpp:201
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
Q_GADGET bool isNull
Definition: qgsgeometry.h:166
static QgsGeometry fromWkt(const QString &wkt)
Creates a new geometry from a WKT string.
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 QString typeToDisplayString(QVariant::Type type, QVariant::Type subType=QVariant::Type::Invalid)
Returns a user-friendly translated string representing a QVariant type.
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:728
QDataStream & operator<<(QDataStream &out, const QgsField &field)
Definition: qgsfield.cpp:703
const QgsField & field
Definition: qgsfield.h:501
const QString & typeName
int precision