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>
This commit is contained in:
Thomas Hartmann
2016-11-17 11:03:06 +01:00
committed by Thomas Hartmann
parent 85d288e3c3
commit 6890e4e131

View File

@@ -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()