diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2011-07-27 13:13:50 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-28 11:27:26 +0200 |
commit | 7edd8ee9a6885e57715c50be1dd402d9bd5118c8 (patch) | |
tree | b26903bbd2d1cc8623da846ca0af5b6f2431370d /src | |
parent | aa2d36a3d7405c3130b27b41b0e3941ca466f3cd (diff) |
Support QT_TRANSLATE_NOOP in ListElement.
Task-number: QTBUG-16289
Change-Id: I13e6859de185478e2c6c9486d8deeda103dd7b90
Reviewed-on: http://codereview.qt.nokia.com/2238
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/util/qdeclarativelistmodel.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/declarative/util/qdeclarativelistmodel.cpp b/src/declarative/util/qdeclarativelistmodel.cpp index e35d64b179..d1496fc886 100644 --- a/src/declarative/util/qdeclarativelistmodel.cpp +++ b/src/declarative/util/qdeclarativelistmodel.cpp @@ -42,6 +42,8 @@ #include "private/qdeclarativelistmodel_p_p.h" #include "private/qdeclarativelistmodelworkeragent_p.h" #include "private/qdeclarativeopenmetaobject_p.h" +#include "parser/qdeclarativejsast_p.h" +#include "parser/qdeclarativejsengine_p.h" #include <qdeclarativecustomparser_p.h> #include <qdeclarativeparser_p.h> @@ -840,9 +842,32 @@ bool QDeclarativeListModelParser::compileProperty(const QDeclarativeCustomParser QByteArray script = variant.asScript().toUtf8(); int v = evaluateEnum(script); if (v<0) { - if (script.startsWith("QT_TR_NOOP(\"") && script.endsWith("\")")) { + using namespace QDeclarativeJS; + AST::Node *node = variant.asAST(); + AST::StringLiteral *literal = 0; + if (AST::CallExpression *callExpr = AST::cast<AST::CallExpression *>(node)) { + if (AST::IdentifierExpression *idExpr = AST::cast<AST::IdentifierExpression *>(callExpr->base)) { + if (idExpr->name->asString() == QLatin1String("QT_TR_NOOP")) { + if (callExpr->arguments && !callExpr->arguments->next) + literal = AST::cast<AST::StringLiteral *>(callExpr->arguments->expression); + if (!literal) { + error(prop, QDeclarativeListModel::tr("ListElement: improperly specified QT_TR_NOOP")); + return false; + } + } else if (idExpr->name->asString() == QLatin1String("QT_TRANSLATE_NOOP")) { + if (callExpr->arguments && callExpr->arguments->next && !callExpr->arguments->next->next) + literal = AST::cast<AST::StringLiteral *>(callExpr->arguments->next->expression); + if (!literal) { + error(prop, QDeclarativeListModel::tr("ListElement: improperly specified QT_TRANSLATE_NOOP")); + return false; + } + } + } + } + + if (literal) { d[0] = char(QDeclarativeParser::Variant::String); - d += script.mid(12,script.length()-14); + d += literal->value->asString().toUtf8(); } else { error(prop, QDeclarativeListModel::tr("ListElement: cannot use script for property value")); return false; |