Commit 1a2e16ae authored by Kai Koehne's avatar Kai Koehne Committed by hjk
Browse files

QmlOutline: Show functions in outline

Reviewed-by: Christiaan Janssen
(cherry picked from commit e871b7e3)
parent 17ce6be5
......@@ -3,5 +3,6 @@
<file>images/element.png</file>
<file>images/property.png</file>
<file>images/publicmember.png</file>
<file>images/func.png</file>
</qresource>
</RCC>
......@@ -50,6 +50,7 @@ public:
QIcon elementIcon;
QIcon propertyIcon;
QIcon publicMemberIcon;
QIcon functionDeclarationIcon;
QHash<QPair<QString,QString>,QIcon> iconHash;
QString resourcePath;
};
......@@ -62,6 +63,7 @@ Icons::Icons()
m_d->elementIcon = QIcon(QLatin1String(":/qmljs/images/element.png"));
m_d->propertyIcon = QIcon(QLatin1String(":/qmljs/images/property.png"));
m_d->publicMemberIcon = QIcon(QLatin1String(":/qmljs/images/publicmember.png"));
m_d->functionDeclarationIcon = QIcon(QLatin1String(":/qmljs/images/func.png"));
}
Icons::~Icons()
......@@ -141,3 +143,8 @@ QIcon Icons::publicMemberIcon() const
{
return m_d->publicMemberIcon;
}
QIcon Icons::functionDeclarationIcon() const
{
return m_d->functionDeclarationIcon;
}
......@@ -53,6 +53,7 @@ public:
QIcon objectDefinitionIcon() const;
QIcon scriptBindingIcon() const;
QIcon publicMemberIcon() const;
QIcon functionDeclarationIcon() const;
private:
Icons();
......
......@@ -223,6 +223,19 @@ private:
m_model->leavePublicMember();
}
bool visit(AST::FunctionDeclaration *functionDeclaration)
{
QModelIndex index = m_model->enterFunctionDeclaration(functionDeclaration);
m_nodeToIndex.insert(functionDeclaration, index);
return true;
}
void endVisit(AST::FunctionDeclaration * /*functionDeclaration*/)
{
m_model->leaveFunctionDeclaration();
}
QmlOutlineModel *m_model;
QHash<AST::Node*, QModelIndex> m_nodeToIndex;
......@@ -474,6 +487,23 @@ void QmlOutlineModel::leavePublicMember()
leaveNode();
}
QModelIndex QmlOutlineModel::enterFunctionDeclaration(AST::FunctionDeclaration *functionDeclaration)
{
QMap<int, QVariant> objectData;
objectData.insert(Qt::DisplayRole, functionDeclaration->name->asString());
objectData.insert(ItemTypeRole, ElementBindingType);
QmlOutlineItem *item = enterNode(objectData, functionDeclaration, 0, m_icons->functionDeclarationIcon());
return item->index();
}
void QmlOutlineModel::leaveFunctionDeclaration()
{
leaveNode();
}
AST::Node *QmlOutlineModel::nodeForIndex(const QModelIndex &index) const
{
QTC_ASSERT(index.isValid() && (index.model() == this), return 0);
......@@ -491,8 +521,11 @@ AST::SourceLocation QmlOutlineModel::sourceLocation(const QModelIndex &index) co
QTC_ASSERT(index.isValid() && (index.model() == this), return location);
AST::Node *node = nodeForIndex(index);
if (node) {
if (AST::UiObjectMember *member = node->uiObjectMemberCast())
if (AST::UiObjectMember *member = node->uiObjectMemberCast()) {
location = getLocation(member);
} else if (AST::ExpressionNode *expression = node->expressionCast()) {
location = getLocation(expression);
}
}
return location;
}
......@@ -755,6 +788,15 @@ AST::SourceLocation QmlOutlineModel::getLocation(AST::UiObjectMember *objMember)
return location;
}
AST::SourceLocation QmlOutlineModel::getLocation(AST::ExpressionNode *exprNode) {
AST::SourceLocation location;
location.offset = exprNode->firstSourceLocation().offset;
location.length = exprNode->lastSourceLocation().offset
- exprNode->firstSourceLocation().offset
+ exprNode->lastSourceLocation().length;
return location;
}
QIcon QmlOutlineModel::getIcon(AST::UiQualifiedId *qualifiedId) {
const Interpreter::Value *value = m_context->evaluate(qualifiedId);
......
......@@ -89,6 +89,9 @@ private:
QModelIndex enterPublicMember(QmlJS::AST::UiPublicMember *publicMember);
void leavePublicMember();
QModelIndex enterFunctionDeclaration(QmlJS::AST::FunctionDeclaration *functionDeclaration);
void leaveFunctionDeclaration();
private:
QmlOutlineItem *enterNode(QMap<int, QVariant> data, QmlJS::AST::Node *node, QmlJS::AST::UiQualifiedId *idNode, const QIcon &icon);
void leaveNode();
......@@ -102,6 +105,7 @@ private:
static QString asString(QmlJS::AST::UiQualifiedId *id);
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::UiObjectMember *objMember);
static QmlJS::AST::SourceLocation getLocation(QmlJS::AST::ExpressionNode *exprNode);
QIcon getIcon(QmlJS::AST::UiQualifiedId *objDef);
QString getAnnotation(QmlJS::AST::UiObjectInitializer *objInitializer);
......
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