Gui: PythonWrapper: Consolidate typeName handling
Use typeName consistently for both PySide and Python interface code paths.
This commit is contained in:
@@ -612,9 +612,9 @@ QImage *PythonWrapper::toQImage(PyObject *pyobj)
|
||||
Py::Object PythonWrapper::fromQIcon(const QIcon* icon)
|
||||
{
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
const char* typeName = typeid(*const_cast<QIcon*>(icon)).name();
|
||||
auto type = getPyTypeObjectForTypeName<QIcon>();
|
||||
if (type) {
|
||||
const char* typeName = typeid(*const_cast<QIcon*>(icon)).name();
|
||||
PyObject* pyobj = Shiboken::Object::newObject(type, const_cast<QIcon*>(icon), true, false, typeName);
|
||||
return Py::asObject(pyobj);
|
||||
}
|
||||
@@ -636,14 +636,18 @@ QIcon *PythonWrapper::toQIcon(PyObject *pyobj)
|
||||
Py::Object PythonWrapper::fromQDir(const QDir& dir)
|
||||
{
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
const char* typeName = typeid(dir).name();
|
||||
auto type = getPyTypeObjectForTypeName<QDir>();
|
||||
if (type) {
|
||||
const char* typeName = typeid(dir).name();
|
||||
PyObject* pyobj = Shiboken::Object::newObject(type, const_cast<QDir*>(&dir), false, false, typeName);
|
||||
return Py::asObject(pyobj);
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(dir)
|
||||
// Access shiboken/PySide via Python
|
||||
Py::Object obj = qt_wrapInstance<const QDir*>(&dir, "QDir", "QtGui");
|
||||
if (!obj.isNull()) {
|
||||
return obj;
|
||||
}
|
||||
#endif
|
||||
throw Py::RuntimeError("Failed to wrap directory");
|
||||
}
|
||||
@@ -713,32 +717,23 @@ Py::Object PythonWrapper::fromQObject(QObject* object, const char* className)
|
||||
if (!object) {
|
||||
return Py::None();
|
||||
}
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
// Access shiboken/PySide via C++
|
||||
auto type = getPyTypeObjectForTypeName<QObject>();
|
||||
if (type) {
|
||||
std::string typeName;
|
||||
if (className) {
|
||||
typeName = className;
|
||||
}
|
||||
else {
|
||||
typeName = object->metaObject()->className();
|
||||
}
|
||||
|
||||
PyObject* pyobj = Shiboken::Object::newObject(type, object, false, false, typeName.c_str());
|
||||
WrapperManager::instance().addQObject(object, pyobj);
|
||||
return Py::asObject(pyobj);
|
||||
}
|
||||
#else
|
||||
// Access shiboken/PySide via Python
|
||||
std::string typeName;
|
||||
const char* typeName;
|
||||
if (className) {
|
||||
typeName = className;
|
||||
}
|
||||
else {
|
||||
typeName = object->metaObject()->className();
|
||||
}
|
||||
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
// Access shiboken/PySide via C++
|
||||
auto type = getPyTypeObjectForTypeName<QObject>();
|
||||
if (type) {
|
||||
PyObject* pyobj = Shiboken::Object::newObject(type, object, false, false, typeName);
|
||||
WrapperManager::instance().addQObject(object, pyobj);
|
||||
return Py::asObject(pyobj);
|
||||
}
|
||||
#else
|
||||
// Access shiboken/PySide via Python
|
||||
Py::Object obj = qt_wrapInstance<QObject*>(object, typeName, "QtCore");
|
||||
if (!obj.isNull()) {
|
||||
return obj;
|
||||
@@ -749,32 +744,23 @@ Py::Object PythonWrapper::fromQObject(QObject* object, const char* className)
|
||||
|
||||
Py::Object PythonWrapper::fromQWidget(QWidget* widget, const char* className)
|
||||
{
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
// Access shiboken/PySide via C++
|
||||
auto type = getPyTypeObjectForTypeName<QWidget>();
|
||||
if (type) {
|
||||
std::string typeName;
|
||||
if (className) {
|
||||
typeName = className;
|
||||
}
|
||||
else {
|
||||
typeName = widget->metaObject()->className();
|
||||
}
|
||||
|
||||
PyObject* pyobj = Shiboken::Object::newObject(type, widget, false, false, typeName.c_str());
|
||||
WrapperManager::instance().addQObject(widget, pyobj);
|
||||
return Py::asObject(pyobj);
|
||||
}
|
||||
#else
|
||||
// Access shiboken/PySide via Python
|
||||
std::string typeName;
|
||||
const char* typeName;
|
||||
if (className) {
|
||||
typeName = className;
|
||||
}
|
||||
else {
|
||||
typeName = widget->metaObject()->className();
|
||||
}
|
||||
|
||||
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
|
||||
// Access shiboken/PySide via C++
|
||||
auto type = getPyTypeObjectForTypeName<QWidget>();
|
||||
if (type) {
|
||||
PyObject* pyobj = Shiboken::Object::newObject(type, widget, false, false, typeName);
|
||||
WrapperManager::instance().addQObject(widget, pyobj);
|
||||
return Py::asObject(pyobj);
|
||||
}
|
||||
#else
|
||||
// Access shiboken/PySide via Python
|
||||
Py::Object obj = qt_wrapInstance<QWidget*>(widget, typeName, "QtWidgets");
|
||||
if (!obj.isNull()) {
|
||||
return obj;
|
||||
|
||||
Reference in New Issue
Block a user