Skip to content

Commit

Permalink
[GUI]Add PySide unwrapper for QGraphicsItem
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Mar 12, 2020
1 parent 4361538 commit 5823fda
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Gui/WidgetFactory.cpp
Expand Up @@ -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<QObject>();
if (type) {
if (Shiboken::Object::checkType(pyPtr)) {
SbkObject* sbkobject = reinterpret_cast<SbkObject*>(pyPtr);
void* cppobject = Shiboken::Object::cppPointer(sbkobject, type);
return reinterpret_cast<QGraphicsItem*>(cppobject);
}
}
#elif QT_VERSION >= 0x050000
// Access shiboken2/PySide2 via Python
//
void* ptr = qt_getCppPointer(Py::asObject(pyPtr), "shiboken2", "getCppPointer");
return reinterpret_cast<QGraphicsItem*>(ptr);
#else
// Access shiboken/PySide via Python
//
void* ptr = qt_getCppPointer(Py::asObject(pyPtr), "shiboken", "getCppPointer");
return reinterpret_cast<QGraphicsItem*>(ptr);
#endif
return nullptr;
}

Py::Object PythonWrapper::fromQIcon(const QIcon* icon)
{
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/WidgetFactory.h
Expand Up @@ -26,6 +26,7 @@

#include <vector>
#include <QUiLoader>
#include <QGraphicsItem>

#include <Base/Factory.h>
#include <Base/PyObjectBase.h>
Expand All @@ -49,6 +50,7 @@ class GuiExport PythonWrapper

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;
/*!
Expand Down

0 comments on commit 5823fda

Please sign in to comment.