diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-11-27 15:25:31 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-12-06 23:22:11 +0100 |
commit | 25ab2a7cbb48990da92960f8779e0f3427436948 (patch) | |
tree | 3cf4becb482aeff19ad754db9cf0ada3a9ed8e30 /src/designer | |
parent | b89284922538eb5c912519469479ec02d2864e6c (diff) |
Qt Designer: Remove functions fixing enumeration values
As QMetaEnum now supports arbitrarily scoped values, they
are no longer required. Add a check.
Task-number: QTBUG-118473
Task-number: QTBUG-118240
Change-Id: I06977899f8c43d8d08fc231f7e36f1134185fb46
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/designer')
-rw-r--r-- | src/designer/src/lib/uilib/properties.cpp | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/src/designer/src/lib/uilib/properties.cpp b/src/designer/src/lib/uilib/properties.cpp index d70f4dbfe..872e8975f 100644 --- a/src/designer/src/lib/uilib/properties.cpp +++ b/src/designer/src/lib/uilib/properties.cpp @@ -28,30 +28,6 @@ namespace QFormInternal { #endif -static QStringView fixEnum(QStringView s) -{ - qsizetype valuePos = s.lastIndexOf(u':'); // "E::A" -> 3 - if (valuePos == -1) - valuePos = s.lastIndexOf(u'.'); - return valuePos != -1 ? s.sliced(valuePos + 1) : s; -} - -// "QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok" -// -> "Cancel|Ok" -// ### FIXME Remove/check when QTBUG-118240 is fixed. -static inline QString fixFlags(QStringView s) -{ - QString result; - result.reserve(s.size()); - const auto flags = s.split(u'|'); - for (const auto &flag : flags) { - if (!result.isEmpty()) - result.append(u'|'); - result.append(fixEnum(flag)); - } - return result; -} - // Convert complex DOM types with the help of QAbstractFormBuilder QVariant domPropertyToVariant(QAbstractFormBuilder *afb,const QMetaObject *meta,const DomProperty *p) { @@ -91,13 +67,21 @@ QVariant domPropertyToVariant(QAbstractFormBuilder *afb,const QMetaObject *meta, const QMetaEnum e = meta->property(index).enumerator(); Q_ASSERT(e.isFlag() == true); - return QVariant(e.keysToValue(fixFlags(p->elementSet()).toUtf8())); + bool ok{}; + QVariant result(e.keysToValue(p->elementSet().toUtf8().constData(), &ok)); + if (!ok) { + uiLibWarning(QCoreApplication::translate("QFormBuilder", + "The value \"%1\" of the set-type property %2 could not be read."). + arg(p->attributeName(), p->elementSet())); + return {}; + } + return result; } case DomProperty::Enum: { const QByteArray pname = p->attributeName().toUtf8(); const int index = meta->indexOfProperty(pname); - const QStringView enumValue = fixEnum(p->elementEnum()); + const auto &enumValue = p->elementEnum(); // Triggers in case of objects in Designer like Spacer/Line for which properties // are serialized using language introspection. On preview, however, these objects are // emulated by hacks in the formbuilder (size policy/orientation) @@ -105,14 +89,22 @@ QVariant domPropertyToVariant(QAbstractFormBuilder *afb,const QMetaObject *meta, // ### special-casing for Line (QFrame) -- fix for 4.2. Jambi hack for enumerations if (!qstrcmp(meta->className(), "QFrame") && (pname == QByteArray("orientation"))) { - return QVariant(enumValue == "Horizontal"_L1 ? QFrame::HLine : QFrame::VLine); + return QVariant(enumValue.endsWith("Horizontal"_L1) ? QFrame::HLine : QFrame::VLine); } uiLibWarning(QCoreApplication::translate("QFormBuilder", "The enumeration-type property %1 could not be read.").arg(p->attributeName())); return QVariant(); } const QMetaEnum e = meta->property(index).enumerator(); - return QVariant(e.keyToValue(enumValue.toUtf8())); + bool ok{}; + QVariant result(e.keyToValue(enumValue.toUtf8().constData(), &ok)); + if (!ok) { + uiLibWarning(QCoreApplication::translate("QFormBuilder", + "The value \"%1\" of the enum-type property %2 could not be read."). + arg(p->attributeName(), enumValue)); + return {}; + } + return result; } case DomProperty::Brush: return QVariant::fromValue(afb->setupBrush(p->elementBrush())); |