Draft conversions methods

This commit is contained in:
Mathieu Pellerin 2025-08-20 13:46:48 +07:00 committed by Nyall Dawson
parent 63ed8cb23a
commit 6d2c2adadc
5 changed files with 150 additions and 3 deletions

View File

@ -124,6 +124,10 @@ Encapsulates the data for an XY plot series.
QgsXyPlotSeries();
~QgsXyPlotSeries();
QList<std::pair<double, double>> data() const;
%Docstring
Returns the series' list of XY pairs of double.
%End
void append( const double &x, const double &y );
%Docstring

View File

@ -5,6 +5,7 @@ which are not wrapped by PyQt:
- QVector< QVector< QVector<TYPE> > >
- QList< QList<TYPE> >
- QList<qint64>
- QList< std::pair< double, double > >
- QSet<int>
- QSet<qint64>
- QSet<TYPE>
@ -16,7 +17,7 @@ which are not wrapped by PyQt:
- QMultiMap<double, TYPE2>
- QMultiMap<int, TYPE2>
- QMap<qint64, TYPE>
- QList< QPair< QString, QList<QString> > >
- QMap< QPair< QString, QList<QString> > >
- QVector<TYPE*>
- QMap<qint64, QgsFeature*>
- NULL QVariant which is missing in PyQt5 with sip.enableautoconversion
@ -3136,6 +3137,74 @@ template <TYPE>
%End
};
%MappedType QList< std::pair< double, double > >
{
%TypeHeaderCode
#include <QList>
#include <utility>
%End
%ConvertFromTypeCode
//convert list of pairs to a python array of tuple
PyObject *l;
if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;
// Set the list elements.
QList< std::pair < double, double > >::iterator it = sipCpp->begin();
for (int i = 0; it != sipCpp->end(); ++it, ++i)
{
PyObject *obj;
if ( ( obj = PyTuple_New( 2 ) ) == NULL )
{
Py_DECREF( l );
return NULL;
}
PyObject *v1 = PyFloat_FromDouble( ( *it ).first );
PyTuple_SetItem( obj, 0, v1 );
PyObject *v2 = PyFloat_FromDouble( ( *it ).second );
PyTuple_SetItem( obj, 1, v2 );
PyList_SET_ITEM(l, i, obj);
}
return l;
%End
%ConvertToTypeCode
// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PyList_Check(sipPy))
return 0;
return 1;
}
QList< std::pair < double, double > > *ql = new QList< std::pair< double, double > >;
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
{
int state;
PyObject *sipFirst = PyTuple_GetItem( PyList_GET_ITEM(sipPy, i), 0 );
double v1 = PyFloat_AsDouble(sipFirst);
PyObject *sipSecond = PyTuple_GetItem( PyList_GET_ITEM(sipPy, i), 1 );
double v2 = PyFloat_AsDouble(sipSecond);
ql->append( std::make_pair( v1, v2 ) );
}
*sipCppPtr = ql;
return sipGetState(sipTransferObj);
%End
};
%If (VECTOR_MAPPED_TYPE)
template <TYPE>
%MappedType QVector< TYPE* >

View File

@ -124,6 +124,10 @@ Encapsulates the data for an XY plot series.
QgsXyPlotSeries();
~QgsXyPlotSeries();
QList<std::pair<double, double>> data() const;
%Docstring
Returns the series' list of XY pairs of double.
%End
void append( const double &x, const double &y );
%Docstring

View File

@ -5,6 +5,7 @@ which are not wrapped by PyQt:
- QVector< QVector< QVector<TYPE> > >
- QList< QList<TYPE> >
- QList<qint64>
- QList< std::pair< double, double > >
- QSet<int>
- QSet<qint64>
- QSet<TYPE>
@ -16,7 +17,7 @@ which are not wrapped by PyQt:
- QMultiMap<double, TYPE2>
- QMultiMap<int, TYPE2>
- QMap<qint64, TYPE>
- QList< QPair< QString, QList<QString> > >
- QMap< QPair< QString, QList<QString> > >
- QVector<TYPE*>
- QMap<qint64, QgsFeature*>
- NULL QVariant which is missing in PyQt5 with sip.enableautoconversion
@ -2634,6 +2635,7 @@ template<double, TYPE>
%End
};
%MappedType QMap<double, double>
{
%TypeHeaderCode
@ -3186,6 +3188,74 @@ template <TYPE>
%End
};
%MappedType QList< std::pair< double, double > >
{
%TypeHeaderCode
#include <QList>
#include <utility>
%End
%ConvertFromTypeCode
//convert list of pairs to a python array of tuple
PyObject *l;
if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;
// Set the list elements.
QList< std::pair < double, double > >::iterator it = sipCpp->begin();
for (int i = 0; it != sipCpp->end(); ++it, ++i)
{
PyObject *obj;
if ( ( obj = PyTuple_New( 2 ) ) == NULL )
{
Py_DECREF( l );
return NULL;
}
PyObject *v1 = PyFloat_FromDouble( ( *it ).first );
PyTuple_SetItem( obj, 0, v1 );
PyObject *v2 = PyFloat_FromDouble( ( *it ).second );
PyTuple_SetItem( obj, 1, v2 );
PyList_SET_ITEM(l, i, obj);
}
return l;
%End
%ConvertToTypeCode
// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PyList_Check(sipPy))
return 0;
return 1;
}
QList< std::pair < double, double > > *ql = new QList< std::pair< double, double > >;
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
{
int state;
PyObject *sipFirst = PyTuple_GetItem( PyList_GET_ITEM(sipPy, i), 0 );
double v1 = PyFloat_AsDouble(sipFirst);
PyObject *sipSecond = PyTuple_GetItem( PyList_GET_ITEM(sipPy, i), 1 );
double v2 = PyFloat_AsDouble(sipSecond);
ql->append( std::make_pair( v1, v2 ) );
}
*sipCppPtr = ql;
return sipGetState(sipTransferObj);
%End
};
%If (VECTOR_MAPPED_TYPE)
template <TYPE>
%MappedType QVector< TYPE* >

View File

@ -137,7 +137,7 @@ class CORE_EXPORT QgsXyPlotSeries : public QgsAbstractPlotSeries
/**
* Returns the series' list of XY pairs of double.
*/
QList<std::pair<double, double>> data() const SIP_SKIP;
QList<std::pair<double, double>> data() const;
/**
* Appends a pair of X/Y double values to the series.