aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-01-21 17:11:18 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-21 21:50:32 +0000
commit29bdff9f1466ea46f0a4bd6205c5e39d000666a5 (patch)
treea7f7305dc1229acc5dc4d0691142b7f608c9a767
parent0601dab979f7dfccaf345e4ded2e138ffd0859ab (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.xml4
-rw-r--r--sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml108
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp6
-rw-r--r--sources/pyside6/PySide6/templates/core_common.xml12
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-&gt;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-&gt;type() == QEvent::ChildAdded || %1-&gt;type() == QEvent::ChildPolished || %1-&gt;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-&gt;type() == QEvent::DragEnter"/>
- <object-type name="QDragLeaveEvent" polymorphic-id-expression="%1-&gt;type() == QEvent::DragLeave"/>
- <object-type name="QDragMoveEvent" polymorphic-id-expression="%1-&gt;type() == QEvent::DragMove"/>
+ <object-type name="QDragEnterEvent" polymorphic-id-expression="%1-&gt;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-&gt;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-&gt;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-&gt;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-&gt;type() == QEvent::Enter"/>
<object-type name="QExposeEvent" polymorphic-id-expression="%1-&gt;type() == QEvent::Expose"/>
<object-type name="QFileOpenEvent" polymorphic-id-expression="%1-&gt;type() == QEvent::FileOpen"/>
- <object-type name="QFocusEvent" polymorphic-id-expression="%1-&gt;type() == QEvent::FocusIn || %1-&gt;type() == QEvent::FocusOut"/>
+ <object-type name="QFocusEvent" polymorphic-id-expression="%1-&gt;type() == QEvent::FocusIn || %1-&gt;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-&gt;type() == QEvent::ToolTip || %1-&gt;type() == QEvent::WhatsThis"/>
<object-type name="QHideEvent" copyable="false" polymorphic-id-expression="%1-&gt;type() == QEvent::Hide"/>
<object-type name="QHoverEvent" copyable="false" polymorphic-id-expression="%1-&gt;type() == QEvent::HoverEnter || %1-&gt;type() == QEvent::HoverLeave || %1-&gt;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-&gt;type() == QEvent::InputMethodQuery"/>
- <object-type name="QMoveEvent" copyable = "false" polymorphic-id-expression="%1-&gt;type() == QEvent::Move"/>
+ <object-type name="QMoveEvent" copyable = "false" polymorphic-id-expression="%1-&gt;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-&gt;type() == QEvent::NativeGesture"/>
<object-type name="QPlatformSurfaceEvent" copyable="false"
polymorphic-id-expression="%1-&gt;type() == QEvent::PlatformSurface">
<enum-type name="SurfaceEventType"/>
</object-type>
- <object-type name="QResizeEvent" copyable = "false" polymorphic-id-expression="%1-&gt;type() == QEvent::Resize"/>
+ <object-type name="QResizeEvent" copyable = "false" polymorphic-id-expression="%1-&gt;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-&gt;type() == QEvent::Shortcut">
</object-type>
<object-type name="QShowEvent" copyable= "false" polymorphic-id-expression="%1-&gt;type() == QEvent::Show"/>
<object-type name="QSinglePointEvent" copyable="false" since="6.0"/>
<object-type name="QStatusTipEvent" copyable= "false" polymorphic-id-expression="%1-&gt;type() == QEvent::StatusTip"/>
- <object-type name="QTabletEvent" copyable= "false" polymorphic-id-expression="%1-&gt;type() == QEvent::TabletMove || %1-&gt;type() == QEvent::TabletPress || %1-&gt;type() == QEvent::TabletRelease"/>
+ <object-type name="QTabletEvent" copyable= "false" polymorphic-id-expression="%1-&gt;type() == QEvent::TabletMove || %1-&gt;type() == QEvent::TabletPress || %1-&gt;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-&gt;type() == QEvent::ToolBarChange"/>
<object-type name="QWhatsThisClickedEvent" copyable="false" polymorphic-id-expression="%1-&gt;type() == QEvent::WhatsThisClicked"/>
- <object-type name="QWheelEvent" copyable= "false" polymorphic-id-expression="%1-&gt;type() == QEvent::Wheel"/>
+ <object-type name="QWheelEvent" copyable= "false" polymorphic-id-expression="%1-&gt;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-&gt;type() == QEvent::WindowStateChange"/>
+ <object-type name="QWindowStateChangeEvent" copyable="false" polymorphic-id-expression="%1-&gt;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-&gt;type() == QEvent::KeyPress || %1-&gt;type() == QEvent::KeyRelease || %1-&gt;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-&gt;type() == QEvent::MouseButtonDblClick || %1-&gt;type() == QEvent::MouseButtonPress || %1-&gt;type() == QEvent::MouseButtonRelease || %1-&gt;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-&gt;type() == QEvent::Paint"/>
<object-type name="QScrollEvent" copyable="false" polymorphic-id-expression="%1-&gt;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-&gt;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(&amp;result).nospace() &lt;&lt; "&lt;PySide6.MODULE." &lt;&lt; %CPPSELF &lt;&lt; '>';
+ %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&lt;PyObject*>(%CPPSELF.%FUNCTION_NAME());
if (!%PYARG_0)