diff options
author | mae <qt-info@nokia.com> | 2009-04-21 16:08:59 (GMT) |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-04-24 08:05:53 (GMT) |
commit | 772c321abef5d7c0fca38e3d8045d5a0c7c27ec9 (patch) | |
tree | c9d424e7afeaebcfdeae88615ab74d8c5b18a094 /src/declarative/qml | |
parent | eccf8f33890682a4827134805fa27bb354235e7a (diff) | |
download | Qt-772c321abef5d7c0fca38e3d8045d5a0c7c27ec9.zip Qt-772c321abef5d7c0fca38e3d8045d5a0c7c27ec9.tar.gz Qt-772c321abef5d7c0fca38e3d8045d5a0c7c27ec9.tar.bz2 |
map the ParentChange qml tag to a ParentChangeSet in dui.
It might be a consideration to use the former moveToParent property,
maybe it was a bit hacky, but less to type.
Diffstat (limited to 'src/declarative/qml')
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 277 |
1 files changed, 172 insertions, 105 deletions
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index ba127ef..53ed6ab 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -65,8 +65,12 @@ protected: AST::UiQualifiedId *propertyName, const QString &objectType, AST::UiObjectInitializer *initializer = 0); - QString getPrimitive(const QByteArray &propertyName, AST::ExpressionNode *expr); - void defineProperty(const QString &propertyName, int line, const QString &primitive); + Object *defineObjectBinding_helper(int line, + AST::UiQualifiedId *propertyName, + const QString &objectType, + AST::UiObjectInitializer *initializer = 0); + QString getPrimitive(const QByteArray &propertyName, AST::ExpressionNode *expr); + void defineProperty(const QString &propertyName, int line, const QString &primitive); using AST::Visitor::visit; using AST::Visitor::endVisit; @@ -159,7 +163,7 @@ QString ProcessAST::asString(AST::UiQualifiedId *node) const return s; } -Object *ProcessAST::defineObjectBinding(int line, +Object *ProcessAST::defineObjectBinding_helper(int line, AST::UiQualifiedId *propertyName, const QString &objectType, AST::UiObjectInitializer *initializer) @@ -229,85 +233,15 @@ Object *ProcessAST::defineObjectBinding(int line, return obj; } -void ProcessAST::defineProperty(const QString &propertyName, int line, const QString &primitive) -{ - _stateStack.pushProperty(propertyName, line); - Value *value = new Value; - value->primitive = primitive; - value->line = line; - currentProperty()->addValue(value); - _stateStack.pop(); -} - -// UiProgram: UiImportListOpt UiObjectMemberList ; -bool ProcessAST::visit(AST::UiProgram *node) -{ - accept(node->imports); - accept(node->members->member); - return false; -} - -// UiImport: T_IMPORT T_STRING_LITERAL ; -bool ProcessAST::visit(AST::UiImport *node) -{ - QString fileName = node->fileName->asString(); - _parser->addNamespacePath(fileName); - return false; -} - -// UiObjectMember: T_PUBLIC T_IDENTIFIER T_IDENTIFIER T_COLON Expression UiObjectInitializer ; -bool ProcessAST::visit(AST::UiPublicMember *node) +Object *ProcessAST::defineObjectBinding(int line, + AST::UiQualifiedId *qualifiedId, + const QString &objectType, + AST::UiObjectInitializer *initializer) { - const QString type = node->type->asString(); - const QString name = node->name->asString(); - - if (type == QLatin1String("property")) { - _stateStack.pushProperty(QLatin1String("properties"), node->publicToken.startLine); - - Object *obj = defineObjectBinding(node->identifierToken.startLine, - 0, - QLatin1String("Property")); - - _stateStack.pushObject(obj); - - defineProperty(QLatin1String("name"), node->identifierToken.startLine, name); - if (node->expression) // default value - defineProperty(QLatin1String("value"), node->identifierToken.startLine, getPrimitive("value", node->expression)); - - _stateStack.pop(); // object - _stateStack.pop(); // properties - - } else if (type == QLatin1String("signal")) { - _stateStack.pushProperty(QLatin1String("signals"), node->publicToken.startLine); - - Object *obj = defineObjectBinding(node->identifierToken.startLine, - 0, - QLatin1String("Signal")); - - _stateStack.pushObject(obj); - defineProperty(QLatin1String("name"), node->identifierToken.startLine, name); + if (objectType == QLatin1String("Connection")) { - _stateStack.pop(); // object - _stateStack.pop(); // signals - } else { - qWarning() << "bad public identifier" << type; // ### FIXME - } - - - // ### TODO drop initializer (unless some example needs differnet properties than name and type and value. - - return false; -} - - -// UiObjectMember: T_IDENTIFIER UiObjectInitializer ; -bool ProcessAST::visit(AST::UiObjectDefinition *node) -{ - if (node->name->asString() == QLatin1String("Connection")) { - - AST::UiObjectMemberList *it = node->initializer->members; - int line = node->identifierToken.startLine; + AST::UiObjectMemberList *it = initializer->members; QString sender; QString signal; @@ -349,9 +283,9 @@ bool ProcessAST::visit(AST::UiObjectDefinition *node) //### TODO generate error } } - Object *obj = defineObjectBinding(line, - 0, - QLatin1String("Connection")); + Object *obj = defineObjectBinding_helper(line, + 0, + QLatin1String("Connection")); _stateStack.pushObject(obj); if (!sender.isEmpty()) @@ -361,24 +295,12 @@ bool ProcessAST::visit(AST::UiObjectDefinition *node) if (!signal.isEmpty()) defineProperty(QLatin1String("signal"), line, signal); _stateStack.pop(); // object - } else { - defineObjectBinding(node->identifierToken.startLine, - 0, - node->name->asString(), - node->initializer); - } - return false; -} + return obj; + } else if (objectType == QLatin1String("PropertyChangeSet")) { -// UiObjectMember: UiQualifiedId T_COLON T_IDENTIFIER UiObjectInitializer ; -bool ProcessAST::visit(AST::UiObjectBinding *node) -{ - if (asString(node->qualifiedId) == QLatin1String("propertyChangeSet") - && node->name->asString() == QLatin1String("PropertyChangeSet")) { - - AST::UiObjectMemberList *it = node->initializer->members; + AST::UiObjectMemberList *it = initializer->members; for (; it; it = it->next) { AST::UiScriptBinding *scriptBinding = AST::cast<AST::UiScriptBinding *>(it->member); if (!scriptBinding) @@ -408,9 +330,9 @@ bool ProcessAST::visit(AST::UiObjectBinding *node) // #### TODO generate error } - Object *obj = defineObjectBinding(node->identifierToken.startLine, - 0, - QLatin1String("SetProperty")); + Object *obj = defineObjectBinding_helper(line, + 0, + QLatin1String("SetProperty")); _stateStack.pushObject(obj); if (!target.isEmpty()) @@ -420,14 +342,159 @@ bool ProcessAST::visit(AST::UiObjectBinding *node) if (!value.isEmpty()) defineProperty(QLatin1String("value"), scriptBinding->colonToken.startLine, value); _stateStack.pop(); // object + } - } else { - defineObjectBinding(node->identifierToken.startLine, - node->qualifiedId, - node->name->asString(), - node->initializer); + return 0; + } else if (objectType == QLatin1String("ParentChangeSet")) { + + AST::UiObjectMemberList *it = initializer->members; + for (; it; it = it->next) { + AST::UiScriptBinding *scriptBinding = AST::cast<AST::UiScriptBinding *>(it->member); + if (!scriptBinding) + continue; // ### TODO generate error + + + QString target; + QString property; + QString parent; + + int propertyCount = 0; + AST::UiQualifiedId *propertyName = scriptBinding->qualifiedId; + for (; propertyName; propertyName = propertyName->next){ + if (propertyName->next) { + if (!target.isEmpty()) + target += QLatin1Char('.'); + target += propertyName->name->asString(); + } else { + property = propertyName->name->asString(); + } + ++propertyCount; + } + + if (property != QLatin1String("parent")) { + // ### TODO generate error + } else { + + if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(scriptBinding->statement)) { + parent = getPrimitive(property.toLatin1(), stmt->expression); + } else { + // #### TODO generate error + } + + Object *obj = defineObjectBinding_helper(line, + 0, + QLatin1String("ParentChange")); + + _stateStack.pushObject(obj); + if (!target.isEmpty()) + defineProperty(QLatin1String("target"), scriptBinding->colonToken.startLine, QLatin1Char('{') + target + QLatin1Char('}')); + if (!parent.isEmpty()) + defineProperty(QLatin1String("parent"), scriptBinding->colonToken.startLine, parent); + _stateStack.pop(); // object + } + + } + + return 0; } + + return defineObjectBinding_helper(line, qualifiedId, objectType, initializer); +} + +void ProcessAST::defineProperty(const QString &propertyName, int line, const QString &primitive) +{ + _stateStack.pushProperty(propertyName, line); + Value *value = new Value; + value->primitive = primitive; + value->line = line; + currentProperty()->addValue(value); + _stateStack.pop(); +} + +// UiProgram: UiImportListOpt UiObjectMemberList ; +bool ProcessAST::visit(AST::UiProgram *node) +{ + accept(node->imports); + accept(node->members->member); + return false; +} + +// UiImport: T_IMPORT T_STRING_LITERAL ; +bool ProcessAST::visit(AST::UiImport *node) +{ + QString fileName = node->fileName->asString(); + _parser->addNamespacePath(fileName); + return false; +} + +// UiObjectMember: T_PUBLIC T_IDENTIFIER T_IDENTIFIER T_COLON Expression UiObjectInitializer ; +bool ProcessAST::visit(AST::UiPublicMember *node) +{ + const QString type = node->type->asString(); + const QString name = node->name->asString(); + + if (type == QLatin1String("property")) { + _stateStack.pushProperty(QLatin1String("properties"), node->publicToken.startLine); + + Object *obj = defineObjectBinding(node->identifierToken.startLine, + 0, + QLatin1String("Property")); + + _stateStack.pushObject(obj); + + defineProperty(QLatin1String("name"), node->identifierToken.startLine, name); + if (node->expression) // default value + defineProperty(QLatin1String("value"), node->identifierToken.startLine, getPrimitive("value", node->expression)); + + _stateStack.pop(); // object + _stateStack.pop(); // properties + + } else if (type == QLatin1String("signal")) { + _stateStack.pushProperty(QLatin1String("signals"), node->publicToken.startLine); + + Object *obj = defineObjectBinding(node->identifierToken.startLine, + 0, + QLatin1String("Signal")); + + _stateStack.pushObject(obj); + + defineProperty(QLatin1String("name"), node->identifierToken.startLine, name); + + _stateStack.pop(); // object + _stateStack.pop(); // signals + } else { + qWarning() << "bad public identifier" << type; // ### FIXME + } + + + // ### TODO drop initializer (unless some example needs differnet properties than name and type and value. + + return false; +} + + +// UiObjectMember: T_IDENTIFIER UiObjectInitializer ; +bool ProcessAST::visit(AST::UiObjectDefinition *node) +{ + + defineObjectBinding(node->identifierToken.startLine, + 0, + node->name->asString(), + node->initializer); + + return false; +} + + +// UiObjectMember: UiQualifiedId T_COLON T_IDENTIFIER UiObjectInitializer ; +bool ProcessAST::visit(AST::UiObjectBinding *node) +{ + defineObjectBinding(node->identifierToken.startLine, + node->qualifiedId, + node->name->asString(), + node->initializer); + return false; } |