Commit cff065ce authored by CABEL Tristan's avatar CABEL Tristan

add QVariant wrapper mapping

parent 4595b596
......@@ -177,6 +177,103 @@ namespace Namespace {
}
}
%typemap(out) QVariant {
QVariant val = $1;
PyObject *v;
int type = val.type();
if (type == QMetaType::Int ||
type == QMetaType::UInt ||
type == QMetaType::Long ||
type == QMetaType::ULong ||
type == QMetaType::LongLong ||
type == QMetaType::ULongLong) {
v = PyInt_FromLong(val.value<long>());
} else if (type == QMetaType::Float ||
type == QMetaType::Double) {
v = PyFloat_FromDouble(val.value<double>());
} else if (type == QMetaType::QString) {
v = PyString_FromString(qPrintable(val.value<QString>()));
} else if (type == QMetaType::Bool) {
bool b = val.value<bool>();
v = b ? Py_True : Py_False;
}
$result = v;
}
%typemap(out) const QVariant& {
QVariant val = *($1);
PyObject *v;
int type = val.type();
if (type == QMetaType::Int ||
type == QMetaType::UInt ||
type == QMetaType::Long ||
type == QMetaType::ULong ||
type == QMetaType::LongLong ||
type == QMetaType::ULongLong) {
v = PyInt_FromLong(val.value<long>());
} else if (type == QMetaType::Float ||
type == QMetaType::Double) {
v = PyFloat_FromDouble(val.value<double>());
} else if (type == QMetaType::QString) {
v = PyString_FromString(qPrintable(val.value<QString>()));
} else if (type == QMetaType::Bool) {
bool b = val.value<bool>();
v = b ? Py_True : Py_False;
}
$result = v;
}
%typemap(directorin) QVariant {
QVariant val = $1;
PyObject *v;
int type = val.type();
if (type == QMetaType::Int ||
type == QMetaType::UInt ||
type == QMetaType::Long ||
type == QMetaType::ULong ||
type == QMetaType::LongLong ||
type == QMetaType::ULongLong) {
v = PyInt_FromLong(val.value<long>());
} else if (type == QMetaType::Float ||
type == QMetaType::Double) {
v = PyFloat_FromDouble(val.value<double>());
} else if (type == QMetaType::QString) {
v = PyString_FromString(qPrintable(val.value<QString>()));
} else if (type == QMetaType::Bool) {
bool b = val.value<bool>();
v = b ? Py_True : Py_False;
}
$input = v;
}
%typemap(directorin) const QVariant& {
QVariant val = $1;
PyObject *v;
int type = val.type();
if (type == QMetaType::Int ||
type == QMetaType::UInt ||
type == QMetaType::Long ||
type == QMetaType::ULong ||
type == QMetaType::LongLong ||
type == QMetaType::ULongLong) {
v = PyInt_FromLong(val.value<long>());
} else if (type == QMetaType::Float ||
type == QMetaType::Double) {
v = PyFloat_FromDouble(val.value<double>());
} else if (type == QMetaType::QString) {
v = PyString_FromString(qPrintable(val.value<QString>()));
} else if (type == QMetaType::Bool) {
bool b = val.value<bool>();
v = b ? Py_True : Py_False;
}
$input = v;
}
%typemap(in) QStringList {
if (PyList_Check($input)) {
int i = 0;
......@@ -604,10 +701,10 @@ namespace Namespace {
v = PyInt_FromLong(val.value<long>());
} else if (type == QMetaType::Float ||
type == QMetaType::Double) {
v = PyFloat_AsDouble(val.value<double>());
} else if (type == QMetatype::QString) {
v = PyFloat_FromDouble(val.value<double>());
} else if (type == QMetaType::QString) {
v = PyString_FromString(qPrintable(val.value<QString>()))
} else if (type == QMetatype::Bool) {
} else if (type == QMetaType::Bool) {
bool b = val.value<bool>();
v = b ? Py_True : Py_False;
}
......@@ -634,10 +731,10 @@ namespace Namespace {
v = PyInt_FromLong(val.value<long>());
} else if (type == QMetaType::Float ||
type == QMetaType::Double) {
v = PyFloat_AsDouble(val.value<double>());
} else if (type == QMetatype::QString) {
v = PyFloat_FromDouble(val.value<double>());
} else if (type == QMetaType::QString) {
v = PyString_FromString(qPrintable(val.value<QString>()))
} else if (type == QMetatype::Bool) {
} else if (type == QMetaType::Bool) {
bool b = val.value<bool>();
v = b ? Py_True : Py_False;
}
......
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