QGIS/python/core/auto_generated/qgsfield.sip.in

411 lines
10 KiB
Plaintext
Raw Normal View History

2017-04-30 21:58:30 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfield.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
2019-11-05 10:17:34 +01:00
class QgsField
{
2021-03-22 21:13:52 +01:00
%Docstring(signature="appended")
2017-12-15 10:36:55 -04:00
Encapsulate a field in an attribute table or data source.
:py:class:`QgsField` stores metadata about an attribute field, including name, type
2017-12-15 10:36:55 -04:00
length, and if applicable, precision.
2017-04-30 21:58:30 +02:00
.. note::
:py:class:`QgsField` objects are implicitly shared.
%End
2017-04-30 21:58:30 +02:00
%TypeHeaderCode
#include "qgsfield.h"
%End
public:
static const QMetaObject staticMetaObject;
public:
2016-10-19 13:42:06 +10:00
2017-04-30 21:58:30 +02:00
QgsField( const QString &name = QString(),
QVariant::Type type = QVariant::Invalid,
2017-04-30 21:58:30 +02:00
const QString &typeName = QString(),
int len = 0,
int prec = 0,
2017-04-30 21:58:30 +02:00
const QString &comment = QString(),
QVariant::Type subType = QVariant::Invalid );
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Constructor. Constructs a new QgsField object.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param name: Field name
:param type: Field variant type, currently supported: String / Int / Double
:param typeName: Field type (e.g., char, varchar, text, int, serial, double).
Field types are usually unique to the source and are stored exactly
2018-05-27 16:33:02 +10:00
as returned from the data store.
2017-12-15 10:36:55 -04:00
:param len: Field length
:param prec: Field precision. Usually decimal places but may also be
used in conjunction with other fields types (e.g., variable character fields)
2017-12-15 10:36:55 -04:00
:param comment: Comment for the field
:param subType: If the field is a collection, its element's type. When
all the elements don't need to have the same type, leave
this to QVariant.Invalid.
2017-04-30 21:58:30 +02:00
%End
QgsField( const QgsField &other );
%Docstring
2017-12-15 10:36:55 -04:00
Copy constructor
2017-04-30 21:58:30 +02:00
%End
2015-05-03 17:03:37 +10:00
virtual ~QgsField();
2017-04-30 21:58:30 +02:00
bool operator==( const QgsField &other ) const;
bool operator!=( const QgsField &other ) const;
QString name() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the name of the field.
.. seealso:: :py:func:`setName`
2017-12-15 10:36:55 -04:00
.. seealso:: :py:func:`displayName`
2017-04-30 21:58:30 +02:00
%End
QString displayName() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the name to use when displaying this field. This will be the
field alias if set, otherwise the field name.
.. seealso:: :py:func:`name`
2017-12-15 10:36:55 -04:00
.. seealso:: :py:func:`alias`
2017-12-15 10:36:55 -04:00
2017-04-30 21:58:30 +02:00
.. versionadded:: 3.0
%End
QString displayNameWithAlias() const;
%Docstring
2019-11-03 10:04:07 +01:00
Returns the name to use when displaying this field and adds the alias in parenthesis if it is defined.
2019-11-03 10:04:07 +01:00
This will be used when working close to the data structure (i.e. building expressions and queries),
when the real field name must be shown but the alias is also useful to understand what the field
represents.
.. seealso:: :py:func:`name`
.. seealso:: :py:func:`alias`
.. versionadded:: 3.12
2017-04-30 21:58:30 +02:00
%End
QString displayType( bool showConstraints = false ) const;
%Docstring
Returns the type to use when displaying this field, including the length and precision of the datatype if applicable.
This will be used when the full datatype with details has to displayed to the user.
.. seealso:: :py:func:`type`
.. versionadded:: 3.14
%End
QVariant::Type type() const;
2017-04-30 21:58:30 +02:00
%Docstring
Gets variant type of the field as it will be retrieved from data source
%End
QVariant::Type subType() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
If the field is a collection, gets its element's type.
When all the elements don't need to have the same type, this returns
QVariant.Invalid.
2017-04-30 21:58:30 +02:00
.. versionadded:: 3.0
%End
QString typeName() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Gets the field type. Field types vary depending on the data source. Examples
are char, int, double, blob, geometry, etc. The type is stored exactly as
the data store reports it, with no attempt to standardize the value.
:return: QString containing the field type
2017-04-30 21:58:30 +02:00
%End
int length() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Gets the length of the field.
:return: int containing the length of the field
2017-04-30 21:58:30 +02:00
%End
int precision() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Gets the precision of the field. Not all field types have a related precision.
:return: int containing the precision or zero if not applicable to the field type.
2017-04-30 21:58:30 +02:00
%End
QString comment() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the field comment
2017-04-30 21:58:30 +02:00
%End
bool isNumeric() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns if this field is numeric. Any integer or floating point type
2019-02-26 19:54:09 +10:00
will return ``True`` for this.
2017-12-15 10:36:55 -04:00
2017-04-30 21:58:30 +02:00
.. versionadded:: 2.18
%End
bool isDateOrTime() const;
%Docstring
Returns if this field is a date and/or time type.
.. versionadded:: 3.6
2017-04-30 21:58:30 +02:00
%End
void setName( const QString &name );
%Docstring
2017-12-15 10:36:55 -04:00
Set the field name.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param name: Name of the field
2017-04-30 21:58:30 +02:00
%End
void setType( QVariant::Type type );
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Set variant type.
2017-04-30 21:58:30 +02:00
%End
void setSubType( QVariant::Type subType );
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
If the field is a collection, set its element's type.
When all the elements don't need to have the same type, set this to
QVariant.Invalid.
2017-04-30 21:58:30 +02:00
.. versionadded:: 3.0
%End
2017-04-30 21:58:30 +02:00
void setTypeName( const QString &typeName );
%Docstring
2017-12-15 10:36:55 -04:00
Set the field type.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param typeName: Field type
2017-04-30 21:58:30 +02:00
%End
void setLength( int len );
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Set the field length.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param len: Length of the field
2017-04-30 21:58:30 +02:00
%End
void setPrecision( int precision );
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Set the field precision.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param precision: Precision of the field
2017-04-30 21:58:30 +02:00
%End
void setComment( const QString &comment );
%Docstring
2017-12-15 10:36:55 -04:00
Set the field comment
2017-04-30 21:58:30 +02:00
%End
QgsDefaultValue defaultValueDefinition() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the expression used when calculating the default value for the field.
:return: expression evaluated when calculating default values for field, or an
empty string if no default is set
2017-12-15 10:36:55 -04:00
.. seealso:: :py:func:`setDefaultValueDefinition`
2018-05-28 11:31:08 -04:00
.. versionadded:: 3.0
2017-04-30 21:58:30 +02:00
%End
void setDefaultValueDefinition( const QgsDefaultValue &defaultValueDefinition );
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Sets an expression to use when calculating the default value for the field.
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param defaultValueDefinition: expression to evaluate when calculating default values for field. Pass
a default constructed :py:class:`QgsDefaultValue`() to reset.
2017-12-15 10:36:55 -04:00
.. seealso:: :py:func:`defaultValueDefinition`
2018-05-28 11:31:08 -04:00
.. versionadded:: 3.0
2017-04-30 21:58:30 +02:00
%End
const QgsFieldConstraints &constraints() const;
%Docstring
2017-12-15 10:36:55 -04:00
Returns constraints which are present for the field.
.. seealso:: :py:func:`setConstraints`
2018-05-28 11:31:08 -04:00
.. versionadded:: 3.0
2017-04-30 21:58:30 +02:00
%End
void setConstraints( const QgsFieldConstraints &constraints );
%Docstring
2017-12-15 10:36:55 -04:00
Sets constraints which are present for the field.
.. seealso:: :py:func:`constraints`
2018-05-28 11:31:08 -04:00
.. versionadded:: 3.0
2017-04-30 21:58:30 +02:00
%End
QString alias() const;
2017-04-30 21:58:30 +02:00
%Docstring
2017-12-15 10:36:55 -04:00
Returns the alias for the field (the friendly displayed name of the field ),
or an empty string if there is no alias.
.. seealso:: :py:func:`setAlias`
2017-12-15 10:36:55 -04:00
2017-04-30 21:58:30 +02:00
.. versionadded:: 3.0
%End
void setAlias( const QString &alias );
%Docstring
2017-12-15 10:36:55 -04:00
Sets the alias for the field (the friendly displayed name of the field ).
2017-12-15 21:36:08 -04:00
2017-12-15 10:36:55 -04:00
:param alias: field alias, or empty string to remove an existing alias
.. seealso:: :py:func:`alias`
2017-12-15 10:36:55 -04:00
2017-04-30 21:58:30 +02:00
.. versionadded:: 3.0
%End
2017-04-30 21:58:30 +02:00
QString displayString( const QVariant &v ) const;
%Docstring
Formats string for display
%End
2017-04-30 21:58:30 +02:00
bool convertCompatible( QVariant &v ) const;
%Docstring
2017-12-15 10:36:55 -04:00
Converts the provided variant to a compatible format
2017-04-30 21:58:30 +02:00
:param v: The value to convert
2017-12-15 10:36:55 -04:00
2021-06-25 08:32:25 +10:00
:raises ValueError: if the value could not be converted to a compatible format
2017-04-30 21:58:30 +02:00
%End
%MethodCode
PyObject *sipParseErr = NULL;
{
2017-04-30 21:58:30 +02:00
QVariant *a0;
int a0State = 0;
const QgsField *sipCpp;
2017-04-30 21:58:30 +02:00
if ( sipParseArgs( &sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QgsField, &sipCpp, sipType_QVariant, &a0, &a0State ) )
{
bool sipRes;
QString errorMessage;
Py_BEGIN_ALLOW_THREADS
try
{
sipRes = sipCpp->convertCompatible( *a0, &errorMessage );
}
2017-04-30 21:58:30 +02:00
catch ( ... )
{
Py_BLOCK_THREADS
2017-04-30 21:58:30 +02:00
sipReleaseType( a0, sipType_QVariant, a0State );
sipRaiseUnknownException();
return NULL;
}
Py_END_ALLOW_THREADS
if ( !sipRes )
{
2017-04-30 21:58:30 +02:00
PyErr_SetString( PyExc_ValueError,
QString( "Value could not be converted to field type %1: %2" ).arg( QMetaType::typeName( sipCpp->type() ), errorMessage ).toUtf8().constData() );
sipIsErr = 1;
}
else
{
PyObject *res = sipConvertFromType( a0, sipType_QVariant, NULL );
sipReleaseType( a0, sipType_QVariant, a0State );
return res;
}
}
else
{
// Raise an exception if the arguments couldn't be parsed.
sipNoMethod( sipParseErr, sipName_QgsField, sipName_convertCompatible, doc_QgsField_convertCompatible );
return nullptr;
}
}
%End
operator QVariant() const;
2017-04-30 21:58:30 +02:00
void setEditorWidgetSetup( const QgsEditorWidgetSetup &v );
%Docstring
2017-12-15 10:36:55 -04:00
Set the editor widget setup for the field.
2017-04-30 21:58:30 +02:00
:param v: The value to set
2017-04-30 21:58:30 +02:00
%End
QgsEditorWidgetSetup editorWidgetSetup() const;
%Docstring
Gets the editor widget setup for the field.
2017-12-15 10:36:55 -04:00
Defaults may be set by the provider and can be overridden
by manual field configuration.
2017-04-30 21:58:30 +02:00
2017-12-15 10:36:55 -04:00
:return: the value
%End
void setReadOnly( bool readOnly );
%Docstring
Make field read-only if ``readOnly`` is set to true. This is the case for
providers which support generated fields for instance.
.. versionadded:: 3.18
%End
bool isReadOnly() const;
%Docstring
Returns ``True`` if this field is a read-only field. This is the case for
providers which support generated fields for instance.
.. versionadded:: 3.18
2017-04-30 21:58:30 +02:00
%End
SIP_PYOBJECT __repr__();
%MethodCode
QString str = QStringLiteral( "<QgsField: %1 (%2)>" ).arg( sipCpp->name() ).arg( sipCpp->typeName() );
sipRes = PyUnicode_FromString( str.toUtf8().constData() );
%End
}; // class QgsField
2016-10-19 13:42:06 +10:00
2017-04-30 21:58:30 +02:00
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfield.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/