mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
add conversion for QMap<QString, QVariant::Type>
git-svn-id: http://svn.osgeo.org/qgis/trunk@9077 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
40446fb1f4
commit
48dcaffbd5
@ -6,6 +6,7 @@ which are not wrapped by PyQt:
|
||||
- QSet<int>
|
||||
- QSet<TYPE>
|
||||
- QMap<int, QMap<int, TYPE> >
|
||||
- QMap<QString, QVariant::Type>
|
||||
- QMap<TYPE1, TYPE2*>
|
||||
- QMultiMap<double, TYPE2>
|
||||
*/
|
||||
@ -172,9 +173,6 @@ template <TYPE>
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
%MappedType QSet<int>
|
||||
{
|
||||
%TypeHeaderCode
|
||||
@ -191,16 +189,16 @@ template <TYPE>
|
||||
// Set the list elements.
|
||||
QSet<int>::iterator it = sipCpp->begin();
|
||||
for (int i = 0; it != sipCpp->end(); ++it, ++i)
|
||||
{
|
||||
{
|
||||
PyObject *tobj;
|
||||
|
||||
if ((tobj = PyInt_FromLong(*it)) == NULL)
|
||||
{
|
||||
{
|
||||
Py_DECREF(l);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
PyList_SET_ITEM(l, i, tobj);
|
||||
}
|
||||
}
|
||||
|
||||
return l;
|
||||
%End
|
||||
@ -213,9 +211,9 @@ template <TYPE>
|
||||
QSet<int> *qset = new QSet<int>;
|
||||
|
||||
for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
|
||||
{
|
||||
{
|
||||
qset->insert(PyInt_AsLong(PyList_GET_ITEM(sipPy, i)));
|
||||
}
|
||||
}
|
||||
|
||||
*sipCppPtr = qset;
|
||||
return sipGetState(sipTransferObj);
|
||||
@ -224,7 +222,6 @@ template <TYPE>
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <TYPE>
|
||||
%MappedType QSet<TYPE>
|
||||
{
|
||||
@ -415,6 +412,105 @@ template<TYPE>
|
||||
|
||||
};
|
||||
|
||||
%MappedType QMap<QString, QVariant::Type>
|
||||
{
|
||||
%TypeHeaderCode
|
||||
#include <QMap>
|
||||
%End
|
||||
|
||||
%ConvertFromTypeCode
|
||||
// Create the dictionary.
|
||||
PyObject *d = PyDict_New();
|
||||
|
||||
if (!d)
|
||||
return NULL;
|
||||
|
||||
// Set the dictionary elements.
|
||||
QMap<QString, QVariant::Type>::const_iterator i = sipCpp->constBegin();
|
||||
|
||||
while (i != sipCpp->constEnd())
|
||||
{
|
||||
QString *t1 = new QString(i.key());
|
||||
|
||||
PyObject *t1obj = sipConvertFromNewInstance(t1, sipClass_QString, sipTransferObj);
|
||||
PyObject *t2obj = PyInt_FromLong( (long) i.value() );
|
||||
|
||||
if (t1obj == NULL || t2obj == NULL || PyDict_SetItem(d, t1obj, t2obj) < 0)
|
||||
{
|
||||
Py_DECREF(d);
|
||||
|
||||
if (t1obj) {
|
||||
Py_DECREF(t1obj);
|
||||
} else {
|
||||
delete t1;
|
||||
}
|
||||
|
||||
if (t2obj) {
|
||||
Py_DECREF(t2obj);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_DECREF(t1obj);
|
||||
Py_DECREF(t2obj);
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
return d;
|
||||
%End
|
||||
|
||||
%ConvertToTypeCode
|
||||
PyObject *t1obj, *t2obj;
|
||||
#if PY_VERSION_HEX >= 0x02050000
|
||||
Py_ssize_t i = 0;
|
||||
#else
|
||||
int i = 0;
|
||||
#endif
|
||||
|
||||
|
||||
// Check the type if that is all that is required.
|
||||
if (sipIsErr == NULL)
|
||||
{
|
||||
if (!PyDict_Check(sipPy))
|
||||
return 0;
|
||||
|
||||
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
|
||||
{
|
||||
if (!sipCanConvertToInstance(t1obj, sipClass_QString, SIP_NOT_NONE))
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
QMap<QString, QVariant::Type> *qm = new QMap<QString, QVariant::Type>;
|
||||
|
||||
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
|
||||
{
|
||||
int state;
|
||||
|
||||
QString *t1 = reinterpret_cast<QString *>(sipConvertToInstance(t1obj, sipClass_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
|
||||
QVariant::Type t2 = (QVariant::Type) PyInt_AsLong(t1obj);
|
||||
|
||||
if (*sipIsErr)
|
||||
{
|
||||
sipReleaseInstance(t1, sipClass_QString, state);
|
||||
delete qm;
|
||||
return 0;
|
||||
}
|
||||
|
||||
qm->insert(*t1, t2);
|
||||
|
||||
sipReleaseInstance(t1, sipClass_QString, state);
|
||||
}
|
||||
|
||||
*sipCppPtr = qm;
|
||||
|
||||
return sipGetState(sipTransferObj);
|
||||
%End
|
||||
};
|
||||
|
||||
template<TYPE1, TYPE2>
|
||||
%MappedType QMap<TYPE1, TYPE2*>
|
||||
@ -523,8 +619,6 @@ template<TYPE1, TYPE2>
|
||||
%End
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<double, TYPE2>
|
||||
%MappedType QMultiMap<double, TYPE2>
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user