From 8d48c511754583db3b7b0fb1a7021179f2eaa818 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 13 Jul 2010 11:18:42 +0200 Subject: [PATCH] QmlJSEditor: Delay update of outline by 150 ms --- src/plugins/qmljseditor/qmljseditor.cpp | 37 ++++++++++++++++----- src/plugins/qmljseditor/qmljseditor.h | 2 ++ src/plugins/qmljseditor/qmloutlinemodel.cpp | 7 ++++ src/plugins/qmljseditor/qmloutlinemodel.h | 2 ++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index b50b43b17a8..920cf0cfe9f 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -80,7 +80,7 @@ enum { UPDATE_DOCUMENT_DEFAULT_INTERVAL = 50, UPDATE_USES_DEFAULT_INTERVAL = 150, - UPDATE_METHOD_BOX_INTERVAL = 150 + UPDATE_OUTLINE_INTERVAL = 150 // msecs after new semantic info has been arrived / cursor has moved }; using namespace QmlJS; @@ -648,8 +648,13 @@ QmlJSTextEditor::QmlJSTextEditor(QWidget *parent) : connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument())); connect(this, SIGNAL(textChanged()), this, SLOT(updateUses())); + m_updateOutlineTimer = new QTimer(this); + m_updateOutlineTimer->setInterval(UPDATE_OUTLINE_INTERVAL); + m_updateOutlineTimer->setSingleShot(true); + connect(m_updateOutlineTimer, SIGNAL(timeout()), this, SLOT(updateOutlineNow())); + m_updateMethodBoxTimer = new QTimer(this); - m_updateMethodBoxTimer->setInterval(UPDATE_METHOD_BOX_INTERVAL); + m_updateMethodBoxTimer->setInterval(UPDATE_OUTLINE_INTERVAL); m_updateMethodBoxTimer->setSingleShot(true); connect(m_updateMethodBoxTimer, SIGNAL(timeout()), this, SLOT(updateMethodBoxIndex())); @@ -804,6 +809,8 @@ void QmlJSTextEditor::onDocumentUpdated(QmlJS::Document::Ptr doc) const SemanticHighlighter::Source source = currentSource(/*force = */ true); m_semanticHighlighter->rehighlight(source); + + m_updateOutlineTimer->start(); } else { // show parsing errors QList selections; @@ -830,12 +837,29 @@ void QmlJSTextEditor::jumpToMethod(int /*index*/) setFocus(); } -void QmlJSTextEditor::updateMethodBoxIndex() +void QmlJSTextEditor::updateOutlineNow() { - if (!m_semanticInfo.document) + const Snapshot snapshot = m_modelManager->snapshot(); + Document::Ptr document = snapshot.document(file()->fileName()); + + if (!document) return; - if (m_semanticInfo.document->editorRevision() != editorRevision()) { + if (document->editorRevision() != editorRevision()) { + m_updateOutlineTimer->start(); + return; + } + + m_outlineModel->update(document); + updateMethodBoxIndex(); +} + +void QmlJSTextEditor::updateMethodBoxIndex() +{ + if (!m_outlineModel->document()) + return; + + if (m_outlineModel->document()->editorRevision() != editorRevision()) { m_updateMethodBoxTimer->start(); return; } @@ -1375,9 +1399,6 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) FindDeclarations findDeclarations; m_semanticInfo.declarations = findDeclarations(doc->ast()); - m_outlineModel->update(doc); - updateMethodBoxIndex(); - QTreeView *treeView = static_cast(m_methodCombo->view()); treeView->expandAll(); diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 763481a8f7d..514b7f62693 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -233,6 +233,7 @@ private slots: void updateDocument(); void updateDocumentNow(); void jumpToMethod(int index); + void updateOutlineNow(); void updateMethodBoxIndex(); void updateMethodBoxToolTip(); void updateFileName(); @@ -278,6 +279,7 @@ private: QTimer *m_updateDocumentTimer; QTimer *m_updateUsesTimer; QTimer *m_semanticRehighlightTimer; + QTimer *m_updateOutlineTimer; QTimer *m_updateMethodBoxTimer; QComboBox *m_methodCombo; QmlOutlineModel *m_outlineModel; diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp index f2bff31f320..ae39f23f08a 100644 --- a/src/plugins/qmljseditor/qmloutlinemodel.cpp +++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp @@ -140,8 +140,15 @@ QmlOutlineModel::QmlOutlineModel(QObject *parent) : { } +QmlJS::Document::Ptr QmlOutlineModel::document() const +{ + return m_document; +} + void QmlOutlineModel::update(QmlJS::Document::Ptr doc) { + m_document = doc; + m_treePos.clear(); m_treePos.append(0); m_currentItem = invisibleRootItem(); diff --git a/src/plugins/qmljseditor/qmloutlinemodel.h b/src/plugins/qmljseditor/qmloutlinemodel.h index 8df66e4db5b..f2e914a36c7 100644 --- a/src/plugins/qmljseditor/qmloutlinemodel.h +++ b/src/plugins/qmljseditor/qmloutlinemodel.h @@ -19,6 +19,7 @@ public: QmlOutlineModel(QObject *parent = 0); + QmlJS::Document::Ptr document() const; void update(QmlJS::Document::Ptr doc); QModelIndex enterElement(const QString &typeName, const QString &id, const QmlJS::AST::SourceLocation &location); @@ -36,6 +37,7 @@ private: QStandardItem *parentItem(); + QmlJS::Document::Ptr m_document; QList m_treePos; QStandardItem *m_currentItem; QmlJS::Icons m_icons;