forked from qt-creator/qt-creator
QmlOutline: Filter out 'ghost' elements
The parser represents incomplete script bindings as element definitions,
e.g. for 'Item { id }', 'id' is represented as an UiObjectDefinition.
Catch this in the outline model by explicitly checking whether a
UiObjectDefinition starts with a capital letter.
This commit is contained in:
@@ -67,6 +67,10 @@ private:
|
||||
|
||||
bool visit(AST::UiObjectDefinition *objDef)
|
||||
{
|
||||
if (!validElement(objDef)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
AST::SourceLocation location;
|
||||
location.offset = objDef->firstSourceLocation().offset;
|
||||
location.length = objDef->lastSourceLocation().offset
|
||||
@@ -75,13 +79,16 @@ private:
|
||||
|
||||
const QString typeName = asString(objDef->qualifiedTypeNameId);
|
||||
const QString id = getId(objDef);
|
||||
QModelIndex index = m_model->enterElement(asString(objDef->qualifiedTypeNameId), id, location);
|
||||
QModelIndex index = m_model->enterElement(typeName, id, location);
|
||||
m_nodeToIndex.insert(objDef, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
void endVisit(AST::UiObjectDefinition * /*objDefinition*/)
|
||||
void endVisit(AST::UiObjectDefinition *objDef)
|
||||
{
|
||||
if (!validElement(objDef)) {
|
||||
return;
|
||||
}
|
||||
m_model->leaveElement();
|
||||
}
|
||||
|
||||
@@ -104,6 +111,11 @@ private:
|
||||
m_model->leaveProperty();
|
||||
}
|
||||
|
||||
bool validElement(AST::UiObjectDefinition *objDef) {
|
||||
// For 'Rectangle { id }', id is parsed as UiObjectDefinition ... Filter this out.ctan
|
||||
return objDef->qualifiedTypeNameId->name->asString().at(0).isUpper();
|
||||
}
|
||||
|
||||
QString getId(AST::UiObjectDefinition *objDef) {
|
||||
QString id;
|
||||
for (AST::UiObjectMemberList *it = objDef->initializer->members; it; it = it->next) {
|
||||
|
||||
Reference in New Issue
Block a user