Skip to content
Permalink
Browse files

Add sip conversions for profile times

  • Loading branch information
NathanW2 committed Jun 4, 2016
1 parent 53a57e1 commit 6a4556ddd04a95c5d00c899afa4c20696e484331
Showing with 62 additions and 1 deletion.
  1. +61 −0 python/core/conversions.sip
  2. +1 −1 python/core/qgsruntimeprofiler.sip
@@ -1592,6 +1592,67 @@ template<int, TYPE2*>
%End
};

%MappedType QList < QPair< QString, double > >
{
%TypeHeaderCode
#include <QPair>
#include <QList>
%End

%ConvertFromTypeCode
//convert map to a python dictionary
PyObject *d;

if ((d = PyList_New( sipCpp->size() )) == NULL)
return NULL;

for ( int i = 0; i<sipCpp->size(); i++ )
{
PyObject *p;
if ((p = PyList_New(2) ) == NULL)
{
Py_DECREF(d);
return NULL;
}

PyObject *t1obj = sipConvertFromNewType(new QString(sipCpp->at(i).first), sipType_QString, sipTransferObj);
PyObject *t2obj = PyFloat_FromDouble( (double) sipCpp->at(i).second );
PyList_SetItem( p, 0, t1obj );
PyList_SetItem( p, 1, t2obj );

PyList_SetItem( d, i, p );
}

return d;
%End
%ConvertToTypeCode
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t i = 0;
#else
int i = 0;
#endif
QList < QPair< QString, double > > *qm = new QList< QPair< QString, double > >;

for ( i = 0; i < PyList_GET_SIZE(sipPy); i++ )
{
int state;

PyObject *sipPair = PyList_GetItem( sipPy, i );
PyObject *sipString = PyList_GetItem( sipPair, 0 );
PyObject *sipDouble = PyList_GetItem( sipPair, 1 );

QString *t1 = reinterpret_cast<QString *>(sipConvertToType(sipString, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
double value = PyFloat_AsDouble(sipDouble);
qm->append( qMakePair( *t1, value ) );
sipReleaseType(t1, sipType_QString, state);
}

*sipCppPtr = qm;

return sipGetState(sipTransferObj);
%End
};

%MappedType QList < QPair< QgsVectorLayer *, int > >
{
%TypeHeaderCode
@@ -46,7 +46,7 @@ class QgsRuntimeProfiler
* @brief Return all the current profile times.
* @return A list of profile event names and times.
*/
// const QList<QPair<QString, double>> profileTimes() const;
const QList<QPair<QString, double>> profileTimes() const;

/**
* @brief clear Clear all profile data.

0 comments on commit 6a4556d

Please sign in to comment.
You can’t perform that action at this time.