aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml
Commit message (Collapse)AuthorAgeFilesLines
* qmlcompiler: Sanitize qmldir paths before using themHEADdevUlf Hermann4 hours2-0/+13
| | | | | | | | | | They may contain backslashes. Pick-to: 6.7 6.5 Fixes: QTBUG-125393 Change-Id: Ifd8c97c44b036ab64a221775a7fe6316445f6cf8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Add PlanarTransform object to facilitate 2D transformsEirik Aavitsland3 days1-1/+3
| | | | | | | | | | | | | The existing function for creating a non-identity matrix4x4 requires all of the 16 values to be specified. That is needlessly cumbersome in the common case of a 2D (planar) transform. So add a new interface singleton object to hold invokable methods that simplify specifying such transforms in qml, avoiding exposing the full complexity of the underlying 4x4 matrix in the api. Change-Id: I8a94099da5c94f5483e6b46280c6101c6d3f6dc3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* V4: Slim down FunctionObjectUlf Hermann3 days1-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Most FunctionObjects do not actually need their custom jsCall members. They will only call the functions from the vtable anyway. FunctionObject can therefore be split into a static and a dynamic variant. Only the dyanmic variant needs to carry (and invoke) the extra pointer. The jsCallWithMetaTypes pointer is completely pointless because none of the dynamic functions actually implement it. Furthermore, the QV4::Function and QV4::ExecutionContext pointers in FunctionObject are only needed by actual JavaScript functions. The builtins that like to be dynamic functions never need them. Therefore, split out another class for this. In the generic FunctionObject, we need the capability to decide at run time whether the function shall be a constructor or not. Add a flag to replace the check for jsCallAsConstructor. Also, where we can, avoid the pessimization of checking whether a function is a constructor before trying to call it as constructor. Rather have the default implementation throw the exception. As a side effect, for most functions we don't need an ExecutionContext anymore. The engine is enough. Task-number: QTBUG-124662 Change-Id: Iac657fa71288dd6ec230a33de2986ba3bcf4628c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* ecmascripttests: Actually fail the test if the runner crashesUlf Hermann6 days1-2/+2
| | | | | | | | | | The runner can have a "normal" exit status but a non-zero exit code. That's still a crash. Amends commit 4e0cf9658a28b7d048a016b9d0ab5926964e9a60 Change-Id: Ia803a947b51c9ea5486d0ca5b6cdd9c01040c84f Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* Fix header case issue following qtbase changeMårten Nordheim7 days1-7/+5
| | | | | | | | | | | We send headers as lower-case now. Though this also presents a potential incompat issue, if people are, for some reason, inspecting the headers we intend to send using hard-coded strings they will encounter the same issue... Change-Id: I1a423379939cc72c8c8cf321c7a0de93b4dee994 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Allow numeric separators in numeric literalsLuca Di Sera9 days1-0/+72
| | | | | | | | | | | | | | | | | | | | ES2021 introduced numeric separators in numeric literals to improve readability. For example, one billion can be written "1_000_000_000" where "_" are the numeric separators. Update the QML lexer to allow numeric separators, based on https://262.ecma-international.org/12.0/#prod-NumericLiteralSeparator. Add a non-exhaustive test case to `tst_qqmlparser` to track the behavior. Fixes: QTBUG-123792 Change-Id: Ie62d1f40fc8e0c7678e7dfea16408bdeeba6d150 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Dmitrii Akshintsev <dmitrii.akshintsev@qt.io>
* QtQml: Add a wrapper builtin for QJsonObjectLuca Di Sera9 days4-0/+24
| | | | | | | | | | | | | | Calling `qmllint` can produce warning for usages of the `QJsonObject` type, due to it not being found. Make `QJsonObject` a builtin type so that calls to `qmllint` will import and recognize the type. Add a test-case to ensure that the type is now recognized. Task-number: QTBUG-111015 Change-Id: I09afa006036059b826f6d76adb76fe802ba18f70 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* ecmascripttests: Fail test if the test runner crashesUlf Hermann11 days1-3/+13
| | | | | | Change-Id: I61c8a24cf25fef98df4ce274fb5f829867059922 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* Fix test compilation issues with QtLite configurationJari Helaakoski2024-04-305-3/+18
| | | | | | | | | Now developer build tests compile, but some are not working. Functional fix will come later via separate tasks. Task-number: QTBUG-122999 Change-Id: I0a0dfcf7affb73f928b8be62b3576a6a51658488 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Properly enforce signatures of AOT-compiled functionsUlf Hermann2024-04-263-2/+31
| | | | | | | | | | | | | Pass the metatypes of the contained types rather than the stored types. [ChangeLog][QtQml][Important Behavior Changes] The AOT compiled code for type-annotated JavaScript functions does not let you pass or return values of the wrong type anymore. Fixes: QTBUG-119885 Change-Id: I685d398c0745d32a999a3abd76c622a2c0d6651f Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QML: Introduce aliases for builtin typesUlf Hermann2024-04-253-16/+16
| | | | | | | | | | | | | | | | | | | | | | This way we can express the relationship between qsizetype, qlonglong and int, as well as the equivalents for long, ulong, char, qreal. We consider aliases as equivalent to primitive types in qmltyperegistrar. Therefore, you can only do this with types that don't have a QMetaObject of their own. However, considering the use case, this is not a big restriction. When generating qmltypes, we propagate the aliases. When reading back the qmltypes, we insert the resulting QQmlJSScope under all its separate names. This makes all the aliases discernible, but actually equal types. Since we now record the original type names in the qmltypes, this changes a few test artifacts for qmltyperegistrar and qmllint. Task-number: QTBUG-122582 Task-number: QTBUG-124294 Change-Id: I571684e3020b9bc30f8819bdc39389646fd1ff54 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmltyperegistrar: Check properties, methods, enums for missing typesUlf Hermann2024-04-256-21/+62
| | | | | | | | | | | | | | | | | | | | | | If you have a property of an unknown type, that will create problems later on. The same holds for method arguments, return types and underlying types of enums. qmltyperegistrar now warns about those. When scanning the types, we consider a type potentially primitive if it is not the root type, but one of: a, a self-extending value type b, a type with a JavaScript extension c, a sequence type If those types are found to be "missing" later, we ignore them. All other missing types trigger warnings now. Since we use types from QPA headers in a few places, we now need to recognize QPA headers when looking for private Qt includes. Task-number: QTBUG-101143 Change-Id: Ic4350e8ed46212c0f4af6f10e86323514f710e1e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* gc: Fix stale pointers in WeakValuesFabian Kosmale2024-04-251-0/+44
| | | | | | | | | | | | | | | | | WeakValue::set shold normally not mark objects, given that a weak value is not supposed to keep an object alive. However, if we are past GCState::HandleQObjectWrappers, nothing will reset weak values referencing unmarked values, even if sweep collects the referenced value. That leads to stale pointers, and then most likely to crashes. To avoid this, we mark the objects under this special condition. The test is written in a way that would also allow for resetting the new weak values instead, but the current implementation treats memory usage for throughput and doesn't revisit weak values to reset them. Change-Id: I789f63c1d8609957711c2253d2e76b4bd3f9810a Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Correct am/pm indicators for en_AU to lowercaseEdward Welbourne2024-04-251-2/+4
| | | | | | | | | | | | | | | | | | | | Previously QLocale's digested form of CLDR-derived data for AM/PM indicators was processed through a mapping that always selected the upper-case form, the AP format. Since 6.3, the formatting (and parsing) code has understood an Ap format to select the locale-appropriate case, rather than obliging client code to pick the case regardless of the user's locale. However QLocale's data still selected the upper-case version instead of the "locale-appropriate" form for time and datetime formats. I recently fixed this in qtbase; it's now time for QML's Locale's test-cases to catch up. The en_AU locale inherits lower-case am/pm markers from en_001 ("world" English, rather than plain "en" USAish), so correct the tests that expected upper-case markers. Change-Id: Ie05f5e39278758ea8d9e3ea556c133a143070ab8 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* gc: Prevent recursing into gc from onDestroyedFabian Kosmale2024-04-252-0/+74
| | | | | | | | | We end up in a rather weird state otherwise. Also test that we don't mistakenly collect ObjectWrappers created in onDestroyed. Change-Id: Iab158e5b34510979c8ac9a51a75247a2cee100f3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlformat: "Move" testExample e2e tests to /manualDmitrii Akshintsev2024-04-231-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | testExample, normalizeExample and actually most of the tests in tst_qmlformat are e2e tests and in general QmlFormat lacks unit test coverage, compensating it with e2e. The biggest problem atm that some of those tests (namely testExample) take too much time to execute because it runs QmlFormat over almost all files in examples and tests directories. Unfortunately atm our QA&QE infra can't provide tools for an easy automated setup of potentially time-consuming tests. As a workaround this commit: 1. "Moves" testExample and normalizeExample to the /manual tests 2. Preserves a very small fraction of testData for automated testing "just in case" Steps to repro: 1. configure with the flag `-make manual-tests` 2. `ninja e2e_qmlformat` 3. run ;) Fixes: QTBUG-122990 Change-Id: Id41baee15e8826f4def5787f62790ed46f00e5dc Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qqmljsscope: add ownModuleNameSami Shalayel2024-04-232-0/+39
| | | | | | | | | | | | | | | | | Allow qqmljsscopes of QML components to have "own" module names, and add a helper method moduleName() that helps retrieve the module name of some (possibly non QML component) qqmljsscope by iterating over its parents. That is required for the renaming of qmlcomponents and allows to check if the qml element to be renamed is defined in the same module as the current module. (It is not allowed to rename a QML component from another module). Task-number: QTBUG-114993 Change-Id: I09d57ec87cfc64de31859b2af6334264c4fa6912 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* test262: Remove outdated test runnerUlf Hermann2024-04-231-611/+0
| | | | | | | | | We use the C++ test runner these days. Change-Id: I74c892c43a699b62da396c7b0bd0ec861f3781bd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Lucie Gerard <lucie.gerard@qt.io>
* tst_qqmlmetatype: Improve error messages on mismatchUlf Hermann2024-04-231-2/+10
| | | | | | | | We want to know what types were involved. Change-Id: I456b35e6688b01c14baa681fe62a461a5f082f5d Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmlcachegen: Improve warnings for missing return type annotationsOlivier De Cannière2024-04-237-5/+71
| | | | | | | Fixes: QTBUG-124220 Pick-to: 6.7 Change-Id: Ic31b90b0408d855a45e17647ab659fbbc6e17633 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmltc: Move qlmtc_build_failures to tst_qmltc_qprocessLuca Di Sera2024-04-233-0/+22
| | | | | | | | | | | | | | | | | | | | | | | `qmltc_build_failures` uses the available CMake infrastructure to test for expected build-level failures from a `qmltc` compilation. This allows tracking failures over certain constructs that `qmltc` should not support, but has an high amount of friction when extended, as each "test case" needs to be its own whole project, and doesn't provide an error-level granularity for the failures, so that the success of a "test case" might depend on a failure that is different from the intended one. `tst_qmltc_qprocess` has the infrastructure required to run failing `qmltc` builds in a leaner way, provides an easier extension story, based on the general and well-known testlib-based structure and allows to have tests with an error-level granularity. Hence, remove `qmltc_build_failures` and move the existing "test case" to `tst_qmltc_qprocess`. Change-Id: Ib11227c0da1f6336e6537bea76011ccc0090039f Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmltc: Test fail for unbound outside required property in componentLuca Di Sera2024-04-234-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `qmltc` should fail when it processes a QML file that defines a component that has unbound inner-level required properties imported from an outside type. For example: ``` Item { Component { id: mycomp Item { TypeWithRequiredProperty {} } } } ``` Where `TypeWithRequiredProperty` defines at least one required property. To parse a QML file, `qmltc` uses `QQmlJSImportVisitor`, which will produce an error on encountering such a case. `qmltc` will in turn propagate the error and fail itself, thus acting properly. A new test was added to keep track of the behavior and ensure that `qmltc` rejects a file when this erroneous form is encountered. Fixes: QTBUG-120698 Change-Id: I7f4dab3501c792b2b2a3d97b20ad416748a3d4a9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltc: Test failure for unbound required properties in componentLuca Di Sera2024-04-233-0/+30
| | | | | | | | | | | | | | | | | | | | `qmltc` should fail when it processes a QML file that defines a component that has unbound inner-level required properties, similarly to how it should generally fail when an unbound inner-level required property is present, as those are not settable at a later phase. To parse a QML file, `qmltc` uses `QQmlJSImportVisitor`, which will produce an error on encountering such a case. `qmltc` will in turn propagate the error and fail itself, thus acting properly. A new test was added to keep track of the behavior and ensure that `qmltc` rejects a file when this erroneous form is encountered. Task-number: QTBUG-120698 Change-Id: Iadb9648ea09951a1741679c9c27abe014876656b Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltc: Test failure for unbound required property in inline componentLuca Di Sera2024-04-233-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `qmltc` should fail when it processes a QML file that instances an inline component that has some top-level required properties without setting them when creating the instance. For example: ``` import QtQuick Item { component IC: Item { required property int i } IC { // i needs to be set here as it cannot be set later } } ``` To parse a QML file, `qmltc` uses `QQmlJSImportVisitor`, which will produce an error on encountering such a case. `qmltc` will in turn propagate the error and fail itself, thus acting properly. A new test was added to keep track of the behavior and ensure that `qmltc` rejects a file when this erroneous form is encountered. Task-number: QTBUG-120698 Change-Id: I1a1b7a3d55f3ba5dde7d04b014b7d6a9b53a546d Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QtQml: Fix some type conversion edge casesUlf Hermann2024-04-232-0/+27
| | | | | | | | | | | | If the type conversion code fails to convert an argument, we still need to make sure the argument has a definite value. Otherwise we may trigger undefined behavior somewhere down the line. Furthermore, we want to look at the precise type when converting list properties. Otherwise we get a list property without any methods back when converting. Pick-to: 6.7 6.5 6.2 Change-Id: I012c0360ef1578c768362d5a4648252d3e6803d8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* V4: Handle all array-like containers when converting to QJsonArrayOlivier De Cannière2024-04-224-0/+88
| | | | | | | | | | | | | | | | Commit b9bfdea0e2c6721d2306af0ecc44f88da9988957 removed specialized code for QVariantList conversions by relying on sequences instead. Some checks for sequences and other array-like containers were missed. Add those and perform all calls to QJsonObject::toJsonArray through a common QV4::Object interface. Amends b9bfdea0e2c6721d2306af0ecc44f88da9988957 Pick-to: 6.7 Fixes: QTBUG-123993 Change-Id: Ia671d556af4f2b4d44f652fa93182977d88621f2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmlsc: Support Math static propertiesLuca Di Sera2024-04-184-0/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The javascript Math object presents some static properties that allow access to some general mathematical constants. Currently, `qmlsc` will refuse to generate optimized code for those properties when used in a binding, for example given: ``` import QtQuick Window { width: 200 * Math.PI } ``` `qmlsc` will report a warning and will not generate code for the "width" binding. To allow `qmlsc` to generate optimized code for such cases, the handling of `Math` related properties lookups is now specialized. `QQmlJSTypePropagator::propagatePropertyLookup`, which is called when dealing with an access such as `Math.PI`, was modified to consider the result type a "double" when dealing with properties on the `Math` object. `QQmlJSCodeGenerator::generate_GetLookupHelper`, which generates the code that provides a value for the property access, was modified to special case lookups on the `Math` object. If a property is being looked up on the `Math` object, `qmlsc` will now generate a direct assignment for the output variable to a constant value that is suitable for the accessed property. A test was added to ensure that the snippet from the bug-report now compiles without warnings. A test was added to ensure that the properties from the Math global object have an approximately correct value. Fixes: QTBUG-113150 Change-Id: I8903794fc8ce2b55532a4706e1bda07a7b73f311 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: enable environment variables like QML_IMPORT_PATH via -ESami Shalayel2024-04-181-5/+70
| | | | | | | | | | | Add a -E commandline option for qmllint to enable using environment variables. For now, this only allows using QML_IMPORT_PATH and QML2_IMPORT_PATH to pass import paths to qmllint. Task-number: QTBUG-114969 Change-Id: Ie6baf9c8035703a456ba1e7e575ba424f89d287a Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* QQmlJS: Store method's source location and expose it in QQmlSAOlivier De Cannière2024-04-172-0/+46
| | | | | | | | | This is useful for tooling like Axivion and can help with better error messages. Change-Id: Ic63afd2eeb4ee3627d05303c2518fa90282fb7ab Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* qmllint: do not ignore command line options with --ignore-settingsSami Shalayel2024-04-174-0/+24
| | | | | | | | | | | | | | | Remove a misplaced pair of braces that made --ignore-settings ignore the parsing of command line options like "-I", "-E" and "--bare". Do not populate the settings from a settings file when --ignore-settings is set to make QQmlToolingSettings::isSet() always return false. Discovered while working on QTBUG-114969. Pick-to: 6.7 6.6 6.5 Task-number: QTBUG-114969 Change-Id: Ia8719b33af4a2ebdcb2b81194e0c028164775327 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* Fix adding columns to TreeViewAntti Määttä2024-04-172-0/+29
| | | | | | | | | Handle the column related signals in the qqmltreemodeltotablemodel. Fixes: QTBUG-94100 Pic-to: 6.7 6.6 6.5 Change-Id: I4a1d4ee4e2f927e7798211f314a1356721748c92 Reviewed-by: Antti Määttä <antti.maatta@qt.io>
* QQmlComponent::loadFromModule: Improve error handlingFabian Kosmale2024-04-171-0/+8
| | | | | | | | | | | | | | | | | | | | | Most importantly, fix the (attempted) loading of a non-existent inline component: As soon as we have the compilation unit, we can simply check whether the inline component exists via its name. This avoids an assert down the line in beginCreate which assumes that at this point the inlineComponentName has been properly vetted. This also allows us to create a better error message, and to catch the easy mistake of passing a file name instead of a type name to createComponent. Moreover, ensure that we do not claim that the inline component is ready when only the outer component has been loaded – a direct connection to the changed signals followed by a call to create would otherwise yield surprising results. Fixes: QTBUG-124225 Pick-to: 6.7 Change-Id: I6b1860f594a3060653e732b9570cc3bbff0c34a9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* DelegateChooser: React to changes of choice property (via QAIM)Fabian Kosmale2024-04-162-0/+115
| | | | | | | | | | | | | | | | | | | | Detect when a QAIM changes the value of the role affecting the choice made by DelegateChooser and tell the view to recreate the delegate if necessary. For performance reasons, we don't want to track changes for non-QAIM based models [1]; document this remaining limitation. [1]: We don't have a convenient place where we could detect both the "role" change and the affected index (which means that we would need to invalidate everything, and possibly way too often.). It might be possible to refactor the code to allow for this, too, but that would robably be a larger change, and not suitable for picking it back. Pick-to: 6.7 Fixes: QTBUG-75887 Change-Id: Ic91dc436e53b4280debf2698c76f2ead4bdf15d6 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
* Improve error message for broken QML_SINGLETONCarl Schwan2024-04-151-21/+21
| | | | | | | | | The current error message doesn't cover the case where the class with the QML_SINGLETON is an abstract class. This will still compile but fail at runtime with an error message not mentioning this case. Change-Id: I134254b252ca3c2250e5f5bc2ac9f9d79a2658fd Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmltyperegistrar: Improve readability and performanceUlf Hermann2024-04-132-12/+12
| | | | | | | | | | Instead of working on opaque Cbor objects, we can use structs and classes with named members. This also improves performance as we don't have to repeatedly query the Cbor data structures. Task-number: QTBUG-101143 Change-Id: Ifd889323f0fd723a735be3e7d70230e61039b301 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QtQml: Add a wrapper builtin for QQmlV4Function*Ulf Hermann2024-04-125-7/+7
| | | | | | | | | This way qmltyperegistrar can recognize it and refrain from warning about it. Task-number: QTBUG-101143 Change-Id: I598140e7e90dbd3e27a78c26eff3d46f0fd3e989 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Allow coercion of lists to stringsUlf Hermann2024-04-113-0/+51
| | | | | | | | | | We have to allow two different forms of coercion. When printing directly through console.log etc, we add a pair of square brackets around the string. Fixes: QTBUG-119482 Change-Id: I03177e5905b41f5f0b5aaa867b18379eb9c7a243 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QmlCompiler: Correctly mark side effects for list operationsUlf Hermann2024-04-113-0/+30
| | | | | | | | | | | The contents of a QQmlListProperty are mutable even if the property is not. This is because QQmlListProperty is only a view on a different container. Pick-to: 6.7 Fixes: QTBUG-123196 Change-Id: Id6309b1e1ddc219bf35e8d9888b8415dcc0f9d43 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmlformat: Preserve up to 1 empty line between statementsLuca Di Sera2024-04-118-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When `qmlformat` processes a `ScriptExpression` such as the `onClicked` body in the following snippet: ``` import QtQuick MouseArea { onClicked: { console.log("start"); console.log("end"); } } ``` It will remove every empty lines between statements. For example, in the above snippet, the two log statements will be on successive lines in the formatted output, removing the empty line in-between them in the original version. `qmlformat` will now, instead, allow up to 1 empty line to be preserved between statements, if at least one empty line is present in the original version. The formatting for `StatementList`s in `ScriptExpression`s is handled by the relevant overload of `ScriptFormatter::visit`. The code relative to inserting newlines in-between statements in the list was modified to take into account the possible presence of additional empty lines in between the statements, outputting an adequate amount of newlines to preserve up to 1 empty line. The utility method `ScriptFormatter::newLine`, which is used to output a single newline character, was modified to take a parameter representing the amount of newlines that should be added, allowing multiple newline characters to be written by a single call. A non-exhaustive test-case for the new behavior was added to track it. Certain pre-existing snapshot test-cases were modified to be in line with the new output of `qmlformat`. Fixes: QTBUG-123864 Change-Id: I552d1f7ce2c035b9087cb60a3b6e3480c5ae969a Reviewed-by: Dmitrii Akshintsev <dmitrii.akshintsev@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* Correct license for test filesLucie Gérard2024-04-112-2/+2
| | | | | | | | | | | | | According to QUIP-18 [1], all test files should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Task-number: QTBUG-121787 Pick-to: 6.7 Change-Id: Ib1dea3bf095aeb06e33a64db61a8c01219d12345 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmltc: Enforce basic required propertiesLuca Di Sera2024-04-095-3/+191
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Types in QML can expose "required" properties. A required property is a property that should be initialized when an instance of the type is built. Instantiating a type without initializing its required properties is an hard error. Currently, `qmltc` generated types do not respect the semantic of "required" properties. Instead, `qmltc` will generally default-initialize a required property without notifying the user of the error. `qmtlc`, so as to respect the semantic of required properties, will now require the user to pass an initial value for all required properties at construction time. To do so, `qmltc` will now generate a new inner record, `RequiredPropertiesBundle`, for each compiled top-level type, that contains the required amount of data to initialize each top-level required property that is reachable from the compiled type. An instance of `RequiredPropertiesBundle` will be required, as long as the type presents at least one required property, in the user-facing constructor for the generated type. The information stored in the instance will later be used to provide an initial value for each required property during the construction of the component. An intermediate representation for `RequiredPropertiesBundle` was added to "qmltcoutputir.h". `QmltcCodeWriter`, the component responsible for writing the final C++ code, was modified to take into consideration the presence, or lack thereof, of a `RequiredPropertiesBundle` and output the necessary code when required. The code taking care of populating the various IRs was modified to populate a `RequiredPropertiesBundle` for top-level components as necessary. Similarly, the code populating the parameters of the user-facing constructor was modified to require an instance of `RequiredPropertiesBundle` when necessary. The code that populates the body of the user-facing constructor for top-level types was modified to make use of the parameter by tying into the existing structure for setting initial values. `qmltc` uses a user-provided callback to allow the user to set the initial values for properties when constructing a top-level component. The body of the user-facing constructor was modified to compose the user-provided callback with a callable that sets the initial values for top-level required properties based on the bundle of data in the new `RequiredPropertiesBundle` instance. The code that populates the body of the user-facing constructor was moved into its own free-function, `compileRootExternalConstructorBody`, to be slightly more explicit about the structure of the code. A new test was provided to evaluate, some basic cases for the new behavior. Some pre-existing tests, which made use of required properties, were modified to comply with the new generated API. The documentation for `qmltc` was modified with a note about the new behavior. Task-number: QTBUG-120698 Change-Id: I1e916dcd91ae976629dad8adc7eacc6390bce7e9 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* ListModel: Treat QV4::Sequence and QV4::QmlListWrapper like arraysUlf Hermann2024-04-082-0/+187
| | | | | | | | Pick-to: 6.7 Fixes: QTBUG-124084 Change-Id: I99f900b71d71f33f807f5f69829bb9ef760b40c8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QmlCompiler: Handle scripts as type lookups on GetLookupUlf Hermann2024-04-054-0/+23
| | | | | | | | | | | This can happen if you lookup a script from a type namespace. The type lookup already has facilities for handling (or rather rejecting) it. Pick-to: 6.7 6.5 Fixes: QTBUG-123050 Change-Id: I092b1d2f47edc152b4f3967b4eaf4620a81ce5ef Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* QtQml: Add option to disambiguate resources for qmldir filesUlf Hermann2024-04-051-0/+3
| | | | | | | | | | | | If you have multiple modules with the same target path in the same directory, they will otherwise overwrite each others' .qrc files. This is not a very sane thing to do in general, but it happens in our tests. Task-number: QTBUG-124145 Change-Id: Ice5368d8b61907f610ad7e6e7370b43c2056c2fb Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* QtQml: Resolve generalized group properties during alias resolutionUlf Hermann2024-04-053-0/+151
| | | | | | | | | This way we can know the scope in which to search for the IDs. Pick-to: 6.7 6.5 Fixes: QTBUG-123865 Change-Id: I1dff9bdc69e3edaa80d85c757e3bb2b24e174cd0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* tst_qmltyperegistrar: Add missing autotool setup for plugin targetFabian Kosmale2024-04-051-0/+1
| | | | | | | | | | | | Otherwise, toplevel builds might fail if moc hasn't been build yet. Amends f080d0309d4c1d0d8a96dabe832162c5f41b881f. Pick-to: 6.7 6.5 Change-Id: Ifcdbc05a839f253d2aed192f38826e631bbf09c3 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> Reviewed-by: Matthias Rauter <matthias.rauter@qt.io> Reviewed-by: Orkun Tokdemir <orkun.tokdemir@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: do not construct well known valuetypes from string (part 1)Sami Shalayel2024-04-056-3/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a warning when well-known QML_STRUCTURED_VALUE's type are constructed from strings in bindings, with a fix-it to automatically generate the QML_STRUCTURED_VALUE way of constructing value types. Do not provide a fix-it in the case that a value type is constructed from an invalid string, like "50x70" instead of "50,70" for a QPointF, for example. Previously, qmlcachegen was compiling some of the string assignments for structured types like points, and some not, like vector2d. In the latter case, it printed the generic "Cannot assign literal of type ..." from the qmlIncompatible category. This commit only handles point, size and rect. A later commit will take care of the quick/gui types matrix4x4, vectorNd and quaternion. Now that the methods are all accessible from one point and consistently reused, implement qqmljsvaluetypefromstringcheck that checks if a given type should be constructed from a stringliteral, and generates a suggestion using the new way of constructing structured value types if it can. This is implemented into a separate header because it might be needed for multiple checks. Currently, it is only needed for the stringliteral "binding" check, but it will also be needed for stringliteral "assignment" checks, where you warn about `myPoint ="1,2"`, for example (see QTBUG-118547). To avoid code-duplication in the quicklintplugin, extract the code also needed for the qquickliteralbindingcheck into a separate base class LiteralBindingCheckBase, such that qquickliteralbindingcheck, in a later commit, may just extend LiteralBindingCheckBase using its isValueTypeFromStringConstruction override. Task-number: QTBUG-118323 Fixes: QTBUG-118546 Change-Id: I8572798d94593b1044cdb49116c8468f998dbbd7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: do not complain about JS typesSami Shalayel2024-04-053-0/+17
| | | | | | | | | | | Do not complain about types coming from .js files, as we cannot reasonably verify them. Fixes: QTBUG-120551 Pick-to: 6.7 6.5 Change-Id: Id74b1869f341c29baedddf88e0f9c19654de38e7 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QtQml: Discard events on engine shutdown rather than processing themUlf Hermann2024-04-052-0/+46
| | | | | | | | | | | | | | | This also deletes them, and releases any references they still hold. However, it doesn't give us headaches about delivering events to half-dead objects. Amends commit ebceda0cad6d86f6d6fe5efbf85a3b06fb4222b0 Pick-to: 6.7 6.5 Fixes: QTBUG-122925 Change-Id: I4509d23b2233965b8be8e4069ae61b0b82daf1e5 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sami Varanka <sami.varanka@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* V4: Don't call methods on nullptrUlf Hermann2024-04-051-0/+21
| | | | | | | | | | The root node of a sparse array can be null. Pick-to: 6.7 6.5 6.2 5.15 Fixes: QTBUG-123596 Change-Id: I5ea7fd73aeec460082d0cf19c7fc8a01993ed1f9 Reviewed-by: Semih Yavuz <semih.yavuz@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>