diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-05-14 13:17:45 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-05-14 13:53:47 +0000 |
commit | 486e3ebedc485c9f9c7742f51c96d7e9a96ba935 (patch) | |
tree | 7818bc374153e442d892a8605e7cf55af0c4122d | |
parent | e0205cc7ebc4383f84b2fc05cabe9e6bf5f737e3 (diff) |
ShibokenGenerator::buildAbstractMetaTypeFromString(): Handle QFlags
The function would fail for a QFlags type defined in a dependent
typesystem file with errors like:
Can't write the C++ to Python conversion function for container type
'QPair': Could not find type '::QFlags<QAccessible::RelationFlag>' for
use in 'toPython' conversion.
for example caused by QAccessibleWidget::relation() where the flag is
defined in class QAccessible in QtGui.
The underlying reason is that there is no type entry for the class
QFlags. To work around this, detect it by looking at the instantiated
types and create a flags type accordingly.
Task-number: PYSIDE-487
Change-Id: Ib3c962aeedf8deb1a6b11976bd91316d39738310
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | sources/shiboken2/generator/shiboken2/shibokengenerator.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp index 69d7d5a53..6165ef009 100644 --- a/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp +++ b/sources/shiboken2/generator/shiboken2/shibokengenerator.cpp @@ -2395,7 +2395,18 @@ AbstractMetaType *ShibokenGenerator::buildAbstractMetaTypeFromString(QString typ } } - TypeEntry* typeEntry = TypeDatabase::instance()->findType(adjustedTypeName); + TypeEntry *typeEntry = nullptr; + AbstractMetaType::TypeUsagePattern pattern = AbstractMetaType::InvalidPattern; + + if (instantiations.size() == 1 + && instantiations.at(0)->typeUsagePattern() == AbstractMetaType::EnumPattern + && adjustedTypeName == QLatin1String("QFlags")) { + pattern = AbstractMetaType::FlagsPattern; + typeEntry = TypeDatabase::instance()->findType(typeSignature); + } else { + typeEntry = TypeDatabase::instance()->findType(adjustedTypeName); + } + if (!typeEntry) { if (errorMessage) { QTextStream(errorMessage) << "Cannot find type \"" << adjustedTypeName @@ -2410,8 +2421,17 @@ AbstractMetaType *ShibokenGenerator::buildAbstractMetaTypeFromString(QString typ metaType->setReferenceType(refType); metaType->setConstant(isConst); metaType->setTypeUsagePattern(AbstractMetaType::ContainerPattern); - metaType->setInstantiations(instantiations); - metaType->decideUsagePattern(); + switch (pattern) { + case AbstractMetaType::FlagsPattern: + metaType->setTypeUsagePattern(pattern); + break; + default: + metaType->setInstantiations(instantiations); + metaType->setTypeUsagePattern(AbstractMetaType::ContainerPattern); + metaType->decideUsagePattern(); + break; + } + m_metaTypeFromStringCache.insert(typeSignature, metaType); return metaType; } |