uic/Python: Import base class for flag values

Extend the logic extracting enum base classes to flags
to handle things like  QAbstractItemView::EditTriggers.
Exclude the Qt namespace.

Amends de15836dbf.

Fixes: PYSIDE-1773
Task-number: PYSIDE-1404
Pick-to: 6.2 6.2.3 6.3
Change-Id: Ib0cd0836a91f330e5bc3307690062a965abec7eb
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
This commit is contained in:
Friedemann Kleint 2022-01-12 15:18:02 +01:00
parent 7719fcea4b
commit e376c229e9
2 changed files with 22 additions and 6 deletions

View File

@ -233,16 +233,31 @@ void WriteImports::addPythonCustomWidget(const QString &className, const DomCust
void WriteImports::acceptProperty(DomProperty *node)
{
if (node->kind() == DomProperty::Enum) {
// Add base classes like QFrame for QLabel::frameShape()
const QString &enumV = node->elementEnum();
const auto colonPos = enumV.indexOf(u"::");
if (colonPos > 0)
addQtClass(enumV.left(colonPos));
switch (node->kind()) {
case DomProperty::Enum:
addEnumBaseClass(node->elementEnum());
break;
case DomProperty::Set:
addEnumBaseClass(node->elementSet());
break;
default:
break;
}
WriteIncludesBase::acceptProperty(node);
}
void WriteImports::addEnumBaseClass(const QString &v)
{
// Add base classes like QFrame for QLabel::frameShape()
const auto colonPos = v.indexOf(u"::");
if (colonPos > 0) {
const QString base = v.left(colonPos);
if (base.startsWith(u'Q') && base != u"Qt")
addQtClass(base);
}
}
} // namespace Python
QT_END_NAMESPACE

View File

@ -55,6 +55,7 @@ protected:
private:
void addPythonCustomWidget(const QString &className, const DomCustomWidget *dcw);
bool addQtClass(const QString &className);
void addEnumBaseClass(const QString &v);
void writeImport(const QString &module);
QHash<QString, QString> m_classToModule;