aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/libpyside
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside2/libpyside')
-rw-r--r--sources/pyside2/libpyside/feature_select.cpp20
-rw-r--r--sources/pyside2/libpyside/pyside.cpp16
-rw-r--r--sources/pyside2/libpyside/pyside.h5
3 files changed, 39 insertions, 2 deletions
diff --git a/sources/pyside2/libpyside/feature_select.cpp b/sources/pyside2/libpyside/feature_select.cpp
index 6a21d168d..7604f69aa 100644
--- a/sources/pyside2/libpyside/feature_select.cpp
+++ b/sources/pyside2/libpyside/feature_select.cpp
@@ -255,6 +255,7 @@ static bool replaceClassDict(PyTypeObject *type)
// Replace `__dict__` which usually has refcount 1 (but see cyclic_test.py)
Py_DECREF(type->tp_dict);
type->tp_dict = new_dict;
+ setCurrentSelectId(type, select_id.object());
return true;
}
@@ -275,6 +276,7 @@ static bool addNewDict(PyTypeObject *type, PyObject *select_id)
setNextDict(dict, new_dict);
setNextDict(new_dict, next_dict);
type->tp_dict = new_dict;
+ setCurrentSelectId(type, select_id);
return true;
}
@@ -297,6 +299,7 @@ static bool moveToFeatureSet(PyTypeObject *type, PyObject *select_id)
}
} while (dict != initial_dict);
type->tp_dict = initial_dict;
+ setCurrentSelectId(type, getSelectId(initial_dict));
return false;
}
@@ -418,6 +421,13 @@ void Select(PyObject *obj)
type->tp_dict = SelectFeatureSet(type);
}
+PyObject *Select(PyTypeObject *type)
+{
+ if (featurePointer != nullptr)
+ type->tp_dict = SelectFeatureSet(type);
+ return type->tp_dict;
+}
+
static bool feature_01_addLowerNames(PyTypeObject *type, PyObject *prev_dict, int id);
static bool feature_02_true_property(PyTypeObject *type, PyObject *prev_dict, int id);
static bool feature_04_addDummyNames(PyTypeObject *type, PyObject *prev_dict, int id);
@@ -446,11 +456,11 @@ void finalize()
}
static bool patch_property_impl();
+static bool is_initialized = false;
void init()
{
// This function can be called multiple times.
- static bool is_initialized = false;
if (!is_initialized) {
fast_id_array = &_fast_id_array[1];
for (int idx = -1; idx < 256; ++idx)
@@ -466,6 +476,14 @@ void init()
cached_globals = nullptr;
}
+void Enable(bool enable)
+{
+ if (!is_initialized)
+ return;
+ featurePointer = enable ? featureProcArray : nullptr;
+ initSelectableFeature(enable ? SelectFeatureSet : nullptr);
+}
+
//////////////////////////////////////////////////////////////////////////////
//
// PYSIDE-1019: Support switchable extensions
diff --git a/sources/pyside2/libpyside/pyside.cpp b/sources/pyside2/libpyside/pyside.cpp
index 5d0859adc..7b01c5b8f 100644
--- a/sources/pyside2/libpyside/pyside.cpp
+++ b/sources/pyside2/libpyside/pyside.cpp
@@ -412,7 +412,7 @@ static const char invalidatePropertyName[] = "_PySideInvalidatePtr";
// PYSIDE-1214, when creating new wrappers for classes inheriting QObject but
// not exposed to Python, try to find the best-matching (most-derived) Qt
// class by walking up the meta objects.
-static const char *typeName(QObject *cppSelf)
+static const char *typeName(const QObject *cppSelf)
{
const char *typeName = typeid(*cppSelf).name();
if (!Shiboken::Conversions::getConverter(typeName)) {
@@ -427,6 +427,20 @@ static const char *typeName(QObject *cppSelf)
return typeName;
}
+PyTypeObject *getTypeForQObject(const QObject *cppSelf)
+{
+ // First check if there are any instances of Python implementations
+ // inheriting a PySide class.
+ auto *existing = Shiboken::BindingManager::instance().retrieveWrapper(cppSelf);
+ if (existing != nullptr)
+ return reinterpret_cast<PyObject *>(existing)->ob_type;
+ // Find the best match (will return a PySide type)
+ auto *sbkObjectType = Shiboken::ObjectType::typeForTypeName(typeName(cppSelf));
+ if (sbkObjectType != nullptr)
+ return reinterpret_cast<PyTypeObject *>(sbkObjectType);
+ return nullptr;
+}
+
PyObject *getWrapperForQObject(QObject *cppSelf, SbkObjectType *sbk_type)
{
PyObject *pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(cppSelf));
diff --git a/sources/pyside2/libpyside/pyside.h b/sources/pyside2/libpyside/pyside.h
index a465fec47..c72f37ae7 100644
--- a/sources/pyside2/libpyside/pyside.h
+++ b/sources/pyside2/libpyside/pyside.h
@@ -140,6 +140,11 @@ PYSIDE_API void setNextQObjectMemoryAddr(void *addr);
PYSIDE_API PyObject *getWrapperForQObject(QObject *cppSelf, SbkObjectType *sbk_type);
+/// Return the best-matching type for a QObject (Helper for QObject.findType())
+/// \param cppSelf QObject instance
+/// \return type object
+PYSIDE_API PyTypeObject *getTypeForQObject(const QObject *cppSelf);
+
#ifdef PYSIDE_QML_SUPPORT
// Used by QtQuick module to notify QtQml that custom QtQuick items can be registered.
typedef bool (*QuickRegisterItemFunction)(PyObject *pyObj, const char *uri, int versionMajor,