fixes related to update of delta

This commit is contained in:
Lasse Holmstedt
2010-07-13 14:08:11 +02:00
committed by Olivier Goffart
parent d98977513d
commit 25b86926c7
3 changed files with 39 additions and 18 deletions

View File

@@ -143,7 +143,7 @@ Inspector::Inspector(QObject *parent)
connect(m_clientProxy, SIGNAL(aboutToReloadEngines()), SLOT(aboutToReloadEngines())); connect(m_clientProxy, SIGNAL(aboutToReloadEngines()), SLOT(aboutToReloadEngines()));
connect(m_clientProxy, SIGNAL(enginesChanged()), SLOT(updateEngineList())); connect(m_clientProxy, SIGNAL(enginesChanged()), SLOT(updateEngineList()));
connect(m_clientProxy, SIGNAL(aboutToDisconnect()), SLOT(disconnectWidgets())); connect(m_clientProxy, SIGNAL(aboutToDisconnect()), SLOT(disconnectWidgets()));
connect(m_clientProxy, SIGNAL(objectTreeUpdated(QDeclarativeDebugObjectReference)),SLOT(objectTreeUpdated(QDeclarativeDebugObjectReference))); connect(m_clientProxy, SIGNAL(objectTreeUpdated(QDeclarativeDebugObjectReference)), SLOT(objectTreeUpdated(QDeclarativeDebugObjectReference)));
connect(Debugger::DebuggerPlugin::instance(), connect(Debugger::DebuggerPlugin::instance(),
SIGNAL(stateChanged(int)), this, SLOT(debuggerStateChanged(int))); SIGNAL(stateChanged(int)), this, SLOT(debuggerStateChanged(int)));
@@ -632,5 +632,3 @@ void QmlJSInspector::Internal::Inspector::objectTreeUpdated(const QDeclarativeDe
m_textPreview->m_initialTable = allDebugIds; m_textPreview->m_initialTable = allDebugIds;
m_textPreview->m_debugIds.clear(); m_textPreview->m_debugIds.clear();
} }

View File

@@ -52,15 +52,30 @@ void QmlJSLiveTextPreview::updateDocuments()
SLOT(documentChanged(QmlJS::Document::Ptr))); SLOT(documentChanged(QmlJS::Document::Ptr)));
} }
QList<QDeclarativeDebugObjectReference > QmlJSLiveTextPreview::objectReferencesForOffset(quint32 offset) const
{
QList<QDeclarativeDebugObjectReference > result;
QHashIterator<QmlJS::AST::UiObjectMember*, QList<QDeclarativeDebugObjectReference > > iter(m_debugIds);
while(iter.hasNext()) {
iter.next();
QmlJS::AST::UiObjectMember *member = iter.key();
if (member->firstSourceLocation().offset == offset) {
result = iter.value();
break;
}
}
return result;
}
void QmlJSLiveTextPreview::changeSelectedElements(QList<int> offsets, const QString &wordAtCursor) void QmlJSLiveTextPreview::changeSelectedElements(QList<int> offsets, const QString &wordAtCursor)
{ {
if (!m_currentEditor) if (!m_currentEditor || !m_previousDoc)
return; return;
if (m_debugIds.isEmpty())
m_debugIds = m_initialTable.value(m_previousDoc->fileName());
ClientProxy *clientProxy = ClientProxy::instance(); ClientProxy *clientProxy = ClientProxy::instance();
QUrl url = QUrl::fromLocalFile(m_currentEditor.data()->file()->fileName());
QmlJS::Document::Ptr doc = modelManager()->snapshot().document(m_currentEditor.data()->file()->fileName());
ScriptBindingParser info(doc, clientProxy->objectReferences(url));
QDeclarativeDebugObjectReference objectRefUnderCursor; QDeclarativeDebugObjectReference objectRefUnderCursor;
@@ -73,22 +88,23 @@ void QmlJSLiveTextPreview::changeSelectedElements(QList<int> offsets, const QStr
} }
QList<QDeclarativeDebugObjectReference> selectedReferences; QList<QDeclarativeDebugObjectReference> selectedReferences;
bool containsReference = false;
foreach(int offset, offsets) { foreach(int offset, offsets) {
if (offset >= 0) { if (offset >= 0) {
QDeclarativeDebugObjectReference ref = info.objectReferenceForOffset(offset); QList<QDeclarativeDebugObjectReference> list = objectReferencesForOffset(offset);
if (ref.debugId() != -1)
selectedReferences << ref;
}
}
bool containsReference = false; if (!containsReference) {
foreach(const QDeclarativeDebugObjectReference &ref, selectedReferences) { foreach(const QDeclarativeDebugObjectReference &ref, list) {
if (ref.debugId() == objectRefUnderCursor.debugId()) { if (ref.debugId() == objectRefUnderCursor.debugId()) {
containsReference = true; containsReference = true;
break; break;
} }
} }
}
selectedReferences << list;
}
}
if (!containsReference && objectRefUnderCursor.debugId() != -1) if (!containsReference && objectRefUnderCursor.debugId() != -1)
selectedReferences << objectRefUnderCursor; selectedReferences << objectRefUnderCursor;
@@ -103,12 +119,15 @@ void QmlJSLiveTextPreview::setEditor(Core::IEditor *editor)
disconnect(m_currentEditor.data(), SIGNAL(selectedElementsChanged(QList<int>, QString)), this, SLOT(changeSelectedElements(QList<int>, QString))); disconnect(m_currentEditor.data(), SIGNAL(selectedElementsChanged(QList<int>, QString)), this, SLOT(changeSelectedElements(QList<int>, QString)));
m_currentEditor.clear(); m_currentEditor.clear();
m_previousDoc.clear(); m_previousDoc.clear();
m_debugIds.clear();
} }
if (editor) { if (editor) {
m_currentEditor = qobject_cast<QmlJSEditor::Internal::QmlJSTextEditor*>(editor->widget()); m_currentEditor = qobject_cast<QmlJSEditor::Internal::QmlJSTextEditor*>(editor->widget());
if (m_currentEditor) { if (m_currentEditor) {
connect(m_currentEditor.data(), SIGNAL(selectedElementsChanged(QList<int>, QString)), SLOT(changeSelectedElements(QList<int>, QString))); connect(m_currentEditor.data(), SIGNAL(selectedElementsChanged(QList<int>, QString)), SLOT(changeSelectedElements(QList<int>, QString)));
m_previousDoc = m_snapshot.document(editor->file()->fileName()); m_previousDoc = m_snapshot.document(editor->file()->fileName());
m_debugIds = m_initialTable.value(editor->file()->fileName());
} }
} }
} }
@@ -122,8 +141,11 @@ void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
return; return;
if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName()) { if (doc && m_previousDoc && doc->fileName() == m_previousDoc->fileName()) {
if (m_debugIds.isEmpty())
m_debugIds = m_initialTable.value(doc->fileName());
Delta delta; Delta delta;
delta(doc, m_previousDoc); m_debugIds = delta(m_previousDoc, doc, m_debugIds);
m_previousDoc = doc; m_previousDoc = doc;
} }
} }

View File

@@ -52,6 +52,7 @@ private slots:
void setEditor(Core::IEditor *editor); void setEditor(Core::IEditor *editor);
private: private:
QList<QDeclarativeDebugObjectReference > objectReferencesForOffset(quint32 offset) const;
QVariant castToLiteral(const QString &expression, QmlJS::AST::UiScriptBinding *scriptBinding); QVariant castToLiteral(const QString &expression, QmlJS::AST::UiScriptBinding *scriptBinding);
private: private: