QQmlJSMetaPropertyBinding:add group type fetching function, extend tests
Change-Id: I754349ab5b6a8125ccc373210fc073dd71583c6f Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
4ace8a4cfb
commit
5b63902d5c
|
@ -668,6 +668,14 @@ public:
|
|||
return {};
|
||||
}
|
||||
|
||||
QSharedPointer<const QQmlJSScope> groupType() const
|
||||
{
|
||||
if (auto *group = std::get_if<Content::GroupProperty>(&m_bindingContent))
|
||||
return group->groupScope.lock();
|
||||
// warn
|
||||
return {};
|
||||
}
|
||||
|
||||
bool hasLiteral() const
|
||||
{
|
||||
// TODO: Assumption: if the type is literal, we must have one
|
||||
|
|
|
@ -2,4 +2,5 @@ import QtQuick
|
|||
|
||||
GroupBase {
|
||||
anchors.left: parent.right
|
||||
anchors.leftMargin: 42
|
||||
}
|
||||
|
|
|
@ -273,8 +273,35 @@ void tst_qqmljsscope::groupedProperties()
|
|||
QVERIFY(root);
|
||||
|
||||
QVERIFY(root->hasProperty(u"anchors"_qs));
|
||||
auto anchorBindings = root->propertyBindings(u"anchors"_qs);
|
||||
const auto anchorBindings = root->propertyBindings(u"anchors"_qs);
|
||||
QVERIFY(!anchorBindings.isEmpty());
|
||||
QCOMPARE(anchorBindings.size(), 2); // from type itself and from the base type
|
||||
|
||||
const auto getBindingsWithinGroup =
|
||||
[&](QMultiHash<QString, QQmlJSMetaPropertyBinding> *bindings, qsizetype index) -> void {
|
||||
const auto &binding = anchorBindings[index];
|
||||
QCOMPARE(binding.bindingType(), QQmlJSMetaPropertyBinding::GroupProperty);
|
||||
auto anchorScope = binding.groupType();
|
||||
QVERIFY(anchorScope);
|
||||
*bindings = anchorScope->ownPropertyBindings();
|
||||
};
|
||||
|
||||
const auto value = [](const QMultiHash<QString, QQmlJSMetaPropertyBinding> &bindings,
|
||||
const QString &key) {
|
||||
return bindings.value(key, QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation {}));
|
||||
};
|
||||
|
||||
QMultiHash<QString, QQmlJSMetaPropertyBinding> bindingsOfType;
|
||||
getBindingsWithinGroup(&bindingsOfType, 0);
|
||||
QCOMPARE(bindingsOfType.size(), 2);
|
||||
QCOMPARE(value(bindingsOfType, u"left"_qs).bindingType(), QQmlJSMetaPropertyBinding::Script);
|
||||
QCOMPARE(value(bindingsOfType, u"leftMargin"_qs).bindingType(),
|
||||
QQmlJSMetaPropertyBinding::NumberLiteral);
|
||||
|
||||
QMultiHash<QString, QQmlJSMetaPropertyBinding> bindingsOfBaseType;
|
||||
getBindingsWithinGroup(&bindingsOfBaseType, 1);
|
||||
QCOMPARE(bindingsOfBaseType.size(), 1);
|
||||
QCOMPARE(value(bindingsOfBaseType, u"top"_qs).bindingType(), QQmlJSMetaPropertyBinding::Script);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_qqmljsscope)
|
||||
|
|
Loading…
Reference in New Issue