aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-08-08 15:31:15 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-15 17:09:41 +0000
commitf939f1b55b29d921f13397e2468d5b545d15f30d (patch)
tree35516c72a23c425cc7fe9be2b5caa009733aac2a
parente898d7a3a12b2a97d796acd48441775c41faa994 (diff)
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 <Friedemann.Kleint@qt.io> (cherry picked from commit 3d8ade9b5bd6f8114bd52b33d454bfc141684d54) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem_enums.h2
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemparser.cpp4
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp5
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<QString> 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;