diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2016-11-17 11:03:06 +0100 |
---|---|---|
committer | Thomas Hartmann <Thomas.Hartmann@theqtcompany.com> | 2016-11-17 10:34:56 +0000 |
commit | 6890e4e1315bf71c547498ab49af42f66cb6e069 (patch) | |
tree | 17d74020f46ebc09944df35aa5b789dce6326c8f /src/libs/qmljs/qmljscheck.cpp | |
parent | 85d288e3c3a0ca829e39e5aa6bfb7dc71ec69e90 (diff) | |
download | qt-creator-6890e4e1315bf71c547498ab49af42f66cb6e069.tar.gz |
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 <jpnurmi@qt.io>
Reviewed-by: Marco Benelli <marco.benelli@qt.io>
Diffstat (limited to 'src/libs/qmljs/qmljscheck.cpp')
-rw-r--r-- | src/libs/qmljs/qmljscheck.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
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<FieldMemberExpression *>(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() |