Sipify QgsField

This commit is contained in:
arnaud.morvan@camptocamp.com 2017-04-30 21:58:30 +02:00 committed by Denis Rouzaud
parent 5d5bb34383
commit 8376a30f7a
3 changed files with 294 additions and 179 deletions

View File

@ -13,7 +13,6 @@ core/qgsexpressioncontextgenerator.sip
core/qgsfeaturefilterprovider.sip
core/qgsfeatureiterator.sip
core/qgsfeaturerequest.sip
core/qgsfield.sip
core/qgsfieldconstraints.sip
core/qgsfields.sip
core/qgsfieldformatterregistry.sip

View File

@ -1,216 +1,261 @@
/** \class QgsField
* \ingroup core
* Encapsulate a field in an attribute table or data source.
* QgsField stores metadata about an attribute field, including name, type
* length, and if applicable, precision.
* \note QgsField objects are implicitly shared.
*/
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfield.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
class QgsField
{
%Docstring
Encapsulate a field in an attribute table or data source.
QgsField stores metadata about an attribute field, including name, type
length, and if applicable, precision.
.. note::
%TypeHeaderCode
#include <qgsfield.h>
QgsField objects are implicitly shared.
%End
%TypeHeaderCode
#include "qgsfield.h"
%End
public:
/** Constructor. Constructs a new QgsField object.
* @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
* as returned from the data store.
* @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)
* @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.
*/
QgsField( const QString& name = QString(),
QgsField( const QString &name = QString(),
QVariant::Type type = QVariant::Invalid,
const QString& typeName = QString(),
const QString &typeName = QString(),
int len = 0,
int prec = 0,
const QString& comment = QString(),
const QString &comment = QString(),
QVariant::Type subType = QVariant::Invalid );
%Docstring
Constructor. Constructs a new QgsField object.
\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
as returned from the data store.
\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)
\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.
%End
QgsField( const QgsField &other );
%Docstring
Copy constructor
%End
/** Copy constructor
*/
QgsField( const QgsField& other );
//! Destructor
virtual ~QgsField();
bool operator==( const QgsField& other ) const;
bool operator!=( const QgsField& other ) const;
bool operator==( const QgsField &other ) const;
%Docstring
:rtype: bool
%End
bool operator!=( const QgsField &other ) const;
%Docstring
:rtype: bool
%End
/** Returns the name of the field.
* @see setName()
* @see displayName()
*/
QString name() const;
%Docstring
Returns the name of the field.
.. seealso:: setName()
.. seealso:: displayName()
:rtype: str
%End
/** Returns the name to use when displaying this field. This will be the
* field alias if set, otherwise the field name.
* @see name()
* @see alias()
* @note added in QGIS 3.0
*/
QString displayName() const;
%Docstring
Returns the name to use when displaying this field. This will be the
field alias if set, otherwise the field name.
.. seealso:: name()
.. seealso:: alias()
.. versionadded:: 3.0
:rtype: str
%End
//! Gets variant type of the field as it will be retrieved from data source
QVariant::Type type() const;
%Docstring
Gets variant type of the field as it will be retrieved from data source
:rtype: QVariant.Type
%End
/**
* 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.
* @note added in QGIS 3.0
*/
QVariant::Type subType() const;
%Docstring
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.
.. versionadded:: 3.0
:rtype: QVariant.Type
%End
/**
* 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
*/
QString typeName() const;
%Docstring
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
:rtype: str
%End
/**
* Gets the length of the field.
* @return int containing the length of the field
*/
int length() const;
%Docstring
Gets the length of the field.
:return: int containing the length of the field
:rtype: int
%End
/**
* 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.
*/
int precision() const;
%Docstring
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.
:rtype: int
%End
/**
* Returns the field comment
*/
QString comment() const;
%Docstring
Returns the field comment
:rtype: str
%End
/**
* Returns if this field is numeric. Any integer or floating point type
* will return true for this.
*
* @note added in QGIS 2.18
*/
bool isNumeric() const;
%Docstring
Returns if this field is numeric. Any integer or floating point type
will return true for this.
/**
* Set the field name.
* @param name Name of the field
*/
void setName( const QString& name );
.. versionadded:: 2.18
:rtype: bool
%End
void setName( const QString &name );
%Docstring
Set the field name.
\param name Name of the field
%End
/**
* Set variant type.
*/
void setType( QVariant::Type type );
%Docstring
Set variant type.
%End
/**
* 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.
* @note added in QGIS 3.0
*/
void setSubType( QVariant::Type subType );
%Docstring
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.
.. versionadded:: 3.0
%End
/**
* Set the field type.
* @param typeName Field type
*/
void setTypeName( const QString& typeName );
void setTypeName( const QString &typeName );
%Docstring
Set the field type.
\param typeName Field type
%End
/**
* Set the field length.
* @param len Length of the field
*/
void setLength( int len );
%Docstring
Set the field length.
\param len Length of the field
%End
/**
* Set the field precision.
* @param precision Precision of the field
*/
void setPrecision( int precision );
%Docstring
Set the field precision.
\param precision Precision of the field
%End
/**
* Set the field comment
*/
void setComment( const QString& comment );
void setComment( const QString &comment );
%Docstring
Set the field comment
%End
/** Returns the expression used when calculating the default value for the field.
* @returns expression evaluated when calculating default values for field, or an
* empty string if no default is set
* @note added in QGIS 3.0
* @see setDefaultValueExpression()
*/
QString defaultValueExpression() const;
%Docstring
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
.. versionadded:: 3.0
.. seealso:: setDefaultValueExpression()
:rtype: str
%End
/** Sets an expression to use when calculating the default value for the field.
* @param expression expression to evaluate when calculating default values for field. Pass
* an empty expression to clear the default.
* @note added in QGIS 3.0
* @see defaultValueExpression()
*/
void setDefaultValueExpression( const QString& expression );
void setDefaultValueExpression( const QString &expression );
%Docstring
Sets an expression to use when calculating the default value for the field.
\param expression expression to evaluate when calculating default values for field. Pass
an empty expression to clear the default.
.. versionadded:: 3.0
.. seealso:: defaultValueExpression()
%End
/**
* Returns constraints which are present for the field.
* @note added in QGIS 3.0
* @see setConstraints()
*/
const QgsFieldConstraints& constraints() const;
const QgsFieldConstraints &constraints() const;
%Docstring
Returns constraints which are present for the field.
.. versionadded:: 3.0
.. seealso:: setConstraints()
:rtype: QgsFieldConstraints
%End
/**
* Sets constraints which are present for the field.
* @note added in QGIS 3.0
* @see constraints()
*/
void setConstraints( const QgsFieldConstraints& constraints );
void setConstraints( const QgsFieldConstraints &constraints );
%Docstring
Sets constraints which are present for the field.
.. versionadded:: 3.0
.. seealso:: constraints()
%End
/** Returns the alias for the field (the friendly displayed name of the field ),
* or an empty string if there is no alias.
* @see setAlias()
* @note added in QGIS 3.0
*/
QString alias() const;
%Docstring
Returns the alias for the field (the friendly displayed name of the field ),
or an empty string if there is no alias.
.. seealso:: setAlias()
.. versionadded:: 3.0
:rtype: str
%End
/** Sets the alias for the field (the friendly displayed name of the field ).
* @param alias field alias, or empty string to remove an existing alias
* @see alias()
* @note added in QGIS 3.0
*/
void setAlias( const QString& alias );
void setAlias( const QString &alias );
%Docstring
Sets the alias for the field (the friendly displayed name of the field ).
\param alias field alias, or empty string to remove an existing alias
.. seealso:: alias()
.. versionadded:: 3.0
%End
/** Formats string for display*/
QString displayString( const QVariant& v ) const;
QString displayString( const QVariant &v ) const;
%Docstring
Formats string for display
:rtype: str
%End
/**
* Converts the provided variant to a compatible format
*
* @param v The value to convert
*
* @return True if the conversion was successful
*/
QVariant convertCompatible( QVariant& v ) const;
bool convertCompatible( QVariant &v ) const;
%Docstring
Converts the provided variant to a compatible format
\param v The value to convert
:return: True if the conversion was successful
:rtype: bool
%End
%MethodCode
PyObject *sipParseErr = NULL;
{
QVariant * a0;
QVariant *a0;
int a0State = 0;
const QgsField *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QgsField, &sipCpp, sipType_QVariant,&a0, &a0State))
if ( sipParseArgs( &sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QgsField, &sipCpp, sipType_QVariant, &a0, &a0State ) )
{
bool sipRes;
@ -218,55 +263,72 @@ class QgsField
try
{
QgsDebugMsg( a0->toString() );
sipRes = sipCpp->convertCompatible(*a0);
sipRes = sipCpp->convertCompatible( *a0 );
QgsDebugMsg( a0->toString() );
}
catch (...)
catch ( ... )
{
Py_BLOCK_THREADS
sipReleaseType(a0,sipType_QVariant,a0State);
sipRaiseUnknownException();
return NULL;
sipReleaseType( a0, sipType_QVariant, a0State );
sipRaiseUnknownException();
return NULL;
}
Py_END_ALLOW_THREADS
PyObject* res = sipConvertFromType( a0, sipType_QVariant, NULL );
sipReleaseType(a0,sipType_QVariant,a0State);
PyObject *res = sipConvertFromType( a0, sipType_QVariant, NULL );
sipReleaseType( a0, sipType_QVariant, a0State );
if ( !sipRes )
{
PyErr_SetString(PyExc_ValueError,
QString( "Value %1 (%2) could not be converted to field type %3." ).arg( a0->toString(), a0->typeName() ).arg( sipCpp->type() ).toUtf8().constData() );
sipError = sipErrorFail;
PyErr_SetString( PyExc_ValueError,
QString( "Value %1 (%2) could not be converted to field type %3." ).arg( a0->toString(), a0->typeName() ).arg( sipCpp->type() ).toUtf8().constData() );
sipError = sipErrorFail;
}
return res;
}
}
/* Raise an exception if the arguments couldn't be parsed. */
sipNoMethod(sipParseErr, sipName_QgsField, sipName_convertCompatible, doc_QgsField_convertCompatible);
// Raise an exception if the arguments couldn't be parsed.
sipNoMethod( sipParseErr, sipName_QgsField, sipName_convertCompatible, doc_QgsField_convertCompatible );
return nullptr;
return 0;
%End
//! Allows direct construction of QVariants from fields.
operator QVariant() const;
%Docstring
Allows direct construction of QVariants from fields.
%End
/**
* Set the editor widget setup for the field.
*
* @param v The value to set
*/
void setEditorWidgetSetup( const QgsEditorWidgetSetup& v );
void setEditorWidgetSetup( const QgsEditorWidgetSetup &v );
%Docstring
Set the editor widget setup for the field.
\param v The value to set
%End
QgsEditorWidgetSetup editorWidgetSetup() const;
%Docstring
Get the editor widget setup for the field.
Defaults may be set by the provider and can be overridden
by manual field configuration.
:return: the value
:rtype: QgsEditorWidgetSetup
%End
/**
* Get the editor widget setup for the field.
*
* @return the value
*/
const QgsEditorWidgetSetup& editorWidgetSetup() const;
}; // class QgsField
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsfield.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

View File

@ -22,8 +22,11 @@
#include <QSharedDataPointer>
#include "qgsfield_p.h"
#include "qgis_core.h"
#include "qgis.h"
#ifndef SIP_RUN
typedef QList<int> QgsAttributeList;
#endif
/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
@ -85,7 +88,7 @@ class CORE_EXPORT QgsField
/** Assignment operator
*/
QgsField &operator =( const QgsField &other );
QgsField &operator =( const QgsField &other ) SIP_SKIP;
virtual ~QgsField() = default;
@ -247,6 +250,57 @@ class CORE_EXPORT QgsField
* \returns True if the conversion was successful
*/
bool convertCompatible( QVariant &v ) const;
#ifdef SIP_RUN
% MethodCode
PyObject *sipParseErr = NULL;
{
QVariant *a0;
int a0State = 0;
const QgsField *sipCpp;
if ( sipParseArgs( &sipParseErr, sipArgs, "BJ1", &sipSelf, sipType_QgsField, &sipCpp, sipType_QVariant, &a0, &a0State ) )
{
bool sipRes;
Py_BEGIN_ALLOW_THREADS
try
{
QgsDebugMsg( a0->toString() );
sipRes = sipCpp->convertCompatible( *a0 );
QgsDebugMsg( a0->toString() );
}
catch ( ... )
{
Py_BLOCK_THREADS
sipReleaseType( a0, sipType_QVariant, a0State );
sipRaiseUnknownException();
return NULL;
}
Py_END_ALLOW_THREADS
PyObject *res = sipConvertFromType( a0, sipType_QVariant, NULL );
sipReleaseType( a0, sipType_QVariant, a0State );
if ( !sipRes )
{
PyErr_SetString( PyExc_ValueError,
QString( "Value %1 (%2) could not be converted to field type %3." ).arg( a0->toString(), a0->typeName() ).arg( sipCpp->type() ).toUtf8().constData() );
sipError = sipErrorFail;
}
return res;
}
}
// Raise an exception if the arguments couldn't be parsed.
sipNoMethod( sipParseErr, sipName_QgsField, sipName_convertCompatible, doc_QgsField_convertCompatible );
return nullptr;
% End
#endif
//! Allows direct construction of QVariants from fields.
operator QVariant() const