qmltc: test support for generalized group properties

Test support for generalized group properties in qmltc.

Also, force group property bindings to be deferred when they belong to a
generalized grouped property, while "not-generalized" grouped properties
never are deferred.

Fixes: QTBUG-105378
Change-Id: Iadc64d7033f9446ccf53e305d8831c7d348f257c
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Sami Shalayel 2022-08-05 16:17:07 +02:00
parent 2879c7c341
commit d9add5c2d4
7 changed files with 111 additions and 2 deletions

View File

@ -99,6 +99,7 @@ set(qml_sources
valueTypeListProperty.qml
translations.qml
translationsById.qml
generalizedGroupedProperty.qml
# support types:
DefaultPropertySingleChild.qml

View File

@ -63,8 +63,17 @@ void TestTypeGrouped::setStr(const QString &s)
}
QmlGroupPropertyTestType::QmlGroupPropertyTestType(QObject *parent) : QObject(parent) { }
TestTypeGrouped *QmlGroupPropertyTestType::getGroup()
{
return &m_group;
}
QmlGeneralizedGroupPropertyTestType::QmlGeneralizedGroupPropertyTestType(QObject *parent)
: QObject(parent)
{
}
TestTypeGrouped *QmlGeneralizedGroupPropertyTestType::getGroup()
{
return &m_group;
}

View File

@ -61,4 +61,28 @@ public:
TestTypeGrouped *getGroup();
};
class QmlGeneralizedGroupPropertyTestType : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_CLASSINFO("ImmediatePropertyNames", "myInt,group")
Q_PROPERTY(TestTypeGrouped *group READ getGroup)
TestTypeGrouped m_group;
public:
QmlGeneralizedGroupPropertyTestType(QObject *parent = nullptr);
TestTypeGrouped *getGroup();
};
class MyImmediateQtObject : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_CLASSINFO("ImmediatePropertyNames", "myInt");
};
#endif // TESTGROUPEDTYPE_H

View File

@ -0,0 +1,22 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
import QtQml
import QtQuick
import QmltcTests
QmlGeneralizedGroupPropertyTestType {
id: root
property int myInt: 5
group.count: myInt
group.formula: 3 + 5
group.str: "Hello World!"
group.object: MyImmediateQtObject {
property int myInt: 42
root.group.count: myInt
root.group.formula: 3 - 5
root.group.str: "Goodbye World!"
}
}

View File

@ -74,6 +74,7 @@
#include "translations.h"
#include "translationsbyid.h"
#include "defaultalias.h"
#include "generalizedgroupedproperty.h"
#include "testprivateproperty.h"
@ -2516,4 +2517,52 @@ void tst_qmltc::translations()
}
}
void tst_qmltc::generalizedGroupedProperty()
{
QQmlEngine e;
{
PREPEND_NAMESPACE(generalizedGroupedProperty) fromQmltc(&e);
QCOMPARE(fromQmltc.getGroup()->getCount(), 5);
fromQmltc.setMyInt(42);
QCOMPARE(fromQmltc.getGroup()->getCount(), 42);
fromQmltc.getGroup()->setCount(55);
QCOMPARE(fromQmltc.getGroup()->getCount(), 55);
QCOMPARE(fromQmltc.myInt(), 42);
QCOMPARE(fromQmltc.getGroup()->getFormula(), 8);
QCOMPARE(fromQmltc.getGroup()->getStr(), "Hello World!");
qmlExecuteDeferred(&fromQmltc);
QCOMPARE(fromQmltc.getGroup()->getCount(), 55);
QCOMPARE(fromQmltc.getGroup()->getFormula(), 8);
QCOMPARE(fromQmltc.getGroup()->getStr(), "Hello World!");
}
{
QQmlComponent component(&e, "qrc:/qt/qml/QmltcTests/generalizedGroupedProperty.qml");
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QScopedPointer<QObject> fromEngine(component.create());
QCOMPARE(fromEngine->property("group").value<QObject *>()->property("count"), 5);
fromEngine->setProperty("myInt", 43);
QCOMPARE(fromEngine->property("group").value<QObject *>()->property("count"), 43);
fromEngine->property("group").value<QObject *>()->setProperty("count", 56);
QCOMPARE(fromEngine->property("group").value<QObject *>()->property("count"), 56);
QCOMPARE(fromEngine->property("myInt").value<int>(), 43);
QCOMPARE(fromEngine->property("group").value<QObject *>()->property("formula").value<int>(),
8);
QCOMPARE(fromEngine->property("group").value<QObject *>()->property("str").toString(),
"Hello World!");
qmlExecuteDeferred(fromEngine.data());
QCOMPARE(fromEngine->property("group").value<QObject *>()->property("count"), 56);
QCOMPARE(fromEngine->property("group").value<QObject *>()->property("formula").value<int>(),
8);
QCOMPARE(fromEngine->property("group").value<QObject *>()->property("str").toString(),
"Hello World!");
}
}
QTEST_MAIN(tst_qmltc)

View File

@ -85,4 +85,5 @@ private slots:
void trickyPropertyChangeAndSignalHandlers();
void valueTypeListProperty();
void translations();
void generalizedGroupedProperty();
};

View File

@ -875,7 +875,10 @@ void QmltcCompiler::compileBinding(QmltcType &current, const QQmlJSMetaPropertyB
// (potentially, with all the bindings inside of it), period.
if (type->isNameDeferred(propertyName)) {
const auto location = binding.sourceLocation();
if (bindingType == QQmlJSMetaPropertyBinding::GroupProperty) {
// make sure group property is not generalized by checking if type really has a property
// called propertyName. If not, it is probably an id.
if (bindingType == QQmlJSMetaPropertyBinding::GroupProperty
&& type->hasProperty(propertyName)) {
qCWarning(lcQmltcCompiler)
<< QStringLiteral("Binding at line %1 column %2 is not deferred as it is a "
"binding on a group property.")