Skip to content

Commit

Permalink
Add enum values to the enum type object itself in any case...
Browse files Browse the repository at this point in the history
...not just when it is a enum class in C++. It seems PySide does this too.
  • Loading branch information
usiems authored and mrbean-bremen committed Dec 20, 2023
1 parent e9197ec commit d059d72
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/PythonQtClassInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,26 +870,19 @@ PyObject* PythonQtClassInfo::findEnumWrapper(const QByteArray& name, PythonQtCla
return enumWrapper;
}

// required for the code below (for versions before Qt 6)
Q_DECLARE_METATYPE(PythonQtObjectPtr)

void PythonQtClassInfo::createEnumWrappers(const QMetaObject* meta)
{
for (int i = meta->enumeratorOffset();i<meta->enumeratorCount();i++) {
QMetaEnum e = meta->enumerator(i);
PythonQtObjectPtr p;
p.setNewRef(PythonQtPrivate::createNewPythonQtEnumWrapper(e.name(), _pythonQtClassWrapper));
#if QT_VERSION > 0x050800
if (e.isScoped()) {
// add enum values to the enum type itself, in case enum value names are so generic
// that they are not unique
for (int j = 0; j < e.keyCount(); j++) {
PythonQtObjectPtr enumValuePtr;
enumValuePtr.setNewRef(PythonQtPrivate::createEnumValueInstance(p.object(), e.value(j)));
p.addVariable(escapeReservedNames(e.key(j)), QVariant::fromValue(enumValuePtr));
}
// add enum values to the enum type itself, in case enum value names are so generic
// that they are not unique
for (int j = 0; j < e.keyCount(); j++) {
PythonQtObjectPtr enumValuePtr;
enumValuePtr.setNewRef(PythonQtPrivate::createEnumValueInstance(p.object(), e.value(j)));
p.addVariable(escapeReservedNames(e.key(j)), enumValuePtr.toLocalVariant());
}
#endif
_enumWrappers.append(p);
}
}
Expand Down

0 comments on commit d059d72

Please sign in to comment.