Commit 2170cd10 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Add typemap for const QMap& and QMap&.

parent 6b869ad8
......@@ -368,7 +368,7 @@ namespace Namespace {
long k = PyInt_AS_LONG(key);
if (PyString_Check(value)) {
v = QVariant::fromValue(QString(PyString_AsString(value)));
} else if (PyLong_Check(value)) {
} else if (PyInt_Check(value) || PyLong_Check(value)) {
v = QVariant::fromValue(PyInt_AsLong(value));
} else if (PyFloat_Check(value)) {
v = QVariant::fromValue(PyFloat_AsDouble(value));
......@@ -382,6 +382,56 @@ namespace Namespace {
}
}
%typemap(directorout) const QMap<long, QVariant>& {
PyObject *dict = static_cast<PyObject *>($1);
if (PyDict_Check(dict)) {
$result = new QMap<long, QVariant>();
PyObject *key, *value;
Py_ssize_t pos = 0;
QVariant v;
while (PyDict_Next(dict, &pos, &key, &value)) {
long k = PyInt_AS_LONG(key);
if (PyString_Check(value)) {
v = QVariant::fromValue(QString(PyString_AsString(value)));
} else if (PyInt_Check(value) || PyLong_Check(value)) {
v = QVariant::fromValue(PyInt_AsLong(value));
} else if (PyFloat_Check(value)) {
v = QVariant::fromValue(PyFloat_AsDouble(value));
} else {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$result->insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<long, QVariant> is returned.");
}
}
%typemap(directorout) QMap<long, QVariant>& {
PyObject *dict = static_cast<PyObject *>($1);
if (PyDict_Check(dict)) {
$result = new QMap<long, QVariant>();
PyObject *key, *value;
Py_ssize_t pos = 0;
QVariant v;
while (PyDict_Next(dict, &pos, &key, &value)) {
long k = PyInt_AS_LONG(key);
if (PyString_Check(value)) {
v = QVariant::fromValue(QString(PyString_AsString(value)));
} else if (PyInt_Check(value) || PyLong_Check(value)) {
v = QVariant::fromValue(PyInt_AsLong(value));
} else if (PyFloat_Check(value)) {
v = QVariant::fromValue(PyFloat_AsDouble(value));
} else {
qDebug("Value type is not handled. Empty QVariant is set.");
}
$result->insert(k, v);
}
} else {
qDebug("PyDict is expected as input. Empty QMap<long, QVariant> is returned.");
}
}
// C++ -> Python
%typemap(out) qlonglong {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment