Skip to content

Commit

Permalink
Add sip conversions for profile times
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Jun 5, 2016
1 parent 53a57e1 commit 6a4556d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
61 changes: 61 additions & 0 deletions python/core/conversions.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsruntimeprofiler.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6a4556d

Please sign in to comment.