mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Fixes and tests.
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
|
||||
#include "pybind11_qt/details/pybind11_qt_utils.h"
|
||||
|
||||
// need to import containers to get QVariantList and QVariantMap
|
||||
#include "pybind11_qt/pybind11_qt_containers.h"
|
||||
|
||||
namespace pybind11::detail {
|
||||
|
||||
template <class CharT>
|
||||
@@ -83,13 +86,22 @@ namespace pybind11::detail {
|
||||
|
||||
bool type_caster<QVariant>::load(handle src, bool implicit)
|
||||
{
|
||||
if (PyList_Check(src.ptr())) {
|
||||
// test for string first otherwise PyList_Check also works
|
||||
if (PyBytes_Check(src.ptr()) || PyUnicode_Check(src.ptr())) {
|
||||
value = src.cast<QString>();
|
||||
return true;
|
||||
}
|
||||
else if (PySequence_Check(src.ptr())) {
|
||||
// we could check if all the elements can be converted to QString
|
||||
// and store a QStringList in the QVariant but I am not sure that is
|
||||
// really useful.
|
||||
value = src.cast<QVariantList>();
|
||||
return true;
|
||||
}
|
||||
else if (PyMapping_Check(src.ptr())) {
|
||||
value = src.cast<QVariantMap>();
|
||||
return true;
|
||||
}
|
||||
else if (src == Py_None) {
|
||||
value = QVariant();
|
||||
return true;
|
||||
@@ -98,10 +110,6 @@ namespace pybind11::detail {
|
||||
value = src.cast<QVariantMap>();
|
||||
return true;
|
||||
}
|
||||
else if (PyBytes_Check(src.ptr()) || PyUnicode_Check(src.ptr())) {
|
||||
value = src.cast<QString>();
|
||||
return true;
|
||||
}
|
||||
// PyBool will also return true for PyLong_Check but not the other way
|
||||
// around, so the order here is relevant.
|
||||
else if (PyBool_Check(src.ptr())) {
|
||||
|
||||
Reference in New Issue
Block a user