aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6
diff options
context:
space:
mode:
authorChristian Tismer <[email protected]>2022-08-03 16:30:51 +0200
committerChristian Tismer <[email protected]>2022-08-13 11:36:08 +0200
commit0f5dcb03eb258280acd10a0f4f2889301a9ef365 (patch)
tree561cb3799bd8e0f9d558f25221e1bf6218fcb6e6 /sources/pyside6/PySide6
parent2d7a4fc710e59d0e766ffa101dba383eff46bb50 (diff)
PyEnum: Define a fixed list of Int(Enum|Flag) decisions
This was "PyEnum: Write a default Int decisor for Enum and Flag". Historically, C++ enums were all compatible with int. The new Python enums are more diverse here. There are the basic types Enum/IntEnum and Flag/IntFlag. We have tried a lot to come up with a sensible default heuristic computed from the data. In the end, this was reverted and replaced by a fixed list that was collected from similar implementations. By the move away from Int inheritance, a few classes needed extra support. Python 3.11.0b5 also required the Flag creation parameter "boundary=KEEP". It is not clear if this is correct, yet. [ChangeLog][shiboken6] Most former IntEnum/IntFlag are replaced by pure Enum/Flag classes in a generally compatible way to other implementations. Change-Id: I1dbe7b0556a3375df89eb40e9d9f495f14bf42b1 Pick-to: 6.3 Task-number: PYSIDE-1735 Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Shyamnath Premnadh <[email protected]> Reviewed-by: Friedemann Kleint <[email protected]>
Diffstat (limited to 'sources/pyside6/PySide6')
-rw-r--r--sources/pyside6/PySide6/QtCore/typesystem_core_common.xml35
-rw-r--r--sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml10
-rw-r--r--sources/pyside6/PySide6/QtMultimedia/typesystem_multimedia.xml2
-rw-r--r--sources/pyside6/PySide6/QtQuick/typesystem_quick.xml2
-rw-r--r--sources/pyside6/PySide6/QtSerialPort/typesystem_serialport.xml2
-rw-r--r--sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml34
-rw-r--r--sources/pyside6/PySide6/glue/qtcore.cpp15
7 files changed, 62 insertions, 38 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
index bacccebe5..c4e35f5df 100644
--- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
+++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
@@ -319,12 +319,17 @@
<extra-includes>
<include file-name="pysidemetatype.h" location="global"/>
</extra-includes>
- <enum-type name="Type"/>
+ <enum-type name="Type" python-type="IntEnum"/>
<enum-type name="TypeFlag" flags="TypeFlags"/>
<add-function signature="QMetaType(PyTypeObject*)">
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp"
snippet="metatype-from-type"/>
</add-function>
+ <!-- PYSIDE-1735: The class QMetaType.Type must be allowed because int is gone -->
+ <add-function signature="QMetaType(QMetaType::Type)">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp"
+ snippet="metatype-from-metatype-type"/>
+ </add-function>
<conversion-rule>
<native-to-target file="../glue/qtcore.cpp" snippet="conversion-qmetatype-pytypeobject"/>
<target-to-native>
@@ -517,7 +522,7 @@
<extra-includes>
<include file-name="QtCore/QProperty" location="global"/>
</extra-includes>
- <enum-type name="AlignmentFlag" flags="Alignment"/>
+ <enum-type name="AlignmentFlag" python-type="IntFlag" flags="Alignment"/>
<enum-type name="AnchorPoint" since="4.6"/>
<enum-type name="ApplicationAttribute"/>
<enum-type name="ApplicationState" flags="ApplicationStates" since="5.1"/>
@@ -548,7 +553,7 @@
<enum-type name="FocusReason"/>
<enum-type name="GestureFlag" flags="GestureFlags" since="4.6"/>
<enum-type name="GestureState" since="4.6"/>
- <enum-type name="GestureType" since="4.6"/>
+ <enum-type name="GestureType" python-type="IntEnum" since="4.6"/>
<enum-type name="GlobalColor"/>
<enum-type name="HighDpiScaleFactorRoundingPolicy" since="5.14"/>
<enum-type name="HitTestAccuracy"/>
@@ -556,11 +561,11 @@
<enum-type name="InputMethodHint" flags="InputMethodHints" since="4.6"/>
<enum-type name="InputMethodQuery" flags="InputMethodQueries"/>
<enum-type name="EnterKeyType" since="5.6"/>
- <enum-type name="ItemDataRole"/>
+ <enum-type name="ItemDataRole" python-type="IntEnum"/>
<enum-type name="ItemFlag" flags="ItemFlags"/>
<enum-type name="ItemSelectionMode"/>
<enum-type name="ItemSelectionOperation" since="5.5"/>
- <enum-type name="Key"/>
+ <enum-type name="Key" python-type="IntEnum"/>
<enum-type name="KeyboardModifier" flags="KeyboardModifiers"/>
<enum-type name="LayoutDirection"/>
<enum-type name="MaskMode"/>
@@ -586,7 +591,7 @@
<enum-type name="SplitBehaviorFlags" flags="SplitBehavior" since="5.14"/>
<enum-type name="TabFocusBehavior" since="5.5"/>
<enum-type name="TextElideMode"/>
- <enum-type name="TextFlag"/>
+ <enum-type name="TextFlag" python-type="IntFlag"/>
<enum-type name="TextFormat"/>
<enum-type name="TextInteractionFlag" flags="TextInteractionFlags"/>
<enum-type name="TileRule" since="4.6"/>
@@ -603,7 +608,7 @@
<enum-type name="WindowFrameSection"/>
<enum-type name="WindowModality"/>
<enum-type name="WindowState" flags="WindowStates"/>
- <enum-type name="WindowType" flags="WindowFlags"/>
+ <enum-type name="WindowType" python-type="IntFlag" flags="WindowFlags"/>
<enum-type name="CursorMoveStyle" since="4.8" revision="4800"/>
<modify-function signature="^operator.\(Qt::AlignmentFlag,Qt::TextFlag\)$"
@@ -859,6 +864,10 @@
<add-function signature="QDateTime(int,int,int,int,int,int)">
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qdatetime-2"/>
</add-function>
+ <!-- PYSIDE-1735: Qt::TimeSpec is no more compatible with int -->
+ <add-function signature="QDateTime(int,int,int,int,int,int,int,Qt::TimeSpec=Qt::LocalTime)">
+ <inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qdatetime-3"/>
+ </add-function>
<add-function signature="__repr__" return-type="PyObject*">
<inject-code class="target" position="beginning">
<insert-template name="repr_code">
@@ -1287,10 +1296,10 @@
<value-type name="QLocale">
<enum-type name="Country"/>
<enum-type name="DataSizeFormat" flags="DataSizeFormats" since="5.10"/>
- <enum-type name="FloatingPointPrecisionOption" since="5.7"/>
+ <enum-type name="FloatingPointPrecisionOption" python-type="IntEnum" since="5.7"/>
<enum-type name="FormatType"/>
<enum-type name="Language"/>
- <enum-type name="LanguageCodeType" flags="LanguageCodeTypes" since="6.3"/>
+ <enum-type name="LanguageCodeType" python-type="IntFlag" flags="LanguageCodeTypes" since="6.3"/>
<enum-type name="MeasurementSystem"/>
<enum-type name="NumberOption" flags="NumberOptions"/>
<enum-type name="Script" since="4.8" revision="4800"/>
@@ -1785,9 +1794,9 @@
<value-type name="QUrl" hash-function="PySide::hash">
<!-- Qt5: lots of changes -->
- <enum-type name="ComponentFormattingOption" flags="ComponentFormattingOptions,FormattingOptions"/>
+ <enum-type name="ComponentFormattingOption" python-type="IntFlag" flags="ComponentFormattingOptions,FormattingOptions"/>
<!-- note: above duplication of attribute is not by default XML compliant! -->
- <enum-type name="UrlFormattingOption"/>
+ <enum-type name="UrlFormattingOption" python-type="IntFlag"/>
<enum-type name="UserInputResolutionOption" flags="UserInputResolutionOptions"/>
<enum-type name="ParsingMode"/>
<enum-type name="AceProcessingOption" flags="AceProcessingOptions" since="6.3"/>
@@ -2569,7 +2578,7 @@
</object-type>
<object-type name="QEvent" polymorphic-id-expression="%1-&gt;type() == QEvent::None"
qt-register-metatype="base">
- <enum-type name="Type"/>
+ <enum-type name="Type" python-type="IntEnum"/>
<add-function signature="__repr__" return-type="PyObject">
<inject-code class="target" position="beginning"
file="../glue/qtcore.cpp" snippet="repr-qevent"/>
@@ -2589,7 +2598,7 @@
<object-type name="QDataStream" stream="yes">
<enum-type name="FloatingPointPrecision" since="4.6"/>
<enum-type name="Status"/>
- <enum-type name="Version"/>
+ <enum-type name="Version" python-type="IntEnum"/>
<enum-type name="ByteOrder"/>
<extra-includes>
<include file-name="QtCore/QtCore" location="global"/>
diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
index 49399bc72..923abfd2a 100644
--- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
+++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml
@@ -478,10 +478,10 @@
<enum-type name="VerticalAlignment"/>
</value-type>
<value-type name="QTextFormat" >
- <enum-type name="FormatType"/>
- <enum-type name="ObjectTypes"/>
+ <enum-type name="FormatType" python-type="IntEnum"/>
+ <enum-type name="ObjectTypes" python-type="IntEnum"/>
<enum-type name="PageBreakFlag" flags="PageBreakFlags"/>
- <enum-type name="Property"/>
+ <enum-type name="Property" python-type="IntEnum"/>
</value-type>
<value-type name="QTextListFormat">
<enum-type name="Style"/>
@@ -655,11 +655,11 @@
<value-type name="QFont" >
<enum-type name="Capitalization"/>
<enum-type name="SpacingType"/>
- <enum-type name="Stretch"/>
+ <enum-type name="Stretch" python-type="IntEnum"/>
<enum-type name="Style"/>
<enum-type name="StyleHint"/>
<enum-type name="StyleStrategy"/>
- <enum-type name="Weight"/>
+ <enum-type name="Weight" python-type="IntEnum"/>
<enum-type name="HintingPreference" since="4.8" revision="4800"/>
<extra-includes>
<include file-name="QStringList" location="global"/>
diff --git a/sources/pyside6/PySide6/QtMultimedia/typesystem_multimedia.xml b/sources/pyside6/PySide6/QtMultimedia/typesystem_multimedia.xml
index 7d59b4398..3fa7e6e6d 100644
--- a/sources/pyside6/PySide6/QtMultimedia/typesystem_multimedia.xml
+++ b/sources/pyside6/PySide6/QtMultimedia/typesystem_multimedia.xml
@@ -110,7 +110,7 @@
<enum-type name="MediaStatus"/>
<enum-type name="PlaybackState" since="6.1"/>
<enum-type name="Error"/>
- <enum-type name="Loops" since="6.2.3"/>
+ <enum-type name="Loops" python-type="IntEnum" since="6.2.3"/>
</object-type>
<!-- see qtmultimedia/5773f7214c7430a98dea3974c0597cb3ee0ea7f5 might reappear in 6.3
<object-type name="QMediaPlaylist"/>
diff --git a/sources/pyside6/PySide6/QtQuick/typesystem_quick.xml b/sources/pyside6/PySide6/QtQuick/typesystem_quick.xml
index f4cadad7c..87fcc8514 100644
--- a/sources/pyside6/PySide6/QtQuick/typesystem_quick.xml
+++ b/sources/pyside6/PySide6/QtQuick/typesystem_quick.xml
@@ -103,7 +103,7 @@
<object-type name="QSGGeometry">
<enum-type name="DataPattern"/>
<enum-type name="AttributeType" since="5.8"/>
- <enum-type name="DrawingMode" since="5.8"/>
+ <enum-type name="DrawingMode" python-type="IntEnum" since="5.8"/>
<enum-type name="Type" since="5.8"/>
<value-type name="Attribute"/>
<value-type name="AttributeSet"/>
diff --git a/sources/pyside6/PySide6/QtSerialPort/typesystem_serialport.xml b/sources/pyside6/PySide6/QtSerialPort/typesystem_serialport.xml
index b49abacc6..929a8e909 100644
--- a/sources/pyside6/PySide6/QtSerialPort/typesystem_serialport.xml
+++ b/sources/pyside6/PySide6/QtSerialPort/typesystem_serialport.xml
@@ -6,7 +6,7 @@
<typesystem package="PySide6.QtSerialPort">
<load-typesystem name="QtCore/typesystem_core.xml" generate="no"/>
<object-type name="QSerialPort">
- <enum-type name="BaudRate"/>
+ <enum-type name="BaudRate" python-type="IntEnum"/>
<enum-type name="DataBits"/>
<enum-type name="Direction" flags="Directions"/>
<enum-type name="FlowControl"/>
diff --git a/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml b/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml
index fe8aced95..3f2afbdeb 100644
--- a/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml
+++ b/sources/pyside6/PySide6/QtWidgets/typesystem_widgets_common.xml
@@ -183,7 +183,7 @@
<value-type name="QSizePolicy">
<enum-type name="ControlType" flags="ControlTypes"/>
<enum-type name="Policy"/>
- <enum-type name="PolicyFlag"/>
+ <enum-type name="PolicyFlag" python-type="IntFlag"/>
</value-type>
<value-type name="QTableWidgetSelectionRange"/>
@@ -475,7 +475,7 @@
</object-type>
<object-type name="QDateEdit"/>
<object-type name="QDialog">
- <enum-type name="DialogCode"/>
+ <enum-type name="DialogCode" python-type="IntEnum"/>
<modify-function signature="exec()" allow-thread="yes"/>
<add-function signature="exec_()" return-type="int">
<inject-code file="../glue/qtwidgets.cpp" snippet="qapplication-exec"/>
@@ -1120,17 +1120,17 @@
</add-function>
</object-type>
<object-type name="QStyle">
- <enum-type name="ComplexControl"/>
- <enum-type name="ContentsType"/>
- <enum-type name="ControlElement"/>
- <enum-type name="PixelMetric"/>
- <enum-type name="PrimitiveElement"/>
+ <enum-type name="ComplexControl" python-type="IntEnum"/>
+ <enum-type name="ContentsType" python-type="IntEnum"/>
+ <enum-type name="ControlElement" python-type="IntEnum"/>
+ <enum-type name="PixelMetric" python-type="IntEnum"/>
+ <enum-type name="PrimitiveElement" python-type="IntEnum"/>
<enum-type name="RequestSoftwareInputPanel" since="4.6"/>
- <enum-type name="StandardPixmap"/>
+ <enum-type name="StandardPixmap" python-type="IntEnum"/>
<enum-type name="StateFlag" flags="State"/>
- <enum-type name="StyleHint"/>
+ <enum-type name="StyleHint" python-type="IntEnum"/>
<enum-type name="SubControl" flags="SubControls"/>
- <enum-type name="SubElement"/>
+ <enum-type name="SubElement" python-type="IntEnum"/>
<modify-function signature="drawComplexControl(QStyle::ComplexControl,const QStyleOptionComplex*,QPainter*,const QWidget*)const">
<modify-argument index="3" invalidate-after-use="yes"/>
<modify-argument index="4">
@@ -1748,7 +1748,7 @@
<modify-function signature="closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)" allow-thread="yes"/>
</object-type>
<object-type name="QTableWidgetItem" >
- <enum-type name="ItemType"/>
+ <enum-type name="ItemType" python-type="IntEnum"/>
<modify-function signature="read(QDataStream&amp;)" allow-thread="yes">
<modify-argument index="1" invalidate-after-use="yes"/>
</modify-function>
@@ -1757,7 +1757,7 @@
</modify-function>
</object-type>
<object-type name="QListWidgetItem" >
- <enum-type name="ItemType"/>
+ <enum-type name="ItemType" python-type="IntEnum"/>
<modify-function signature="QListWidgetItem(const QString&amp;,QListWidget*,int)">
<modify-argument index="this">
<parent index="2" action="add"/>
@@ -1817,7 +1817,7 @@
</object-type>
<object-type name="QTreeWidgetItem" hash-function="qHash" parent-management="true">
<enum-type name="ChildIndicatorPolicy"/>
- <enum-type name="ItemType"/>
+ <enum-type name="ItemType" python-type="IntEnum"/>
<modify-function signature="read(QDataStream&amp;)" allow-thread="yes">
<modify-argument index="1" invalidate-after-use="yes"/>
</modify-function>
@@ -2251,7 +2251,7 @@
<object-type name="QMessageBox">
<enum-type name="ButtonRole"/>
<enum-type name="Icon"/>
- <enum-type name="StandardButton" flags="StandardButtons"/>
+ <enum-type name="StandardButton" python-type="IntFlag" flags="StandardButtons"/>
<modify-function signature="removeButton(QAbstractButton*)">
<modify-argument index="1">
<parent index="this" action="add"/>
@@ -2706,8 +2706,8 @@
</modify-function>
</object-type>
<object-type name="QFrame">
- <enum-type name="Shadow"/>
- <enum-type name="Shape"/>
+ <enum-type name="Shadow" python-type="IntEnum"/>
+ <enum-type name="Shape" python-type="IntEnum"/>
<enum-type name="StyleMask"/>
</object-type>
<object-type name="QSpinBox"/>
@@ -2861,7 +2861,7 @@
<object-type name="QCommandLinkButton"/>
<!-- FIXME PYSIDE7: Move to QtGui -->
<object-type name="QFileSystemModel" polymorphic-id-expression="qobject_cast&lt;QFileSystemModel*&gt;(%1)">
- <enum-type name="Roles"/>
+ <enum-type name="Roles" python-type="IntEnum"/>
<enum-type name="Option" flags="Options" since="5.14"/>
<modify-function signature="setIconProvider(QAbstractFileIconProvider*)">
<modify-argument index="1">
diff --git a/sources/pyside6/PySide6/glue/qtcore.cpp b/sources/pyside6/PySide6/glue/qtcore.cpp
index 68fcdcd05..7d1928c00 100644
--- a/sources/pyside6/PySide6/glue/qtcore.cpp
+++ b/sources/pyside6/PySide6/glue/qtcore.cpp
@@ -128,6 +128,15 @@ else {
%0 = new %TYPE(PySide::qMetaTypeFromPyType(reinterpret_cast<PyTypeObject *&>(%1)));
// @snippet metatype-from-type
+// @snippet metatype-from-metatype-type
+Shiboken::AutoDecRef intArg;
+if (usingNewEnum())
+ intArg.reset(PyObject_GetAttrString(%PYARG_1, "value"));
+else
+ intArg.reset(PyObject_CallMethod(%PYARG_1, "__int__", nullptr));
+%0 = new %TYPE(PyLong_AsLong(intArg));
+// @snippet metatype-from-metatype-type
+
// @snippet conversion-pytypeobject-qmetatype
auto *pyType = reinterpret_cast<PyTypeObject *&>(%in);
%out = PySide::qMetaTypeFromPyType(pyType);
@@ -403,6 +412,12 @@ QTime time(%4, %5, %6);
%0 = new %TYPE(date, time);
// @snippet qdatetime-2
+// @snippet qdatetime-3
+QDate date(%1, %2, %3);
+QTime time(%4, %5, %6, %7);
+%0 = new %TYPE(date, time, %8);
+// @snippet qdatetime-3
+
// @snippet qdatetime-topython
QDate date = %CPPSELF.date();
QTime time = %CPPSELF.time();