aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2023-03-17 15:54:25 +0100
committerUlf Hermann <ulf.hermann@qt.io>2023-04-12 03:36:21 +0200
commit69db2dbc4a799455884e94f69446152720e36de8 (patch)
tree73d7f258299c5e08e5a659db0518bd2615790674 /src
parent951ab9f3c06311458bc7d44c127e034af3e4cff5 (diff)
QML: Allow some more backing types for enums
Task-number: QTBUG-112180 Done-with: Fabian Kosmale <fabian.kosmale@qt.io> Change-Id: I48a2a696d3424ab1d8b9e693a92361a978ad70e9 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp5
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp2
-rw-r--r--src/qml/jsruntime/qv4variantobject.cpp3
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp2
-rw-r--r--src/qml/qml/qqmlmetaobject.cpp4
-rw-r--r--src/qml/qml/qqmlproperty.cpp9
-rw-r--r--src/qml/qml/qqmlvaluetypewrapper.cpp2
7 files changed, 11 insertions, 16 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 41c7a90906..809892dacf 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -1850,7 +1850,7 @@ QV4::ReturnedValue ExecutionEngine::fromData(
}
}
- } else {
+ } else if (!(metaType.flags() & QMetaType::IsEnumeration)) {
QV4::Scope scope(this);
if (metaType == QMetaType::fromType<QQmlListReference>()) {
typedef QQmlListReferencePrivate QDLRP;
@@ -1936,9 +1936,8 @@ QV4::ReturnedValue ExecutionEngine::fromData(
// + QObjectList
// + QList<int>
- // Enumeration types can just be treated as integers for now
if (metaType.flags() & QMetaType::IsEnumeration)
- return QV4::Encode(*reinterpret_cast<const int *>(ptr));
+ return fromData(metaType.underlyingType(), ptr, container, property, flags);
return QV4::Encode(newVariantObject(metaType, ptr));
}
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index e2ebda7d0e..865f2af699 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -131,7 +131,7 @@ static ReturnedValue loadProperty(
return QmlListWrapper::create(v4, object, property.coreIndex(), propMetaType);
// TODO: Check all the builtin types here. See getGadgetProperty() in qqmlvaluetypewrapper.cpp
- switch (property.isEnum() ? QMetaType::Int : propMetaType.id()) {
+ switch (property.isEnum() ? propMetaType.underlyingType().id() : propMetaType.id()) {
case QMetaType::Int: {
int v = 0;
property.readProperty(object, &v);
diff --git a/src/qml/jsruntime/qv4variantobject.cpp b/src/qml/jsruntime/qv4variantobject.cpp
index ccea9cac2a..62e21a120c 100644
--- a/src/qml/jsruntime/qv4variantobject.cpp
+++ b/src/qml/jsruntime/qv4variantobject.cpp
@@ -131,7 +131,8 @@ ReturnedValue VariantPrototype::method_valueOf(const FunctionObject *b, const Va
return Encode(v.toBool());
default:
if (QMetaType(v.metaType()).flags() & QMetaType::IsEnumeration)
- return Encode(v.toInt());
+ if (v.metaType().sizeOf() <= qsizetype(sizeof(int)))
+ return Encode(v.toInt());
if (v.canConvert<double>())
return Encode(v.toDouble());
if (v.canConvert<int>())
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index da81244f18..55e21abae2 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -183,7 +183,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
if (!type.isValid())
argCount = 0;
else if (type.flags().testFlag(QMetaType::IsEnumeration))
- storage.append(QMetaType::fromType<int>());
+ storage.append(type.underlyingType());
else
storage.append(type);
}
diff --git a/src/qml/qml/qqmlmetaobject.cpp b/src/qml/qml/qqmlmetaobject.cpp
index d5f1fb3b96..82903f80b2 100644
--- a/src/qml/qml/qqmlmetaobject.cpp
+++ b/src/qml/qml/qqmlmetaobject.cpp
@@ -48,7 +48,7 @@ QMetaType QQmlMetaObject::methodReturnType(const QQmlPropertyData &data, QByteAr
type = _m->method(data.coreIndex()).returnMetaType();
}
if (type.flags().testFlag(QMetaType::IsEnumeration))
- type = QMetaType::fromType<int>();
+ type = type.underlyingType();
if (type.isValid())
return type;
else if (unknownTypeError)
@@ -83,7 +83,7 @@ bool QQmlMetaObject::methodParameterTypes(const QMetaMethod &m, ArgTypeStorage *
QMetaType type = m.parameterMetaType(ii);
// we treat enumerations as int
if (type.flags().testFlag(QMetaType::IsEnumeration))
- type = QMetaType::fromType<int>();
+ type = type.underlyingType();
if (!type.isValid()) {
if (unknownTypeError)
*unknownTypeError = m.parameterTypeName(ii);
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 3c039ba55d..c1f327cd5a 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -1225,14 +1225,9 @@ bool QQmlPropertyPrivate::writeEnumProperty(const QMetaProperty &prop, int idx,
v = QVariant(menum.keyToValue(value.toByteArray(), &ok));
if (!ok)
return false;
- } else if (v.userType() != QMetaType::Int && v.userType() != QMetaType::UInt) {
- int enumMetaTypeId = QMetaType::fromName(
- QByteArray(menum.scope() + QByteArray("::") + menum.name())).id();
- if ((enumMetaTypeId == QMetaType::UnknownType) || (v.userType() != enumMetaTypeId) || !v.constData())
- return false;
- v = QVariant(*reinterpret_cast<const int *>(v.constData()));
}
- v.convert(QMetaType(QMetaType::Int));
+ if (!v.convert(prop.metaType())) // ### TODO: underlyingType might be faster?
+ return false;
}
// the status variable is changed by qt_metacall to indicate what it did
diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp
index be44f1e8c2..b20e1c79b7 100644
--- a/src/qml/qml/qqmlvaluetypewrapper.cpp
+++ b/src/qml/qml/qqmlvaluetypewrapper.cpp
@@ -368,7 +368,7 @@ static ReturnedValue getGadgetProperty(ExecutionEngine *engine,
QMetaObject::ReadProperty, &metaObject, &index);
const int metaTypeId = isEnum
- ? QMetaType::Int
+ ? metaType.underlyingType().id()
: (metaType.flags() & QMetaType::PointerToQObject)
? QMetaType::QObjectStar
: metaType.id();