diff options
author | Christian Kamm <[email protected]> | 2011-10-05 14:14:35 +0200 |
---|---|---|
committer | Christian Kamm <[email protected]> | 2011-10-12 10:29:27 +0200 |
commit | 010ce2d20dc8d776fad3062cf68ad2c3535c9d2b (patch) | |
tree | c68fff9977c4b23a413bf7b4e1b93b40f2cc27dc /src/libs/qmljs/qmljsscopebuilder.cpp | |
parent | 03689eeb5043dd8c49be87ec45b92a388232fdcf (diff) |
QmlJS: Set correct scope in signal handlers.
This means the code model will now offer correct completion and
highlighting for arguments of signals in their handlers, example:
MouseArea {
onClicked: {
mou<complete> // now also completes 'mouse'
}
}
Reviewed-by: Fawzi Mohamed
Change-Id: I01838ef00e391b13e6e5a832c9ec3cd983689c5b
Reviewed-on: http://codereview.qt-project.org/6147
Reviewed-by: Christian Kamm <[email protected]>
Sanity-Review: Christian Kamm <[email protected]>
Diffstat (limited to 'src/libs/qmljs/qmljsscopebuilder.cpp')
-rw-r--r-- | src/libs/qmljs/qmljsscopebuilder.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/libs/qmljs/qmljsscopebuilder.cpp b/src/libs/qmljs/qmljsscopebuilder.cpp index ed52edb6a80..fd72b565338 100644 --- a/src/libs/qmljs/qmljsscopebuilder.cpp +++ b/src/libs/qmljs/qmljsscopebuilder.cpp @@ -67,6 +67,35 @@ void ScopeBuilder::push(AST::Node *node) setQmlScopeObject(qmlObject); } + // JS signal handler scope + if (UiScriptBinding *script = cast<UiScriptBinding *>(node)) { + QString name; + if (script->qualifiedId) + name = script->qualifiedId->name.toString(); + if (!_scopeChain->qmlScopeObjects().isEmpty() + && name.startsWith(QLatin1String("on")) + && !script->qualifiedId->next) { + const ObjectValue *owner = 0; + const Value *value = 0; + // try to find the name on the scope objects + foreach (const ObjectValue *scope, _scopeChain->qmlScopeObjects()) { + value = scope->lookupMember(name, _scopeChain->context(), &owner); + if (value) + break; + } + // signals defined in QML + if (const ASTSignal *astsig = dynamic_cast<const ASTSignal *>(value)) { + _scopeChain->appendJsScope(astsig->bodyScope()); + } + // signals defined in C++ + else if (const QmlObjectValue *qmlObject = dynamic_cast<const QmlObjectValue *>(owner)) { + if (const ObjectValue *scope = qmlObject->signalScope(name)) { + _scopeChain->appendJsScope(scope); + } + } + } + } + // JS scopes switch (node->kind) { case Node::Kind_UiScriptBinding: @@ -75,11 +104,8 @@ void ScopeBuilder::push(AST::Node *node) case Node::Kind_UiPublicMember: { ObjectValue *scope = _scopeChain->document()->bind()->findAttachedJSScope(node); - if (scope) { - QList<const ObjectValue *> jsScopes = _scopeChain->jsScopes(); - jsScopes += scope; - _scopeChain->setJsScopes(jsScopes); - } + if (scope) + _scopeChain->appendJsScope(scope); break; } default: |