diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-01-07 20:19:20 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-01-25 23:55:27 +0100 |
commit | 5a908de8b7e772e78adb30cc3205c7cf5bd622f5 (patch) | |
tree | 0a803fb250a3b89133935ba1e75d2e0eac2f7c23 /src/qml/compiler/qqmlirbuilder.cpp | |
parent | 17dcba699566bfe052bf2c320e07c2c7cc53094b (diff) |
Allow custom named value types in QML
You can now add your own, lower-case named, value types to your own
module, and use them in QML. Previously the names had been ignored, but
now you can actually declare properties using the value types.
The QtQuick value types are now handled exactly this way, and their
special casing at compile time is removed.
[ChangeLog][QML][Important Behavior Changes] You can now add your own
value types to QML modules. This works exactly like the registration of
object types, just with Q_GADGET instead of QObject/Q_OBJECT. In turn,
the QtQuick value types are only available from QtQuick now. Previously
you could declare unusable properties of QtQuick value types when only
importing QtQml. This is not possible anymore.
Task-number: QTBUG-82443
Change-Id: I5b2e867141244531cb13d789678fb7e06a6e41e7
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Konstantin Shegunov <kshegunov@gmail.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/qml/compiler/qqmlirbuilder.cpp')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 44 |
1 files changed, 10 insertions, 34 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 9078b21ccd..a4cb3f2535 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -111,7 +111,7 @@ bool Parameter::initType(QV4::CompiledData::ParameterType *paramType, const QV4: const QString typeName = stringGenerator->stringForIndex(typeNameIndex); auto builtinType = stringToBuiltinType(typeName); if (builtinType == QV4::CompiledData::BuiltinType::InvalidBuiltin) { - if (typeName.isEmpty() || !typeName.at(0).isUpper()) + if (typeName.isEmpty()) return false; paramType->indexIsBuiltinType = false; paramType->typeNameIndexOrBuiltinType = typeNameIndex; @@ -137,23 +137,10 @@ QV4::CompiledData::BuiltinType Parameter::stringToBuiltinType(const QString &typ { "real", strlen("real"), QV4::CompiledData::BuiltinType::Real }, { "string", strlen("string"), QV4::CompiledData::BuiltinType::String }, { "url", strlen("url"), QV4::CompiledData::BuiltinType::Url }, - { "color", strlen("color"), QV4::CompiledData::BuiltinType::Color }, - // Internally QTime, QDate and QDateTime are all supported. - // To be more consistent with JavaScript we expose only - // QDateTime as it matches closely with the Date JS type. - // We also call it "date" to match. - // { "time", strlen("time"), Property::Time }, - // { "date", strlen("date"), Property::Date }, { "date", strlen("date"), QV4::CompiledData::BuiltinType::DateTime }, { "rect", strlen("rect"), QV4::CompiledData::BuiltinType::Rect }, { "point", strlen("point"), QV4::CompiledData::BuiltinType::Point }, { "size", strlen("size"), QV4::CompiledData::BuiltinType::Size }, - { "font", strlen("font"), QV4::CompiledData::BuiltinType::Font }, - { "vector2d", strlen("vector2d"), QV4::CompiledData::BuiltinType::Vector2D }, - { "vector3d", strlen("vector3d"), QV4::CompiledData::BuiltinType::Vector3D }, - { "vector4d", strlen("vector4d"), QV4::CompiledData::BuiltinType::Vector4D }, - { "quaternion", strlen("quaternion"), QV4::CompiledData::BuiltinType::Quaternion }, - { "matrix4x4", strlen("matrix4x4"), QV4::CompiledData::BuiltinType::Matrix4x4 }, { "variant", strlen("variant"), QV4::CompiledData::BuiltinType::Var }, { "var", strlen("var"), QV4::CompiledData::BuiltinType::Var } }; @@ -987,29 +974,18 @@ bool IRBuilder::visit(QQmlJS::AST::UiPublicMember *node) property->isReadOnly = node->isReadonly(); property->isRequired = node->isRequired(); - QV4::CompiledData::BuiltinType builtinPropertyType = Parameter::stringToBuiltinType(memberType); - bool typeFound = builtinPropertyType != QV4::CompiledData::BuiltinType::InvalidBuiltin; - if (typeFound) + const QV4::CompiledData::BuiltinType builtinPropertyType + = Parameter::stringToBuiltinType(memberType); + if (builtinPropertyType != QV4::CompiledData::BuiltinType::InvalidBuiltin) property->setBuiltinType(builtinPropertyType); - - if (!typeFound && memberType.at(0).isUpper()) { - const QStringView &typeModifier = node->typeModifier; - + else property->setCustomType(registerString(memberType)); - if (typeModifier == QLatin1String("list")) { - property->isList = true; - } else if (!typeModifier.isEmpty()) { - recordError(node->typeModifierToken, QCoreApplication::translate("QQmlParser","Invalid property type modifier")); - return false; - } - typeFound = true; - } else if (!node->typeModifier.isNull()) { - recordError(node->typeModifierToken, QCoreApplication::translate("QQmlParser","Unexpected property type modifier")); - return false; - } - if (!typeFound) { - recordError(node->typeToken, QCoreApplication::translate("QQmlParser","Expected property type")); + const QStringView &typeModifier = node->typeModifier; + if (typeModifier == QLatin1String("list")) { + property->isList = true; + } else if (!typeModifier.isEmpty()) { + recordError(node->typeModifierToken, QCoreApplication::translate("QQmlParser","Invalid property type modifier")); return false; } |