summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-02-19 17:37:54 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-19 19:21:23 +0000
commite27bcd5abd2364a4b184b105d1b5b6111d19cbd9 (patch)
tree5aad02fcaf37b7c4e7e4c71f8ea29fb491aa4a8e
parent903f643c501a41473e0c8f4f8bd78fa4a52bcd7d (diff)
QML: Make retrieval of a signal name from a handler accessible
We want to do that in other places, too. Change-Id: Id42495d239c2dccffa390478c8b57ec1acab7408 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 1daee0b03050487cfc4b483262ca73e5a24267ff) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/compiler/qqmlirbuilder.cpp19
-rw-r--r--src/qml/compiler/qqmlirbuilder_p.h1
-rw-r--r--src/qml/qml/qqmltypecompiler.cpp26
3 files changed, 28 insertions, 18 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp
index b6bc48c833..c7343e709c 100644
--- a/src/qml/compiler/qqmlirbuilder.cpp
+++ b/src/qml/compiler/qqmlirbuilder.cpp
@@ -501,6 +501,25 @@ bool IRBuilder::isSignalPropertyName(const QString &name)
return false; // consists solely of underscores - invalid.
}
+QString IRBuilder::signalNameFromSignalPropertyName(const QString &signalPropertyName)
+{
+ Q_ASSERT(signalPropertyName.startsWith(QLatin1String("on")));
+ QString signalNameCandidate = signalPropertyName;
+ signalNameCandidate.remove(0, 2);
+
+ // Note that the property name could start with any alpha or '_' or '$' character,
+ // so we need to do the lower-casing of the first alpha character.
+ for (int firstAlphaIndex = 0; firstAlphaIndex < signalNameCandidate.size(); ++firstAlphaIndex) {
+ if (signalNameCandidate.at(firstAlphaIndex).isUpper()) {
+ signalNameCandidate[firstAlphaIndex] = signalNameCandidate.at(firstAlphaIndex).toLower();
+ return signalNameCandidate;
+ }
+ }
+
+ Q_UNREACHABLE();
+ return QString();
+}
+
bool IRBuilder::visit(QQmlJS::AST::UiArrayMemberList *ast)
{
return QQmlJS::AST::Visitor::visit(ast);
diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h
index e755694335..99c1af6cbf 100644
--- a/src/qml/compiler/qqmlirbuilder_p.h
+++ b/src/qml/compiler/qqmlirbuilder_p.h
@@ -461,6 +461,7 @@ public:
bool generateFromQml(const QString &code, const QString &url, Document *output);
static bool isSignalPropertyName(const QString &name);
+ static QString signalNameFromSignalPropertyName(const QString &signalPropertyName);
using QQmlJS::AST::Visitor::visit;
using QQmlJS::AST::Visitor::endVisit;
diff --git a/src/qml/qml/qqmltypecompiler.cpp b/src/qml/qml/qqmltypecompiler.cpp
index f04272e5b9..3be3c6fc0e 100644
--- a/src/qml/qml/qqmltypecompiler.cpp
+++ b/src/qml/qml/qqmltypecompiler.cpp
@@ -356,30 +356,20 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio
QQmlPropertyResolver resolver(propertyCache);
- Q_ASSERT(bindingPropertyName.startsWith(QLatin1String("on")));
- QString signalNameCandidate = bindingPropertyName;
- signalNameCandidate.remove(0, 2);
-
- // Note that the property name could start with any alpha or '_' or '$' character,
- // so we need to do the lower-casing of the first alpha character.
- for (int firstAlphaIndex = 0; firstAlphaIndex < signalNameCandidate.size(); ++firstAlphaIndex) {
- if (signalNameCandidate.at(firstAlphaIndex).isUpper()) {
- signalNameCandidate[firstAlphaIndex] = signalNameCandidate.at(firstAlphaIndex).toLower();
- break;
- }
- }
+ const QString signalName = QmlIR::IRBuilder::signalNameFromSignalPropertyName(
+ bindingPropertyName);
QString qPropertyName;
- if (signalNameCandidate.endsWith(QLatin1String("Changed")))
- qPropertyName = signalNameCandidate.mid(0, signalNameCandidate.length() - static_cast<int>(strlen("Changed")));
+ if (signalName.endsWith(QLatin1String("Changed")))
+ qPropertyName = signalName.mid(0, signalName.length() - static_cast<int>(strlen("Changed")));
QList<QString> parameters;
bool notInRevision = false;
- QQmlPropertyData * const signal = resolver.signal(signalNameCandidate, &notInRevision);
- QQmlPropertyData * const signalPropertyData = resolver.property(signalNameCandidate, /*notInRevision ptr*/nullptr);
+ QQmlPropertyData * const signal = resolver.signal(signalName, &notInRevision);
+ QQmlPropertyData * const signalPropertyData = resolver.property(signalName, /*notInRevision ptr*/nullptr);
QQmlPropertyData * const qPropertyData = !qPropertyName.isEmpty() ? resolver.property(qPropertyName) : nullptr;
- QString finalSignalHandlerPropertyName = signalNameCandidate;
+ QString finalSignalHandlerPropertyName = signalName;
uint flags = QV4::CompiledData::Binding::IsSignalHandlerExpression;
const bool isPropertyObserver = !signalPropertyData && qPropertyData && qPropertyData->isBindable();
@@ -439,7 +429,7 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio
}
}
- QHash<QString, QStringList>::ConstIterator entry = customSignals.constFind(signalNameCandidate);
+ QHash<QString, QStringList>::ConstIterator entry = customSignals.constFind(signalName);
if (entry == customSignals.constEnd() && !qPropertyName.isEmpty())
entry = customSignals.constFind(qPropertyName);