Warning, /graphics/krita/plugins/extensions/pykrita/sip/krita/Conversions.sip is written in an unsupported language. File is not indexed.

0001 %MappedType QMap<QString, Resource*>
0002 {
0003 %TypeHeaderCode
0004 #include <QMap>
0005 #include <QString>
0006 #include <Resource.h>
0007 %End
0008 
0009 %ConvertFromTypeCode
0010     // Create the dictionary.
0011     PyObject *d = PyDict_New();
0012 
0013     if (!d)
0014         return NULL;
0015 
0016     // Set the dictionary elements.
0017     QMap<QString, Resource*>::const_iterator i = sipCpp->constBegin();
0018 
0019     while (i != sipCpp->constEnd())
0020     {
0021         QString *t1 = new QString(i.key());
0022 
0023         PyObject *t1obj = sipConvertFromNewType(t1, sipType_QString, sipTransferObj);
0024         PyObject* t2obj = sipConvertFromType(i.value(), sipType_Resource, sipTransferObj);
0025 
0026         if (t1obj == NULL || t2obj == NULL || PyDict_SetItem(d, t1obj, t2obj) < 0)
0027         {
0028             Py_DECREF(d);
0029 
0030             if (t1obj) {
0031               Py_DECREF(t1obj);
0032             }
0033 
0034             if (t2obj) {
0035               Py_DECREF(t2obj);
0036             }
0037 
0038             return NULL;
0039         }
0040 
0041         Py_DECREF(t1obj);
0042         Py_DECREF(t2obj);
0043 
0044         ++i;
0045     }
0046 
0047     return d;
0048 %End
0049 
0050 %ConvertToTypeCode
0051     PyObject *t1obj, *t2obj;
0052     Py_ssize_t i = 0;
0053 
0054     // Check the type if that is all that is required.
0055     if (sipIsErr == NULL)
0056     {
0057         if (!PyDict_Check(sipPy))
0058             return 0;
0059 
0060         while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
0061         {
0062             if (!sipCanConvertToType(t1obj, sipType_QString, SIP_NOT_NONE))
0063                 return 0;
0064         }
0065 
0066         return 1;
0067     }
0068 
0069     QMap<QString, Resource*> *qm = new QMap<QString, Resource*>;
0070 
0071     while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
0072     {
0073         int state;
0074 
0075         QString *t1 = reinterpret_cast<QString *>(sipConvertToType(t1obj, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
0076         Resource *t2 = reinterpret_cast<Resource*>(sipConvertToType(t2obj, sipType_Resource, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
0077 
0078         if (*sipIsErr)
0079         {
0080             sipReleaseType(t1, sipType_QString, state);
0081             delete qm;
0082             return 0;
0083         }
0084 
0085         qm->insert(*t1, t2);
0086 
0087         sipReleaseType(t1, sipType_QString, state);
0088     }
0089 
0090     *sipCppPtr = qm;
0091 
0092     return sipGetState(sipTransferObj);
0093 %End
0094 };
0095 
0096