aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2022-08-22 11:13:03 +0200
committerSami Shalayel <sami.shalayel@qt.io>2022-08-31 09:33:02 +0200
commit8120ec1d3dd356194203a723e53a8b72e793d1e0 (patch)
tree8a8723705bc7d33b21d34ad1f8f52f213b1157fa /tools
parentb6463590fa45204052028e4715a06fea7ea97dd5 (diff)
qmltc: test alias on properties with attributes
Add tests to qmltc to see if it behaves well for aliases to different kinds of properties, and compares if the engine shares the same behavior. Same for the attributes in the QMetaProperties. Changes: * add some more MOC information to aliases ** always add NOTIFY to aliases (like the engine does) ** always set DESIGNABLE to false for aliases (like the engine does) ** always set CONSTANT to false for aliases (like the engine does) ** always set STORED to false for aliases (like the engine does) Test if: * default aliases works when compiled via qmltc * attributes of aliases are set correctly in QMetaProperty and compare it to the attributes of the QMetaProperty obtained from the engine. * aliases can read/written/reset/notified Fixes: QTBUG-105708 Change-Id: I66b9c43c8c8de3dbd2b33d5ce15cd42ffb377ce7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmltc/qmltccompiler.cpp21
-rw-r--r--tools/qmltc/qmltcvisitor.cpp6
2 files changed, 23 insertions, 4 deletions
diff --git a/tools/qmltc/qmltccompiler.cpp b/tools/qmltc/qmltccompiler.cpp
index ee932a84cd..57e8363bae 100644
--- a/tools/qmltc/qmltccompiler.cpp
+++ b/tools/qmltc/qmltccompiler.cpp
@@ -733,10 +733,20 @@ void QmltcCompiler::compileAlias(QmltcType &current, const QQmlJSMetaProperty &a
current.functions.emplaceBack(bindable);
mocLines << u"BINDABLE"_s << bindable.name;
}
+
// 3. add notify - which is pretty special
- if (QString notifyName = result.property.notify(); !notifyName.isEmpty()) {
+ // step 1: generate the moc instructions
+ // mimic the engines behavior: do it even if the notify will never be emitted
+ if (const QString aliasNotifyName = alias.notify(); !aliasNotifyName.isEmpty()) {
+
Q_ASSERT(result.kind == QQmlJSUtils::AliasTarget_Property); // property is invalid otherwise
+ mocLines << u"NOTIFY"_s << aliasNotifyName;
+ }
+
+ // step 2: connect the notifier to the aliased property notifier, if this latter exists
+ // otherwise, mimic the engines behavior and generate a useless notify
+ if (const QString notifyName = result.property.notify(); !notifyName.isEmpty()) {
auto notifyFrames = frames;
notifyFrames.pop(); // we don't need the last frame at all in this case
@@ -762,6 +772,7 @@ void QmltcCompiler::compileAlias(QmltcType &current, const QQmlJSMetaProperty &a
current.endInit.body += notifyEpilogue;
current.endInit.body << u"}"_s;
}
+
if (QString resetName = result.property.reset(); !resetName.isEmpty()) {
Q_ASSERT(result.kind == QQmlJSUtils::AliasTarget_Property); // property is invalid otherwise
QmltcMethod reset {};
@@ -775,8 +786,12 @@ void QmltcCompiler::compileAlias(QmltcType &current, const QQmlJSMetaProperty &a
mocLines << u"RESET"_s << reset.name;
}
- if (result.property.isConstant())
- mocLines << u"CONSTANT"_s;
+ // mimic the engines behavior: aliases are never constants
+ // mocLines << u"CONSTANT"_s;
+ // mimic the engines behavior: aliases are never stored
+ mocLines << u"STORED"_s << u"false"_s;
+ // mimic the engines behavior: aliases are never designable
+ mocLines << u"DESIGNABLE"_s << u"false"_s;
// 4. add moc entry
// Q_PROPERTY(QString text READ text WRITE setText BINDABLE bindableText NOTIFY textChanged)
diff --git a/tools/qmltc/qmltcvisitor.cpp b/tools/qmltc/qmltcvisitor.cpp
index aeea6371ab..017b5d5440 100644
--- a/tools/qmltc/qmltcvisitor.cpp
+++ b/tools/qmltc/qmltcvisitor.cpp
@@ -562,8 +562,12 @@ static void setAliasData(QQmlJSMetaProperty *alias, const QQmlJSUtils::ResolvedA
return;
if (origin.property.isWritable() && alias->write().isEmpty())
alias->setWrite(compiledData.write);
- if (!origin.property.notify().isEmpty() && alias->notify().isEmpty())
+
+ // the engine always compiles a notify for properties/aliases defined in qml code
+ // Yes, this generated notify will never be emitted.
+ if (alias->notify().isEmpty())
alias->setNotify(compiledData.notify);
+
if (!origin.property.bindable().isEmpty() && alias->bindable().isEmpty())
alias->setBindable(compiledData.bindable);
}