diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-01-21 17:11:18 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-01-21 21:50:32 +0000 |
commit | 29bdff9f1466ea46f0a4bd6205c5e39d000666a5 (patch) | |
tree | a7f7305dc1229acc5dc4d0691142b7f608c9a767 | |
parent | 0601dab979f7dfccaf345e4ded2e138ffd0859ab (diff) |
PySide6: Add __repr__ to QEvents
Add a basic __repr__ function to QEvent that shows the type enumeration
value. For QtGui, use the debug operator from qevent.h for the relevant
events. Add a generic template for using QDebug with module name.
[ChangeLog][PySide6] __repr__ functions for some QEvent-derived
classes were added.
Task-number: PYSIDE-1788
Change-Id: I02aca4c98cf3ebd69558103c7d23660d1eb840fb
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
(cherry picked from commit 3706622525261e10c4f8eaeecd977de7e455b8f5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/pyside6/PySide6/QtCore/typesystem_core_common.xml | 4 | ||||
-rw-r--r-- | sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml | 108 | ||||
-rw-r--r-- | sources/pyside6/PySide6/glue/qtcore.cpp | 6 | ||||
-rw-r--r-- | sources/pyside6/PySide6/templates/core_common.xml | 12 |
4 files changed, 119 insertions, 11 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml index 4e9a1c55a..f00d01680 100644 --- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml +++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml @@ -2562,6 +2562,10 @@ </object-type> <object-type name="QEvent" polymorphic-id-expression="%1->type() == QEvent::None"> <enum-type name="Type"/> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning" + file="../glue/qtcore.cpp" snippet="repr-qevent"/> + </add-function> </object-type> <object-type name="QChildEvent" polymorphic-id-expression="%1->type() == QEvent::ChildAdded || %1->type() == QEvent::ChildPolished || %1->type() == QEvent::ChildRemoved"> <modify-function signature="child()const"> diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml index caecca7bf..6c3c97c0f 100644 --- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml +++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml @@ -1390,20 +1390,49 @@ <value-type name="QEventPoint" since="6.0"> <enum-type name="State"/> </value-type> - <object-type name="QDragEnterEvent" polymorphic-id-expression="%1->type() == QEvent::DragEnter"/> - <object-type name="QDragLeaveEvent" polymorphic-id-expression="%1->type() == QEvent::DragLeave"/> - <object-type name="QDragMoveEvent" polymorphic-id-expression="%1->type() == QEvent::DragMove"/> + <object-type name="QDragEnterEvent" polymorphic-id-expression="%1->type() == QEvent::DragEnter"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> + <object-type name="QDragLeaveEvent" polymorphic-id-expression="%1->type() == QEvent::DragLeave"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> + <object-type name="QDragMoveEvent" polymorphic-id-expression="%1->type() == QEvent::DragMove"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> <object-type name="QDropEvent" polymorphic-id-expression="%1->type() == QEvent::Drop"> <modify-function signature="source()const"> <modify-argument index="return"> <define-ownership class="target" owner="default"/> </modify-argument> </modify-function> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> </object-type> <object-type name="QEnterEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::Enter"/> <object-type name="QExposeEvent" polymorphic-id-expression="%1->type() == QEvent::Expose"/> <object-type name="QFileOpenEvent" polymorphic-id-expression="%1->type() == QEvent::FileOpen"/> - <object-type name="QFocusEvent" polymorphic-id-expression="%1->type() == QEvent::FocusIn || %1->type() == QEvent::FocusOut"/> + <object-type name="QFocusEvent" polymorphic-id-expression="%1->type() == QEvent::FocusIn || %1->type() == QEvent::FocusOut"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> <object-type name="QHelpEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::ToolTip || %1->type() == QEvent::WhatsThis"/> <object-type name="QHideEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::Hide"/> <object-type name="QHoverEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::HoverEnter || %1->type() == QEvent::HoverLeave || %1->type() == QEvent::HoverMove"/> @@ -1415,35 +1444,75 @@ <value-type name="Attribute"> <include file-name="QInputMethodEvent" location="global"/> </value-type> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> <!-- endif ndef QT_NO_INPUTMETHOD --> </object-type> <object-type name="QInputMethodQueryEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::InputMethodQuery"/> - <object-type name="QMoveEvent" copyable = "false" polymorphic-id-expression="%1->type() == QEvent::Move"/> + <object-type name="QMoveEvent" copyable = "false" polymorphic-id-expression="%1->type() == QEvent::Move"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> <object-type name="QNativeGestureEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::NativeGesture"/> <object-type name="QPlatformSurfaceEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::PlatformSurface"> <enum-type name="SurfaceEventType"/> </object-type> - <object-type name="QResizeEvent" copyable = "false" polymorphic-id-expression="%1->type() == QEvent::Resize"/> + <object-type name="QResizeEvent" copyable = "false" polymorphic-id-expression="%1->type() == QEvent::Resize"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> <object-type name="QShortcutEvent" copyable = "false" polymorphic-id-expression="%1->type() == QEvent::Shortcut"> </object-type> <object-type name="QShowEvent" copyable= "false" polymorphic-id-expression="%1->type() == QEvent::Show"/> <object-type name="QSinglePointEvent" copyable="false" since="6.0"/> <object-type name="QStatusTipEvent" copyable= "false" polymorphic-id-expression="%1->type() == QEvent::StatusTip"/> - <object-type name="QTabletEvent" copyable= "false" polymorphic-id-expression="%1->type() == QEvent::TabletMove || %1->type() == QEvent::TabletPress || %1->type() == QEvent::TabletRelease"/> + <object-type name="QTabletEvent" copyable= "false" polymorphic-id-expression="%1->type() == QEvent::TabletMove || %1->type() == QEvent::TabletPress || %1->type() == QEvent::TabletRelease"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> <object-type name="QToolBarChangeEvent" polymorphic-id-expression="%1->type() == QEvent::ToolBarChange"/> <object-type name="QWhatsThisClickedEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::WhatsThisClicked"/> - <object-type name="QWheelEvent" copyable= "false" polymorphic-id-expression="%1->type() == QEvent::Wheel"/> + <object-type name="QWheelEvent" copyable= "false" polymorphic-id-expression="%1->type() == QEvent::Wheel"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> <!-- Qt5.5: suppress this nameless enum --> <suppress-warning text="enum 'QWheelEvent::DefaultDeltasPerStep' does not have a type entry or is not an enum"/> - <object-type name="QWindowStateChangeEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::WindowStateChange"/> + <object-type name="QWindowStateChangeEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::WindowStateChange"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> <object-type name="QInputEvent" copyable="false"/> <object-type name="QKeyEvent" copyable= "false" polymorphic-id-expression="%1->type() == QEvent::KeyPress || %1->type() == QEvent::KeyRelease || %1->type() == QEvent::ShortcutOverride"> <add-function signature="operator!=(QKeySequence::StandardKey)"> <inject-code class="target" file="../glue/qtgui.cpp" snippet="qkeyevent-operatornotequal"/> </add-function> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> </object-type> <object-type name="QMouseEvent" copyable= "false" polymorphic-id-expression="%1->type() == QEvent::MouseButtonDblClick || %1->type() == QEvent::MouseButtonPress || %1->type() == QEvent::MouseButtonRelease || %1->type() == QEvent::MouseMove"> @@ -1456,12 +1525,23 @@ <modify-function signature="y() const" deprecated="yes"/> <modify-function signature="globalX() const" deprecated="yes"/> <modify-function signature="globalY() const" deprecated="yes"/> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> </object-type> <object-type name="QPaintEvent" copyable= "false" polymorphic-id-expression="%1->type() == QEvent::Paint"/> <object-type name="QScrollEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::Scroll"> <enum-type name="ScrollState"/> </object-type> - <object-type name="QPointerEvent" copyable= "false" since="6.0"/> + <object-type name="QPointerEvent" copyable= "false" since="6.0"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> <object-type name="QScrollPrepareEvent" copyable="false" polymorphic-id-expression="%1->type() == QEvent::ScrollPrepare"/> <object-type name="QTextFrame" > @@ -2366,7 +2446,13 @@ <modify-function signature="getEulerAngles(float*,float*,float*)const" since="5.5" remove="all"/> </value-type> - <object-type name="QTouchEvent" since="4.6"/> + <object-type name="QTouchEvent" since="4.6"> + <add-function signature="__repr__" return-type="PyObject"> + <inject-code class="target" position="beginning"> + <insert-template name="repr_qdebug_gui"/> + </inject-code> + </add-function> + </object-type> <object-type name="QInputDevice"> <enum-type name="Capability" flags="Capabilities"/> diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp index da2e016ea..251c660a0 100644 --- a/sources/pyside6/PySide6/glue/qtcore.cpp +++ b/sources/pyside6/PySide6/glue/qtcore.cpp @@ -1995,3 +1995,9 @@ Py_INCREF(callable); %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(cppCallback); %PYARG_0 = %CONVERTTOPYTHON[int](cppResult); // @snippet qthreadpool-trystart + +// @snippet repr-qevent +QString result; +QDebug(&result).nospace() << "<PySide6.QtCore.QEvent(" << %CPPSELF->type() << ")>"; +%PYARG_0 = Shiboken::String::fromCString(qPrintable(result)); +// @snippet repr-qevent diff --git a/sources/pyside6/PySide6/templates/core_common.xml b/sources/pyside6/PySide6/templates/core_common.xml index abc0d6425..044122457 100644 --- a/sources/pyside6/PySide6/templates/core_common.xml +++ b/sources/pyside6/PySide6/templates/core_common.xml @@ -249,6 +249,18 @@ %PYARG_0 = Shiboken::String::fromCString(qPrintable(format)); </template> + <template name="repr_qdebug"> + QString result; + QDebug(&result).nospace() << "<PySide6.MODULE." << %CPPSELF << '>'; + %PYARG_0 = Shiboken::String::fromCString(qPrintable(result)); + </template> + + <template name="repr_qdebug_gui"> + <insert-template name="repr_qdebug"> + <replace from="MODULE" to="QtGui"/> + </insert-template> + </template> + <template name="return_internal_pointer"> %PYARG_0 = reinterpret_cast<PyObject*>(%CPPSELF.%FUNCTION_NAME()); if (!%PYARG_0) |