diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-10-18 16:19:06 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-10-19 11:30:31 +0000 |
commit | bfe91d1d5075eb2455c29ad4034ad2557776655c (patch) | |
tree | 4a5e3c0253c2be0f22237f67d1742e88e7017719 | |
parent | 2b22707db650e5c8d4a94d0f9062dfcd3ff42384 (diff) |
shiboken6: Add a way of specifying types for casting enum values
Fixes: PYSIDE-2088
Change-Id: Ib571f67117403881001b51b1fda573074aa3fefc
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 328b8a52e9dda9d9f9a6daca1d2981f022be1720)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
7 files changed, 36 insertions, 3 deletions
diff --git a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml index d20dc5144..f606935ee 100644 --- a/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml +++ b/sources/pyside6/PySide6/QtGui/typesystem_gui_common.xml @@ -301,7 +301,8 @@ <value-type name="QTextInlineObject"/> <value-type name="QTextDocumentFragment"/> <value-type name="QTextOption"> - <enum-type name="Flag" flags="Flags"/> + <!-- PYSIDE-2088, Avoid MSVC signedness issues --> + <enum-type name="Flag" flags="Flags" cpp-type="unsigned"/> <enum-type name="TabType"/> <enum-type name="WrapMode"/> <value-type name="Tab"/> diff --git a/sources/pyside6/tests/QtGui/qtextline_test.py b/sources/pyside6/tests/QtGui/qtextline_test.py index ea317848f..ea39d536d 100644 --- a/sources/pyside6/tests/QtGui/qtextline_test.py +++ b/sources/pyside6/tests/QtGui/qtextline_test.py @@ -10,7 +10,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(False) -from PySide6.QtGui import QTextLayout +from PySide6.QtGui import QTextLayout, QTextOption from helper.usesqguiapplication import UsesQGuiApplication @@ -28,6 +28,11 @@ class QTextLineTest(UsesQGuiApplication): self.assertEqual(type(x), float) self.assertEqual(type(cursorPos), int) + def testTextOption(self): + """PYSIDE-2088, large enum values causing MSVC issues.""" + v = QTextOption.IncludeTrailingSpaces | QTextOption.ShowTabsAndSpaces + self.assertEqual(v.value, 2147483649) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/ApiExtractor/enumtypeentry.h b/sources/shiboken6/ApiExtractor/enumtypeentry.h index 60e16a113..16e0362aa 100644 --- a/sources/shiboken6/ApiExtractor/enumtypeentry.h +++ b/sources/shiboken6/ApiExtractor/enumtypeentry.h @@ -31,6 +31,9 @@ public: void setFlags(FlagsTypeEntry *flags); FlagsTypeEntry *flags() const; + QString cppType() const; + void setCppType(const QString &t); + bool isEnumValueRejected(const QString &name) const; void addEnumValueRejection(const QString &name); QStringList enumValueRejections() const; diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp index 36f411a09..34b25a29f 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.cpp +++ b/sources/shiboken6/ApiExtractor/typesystem.cpp @@ -961,6 +961,7 @@ public: const EnumValueTypeEntry *m_nullValue = nullptr; QStringList m_rejectedEnums; FlagsTypeEntry *m_flags = nullptr; + QString m_cppType; TypeSystem::PythonEnumType m_pythonEnumType = TypeSystem::PythonEnumType::Unspecified; }; @@ -1024,6 +1025,18 @@ FlagsTypeEntry *EnumTypeEntry::flags() const return d->m_flags; } +QString EnumTypeEntry::cppType() const +{ + S_D(const EnumTypeEntry); + return d->m_cppType; +} + +void EnumTypeEntry::setCppType(const QString &t) +{ + S_D(EnumTypeEntry); + d->m_cppType = t; +} + bool EnumTypeEntry::isEnumValueRejected(const QString &name) const { S_D(const EnumTypeEntry); diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp index aa2349725..994acb213 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp @@ -90,6 +90,7 @@ static inline QString positionAttribute() { return QStringLiteral("position"); } static inline QString preferredConversionAttribute() { return QStringLiteral("preferred-conversion"); } static inline QString preferredTargetLangTypeAttribute() { return QStringLiteral("preferred-target-lang-type"); } static inline QString pythonEnumTypeAttribute() { return QStringLiteral("python-type"); } +static inline QString cppEnumTypeAttribute() { return QStringLiteral("cpp-type"); } static inline QString qtMetaTypeAttribute() { return QStringLiteral("qt-register-metatype"); } static inline QString removeAttribute() { return QStringLiteral("remove"); } static inline QString renameAttribute() { return QStringLiteral("rename"); } @@ -1561,6 +1562,8 @@ EnumTypeEntry * qCWarning(lcShiboken, "%s", qPrintable(msgInvalidAttributeValue(attribute))); } + } else if (name == cppEnumTypeAttribute()) { + entry->setCppType(attributes->takeAt(i).value().toString()); } else if (name == extensibleAttribute()) { qCWarning(lcShiboken, "%s", qPrintable(msgUnimplementedAttributeWarning(reader, name))); diff --git a/sources/shiboken6/doc/typesystem_specifying_types.rst b/sources/shiboken6/doc/typesystem_specifying_types.rst index 04ad743bd..8f3874a39 100644 --- a/sources/shiboken6/doc/typesystem_specifying_types.rst +++ b/sources/shiboken6/doc/typesystem_specifying_types.rst @@ -252,6 +252,7 @@ enum-type since="..." flags="yes | no" flags-revision="..." + cpp-type = "..." python-type = "IntEnum | IntFlag" lower-bound="..." upper-bound="..." @@ -282,6 +283,10 @@ enum-type The *optional* **python-type** attribute specifies the underlying Python type. + The *optional* **cpp-type** attribute specifies a C++ to be used for + casting values. This can be useful for large values triggering MSVC + signedness issues. + The **revision** attribute can be used to specify a revision for each type, easing the production of ABI compatible bindings. diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 2f192840e..a1bb290e2 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -5631,7 +5631,10 @@ void CppGenerator::writeEnumInitialization(TextStream &s, const AbstractMetaEnum QString enumValueText; if (!avoidProtectedHack() || !cppEnum.isProtected()) { - enumValueText = u"Shiboken::Enum::EnumValueType("_s; + enumValueText = cppEnum.typeEntry()->cppType(); + if (enumValueText.isEmpty()) + enumValueText = u"Shiboken::Enum::EnumValueType"_s; + enumValueText += u'('; if (cppEnum.enclosingClass()) enumValueText += cppEnum.enclosingClass()->qualifiedCppName() + u"::"_s; // Fully qualify the value which is required for C++ 11 enum classes. |