forked from qt-creator/qt-creator
QmlOutline: Also show custom properties
Also show properties defined in the component, e.g. by 'property x', in the outline.
This commit is contained in:
@@ -2,5 +2,6 @@
|
|||||||
<qresource prefix="/qmljs">
|
<qresource prefix="/qmljs">
|
||||||
<file>images/element.png</file>
|
<file>images/element.png</file>
|
||||||
<file>images/property.png</file>
|
<file>images/property.png</file>
|
||||||
|
<file>images/publicmember.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class IconsPrivate
|
|||||||
public:
|
public:
|
||||||
QIcon elementIcon;
|
QIcon elementIcon;
|
||||||
QIcon propertyIcon;
|
QIcon propertyIcon;
|
||||||
|
QIcon publicMemberIcon;
|
||||||
QHash<QPair<QString,QString>,QIcon> iconHash;
|
QHash<QPair<QString,QString>,QIcon> iconHash;
|
||||||
QString resourcePath;
|
QString resourcePath;
|
||||||
};
|
};
|
||||||
@@ -60,6 +61,7 @@ Icons::Icons()
|
|||||||
{
|
{
|
||||||
m_d->elementIcon = QIcon(QLatin1String(":/qmljs/images/element.png"));
|
m_d->elementIcon = QIcon(QLatin1String(":/qmljs/images/element.png"));
|
||||||
m_d->propertyIcon = QIcon(QLatin1String(":/qmljs/images/property.png"));
|
m_d->propertyIcon = QIcon(QLatin1String(":/qmljs/images/property.png"));
|
||||||
|
m_d->publicMemberIcon = QIcon(QLatin1String(":/qmljs/images/publicmember.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Icons::~Icons()
|
Icons::~Icons()
|
||||||
@@ -134,3 +136,8 @@ QIcon Icons::scriptBindingIcon() const
|
|||||||
{
|
{
|
||||||
return m_d->propertyIcon;
|
return m_d->propertyIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QIcon Icons::publicMemberIcon() const
|
||||||
|
{
|
||||||
|
return m_d->publicMemberIcon;
|
||||||
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public:
|
|||||||
|
|
||||||
QIcon objectDefinitionIcon() const;
|
QIcon objectDefinitionIcon() const;
|
||||||
QIcon scriptBindingIcon() const;
|
QIcon scriptBindingIcon() const;
|
||||||
|
QIcon publicMemberIcon() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Icons();
|
Icons();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using namespace QmlJS;
|
|||||||
using namespace QmlJSEditor::Internal;
|
using namespace QmlJSEditor::Internal;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
debug = false
|
debug = true
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
@@ -85,11 +85,7 @@ private:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
AST::SourceLocation location;
|
AST::SourceLocation location = getLocation(objDef);
|
||||||
location.offset = objDef->firstSourceLocation().offset;
|
|
||||||
location.length = objDef->lastSourceLocation().offset
|
|
||||||
- objDef->firstSourceLocation().offset
|
|
||||||
+ objDef->lastSourceLocation().length;
|
|
||||||
|
|
||||||
const QString typeName = asString(objDef->qualifiedTypeNameId);
|
const QString typeName = asString(objDef->qualifiedTypeNameId);
|
||||||
|
|
||||||
@@ -114,13 +110,9 @@ private:
|
|||||||
|
|
||||||
bool visit(AST::UiScriptBinding *scriptBinding)
|
bool visit(AST::UiScriptBinding *scriptBinding)
|
||||||
{
|
{
|
||||||
AST::SourceLocation location;
|
AST::SourceLocation location = getLocation(scriptBinding);
|
||||||
location.offset = scriptBinding->firstSourceLocation().offset;
|
|
||||||
location.length = scriptBinding->lastSourceLocation().offset
|
|
||||||
- scriptBinding->firstSourceLocation().offset
|
|
||||||
+ scriptBinding->lastSourceLocation().length;
|
|
||||||
|
|
||||||
QModelIndex index = m_model->enterProperty(asString(scriptBinding->qualifiedId), location);
|
QModelIndex index = m_model->enterProperty(asString(scriptBinding->qualifiedId), false, location);
|
||||||
m_nodeToIndex.insert(scriptBinding, index);
|
m_nodeToIndex.insert(scriptBinding, index);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -131,6 +123,20 @@ private:
|
|||||||
m_model->leaveProperty();
|
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) {
|
bool validElement(AST::UiObjectDefinition *objDef) {
|
||||||
// For 'Rectangle { id }', id is parsed as UiObjectDefinition ... Filter this out.
|
// For 'Rectangle { id }', id is parsed as UiObjectDefinition ... Filter this out.
|
||||||
return objDef->qualifiedTypeNameId->name->asString().at(0).isUpper();
|
return objDef->qualifiedTypeNameId->name->asString().at(0).isUpper();
|
||||||
@@ -178,6 +184,14 @@ private:
|
|||||||
return id;
|
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;
|
QmlOutlineModel *m_model;
|
||||||
LookupContext::Ptr m_context;
|
LookupContext::Ptr m_context;
|
||||||
@@ -232,11 +246,15 @@ void QmlOutlineModel::leaveElement()
|
|||||||
leaveNode();
|
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);
|
QStandardItem *item = enterNode(sourceLocation);
|
||||||
item->setText(name);
|
item->setText(name);
|
||||||
|
if (isCustomProperty) {
|
||||||
|
item->setIcon(m_icons->publicMemberIcon());
|
||||||
|
} else {
|
||||||
item->setIcon(m_icons->scriptBindingIcon());
|
item->setIcon(m_icons->scriptBindingIcon());
|
||||||
|
}
|
||||||
return item->index();
|
return item->index();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,12 @@ public:
|
|||||||
QmlJS::Document::Ptr document() const;
|
QmlJS::Document::Ptr document() const;
|
||||||
void update(QmlJS::Document::Ptr doc, const QmlJS::Snapshot &snapshot);
|
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();
|
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();
|
void leaveProperty();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
Reference in New Issue
Block a user