From 1daee0b03050487cfc4b483262ca73e5a24267ff Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 19 Feb 2021 17:37:54 +0100 Subject: QML: Make retrieval of a signal name from a handler accessible We want to do that in other places, too. Pick-to: 6.1 Change-Id: Id42495d239c2dccffa390478c8b57ec1acab7408 Reviewed-by: Fabian Kosmale --- src/qml/compiler/qqmlirbuilder.cpp | 19 +++++++++++++++++++ src/qml/compiler/qqmlirbuilder_p.h | 1 + 2 files changed, 20 insertions(+) (limited to 'src/qml/compiler') 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; -- cgit v1.2.3