Skip to content

Commit dabe7d3

Browse files
committedAug 7, 2015
Merge pull request #2239 from elpaso/move-conversions-sip
Moved QMultiMap<int, TYPE2*> to conversion.sip
2 parents 71e7aab + e48b6e8 commit dabe7d3

File tree

3 files changed

+126
-150
lines changed

3 files changed

+126
-150
lines changed
 

‎python/core/conversions.sip

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ which are not wrapped by PyQt:
1414
- QMap<TYPE1, TYPE2*>
1515
- QMap<double, TYPE>
1616
- QMultiMap<double, TYPE2>
17+
- QMultiMap<int, TYPE2>
1718
- QMap<qint64, TYPE>
1819
- QList< QPair< QString, QList<QString> > >
1920
- QVector<TYPE*>
@@ -1407,6 +1408,131 @@ template<double, TYPE2>
14071408
%End
14081409
};
14091410

1411+
1412+
template<int, TYPE2*>
1413+
%MappedType QMultiMap<int, TYPE2*>
1414+
{
1415+
%TypeHeaderCode
1416+
#include <QMultiMap>
1417+
%End
1418+
1419+
%ConvertFromTypeCode
1420+
// Convert to Python: create the dictionary.
1421+
PyObject *d = PyDict_New();
1422+
1423+
if (!d)
1424+
{
1425+
return NULL;
1426+
}
1427+
1428+
// Set the dictionary elements.
1429+
QMultiMap<int, TYPE2*>::iterator i = sipCpp->begin();
1430+
1431+
while (i != sipCpp->end())
1432+
{
1433+
1434+
const int t1 = i.key();
1435+
TYPE2 * t2 = i.value();
1436+
PyObject *t1obj = PyInt_FromSize_t(t1);
1437+
PyObject *t2obj = sipConvertFromType(t2, sipType_TYPE2, sipTransferObj);
1438+
if (PyDict_GetItem(d, t1obj) == NULL)
1439+
{
1440+
PyObject *lst = PyList_New(0);
1441+
PyDict_SetItem(d, t1obj, lst);
1442+
if (lst)
1443+
{
1444+
Py_DECREF(lst);
1445+
}
1446+
}
1447+
1448+
if (t1obj == NULL || t2obj == NULL ||
1449+
PyList_Append(PyDict_GetItem(d, t1obj), t2obj) < 0)
1450+
{
1451+
Py_DECREF(d);
1452+
if (t1obj)
1453+
{
1454+
Py_DECREF(t1obj);
1455+
}
1456+
1457+
if (t2obj)
1458+
{
1459+
Py_DECREF(t2obj);
1460+
}
1461+
1462+
return NULL;
1463+
}
1464+
Py_DECREF(t1obj);
1465+
Py_DECREF(t2obj);
1466+
1467+
++i;
1468+
}
1469+
1470+
return d;
1471+
%End
1472+
1473+
%ConvertToTypeCode
1474+
// Convert from Python:
1475+
PyObject *t1obj, *t2obj;
1476+
#if PY_VERSION_HEX >= 0x02050000
1477+
Py_ssize_t i = 0;
1478+
#else
1479+
int i = 0;
1480+
#endif
1481+
1482+
// Check the type if that is all that is required.
1483+
if (sipIsErr == NULL)
1484+
{
1485+
if (!PyDict_Check(sipPy))
1486+
return 0;
1487+
1488+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
1489+
{
1490+
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i) {
1491+
if (!sipCanConvertToType(PyList_GET_ITEM(t2obj, i),
1492+
sipType_TYPE2, SIP_NOT_NONE))
1493+
return 0;
1494+
}
1495+
}
1496+
1497+
return 1;
1498+
}
1499+
1500+
QMultiMap<int, TYPE2*> *qm = new QMultiMap<int, TYPE2*>;
1501+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
1502+
{
1503+
int state2;
1504+
int k = (int) PyInt_AsLong(t1obj);
1505+
for (int i = 0; i < PyList_GET_SIZE(t2obj); ++i)
1506+
{
1507+
TYPE2 *t2 =
1508+
reinterpret_cast<TYPE2 *>(sipConvertToType(PyList_GET_ITEM(t2obj, i),
1509+
sipType_TYPE2,
1510+
sipTransferObj,
1511+
SIP_NOT_NONE,
1512+
&state2,
1513+
sipIsErr));
1514+
1515+
if (*sipIsErr)
1516+
{
1517+
sipReleaseType(t2, sipType_TYPE2, state2);
1518+
1519+
delete qm;
1520+
return 0;
1521+
}
1522+
1523+
qm->insert(k, t2);
1524+
1525+
sipReleaseType(t2, sipType_TYPE2, state2);
1526+
}
1527+
}
1528+
1529+
*sipCppPtr = qm;
1530+
1531+
return sipGetState(sipTransferObj);
1532+
%End
1533+
};
1534+
1535+
14101536
%MappedType QList < QPair< QString, QList<QString> > >
14111537
{
14121538
%TypeHeaderCode

‎python/server/conversions.sip

Lines changed: 0 additions & 147 deletions
This file was deleted.

‎python/server/server.sip

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
%Import QtGui/QtGuimod.sip
88
%Import QtXml/QtXmlmod.sip
99

10-
11-
%Include conversions.sip
12-
1310
%Import core/core.sip
1411

1512
%Feature HAVE_SERVER_PYTHON_PLUGINS

0 commit comments

Comments
 (0)
Please sign in to comment.