aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetalang.cpp56
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetalang.h4
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp4
3 files changed, 32 insertions, 32 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp
index 080257346..95d33c519 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp
+++ b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp
@@ -160,24 +160,6 @@ void AbstractMetaClass::operator-=(AbstractMetaClass::Attribute attribute)
d->m_attributes.setFlag(attribute, false);
}
-/*******************************************************************************
- * Returns true if this class is a subclass of the given class
- */
-bool AbstractMetaClass::inheritsFrom(const AbstractMetaClass *cls) const
-{
- Q_ASSERT(cls);
-
- const AbstractMetaClass *clazz = this;
- while (clazz) {
- if (clazz == cls)
- return true;
-
- clazz = clazz->baseClass();
- }
-
- return false;
-}
-
bool AbstractMetaClass::isPolymorphic() const
{
return d->m_isPolymorphic;
@@ -577,16 +559,6 @@ bool AbstractMetaClass::isInvisibleNamespace() const
&& !NamespaceTypeEntry::isVisibleScope(d->m_typeEntry);
}
-static bool qObjectPredicate(const AbstractMetaClass *c)
-{
- return c->qualifiedCppName() == QLatin1String("QObject");
-}
-
-bool AbstractMetaClass::isQObject() const
-{
- return qObjectPredicate(this) || recurseClassHierarchy(this, qObjectPredicate) != nullptr;
-}
-
bool AbstractMetaClass::isQtNamespace() const
{
return isNamespace() && name() == QLatin1String("Qt");
@@ -1738,6 +1710,34 @@ const AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassCLi
return nullptr;
}
+/// Returns true if this class is a subclass of the given class
+bool AbstractMetaClass::inheritsFrom(const AbstractMetaClass *cls) const
+{
+ Q_ASSERT(cls != nullptr);
+
+ if (this == cls || d->m_templateBaseClass == cls)
+ return true;
+
+ return recurseClassHierarchy(this, [cls](const AbstractMetaClass *c) {
+ return cls == c;
+ }) != nullptr;
+}
+
+bool AbstractMetaClass::inheritsFrom(const QString &name) const
+{
+ if (this->qualifiedCppName() == name)
+ return true;
+
+ if (d->m_templateBaseClass != nullptr
+ && d->m_templateBaseClass->qualifiedCppName() == name) {
+ return true;
+ }
+
+ return recurseClassHierarchy(this, [&name](const AbstractMetaClass *c) {
+ return c->qualifiedCppName() == name;
+ }) != nullptr;
+}
+
const AbstractMetaClass *AbstractMetaClass::findBaseClass(const QString &qualifiedName) const
{
if (d->m_templateBaseClass != nullptr
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.h b/sources/shiboken6/ApiExtractor/abstractmetalang.h
index 6f1971df9..39d5a4a8e 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetalang.h
+++ b/sources/shiboken6/ApiExtractor/abstractmetalang.h
@@ -236,14 +236,14 @@ public:
bool isNamespace() const;
bool isInvisibleNamespace() const;
- bool isQObject() const;
-
+ bool isQObject() const { return inheritsFrom(u"QObject"_qs); }
bool isQtNamespace() const;
QString qualifiedCppName() const;
bool hasSignals() const;
bool inheritsFrom(const AbstractMetaClass *other) const;
+ bool inheritsFrom(const QString &name) const;
/**
* Says if the class that declares or inherits a virtual function.
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 51c6d051d..d49b6971a 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -4281,8 +4281,8 @@ void CppGenerator::writeClassDefinition(TextStream &s,
bool onlyPrivCtor = !metaClass->hasNonPrivateConstructor();
- const AbstractMetaClass *qCoreApp = AbstractMetaClass::findClass(api().classes(), QLatin1String("QCoreApplication"));
- const bool isQApp = qCoreApp != Q_NULLPTR && metaClass->inheritsFrom(qCoreApp);
+ const bool isQApp = usePySideExtensions()
+ && metaClass->inheritsFrom(u"QCoreApplication"_qs);
tp_flags = QLatin1String("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
if (metaClass->isNamespace() || metaClass->hasPrivateDestructor()) {