diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-06-30 11:39:13 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-07-03 08:36:35 +0000 |
| commit | a2d6f90f94179dfc94fc032e0eb299a1556a6808 (patch) | |
| tree | 3f3734a7c3d79b97ef7c7aa64351ae332368127e /sources/shiboken6/ApiExtractor/parser/enumvalue.cpp | |
| parent | 9be2ffc454142f143c4e6949919bc4ba9ae5ae8a (diff) | |
shiboken6: Streamline/Improve enum code
- Remove ShibokenGenerator::getSimplifiedIntTypeName()
(which made assumptions on the width of int/long), use
plain type names instead.
- Use const arrays
- Streamline the formatting with some helper functions
Amends 895c452fd874fe4dfeb5a44e8c959136ceedba13.
Task-number: PYSIDE-1735
Change-Id: Icab3327a282ec3402e04f4fdffa5ffd64b2d3a8f
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/parser/enumvalue.cpp')
| -rw-r--r-- | sources/shiboken6/ApiExtractor/parser/enumvalue.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sources/shiboken6/ApiExtractor/parser/enumvalue.cpp b/sources/shiboken6/ApiExtractor/parser/enumvalue.cpp index 27e3b2e61..09c34cb91 100644 --- a/sources/shiboken6/ApiExtractor/parser/enumvalue.cpp +++ b/sources/shiboken6/ApiExtractor/parser/enumvalue.cpp @@ -7,12 +7,34 @@ #include <QtCore/QString> #include <QtCore/QTextStream> +using namespace Qt::StringLiterals; + QString EnumValue::toString() const { return m_type == EnumValue::Signed ? QString::number(m_value) : QString::number(m_unsignedValue); } +QString EnumValue::toHex(int fieldWidth) const +{ + QString result; + QTextStream str(&result); + // Note: Qt goofes up formatting of negative padded hex numbers, it ends up + // with "0x00-1". Write '-' before. + if (isNegative()) + str << '-'; + str << "0x" << Qt::hex; + if (fieldWidth) { + str.setFieldWidth(fieldWidth); + str.setPadChar(u'0'); + } + if (m_type == EnumValue::Signed) + str << qAbs(m_value); + else + str << m_unsignedValue; + return result; +} + void EnumValue::setValue(qint64 v) { m_value = v; |
