Details
-
Bug
-
Resolution: Unresolved
-
P4: Low
-
6.8.1, 6.9.0
-
None
-
Kubuntu 24.04 LTS
-
-
ee9497fd9 (dev), cf9493ebd (6.9)
-
All
Description
Saving UI-file using QFormBuilder missing properties (unsupported?) (original)
The problem
The when calling QFormBuilder::save(...) many warnings are reported from the designer/uilib library. Originating from a call by uilibWarning(...).
8.510050548s [Warning]; Designer: The property layoutDirection could not be written. The type Qt::LayoutDirection is not supported yet. :0 8.510050548s [Warning]; Designer: The property contextMenuPolicy could not be written. The type Qt::ContextMenuPolicy is not supported yet. :0 8.510050548s [Warning]; Designer: The property focusPolicy could not be written. The type Qt::FocusPolicy is not supported yet. :0 8.510050548s [Warning]; Designer: The property inputMethodHints could not be written. The type QFlags<Qt::InputMethodHint> is not supported yet. :0 8.510050548s [Warning]; Designer: The property windowModality could not be written. The type Qt::WindowModality is not supported yet. :0 8.511050553s [Warning]; Designer: The property sizeConstraint could not be written. The type QLayout::SizeConstraint is not supported yet. :0 8.511050553s [Warning]; Designer: The property contentsMargins could not be written. The type QMargins is not supported yet. :0 8.511050553s [Warning]; Designer: The property layoutDirection could not be written. The type Qt::LayoutDirection is not supported yet. :0 8.511050553s [Warning]; Designer: The property contextMenuPolicy could not be written. The type Qt::ContextMenuPolicy is not supported yet. :0 8.511050553s [Warning]; Designer: The property sceneOptions could not be written. The type QFlags<sf::SceneOption> is not supported yet. :0 8.511050553s [Warning]; Designer: The property focusPolicy could not be written. The type Qt::FocusPolicy is not supported yet. :0 8.511050553s [Warning]; Designer: The property inputMethodHints could not be written. The type QFlags<Qt::InputMethodHint> is not supported yet. :0 8.511050553s [Warning]; Designer: The property windowModality could not be written. The type Qt::WindowModality is not supported yet. :0 8.511050553s [Warning]; Designer: The property exclusionThe CausePolicy could not be written. The type QActionGroup::ExclusionPolicy is not supported yet. :0 8.511050553s [Warning]; Designer: The property priority could not be written. The type QAction::Priority is not supported yet. :0 8.511050553s [Warning]; Designer: The property shortcutContext could not be written. The type Qt::ShortcutContext is not supported yet. :0 8.511050553s [Warning]; Designer: The property menuRole could not be written. The type QAction::MenuRole is not supported yet. :0 8.51205056s [Warning]; Designer: The property priority could not be written. The type QAction::Priority is not supported yet. :0 8.51205056s [Warning]; Designer: The property shortcutContext could not be written. The type Qt::ShortcutContext is not supported yet. :0 8.51205056s [Warning]; Designer: The property menuRole could not be written. The type QAction::MenuRole is not supported yet. :0 8.51205056s [Warning]; Designer: The property priority could not be written. The type QAction::Priority is not supported yet. :0 8.51205056s [Warning]; Designer: The property shortcutContext could not be written. The type Qt::ShortcutContext is not supported yet. :0 8.51205056s [Warning]; Designer: The property menuRole could not be written. The type QAction::MenuRole is not supported yet. :0 8.51205056s [Warning]; Designer: The property priority could not be written. The type QAction::Priority is not supported yet. :0 8.513050566s [Warning]; Designer: The property shortcutContext could not be written. The type Qt::ShortcutContext is not supported yet. :0 8.513050566s [Warning]; Designer: The property menuRole could not be written. The type QAction::MenuRole is not supported yet. :0 8.513050566s [Warning]; Designer: The property priority could not be written. The type QAction::Priority is not supported yet. :0 8.513050566s [Warning]; Designer: The property shortcutContext could not be written. The type Qt::ShortcutContext is not supported yet. :0 8.513050566s [Warning]; Designer: The property menuRole could not be written. The type QAction::MenuRole is not supported yet. :0
Type QFlags<sf::SceneOption> or sf::SceneOptions is a custom type by the way.
The problem is that properties are missing in the resulting ui-file.
This problem does not occur at all in the Qt UI Designer application.
The Cause
The cause of this all is that the QVariant type used for enumerates by Qt UI Designer is not the same as for the QFormBuilder code.
The actual cause is these lines of code
QMetaProperty meta_property = meta->property(pindex); if ((v.metaType().id() == QMetaType::Int || v.metaType().id() == QMetaType::UInt) && meta_property.isEnumType()) { const QMetaEnum e = meta_property.enumerator(); if (e.isFlag()) dom_prop->setElementSet(QString::fromLatin1(e.valueToKeys(v.toInt()))); else dom_prop->setElementEnum(QString::fromLatin1(e.valueToKey(v.toInt()))); return dom_prop; }
Specifically this part where the QVariant type id is only allowed to be of an integer type.
v.metaType().id() == QMetaType::Int || v.metaType().id() == QMetaType::UInt
For example type QAction::MenuRole is not registered as an integer.
Why checking only meta_property.isEnumType() is not sufficient is not clear?
Hack or Workaround
Overriding QAbstractFormBuilder::createProperty(...) like this will do the trick for now.
Also solves the QMargin typed contentsMargins property from QLayout derived classes warning which is a bug on its own.
DomProperty* FormBuilder::createProperty(QObject* object, const QString& name, const QVariant& value) { auto meta = object->metaObject(); const int pindex = meta->indexOfProperty(name.toLatin1()); if (pindex != -1) { // Check for an enumerate value and if it can be converted to an integer. if (meta->property(pindex).isEnumType() && QMetaType::canConvert(value.metaType(), QMetaType(QMetaType::Int))) { //qDebug() << QString("Enum property '%1' with meta type id (%2) is forced to builtin id!").arg(name).arg(value.metaType().id()); // FIXME: Forcing the const variant to be of type 'QMetaType::Int'. const_cast<QVariant&>(value).convert(QMetaType(QMetaType::Int)); } // When the object is a QLayout descendent and 'QMargins' are the type skip them to prevent a warning. if (dynamic_cast<QLayout*>(object) && value.typeId() == QMetaType::fromType<QMargins>().id()) { //qDebug() << QString("Ignoring layout class '%1' property '%2' !").arg(SF_RTTI_NAME(*object).data()).arg(name); return nullptr; } } return QFormBuilder::createProperty(object, name, value); }
Suggested Solution
Modify function variantToDomProperty(...) like this:
QMetaProperty meta_property = meta->property(pindex); if ((meta_property.isEnumType() && QMetaType::canConvert(v.metaType(), QMetaType(QMetaType::Int)) { const QMetaEnum e = meta_property.enumerator(); if (e.isFlag()) dom_prop->setElementSet(QString::fromLatin1(e.valueToKeys(v.toInt()))); else dom_prop->setElementEnum(QString::fromLatin1(e.valueToKey(v.toInt()))); return dom_prop; }
Attachments
Issue Links
- relates to
-
QTBUG-97519 QFormBuilder - Saves all children to file making the file unsuited for reading
-
- Reported
-
Gerrit Reviews
For Gerrit Dashboard: QTBUG-136164 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
641381,7 | QFormBuilder::save(): Handle enumerations/flags | dev | qt/qttools | Status: NEW | 0 | 0 |