From 5823fdaf8edf4cd2889069262eb3ca64c812fd35 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 11 Mar 2020 16:25:08 -0400 Subject: [PATCH] [GUI]Add PySide unwrapper for QGraphicsItem --- src/Gui/WidgetFactory.cpp | 25 +++++++++++++++++++++++++ src/Gui/WidgetFactory.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/src/Gui/WidgetFactory.cpp b/src/Gui/WidgetFactory.cpp index a032414674..693229b918 100644 --- a/src/Gui/WidgetFactory.cpp +++ b/src/Gui/WidgetFactory.cpp @@ -386,6 +386,31 @@ QObject* PythonWrapper::toQObject(const Py::Object& pyobject) return 0; } +QGraphicsItem* PythonWrapper::toQGraphicsItem(PyObject* pyPtr) +{ +#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) + PyTypeObject* type = getPyTypeObjectForTypeName(); + if (type) { + if (Shiboken::Object::checkType(pyPtr)) { + SbkObject* sbkobject = reinterpret_cast(pyPtr); + void* cppobject = Shiboken::Object::cppPointer(sbkobject, type); + return reinterpret_cast(cppobject); + } + } +#elif QT_VERSION >= 0x050000 + // Access shiboken2/PySide2 via Python + // + void* ptr = qt_getCppPointer(Py::asObject(pyPtr), "shiboken2", "getCppPointer"); + return reinterpret_cast(ptr); +#else + // Access shiboken/PySide via Python + // + void* ptr = qt_getCppPointer(Py::asObject(pyPtr), "shiboken", "getCppPointer"); + return reinterpret_cast(ptr); +#endif + return nullptr; +} + Py::Object PythonWrapper::fromQIcon(const QIcon* icon) { #if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE) diff --git a/src/Gui/WidgetFactory.h b/src/Gui/WidgetFactory.h index 03f0dc095c..2a55d75bca 100644 --- a/src/Gui/WidgetFactory.h +++ b/src/Gui/WidgetFactory.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -49,6 +50,7 @@ public: bool toCString(const Py::Object&, std::string&); QObject* toQObject(const Py::Object&); + QGraphicsItem* toQGraphicsItem(PyObject* ptr); Py::Object fromQWidget(QWidget*, const char* className=0); const char* getWrapperName(QObject*) const; /*!