aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-11-23 12:15:44 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-12-08 10:31:48 +0100
commit16b17fa01ed4851ade068e2500a6bf5170acb03d (patch)
tree7f4f62bc4359ebea374f245cf41c5da4d22137f0
parent948463e3740fecb796f07b1e03ba50f45cca859a (diff)
shiboken6: Refactor writing the meta object functions
Lump the declarations together and add a function for checking. Task-number: PYSIDE-2535 Change-Id: I2f80e789a582beef0487ad3ea704241ddc555544 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp7
-rw-r--r--sources/shiboken6/generator/shiboken/headergenerator.cpp10
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp7
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.h2
4 files changed, 17 insertions, 9 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index b1b29d4d4..51764afc3 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -566,11 +566,10 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon
writeVirtualMethodNative(s, func, maxOverrides++);
}
- if (!avoidProtectedHack() || !metaClass->hasPrivateDestructor()) {
- if (usePySideExtensions() && isQObject(metaClass))
- writeMetaObjectMethod(s, classContext);
+ if (shouldGenerateMetaObjectFunctions(metaClass))
+ writeMetaObjectMethod(s, classContext);
+ if (!avoidProtectedHack() || !metaClass->hasPrivateDestructor())
writeDestructorNative(s, classContext);
- }
}
StringStream smd(TextStream::Language::Cpp);
diff --git a/sources/shiboken6/generator/shiboken/headergenerator.cpp b/sources/shiboken6/generator/shiboken/headergenerator.cpp
index a4f273218..5bee1cb52 100644
--- a/sources/shiboken6/generator/shiboken/headergenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/headergenerator.cpp
@@ -238,10 +238,10 @@ void HeaderGenerator::writeWrapperClassDeclaration(TextStream &s,
TypeSystem::CodeSnipPositionDeclaration, TypeSystem::NativeCode,
classContext);
- if ((!avoidProtectedHack() || !metaClass->hasPrivateDestructor())
- && usePySideExtensions() && isQObject(metaClass)) {
- s << outdent << "public:\n" << indent <<
- R"(int qt_metacall(QMetaObject::Call call, int id, void **args) override;
+ if (shouldGenerateMetaObjectFunctions(metaClass)) {
+ s << R"(
+const ::QMetaObject * metaObject() const override;
+int qt_metacall(QMetaObject::Call call, int id, void **args) override;
void *qt_metacast(const char *_clname) override;
)";
}
@@ -328,7 +328,7 @@ void HeaderGenerator::writeFunction(TextStream &s, const AbstractMetaFunctionCPt
}
const bool isVirtual = generation.testFlag(FunctionGenerationFlag::VirtualMethod);
- if (isVirtual || generation.testFlag(FunctionGenerationFlag::QMetaObjectMethod)) {
+ if (isVirtual) {
s << functionSignature(func, {}, {}, Generator::OriginalTypeDescription)
<< " override;\n";
}
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
index f2d9f0c9c..cdf067b8b 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
@@ -223,6 +223,13 @@ bool ShibokenGenerator::shouldGenerateCppWrapper(const AbstractMetaClassCPtr &me
&& wrapper.testFlag(AbstractMetaClass::CppProtectedHackWrapper));
}
+bool ShibokenGenerator::shouldGenerateMetaObjectFunctions(const AbstractMetaClassCPtr &metaClass)
+{
+ return usePySideExtensions()
+ && (!avoidProtectedHack() || !metaClass->hasPrivateDestructor())
+ && isQObject(metaClass);
+}
+
ShibokenGenerator::FunctionGeneration ShibokenGenerator::functionGeneration(
const AbstractMetaFunctionCPtr &func)
{
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h
index d16394a0e..11983e922 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.h
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h
@@ -202,6 +202,8 @@ protected:
/// instead of only a Python wrapper.
static bool shouldGenerateCppWrapper(const AbstractMetaClassCPtr &metaClass);
+ static bool shouldGenerateMetaObjectFunctions(const AbstractMetaClassCPtr &metaClass);
+
/// Returns which functions need to be generated into the wrapper class
static FunctionGeneration functionGeneration(const AbstractMetaFunctionCPtr &func);