diff options
author | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2019-01-08 09:50:05 +0100 |
---|---|---|
committer | Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2019-01-11 14:59:36 +0000 |
commit | 8b6fbbac601b78f0c0413218ec5d48c60bc014ed (patch) | |
tree | 01354b356d871c9a90e5a9a7f71436351bd6b69c /sources/shiboken2/generator | |
parent | f93dfa8af3f4e7b1f3b84e68ecea21343dc36781 (diff) |
Improve check when a QFlag<Enum> is found
For the case of the method `addAxis` in the QPolarChart class,
the generated code evaluates first the inherited method:
QChart::addAxis(QtCharts::QAbstractAxis*,QFlags<Qt::AlignmentFlag>)
instead of the same class method:
QPolarChart::addAxis(QtCharts::QAbstractAxis*,QtCharts::QPolarChart::PolarOrientation)
The condition to check if an argument was a `QFlags<Qt::AlignmentFlag>`,
was just `PyNumber_Check(...)`, which was too broad, and then any
Enum would pass that condition.
The change was to include an additional condition to check the
type of the EnumType that was passed as argument.
Change-Id: I2eebb6f05c097d170a6d61633698444f03f20b02
Fixes: PYSIDE-898
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken2/generator')
-rw-r--r-- | sources/shiboken2/generator/shiboken2/cppgenerator.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp index 8c433ce82..f619020d5 100644 --- a/sources/shiboken2/generator/shiboken2/cppgenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/cppgenerator.cpp @@ -1207,9 +1207,18 @@ void CppGenerator::writeEnumConverterFunctions(QTextStream& s, const TypeEntry* c << INDENT << "Shiboken::AutoDecRef pyLong(PyNumber_Long(pyIn));" << endl; c << INDENT << "*((" << cppTypeName << "*)cppOut) = " << cppTypeName; c << "(QFlag((int)PyLong_AsLong(pyLong.object())));" << endl; + + // PYSIDE-898: Include an additional condition to detect if the type of the + // enum corresponds to the object that is being evaluated. + // Using only `PyNumber_Check(...)` is too permissive, + // then we would have been unable to detect the difference between + // a PolarOrientation and Qt::AlignmentFlag, which was the main + // issue of the bug. + const QString numberCondition = QStringLiteral("PyNumber_Check(pyIn) && ") + pyTypeCheck; writePythonToCppFunction(s, code, QLatin1String("number"), flagsTypeName); - writeIsPythonConvertibleToCppFunction(s, QLatin1String("number"), flagsTypeName, - QLatin1String("PyNumber_Check(pyIn)")); + writeIsPythonConvertibleToCppFunction(s, QLatin1String("number"), flagsTypeName, numberCondition); + + } void CppGenerator::writeConverterFunctions(QTextStream &s, const AbstractMetaClass *metaClass, |