Commit 95182687 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlJS: Add error message for invalid root item in the designer

Documents with those types do crash the qmlpuppet and confuse the users.
With this patch we give a clear error message and such files are not supported
anymore.

Change-Id: Iba19def2751d4dc81d90684c0c63c0274fdf49cf
Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@digia.com>
parent 5f0da502
......@@ -525,10 +525,24 @@ public:
}
};
class UnsupportedRootObjectTypesByVisualDesigner : public QStringList
{
public:
UnsupportedRootObjectTypesByVisualDesigner()
{
(*this) << QLatin1String("QtObject") << QLatin1String("ListModel")
<< QLatin1String("Component") << QLatin1String("Timer")
<< QLatin1String("Package");
}
};
} // end of anonymous namespace
Q_GLOBAL_STATIC(VisualAspectsPropertyBlackList, visualAspectsPropertyBlackList)
Q_GLOBAL_STATIC(UnsupportedTypesByVisualDesigner, unsupportedTypesByVisualDesigner)
Q_GLOBAL_STATIC(UnsupportedRootObjectTypesByVisualDesigner, unsupportedRootObjectTypesByVisualDesigner)
Check::Check(Document::Ptr doc, const ContextPtr &context)
: _doc(doc)
......@@ -559,6 +573,7 @@ Check::Check(Document::Ptr doc, const ContextPtr &context)
disableMessage(WarnReferenceToParentItemNotSupportedByVisualDesigner);
disableMessage(WarnUndefinedValueForVisualDesigner);
disableMessage(WarnStatesOnlyInRootItemForVisualDesigner);
disableMessage(ErrUnsupportedRootTypeInVisualDesigner);
}
Check::~Check()
......@@ -729,6 +744,13 @@ void Check::visitQmlObject(Node *ast, UiQualifiedId *typeId,
if (m_typeStack.count() > 1 && getRightMostIdentifier(typeId)->name.toString() == QLatin1String("State"))
addMessage(WarnStatesOnlyInRootItemForVisualDesigner, typeErrorLocation);
const QString typeName = getRightMostIdentifier(typeId)->name.toString();
if (m_typeStack.isEmpty()
&& unsupportedRootObjectTypesByVisualDesigner()->contains(typeName))
addMessage(ErrUnsupportedRootTypeInVisualDesigner,
locationFromRange(ast->firstSourceLocation(), ast->lastSourceLocation()), typeName);
bool typeError = false;
if (_importsOk) {
const ObjectValue *prototype = _context->lookupType(_doc.data(), typeId);
......
......@@ -221,6 +221,8 @@ StaticAnalysisMessages::StaticAnalysisMessages()
tr("Qt Quick Designer only supports states in the root item."));
newMsg(WarnAboutQtQuick1InsteadQtQuick2, Warning,
tr("Using Qt Quick 1 code model instead of Qt Quick 2."));
newMsg(ErrUnsupportedRootTypeInVisualDesigner, Error,
tr("This type is not supported as a root element by Qt Quick Designer %1."), 1);
}
} // anonymous namespace
......
......@@ -97,6 +97,7 @@ enum Type
WarnReferenceToParentItemNotSupportedByVisualDesigner = 205,
WarnUndefinedValueForVisualDesigner = 206,
WarnStatesOnlyInRootItemForVisualDesigner = 207,
ErrUnsupportedRootTypeInVisualDesigner = 208,
ErrUnknownComponent = 300,
ErrCouldNotResolvePrototypeOf = 301,
ErrCouldNotResolvePrototype = 302,
......
......@@ -902,6 +902,7 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
check.enableMessage(StaticAnalysis::WarnReferenceToParentItemNotSupportedByVisualDesigner);
check.enableMessage(StaticAnalysis::WarnReferenceToParentItemNotSupportedByVisualDesigner);
check.enableMessage(StaticAnalysis::WarnAboutQtQuick1InsteadQtQuick2);
check.enableMessage(StaticAnalysis::ErrUnsupportedRootTypeInVisualDesigner);
//## triggers too often ## check.enableMessage(StaticAnalysis::WarnUndefinedValueForVisualDesigner);
foreach (const StaticAnalysis::Message &message, check()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment