forked from qt-creator/qt-creator
qml inspector now shows correct categories for custom properties
Also, a class name is added in qmjs::bind so that we have a class name for custom properties defined inside a component.
This commit is contained in:
@@ -250,6 +250,14 @@ QString ObjectPropertiesView::propertyBaseClass(const QDeclarativeDebugObjectRef
|
||||
|
||||
PropertyTypeFinder find(document, snapshot, modelManager->importPaths());
|
||||
QString baseClassName = find(object.source().lineNumber(), object.source().columnNumber(), property.name());
|
||||
|
||||
if (baseClassName.isEmpty()) {
|
||||
if (!object.idString().isEmpty())
|
||||
baseClassName = object.idString();
|
||||
else
|
||||
baseClassName = QString("<%1>").arg(object.className());
|
||||
}
|
||||
|
||||
depth = find.depth();
|
||||
|
||||
return baseClassName;
|
||||
|
||||
@@ -14,7 +14,9 @@ PropertyTypeFinder::PropertyTypeFinder(QmlJS::Document::Ptr doc, QmlJS::Snapshot
|
||||
, m_snapshot(snapshot)
|
||||
, m_engine()
|
||||
, m_context(&m_engine)
|
||||
, m_link(&m_context, doc, snapshot, importPaths), m_depth(0)
|
||||
, m_link(&m_context, doc, snapshot, importPaths)
|
||||
, m_scopeBuilder(doc, &m_context)
|
||||
, m_depth(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -22,20 +24,11 @@ QString PropertyTypeFinder::operator()(int objectLine, int objectColumn, const Q
|
||||
{
|
||||
m_objectLine = objectLine;
|
||||
m_objectColumn = objectColumn;
|
||||
m_typeNameId = 0;
|
||||
m_propertyName = propertyName;
|
||||
m_definingClass.clear();
|
||||
|
||||
Node::accept(m_doc->ast(), this);
|
||||
if (m_typeNameId) {
|
||||
for (const ObjectValue *iter = m_context.lookupType(m_doc.data(), m_typeNameId); iter; iter = iter->prototype(&m_context)) {
|
||||
if (iter->lookupMember(propertyName, &m_context, false)) {
|
||||
// gotcha!
|
||||
return iter->className();
|
||||
}
|
||||
++m_depth;
|
||||
}
|
||||
}
|
||||
//### Eep: we didn't find it...
|
||||
return QString();
|
||||
return m_definingClass;
|
||||
}
|
||||
|
||||
int PropertyTypeFinder::depth() const
|
||||
@@ -45,14 +38,28 @@ int PropertyTypeFinder::depth() const
|
||||
|
||||
bool PropertyTypeFinder::visit(QmlJS::AST::UiObjectBinding *ast)
|
||||
{
|
||||
m_scopeBuilder.push(ast);
|
||||
|
||||
return check(ast->qualifiedTypeNameId);
|
||||
}
|
||||
|
||||
bool PropertyTypeFinder::visit(QmlJS::AST::UiObjectDefinition *ast)
|
||||
{
|
||||
m_scopeBuilder.push(ast);
|
||||
|
||||
return check(ast->qualifiedTypeNameId);
|
||||
}
|
||||
|
||||
void PropertyTypeFinder::endVisit(QmlJS::AST::UiObjectBinding * /*ast*/)
|
||||
{
|
||||
m_scopeBuilder.pop();
|
||||
}
|
||||
|
||||
void PropertyTypeFinder::endVisit(QmlJS::AST::UiObjectDefinition * /*ast*/)
|
||||
{
|
||||
m_scopeBuilder.pop();
|
||||
}
|
||||
|
||||
bool PropertyTypeFinder::check(QmlJS::AST::UiQualifiedId *qId)
|
||||
{
|
||||
if (!qId)
|
||||
@@ -61,7 +68,14 @@ bool PropertyTypeFinder::check(QmlJS::AST::UiQualifiedId *qId)
|
||||
if (qId->identifierToken.startLine == m_objectLine
|
||||
&& qId->identifierToken.startColumn == m_objectColumn) {
|
||||
// got it!
|
||||
m_typeNameId = qId;
|
||||
for (const ObjectValue *iter = m_context.scopeChain().qmlScopeObjects.last(); iter; iter = iter->prototype(&m_context)) {
|
||||
|
||||
if (iter->lookupMember(m_propertyName, &m_context, false)) {
|
||||
m_definingClass = iter->className();
|
||||
return true;
|
||||
}
|
||||
++m_depth;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <qmljs/parser/qmljsastvisitor_p.h>
|
||||
#include <qmljs/qmljsinterpreter.h>
|
||||
#include <qmljs/qmljslink.h>
|
||||
#include <qmljs/qmljsscopebuilder.h>
|
||||
|
||||
namespace Qml {
|
||||
namespace Internal {
|
||||
@@ -18,10 +19,13 @@ public:
|
||||
int depth() const;
|
||||
protected:
|
||||
using QmlJS::AST::Visitor::visit;
|
||||
using QmlJS::AST::Visitor::endVisit;
|
||||
|
||||
virtual bool visit(QmlJS::AST::UiObjectBinding *ast);
|
||||
virtual bool visit(QmlJS::AST::UiObjectDefinition *ast);
|
||||
|
||||
virtual void endVisit(QmlJS::AST::UiObjectBinding *ast);
|
||||
virtual void endVisit(QmlJS::AST::UiObjectDefinition *ast);
|
||||
|
||||
private:
|
||||
bool check(QmlJS::AST::UiQualifiedId *qId);
|
||||
@@ -32,10 +36,12 @@ private:
|
||||
QmlJS::Interpreter::Engine m_engine;
|
||||
QmlJS::Interpreter::Context m_context;
|
||||
QmlJS::Link m_link;
|
||||
QmlJS::ScopeBuilder m_scopeBuilder;
|
||||
|
||||
quint32 m_objectLine;
|
||||
quint32 m_objectColumn;
|
||||
QmlJS::AST::UiQualifiedId *m_typeNameId;
|
||||
QString m_definingClass;
|
||||
QString m_propertyName;
|
||||
quint8 m_depth;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user