aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2022-08-08 15:31:15 +0200
committerChristian Tismer <tismer@stackless.com>2022-08-15 14:19:43 +0200
commit3d8ade9b5bd6f8114bd52b33d454bfc141684d54 (patch)
tree283af67f5032e284715ff8ead47012df4506c298
parent3264ddb29f5ad16f2ed4820398a71a9ef992d514 (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 Pick-to: 6.3 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-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 eb73ff0f2..81304e6c2 100644
--- a/sources/shiboken6/ApiExtractor/typesystem_enums.h
+++ b/sources/shiboken6/ApiExtractor/typesystem_enums.h
@@ -99,7 +99,9 @@ enum class SmartPointerType {
enum class PythonEnumType {
Unspecified,
+ Enum,
IntEnum,
+ Flag,
IntFlag
};
diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
index 4a0ea347c..da6cc8255 100644
--- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp
+++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp
@@ -259,8 +259,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 c523a00db..d475363d2 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -432,7 +432,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;
}
@@ -457,7 +457,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;