Moved debug id -> AST mapping code to livepreview class

This commit is contained in:
Lasse Holmstedt
2010-07-14 17:38:04 +02:00
parent f8fc908460
commit 20902cf189
4 changed files with 72 additions and 68 deletions

View File

@@ -143,7 +143,6 @@ Inspector::Inspector(QObject *parent)
connect(m_clientProxy, SIGNAL(aboutToReloadEngines()), SLOT(aboutToReloadEngines()));
connect(m_clientProxy, SIGNAL(enginesChanged()), SLOT(updateEngineList()));
connect(m_clientProxy, SIGNAL(aboutToDisconnect()), SLOT(disconnectWidgets()));
connect(m_clientProxy, SIGNAL(objectTreeUpdated(QDeclarativeDebugObjectReference)), SLOT(objectTreeUpdated(QDeclarativeDebugObjectReference)));
connect(Debugger::DebuggerPlugin::instance(),
SIGNAL(stateChanged(int)), this, SLOT(debuggerStateChanged(int)));
@@ -569,66 +568,3 @@ bool Inspector::addQuotesForData(const QVariant &value) const
return false;
}
/*!
Associates the UiObjectMember* to their QDeclarativeDebugObjectReference.
*/
class MapObjectWithDebugReference : public Visitor
{
public:
virtual void endVisit(UiObjectDefinition *ast) ;
virtual void endVisit(UiObjectBinding *ast) ;
QDeclarativeDebugObjectReference root;
QString filename;
QHash<UiObjectMember *, QList<QDeclarativeDebugObjectReference> > result;
private:
void processRecursive(const QDeclarativeDebugObjectReference &object, UiObjectMember *ast);
};
void MapObjectWithDebugReference::endVisit(UiObjectDefinition* ast)
{
if (ast->qualifiedTypeNameId->name->asString().at(0).isUpper())
processRecursive(root, ast);
}
void MapObjectWithDebugReference::endVisit(UiObjectBinding* ast)
{
if (ast->qualifiedId->name->asString().at(0).isUpper())
processRecursive(root, ast);
}
void MapObjectWithDebugReference::processRecursive(const QDeclarativeDebugObjectReference& object, UiObjectMember* ast)
{
// If this is too slow, it can be speed up by indexing
// the QDeclarativeDebugObjectReference by filename/loc in a fist pass
SourceLocation loc = ast->firstSourceLocation();
if (object.source().lineNumber() == int(loc.startLine) && object.source().columnNumber() == int(loc.startColumn) && object.source().url().toLocalFile() == filename) {
result[ast] += object;
}
foreach (const QDeclarativeDebugObjectReference &it, object.children()) {
processRecursive(it, ast);
}
}
void QmlJSInspector::Internal::Inspector::objectTreeUpdated(const QDeclarativeDebugObjectReference &ref)
{
QmlJS::ModelManagerInterface *m = QmlJS::ModelManagerInterface::instance();
Snapshot snapshot = m->snapshot();
QHash<QString, QHash<UiObjectMember *, QList< QDeclarativeDebugObjectReference> > > allDebugIds;
foreach(const Document::Ptr &doc, snapshot) {
if (!doc->qmlProgram())
continue;
MapObjectWithDebugReference visitor;
visitor.root = ref;
QString filename = doc->fileName();
visitor.filename = filename;
doc->qmlProgram()->accept(&visitor);
allDebugIds[filename] = visitor.result;
}
//FIXME
m_textPreview->m_initialTable = allDebugIds;
m_textPreview->m_debugIds.clear();
}