Skip to content
Snippets Groups Projects
Commit f00225a0 authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlOutline: Also show custom properties

Also show properties defined in the component, e.g. by 'property x',
in the outline.
parent fe82dd7f
No related branches found
No related tags found
No related merge requests found
......@@ -2,5 +2,6 @@
<qresource prefix="/qmljs">
<file>images/element.png</file>
<file>images/property.png</file>
<file>images/publicmember.png</file>
</qresource>
</RCC>
......@@ -49,6 +49,7 @@ class IconsPrivate
public:
QIcon elementIcon;
QIcon propertyIcon;
QIcon publicMemberIcon;
QHash<QPair<QString,QString>,QIcon> iconHash;
QString resourcePath;
};
......@@ -60,6 +61,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"));
}
Icons::~Icons()
......@@ -134,3 +136,8 @@ QIcon Icons::scriptBindingIcon() const
{
return m_d->propertyIcon;
}
QIcon Icons::publicMemberIcon() const
{
return m_d->publicMemberIcon;
}
......@@ -52,6 +52,7 @@ public:
QIcon objectDefinitionIcon() const;
QIcon scriptBindingIcon() const;
QIcon publicMemberIcon() const;
private:
Icons();
......
......@@ -12,7 +12,7 @@ using namespace QmlJS;
using namespace QmlJSEditor::Internal;
enum {
debug = false
debug = true
};
namespace QmlJSEditor {
......@@ -85,11 +85,7 @@ private:
return true;
}
AST::SourceLocation location;
location.offset = objDef->firstSourceLocation().offset;
location.length = objDef->lastSourceLocation().offset
- objDef->firstSourceLocation().offset
+ objDef->lastSourceLocation().length;
AST::SourceLocation location = getLocation(objDef);
const QString typeName = asString(objDef->qualifiedTypeNameId);
......@@ -114,13 +110,9 @@ private:
bool visit(AST::UiScriptBinding *scriptBinding)
{
AST::SourceLocation location;
location.offset = scriptBinding->firstSourceLocation().offset;
location.length = scriptBinding->lastSourceLocation().offset
- scriptBinding->firstSourceLocation().offset
+ scriptBinding->lastSourceLocation().length;
AST::SourceLocation location = getLocation(scriptBinding);
QModelIndex index = m_model->enterProperty(asString(scriptBinding->qualifiedId), location);
QModelIndex index = m_model->enterProperty(asString(scriptBinding->qualifiedId), false, location);
m_nodeToIndex.insert(scriptBinding, index);
return true;
......@@ -131,6 +123,20 @@ private:
m_model->leaveProperty();
}
bool visit(AST::UiPublicMember *publicMember)
{
AST::SourceLocation location = getLocation(publicMember);
QModelIndex index = m_model->enterProperty(publicMember->name->asString(), true, location);
m_nodeToIndex.insert(publicMember, index);
return true;
}
void endVisit(AST::UiPublicMember * /*publicMember*/)
{
m_model->leaveProperty();
}
bool validElement(AST::UiObjectDefinition *objDef) {
// For 'Rectangle { id }', id is parsed as UiObjectDefinition ... Filter this out.
return objDef->qualifiedTypeNameId->name->asString().at(0).isUpper();
......@@ -178,6 +184,14 @@ private:
return id;
}
AST::SourceLocation getLocation(AST::UiObjectMember *objMember) {
AST::SourceLocation location;
location.offset = objMember->firstSourceLocation().offset;
location.length = objMember->lastSourceLocation().offset
- objMember->firstSourceLocation().offset
+ objMember->lastSourceLocation().length;
return location;
}
QmlOutlineModel *m_model;
LookupContext::Ptr m_context;
......@@ -232,11 +246,15 @@ void QmlOutlineModel::leaveElement()
leaveNode();
}
QModelIndex QmlOutlineModel::enterProperty(const QString &name, const AST::SourceLocation &sourceLocation)
QModelIndex QmlOutlineModel::enterProperty(const QString &name, bool isCustomProperty, const AST::SourceLocation &sourceLocation)
{
QStandardItem *item = enterNode(sourceLocation);
item->setText(name);
item->setIcon(m_icons->scriptBindingIcon());
if (isCustomProperty) {
item->setIcon(m_icons->publicMemberIcon());
} else {
item->setIcon(m_icons->scriptBindingIcon());
}
return item->index();
}
......
......@@ -22,10 +22,12 @@ public:
QmlJS::Document::Ptr document() const;
void update(QmlJS::Document::Ptr doc, const QmlJS::Snapshot &snapshot);
QModelIndex enterElement(const QString &typeName, const QString &id, const QIcon &icon, const QmlJS::AST::SourceLocation &location);
QModelIndex enterElement(const QString &typeName, const QString &id, const QIcon &icon,
const QmlJS::AST::SourceLocation &location);
void leaveElement();
QModelIndex enterProperty(const QString &name, const QmlJS::AST::SourceLocation &location);
QModelIndex enterProperty(const QString &name, bool isCustomProperty,
const QmlJS::AST::SourceLocation &location);
void leaveProperty();
signals:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment