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)
|
bool visit(AST::UiObjectDefinition *objDef)
|
||||||
{
|
{
|
||||||
|
if (!validElement(objDef)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
AST::SourceLocation location;
|
AST::SourceLocation location;
|
||||||
location.offset = objDef->firstSourceLocation().offset;
|
location.offset = objDef->firstSourceLocation().offset;
|
||||||
location.length = objDef->lastSourceLocation().offset
|
location.length = objDef->lastSourceLocation().offset
|
||||||
@@ -75,13 +79,16 @@ private:
|
|||||||
|
|
||||||
const QString typeName = asString(objDef->qualifiedTypeNameId);
|
const QString typeName = asString(objDef->qualifiedTypeNameId);
|
||||||
const QString id = getId(objDef);
|
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);
|
m_nodeToIndex.insert(objDef, index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endVisit(AST::UiObjectDefinition * /*objDefinition*/)
|
void endVisit(AST::UiObjectDefinition *objDef)
|
||||||
{
|
{
|
||||||
|
if (!validElement(objDef)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
m_model->leaveElement();
|
m_model->leaveElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +111,11 @@ private:
|
|||||||
m_model->leaveProperty();
|
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 getId(AST::UiObjectDefinition *objDef) {
|
||||||
QString id;
|
QString id;
|
||||||
for (AST::UiObjectMemberList *it = objDef->initializer->members; it; it = it->next) {
|
for (AST::UiObjectMemberList *it = objDef->initializer->members; it; it = it->next) {
|
||||||
|
|||||||
Reference in New Issue
Block a user