Merge pull request #19 from AnyOldName3/qvariant-from-unicode

Add missing PyUnicode_Check which prevented QVariants being created f…
This commit is contained in:
Al
2018-09-25 20:27:58 +02:00
committed by GitHub
+14 -2
View File
@@ -262,6 +262,7 @@ struct QVariant_to_python_obj
{
static PyObject *convert(const QVariant &var) {
switch (var.type()) {
case QVariant::Invalid: return bpy::incref(Py_None);
case QVariant::Int: return SIPLong_FromLong(var.toInt());
case QVariant::UInt: return PyLong_FromUnsignedLong(var.toUInt());
case QVariant::Bool: return PyBool_FromLong(var.toBool());
@@ -288,8 +289,9 @@ struct QVariant_from_python_obj
}
static void *convertible(PyObject *objPtr) {
if (!SIPBytes_Check(objPtr) && !PyLong_Check(objPtr) &&
!PyBool_Check(objPtr) && !PyList_Check(objPtr)) {
if (!SIPBytes_Check(objPtr) && !PyUnicode_Check(objPtr) && !PyLong_Check(objPtr) &&
!PyBool_Check(objPtr) && !PyList_Check(objPtr) && !PyDict_Check(objPtr) &&
objPtr != Py_None) {
return nullptr;
}
return objPtr;
@@ -304,11 +306,21 @@ struct QVariant_from_python_obj
data->convertible = storage;
}
static void constructVariant(bpy::converter::rvalue_from_python_stage1_data *data) {
void* storage = ((bpy::converter::rvalue_from_python_storage<QVariant>*)data)->storage.bytes;
new (storage) QVariant();
data->convertible = storage;
}
static void construct(PyObject *objPtr, bpy::converter::rvalue_from_python_stage1_data *data) {
// PyBools will also return true for SIPLong_Check but not the other way around, so the order
// here is relevant
if (PyList_Check(objPtr)) {
constructVariant(bpy::extract<QVariantList>(objPtr)(), data);
} else if (objPtr == Py_None) {
constructVariant(data);
} else if (PyDict_Check(objPtr)) {
constructVariant(bpy::extract<QVariantMap>(objPtr)(), data);
} else if (SIPBytes_Check(objPtr) || PyUnicode_Check(objPtr)) {