22 #include <QSharedDataPointer>
23 #include "qgis_core.h"
38 class QgsFieldPrivate;
53 Q_PROPERTY(
bool isNumeric READ isNumeric )
54 Q_PROPERTY(
bool isDateOrTime READ isDateOrTime )
55 Q_PROPERTY(
int length READ length WRITE setLength )
57 Q_PROPERTY( QVariant::Type type READ type WRITE setType )
58 Q_PROPERTY( QString comment READ comment WRITE setComment )
59 Q_PROPERTY( QString name READ name WRITE setName )
60 Q_PROPERTY( QString alias READ alias WRITE setAlias )
61 Q_PROPERTY(
QgsDefaultValue defaultValueDefinition READ defaultValueDefinition WRITE setDefaultValueDefinition )
63 Q_PROPERTY( ConfigurationFlags configurationFlags READ configurationFlags WRITE setConfigurationFlags )
77 #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
84 NotSearchable = 1 << 1,
88 Q_ENUM( ConfigurationFlag )
89 Q_DECLARE_FLAGS( ConfigurationFlags, ConfigurationFlag )
90 #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
92 Q_ENUM( ConfigurationFlags )
94 Q_FLAG( ConfigurationFlags )
113 QgsField(
const QString &name = QString(),
114 QVariant::Type type = QVariant::Invalid,
115 const QString &
typeName = QString(),
118 const QString &comment = QString(),
119 QVariant::Type subType = QVariant::Invalid );
141 QString name()
const;
150 QString displayName()
const;
163 QString displayNameWithAlias()
const;
174 QString displayType(
bool showConstraints =
false )
const;
177 QVariant::Type type()
const;
185 QVariant::Type subType()
const;
210 QString comment()
const;
218 bool isNumeric()
const;
225 bool isDateOrTime()
const;
231 void setName(
const QString &name );
236 void setType( QVariant::Type type );
244 void setSubType( QVariant::Type subType );
250 void setTypeName(
const QString &
typeName );
256 void setLength(
int len );
267 void setComment(
const QString &comment );
285 void setDefaultValueDefinition(
const QgsDefaultValue &defaultValueDefinition );
307 QString alias()
const;
315 void setAlias(
const QString &alias );
321 QgsField::ConfigurationFlags configurationFlags() const
SIP_SKIP;
327 void setConfigurationFlags(
QgsField::ConfigurationFlags configurationFlags )
SIP_SKIP;
330 QString displayString( const QVariant &v ) const;
348 bool convertCompatible( QVariant &v, QString *errorMessage =
nullptr )
const;
358 bool convertCompatible( QVariant &v )
const;
360 PyObject *sipParseErr = NULL;
367 if ( sipParseArgs( &sipParseErr, sipArgs,
"BJ1", &sipSelf, sipType_QgsField, &sipCpp, sipType_QVariant, &a0, &a0State ) )
370 QString errorMessage;
372 Py_BEGIN_ALLOW_THREADS
381 sipReleaseType( a0, sipType_QVariant, a0State );
382 sipRaiseUnknownException();
390 PyErr_SetString( PyExc_ValueError,
391 QString(
"Value could not be converted to field type %1: %2" ).arg(
QMetaType::typeName( sipCpp->
type() ), errorMessage ).toUtf8().constData() );
396 PyObject *res = sipConvertFromType( a0, sipType_QVariant, NULL );
397 sipReleaseType( a0, sipType_QVariant, a0State );
404 sipNoMethod( sipParseErr, sipName_QgsField, sipName_convertCompatible, doc_QgsField_convertCompatible );
414 operator QVariant()
const
416 return QVariant::fromValue( *
this );
437 SIP_PYOBJECT __repr__();
439 QString str = QStringLiteral(
"<QgsField: %1 (%2)>" ).arg( sipCpp->
name() ).arg( sipCpp->
typeName() );
440 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
446 QSharedDataPointer<QgsFieldPrivate> d;
456 CORE_EXPORT QDataStream &operator<<( QDataStream &out, const
QgsField &
field );
458 CORE_EXPORT QDataStream &operator>>( QDataStream &in,
QgsField &
field );