From 6890e4e1315bf71c547498ab49af42f66cb6e069 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Thu, 17 Nov 2016 11:03:06 +0100 Subject: QmlJSCheck: Allow Math. function in ui.qml files The Math. function like Math.max() are quite useful to define more complex layouts. Therefore we allow them. Change-Id: Ia95dcbcc1b8e96c117650dc8643da4a9de0ecdba Reviewed-by: J-P Nurmi Reviewed-by: Marco Benelli --- src/libs/qmljs/qmljscheck.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/libs/qmljs/qmljscheck.cpp') diff --git a/src/libs/qmljs/qmljscheck.cpp b/src/libs/qmljs/qmljscheck.cpp index df463e69e6..483b563a04 100644 --- a/src/libs/qmljs/qmljscheck.cpp +++ b/src/libs/qmljs/qmljscheck.cpp @@ -1428,6 +1428,17 @@ static QString functionName(ExpressionNode *ast, SourceLocation *location) return QString(); } +static QString functionNamespace(ExpressionNode *ast) +{ + if (FieldMemberExpression *fme = cast(ast)) { + if (!fme->name.isEmpty()) { + SourceLocation location; + return functionName(fme->base, &location); + } + } + return QString(); +} + void Check::checkNewExpression(ExpressionNode *ast) { SourceLocation location; @@ -1612,12 +1623,18 @@ bool Check::visit(CallExpression *ast) SourceLocation location; const QString name = functionName(ast->base, &location); + const QString namespaceName = functionNamespace(ast->base); + // We have to allow the qsTr function for translation. - bool isTranslationFunction = (name == QLatin1String("qsTr") || name == QLatin1String("qsTrId")); + + const bool isTranslationFunction = (name == QLatin1String("qsTr") || name == QLatin1String("qsTrId")); + // We allow the Math. functions + + const bool isMathFunction = namespaceName == "Math"; // allow adding connections with the help of the qt quick designer ui bool isDirectInConnectionsScope = (!m_typeStack.isEmpty() && m_typeStack.last() == QLatin1String("Connections")); - if (!isTranslationFunction && !isDirectInConnectionsScope) + if (!isTranslationFunction && !isMathFunction && !isDirectInConnectionsScope) addMessage(ErrFunctionsNotSupportedInQmlUi, location); if (!name.isEmpty() && name.at(0).isUpper() -- cgit v1.2.1