From e52ebf296e8fcd84fa4055c80a3c489ae1431c9e Mon Sep 17 00:00:00 2001 From: Andreas Beckermann Date: Thu, 12 Sep 2019 15:10:46 +0200 Subject: Add support for __repr__ in QObject derived classes Currently shiboken generates classes without __repr__ for QObject derived classes. However for all non-QObject classes that have an operator<<() for QDebug, it *does* add a valid repr implementation. Extend this behavior to QObject classes as well. In order for this to become more useful, also check for the indirection of operator<<(): If operator<<(QDebug, Foo*) is available, use the current non-value-type behavior, (i.e. provide cppSelf to operator<<()), but if operator<<(QDebug, const Foo&) is available instead, use the same behavior as for value-types, i.e. provide *cppSelf. This greatly increases the number of classes where operator<<() provides useful results. Also make sure to check for operator<<() in namespaces (recursively), not just at global scope. Change-Id: Ief9158455a25e332f07169f09692cafb8097078b Reviewed-by: Friedemann Kleint --- sources/pyside2/tests/pysidetest/testobject.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'sources/pyside2/tests/pysidetest/testobject.h') diff --git a/sources/pyside2/tests/pysidetest/testobject.h b/sources/pyside2/tests/pysidetest/testobject.h index 6cfb01101..f8a174d46 100644 --- a/sources/pyside2/tests/pysidetest/testobject.h +++ b/sources/pyside2/tests/pysidetest/testobject.h @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef pysidetest_EXPORTS #define PYSIDE_EXPORTS 1 #endif @@ -81,6 +82,7 @@ private: int m_idValue; QList m_children; }; +PYSIDE_API QDebug operator<<(QDebug dbg, TestObject &testObject); typedef int PySideInt; @@ -104,6 +106,16 @@ signals: void emitSignalWithNamespace(PySideCPP::TestObjectWithNamespace* obj); void emitSignalWithTypedef(PySideInt val); }; +PYSIDE_API QDebug operator<<(QDebug dbg, TestObjectWithNamespace &testObject); + +class PYSIDE_API TestObject2WithNamespace : public QObject +{ + Q_OBJECT +public: + TestObject2WithNamespace(QObject* parent) : QObject(parent) {} + QString name() { return "TestObject2WithNamespace"; } +}; +PYSIDE_API QDebug operator<<(QDebug dbg, TestObject2WithNamespace& testObject); } // Namespace PySideCPP -- cgit v1.2.3