Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-3_40] Optimise conversion of QgsAttributes to Python objects #60713

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions python/PyQt6/core/auto_generated/qgsattributes.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ typedef QMap<int, QString> QgsFieldNameMap;
typedef QMap<int, QgsField> QgsFieldMap;




typedef QVector<QVariant> QgsAttributes;

%MappedType QgsAttributes
Expand All @@ -39,14 +41,60 @@ typedef QVector<QVariant> QgsAttributes;
// Set the list elements.
for ( int i = 0; i < sipCpp->size(); ++i )
{
QVariant *v = new QVariant( sipCpp->at( i ) );
PyObject *tobj;

if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant, Py_None ) ) == NULL )
const QVariant v = sipCpp->at( i );
PyObject *tobj = NULL;
// QByteArray null handling is "special"! See null_from_qvariant_converter in conversions.sip
if ( QgsVariantUtils::isNull( v, true ) && v.userType() != QMetaType::Type::QByteArray )
{
Py_INCREF( Py_None );
tobj = Py_None;
}
else
{
switch ( v.userType() )
{
case QMetaType::Type::Int:
tobj = PyLong_FromLong( v.toInt() );
break;

case QMetaType::Type::UInt:
tobj = PyLong_FromUnsignedLong( v.toUInt() );
break;

case QMetaType::Type::Long:
case QMetaType::Type::LongLong:
tobj = PyLong_FromLongLong( v.toLongLong() );
break;

case QMetaType::Type::ULong:
case QMetaType::Type::ULongLong:
tobj = PyLong_FromUnsignedLongLong( v.toULongLong() );
break;

case QMetaType::Type::Bool:
tobj = PyBool_FromLong( v.toBool() ? 1 : 0 );
break;

case QMetaType::Type::Float:
case QMetaType::Type::Double:
tobj = PyFloat_FromDouble( v.toDouble() );
break;

case QMetaType::Type::QString:
tobj = PyUnicode_FromString( v.toString().toUtf8().constData() );
break;

default:
{
QVariant *newV = new QVariant( v );
tobj = sipConvertFromNewType( newV, sipType_QVariant, sipTransferObj );
break;
}
}
}
if ( tobj == NULL )
{
Py_DECREF( l );
delete v;

return NULL;
}

Expand Down Expand Up @@ -125,8 +173,6 @@ typedef QVector<QVariant> QgsAttributes;
return sipGetState( sipTransferObj );
%End
};


/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
69 changes: 62 additions & 7 deletions python/core/auto_generated/qgsattributes.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef QMap<int, QString> QgsFieldNameMap;
typedef QMap<int, QgsField> QgsFieldMap;



typedef QVector<QVariant> QgsAttributes;

%MappedType QgsAttributes
Expand All @@ -39,14 +40,69 @@ typedef QVector<QVariant> QgsAttributes;
// Set the list elements.
for ( int i = 0; i < sipCpp->size(); ++i )
{
QVariant *v = new QVariant( sipCpp->at( i ) );
PyObject *tobj;

if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant, Py_None ) ) == NULL )
const QVariant v = sipCpp->at( i );
PyObject *tobj = NULL;
if ( !v.isValid() )
{
Py_INCREF( Py_None );
tobj = Py_None;
}
// QByteArray null handling is "special"! See null_from_qvariant_converter in conversions.sip
else if ( QgsVariantUtils::isNull( v, true ) && v.userType() != QMetaType::Type::QByteArray )
{
PyObject *vartype = sipConvertFromEnum( v.type(), sipType_QVariant_Type );
PyObject *args = PyTuple_Pack( 1, vartype );
PyTypeObject *typeObj = sipTypeAsPyTypeObject( sipType_QVariant );
tobj = PyObject_Call( ( PyObject * )typeObj, args, nullptr );
Py_DECREF( args );
Py_DECREF( vartype );
}
else
{
switch ( v.userType() )
{
case QMetaType::Type::Int:
tobj = PyLong_FromLong( v.toInt() );
break;

case QMetaType::Type::UInt:
tobj = PyLong_FromUnsignedLong( v.toUInt() );
break;

case QMetaType::Type::Long:
case QMetaType::Type::LongLong:
tobj = PyLong_FromLongLong( v.toLongLong() );
break;

case QMetaType::Type::ULong:
case QMetaType::Type::ULongLong:
tobj = PyLong_FromUnsignedLongLong( v.toULongLong() );
break;

case QMetaType::Type::Bool:
tobj = PyBool_FromLong( v.toBool() ? 1 : 0 );
break;

case QMetaType::Type::Float:
case QMetaType::Type::Double:
tobj = PyFloat_FromDouble( v.toDouble() );
break;

case QMetaType::Type::QString:
tobj = PyUnicode_FromString( v.toString().toUtf8().constData() );
break;

default:
{
QVariant *newV = new QVariant( v );
tobj = sipConvertFromNewType( newV, sipType_QVariant, sipTransferObj );
break;
}
}
}
if ( tobj == NULL )
{
Py_DECREF( l );
delete v;

return NULL;
}

Expand Down Expand Up @@ -126,7 +182,6 @@ typedef QVector<QVariant> QgsAttributes;
%End
};


/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
Loading
Loading