From f939f1b55b29d921f13397e2468d5b545d15f30d Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Mon, 8 Aug 2022 15:31:15 +0200 Subject: PyEnum: Enable the type definition to override all enum types The new enum support in XML knew IntEnum and IntFlag, only. After we recognized that there exist three cases that should be IntFlag, although there is no according "flags" C++ definition and adding this definition crashes, it became clear that we must allow to override IntEnum by IntFlag, just for Python. But the existence of such cases may be not restricted to IntEnum, it can also occur with normal enums. This patch prepares such an override. It must be still checked if there are such cases at all. Task-number: PYSIDE-1735 Change-Id: I4af1c3153c84f88fbef6ac36e421c47dfb5429a9 Reviewed-by: Friedemann Kleint (cherry picked from commit 3d8ade9b5bd6f8114bd52b33d454bfc141684d54) Reviewed-by: Qt Cherry-pick Bot --- sources/shiboken6/ApiExtractor/typesystem_enums.h | 2 ++ sources/shiboken6/ApiExtractor/typesystemparser.cpp | 4 +++- sources/shiboken6/generator/shiboken/cppgenerator.cpp | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sources/shiboken6/ApiExtractor/typesystem_enums.h b/sources/shiboken6/ApiExtractor/typesystem_enums.h index fba411c2c..0148d1eba 100644 --- a/sources/shiboken6/ApiExtractor/typesystem_enums.h +++ b/sources/shiboken6/ApiExtractor/typesystem_enums.h @@ -109,7 +109,9 @@ enum class CPythonType enum class PythonEnumType { Unspecified, + Enum, IntEnum, + Flag, IntFlag }; diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp index ae929d035..33d40432f 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp @@ -261,8 +261,10 @@ ENUM_LOOKUP_LINEAR_SEARCH() ENUM_LOOKUP_BEGIN(TypeSystem::PythonEnumType, Qt::CaseSensitive, pythonEnumTypeFromAttribute) { + {u"Enum", TypeSystem::PythonEnumType::Enum}, {u"IntEnum", TypeSystem::PythonEnumType::IntEnum}, - {u"IntFlag", TypeSystem::PythonEnumType::IntFlag} + {u"Flag", TypeSystem::PythonEnumType::Flag}, + {u"IntFlag", TypeSystem::PythonEnumType::IntFlag}, }; ENUM_LOOKUP_LINEAR_SEARCH() diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index ae6d83dd5..b165b6076 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -447,7 +447,7 @@ static QSet useIntSet() /* IntEnum */ u"PySide6.QtQuick.QSGGeometry.DrawingMode"_s, // Added because it should really be used as number /* IntEnum */ u"PySide6.QtCore.QMetaType.Type"_s, - /* IntEnum */ u"PySide6.QtSerialPort.QSerialPort.BaudRate"_s + /* IntEnum */ u"PySide6.QtSerialPort.QSerialPort.BaudRate"_s, }; return result; } @@ -472,7 +472,8 @@ static QString BuildEnumFlagInfo(const AbstractMetaEnum &cppEnum) bool _flag = bool(flags); if (decision != TypeSystem::PythonEnumType::Unspecified) { - _int = true; + _int = decision == TypeSystem::PythonEnumType::IntEnum || + decision == TypeSystem::PythonEnumType::IntFlag; if (!flags && decision == TypeSystem::PythonEnumType::IntFlag) { qWarning() << "\nnote: " << enumType->name() << "is set as IntFlag without flags\n"; _flag = true; -- cgit v1.2.3