aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/dynamicqmetaobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/libpyside/dynamicqmetaobject.cpp')
-rw-r--r--sources/pyside6/libpyside/dynamicqmetaobject.cpp65
1 files changed, 31 insertions, 34 deletions
diff --git a/sources/pyside6/libpyside/dynamicqmetaobject.cpp b/sources/pyside6/libpyside/dynamicqmetaobject.cpp
index a3a16b6a0..048001f81 100644
--- a/sources/pyside6/libpyside/dynamicqmetaobject.cpp
+++ b/sources/pyside6/libpyside/dynamicqmetaobject.cpp
@@ -10,6 +10,7 @@
#include "pysideslot_p.h"
#include "pysideqenum.h"
#include "pyside_p.h"
+#include "pysidestaticstrings.h"
#include <shiboken.h>
@@ -23,6 +24,8 @@
#include <cstring>
#include <vector>
+using namespace Qt::StringLiterals;
+
using namespace PySide;
// MetaObjectBuilder: Provides the QMetaObject's returned by
@@ -50,7 +53,8 @@ public:
const QByteArray &signature) const;
int indexOfProperty(const QByteArray &name) const;
int addSlot(const QByteArray &signature);
- int addSlot(const QByteArray &signature, const QByteArray &type);
+ int addSlot(const QByteArray &signature, const QByteArray &type,
+ const QByteArray &tag = {});
int addSignal(const QByteArray &signature);
void removeMethod(QMetaMethod::MethodType mtype, int index);
int getPropertyNotifyId(PySideProperty *property) const;
@@ -181,8 +185,8 @@ int MetaObjectBuilder::indexOfProperty(const QByteArray &name) const
static bool checkMethodSignature(const QByteArray &signature)
{
// Common mistake not to add parentheses to the signature.
- const int openParen = signature.indexOf('(');
- const int closingParen = signature.lastIndexOf(')');
+ const auto openParen = signature.indexOf('(');
+ const auto closingParen = signature.lastIndexOf(')');
const bool ok = openParen != -1 && closingParen != -1 && openParen < closingParen;
if (!ok) {
const QByteArray message =
@@ -208,13 +212,17 @@ int MetaObjectBuilder::addSlot(const char *signature)
}
int MetaObjectBuilderPrivate::addSlot(const QByteArray &signature,
- const QByteArray &type)
+ const QByteArray &type,
+ const QByteArray &tag)
{
if (!checkMethodSignature(signature))
return -1;
m_dirty = true;
QMetaMethodBuilder methodBuilder = ensureBuilder()->addSlot(signature);
- methodBuilder.setReturnType(type);
+ if (!type.isEmpty() && type != "void"_ba)
+ methodBuilder.setReturnType(type);
+ if (!tag.isEmpty())
+ methodBuilder.setTag(tag);
return m_baseObject->methodCount() + methodBuilder.index();
}
@@ -581,7 +589,8 @@ void MetaObjectBuilderPrivate::parsePythonType(PyTypeObject *type)
// Leave the properties to be registered after signals because they may depend on
// notify signals.
for (PyTypeObject *baseType : basesToCheck) {
- PyObject *attrs = baseType->tp_dict;
+ AutoDecRef tpDict(PepType_GetDict(baseType));
+ PyObject *attrs = tpDict.object();
PyObject *key = nullptr;
PyObject *value = nullptr;
Py_ssize_t pos = 0;
@@ -600,51 +609,40 @@ void MetaObjectBuilderPrivate::parsePythonType(PyTypeObject *type)
// Signal(..., arguments=['...', ...]
// the arguments are now on data-data->signalArguments
auto builder = m_builder->addSignal(sig);
- if (data->signalArguments && !data->signalArguments->isEmpty())
- builder.setParameterNames(*data->signalArguments);
+ if (!data->signalArguments.isEmpty())
+ builder.setParameterNames(data->signalArguments);
}
}
}
}
}
- AutoDecRef slotAttrName(String::fromCString(PYSIDE_SLOT_LIST_ATTR));
+ PyObject *slotAttrName = PySide::PySideMagicName::slot_list_attr();
// PYSIDE-315: Now take care of the rest.
// Signals and slots should be separated, unless the types are modified, later.
// We check for this using "is_sorted()". Sorting no longer happens at all.
for (PyTypeObject *baseType : basesToCheck) {
- PyObject *attrs = baseType->tp_dict;
+ AutoDecRef tpDict(PepType_GetDict(baseType));
+ PyObject *attrs = tpDict.object();
PyObject *key = nullptr;
PyObject *value = nullptr;
Py_ssize_t pos = 0;
while (PyDict_Next(attrs, &pos, &key, &value)) {
if (Property::checkType(value)) {
- const int index = m_baseObject->indexOfProperty(String::toCString(key));
+ const QByteArray name = String::toCString(key);
+ const int index = m_baseObject->indexOfProperty(name);
if (index == -1)
- addProperty(String::toCString(key), value);
- } else if (Py_TYPE(value)->tp_call != nullptr) {
+ addProperty(name, value);
+ } else if (PepType_GetSlot(Py_TYPE(value), Py_tp_call) != nullptr) {
// PYSIDE-198: PyFunction_Check does not work with Nuitka.
// Register slots.
if (PyObject_HasAttr(value, slotAttrName)) {
- PyObject *signatureList = PyObject_GetAttr(value, slotAttrName);
- for (Py_ssize_t i = 0, i_max = PyList_Size(signatureList); i < i_max; ++i) {
- PyObject *pySignature = PyList_GET_ITEM(signatureList, i);
- QByteArray signature(String::toCString(pySignature));
- // Split the slot type and its signature.
- QByteArray type;
- const int spacePos = signature.indexOf(' ');
- if (spacePos != -1) {
- type = signature.left(spacePos);
- signature.remove(0, spacePos + 1);
- }
- const int index = m_baseObject->indexOfSlot(signature);
- if (index == -1) {
- if (type.isEmpty() || type == "void")
- addSlot(signature);
- else
- addSlot(signature, type);
- }
+ auto *capsule = PyObject_GetAttr(value, slotAttrName);
+ const auto *entryList = PySide::Slot::dataListFromCapsule(capsule);
+ for (const auto &e : *entryList) {
+ if (m_baseObject->indexOfSlot(e.signature) == -1)
+ addSlot(e.signature, e.resultType, e.tag);
}
}
}
@@ -662,7 +660,7 @@ void MetaObjectBuilderPrivate::parsePythonType(PyTypeObject *type)
AutoDecRef items(PyMapping_Items(members));
Py_ssize_t nr_items = PySequence_Length(items);
- QList<QPair<QByteArray, int> > entries;
+ QList<std::pair<QByteArray, int> > entries;
for (Py_ssize_t idx = 0; idx < nr_items; ++idx) {
AutoDecRef item(PySequence_GetItem(items, idx));
AutoDecRef key(PySequence_GetItem(item, 0));
@@ -670,8 +668,7 @@ void MetaObjectBuilderPrivate::parsePythonType(PyTypeObject *type)
AutoDecRef value(PyObject_GetAttr(member, Shiboken::PyName::value()));
auto ckey = String::toCString(key);
auto ivalue = PyLong_AsSsize_t(value);
- auto thing = QPair<QByteArray, int>(ckey, int(ivalue));
- entries.push_back(thing);
+ entries.push_back(std::make_pair(ckey, int(ivalue)));
}
addEnumerator(name, isFlag, true, entries);
}