diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index cb07da00ce94b9103fc5b5883ca3575ea7ca856a..b68a55a3318fa0dc96a5994f9401a70500166916 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -832,6 +832,7 @@ void CPPEditor::onDocumentUpdated(Document::Ptr doc) } m_overviewModel->rebuild(doc); + OverviewTreeView *treeView = static_cast<OverviewTreeView *>(m_methodCombo->view()); treeView->sync(); updateMethodBoxIndexNow(); @@ -1092,14 +1093,9 @@ void CPPEditor::updateMethodBoxIndexNow() m_updateMethodBoxTimer->stop(); - int line = 0, column = 0; - convertPosition(position(), &line, &column); - - QModelIndex overviewModelIndex = indexForPosition(line, column); - emit overviewModelIndexChanged(overviewModelIndex); - + m_overviewModelIndex = QModelIndex(); //invalidate // ComboBox only let's you select top level indexes! - QModelIndex comboIndex = overviewModelIndex; + QModelIndex comboIndex = overviewModelIndex(); while (comboIndex.parent().isValid()) comboIndex = comboIndex.parent(); @@ -1444,8 +1440,15 @@ CPlusPlus::OverviewModel *CPPEditor::overviewModel() const return m_overviewModel; } -QModelIndex CPPEditor::overviewModelIndex() const +QModelIndex CPPEditor::overviewModelIndex() { + if (!m_overviewModelIndex.isValid()) { + int line = 0, column = 0; + convertPosition(position(), &line, &column); + m_overviewModelIndex = indexForPosition(line, column); + emit overviewModelIndexChanged(m_overviewModelIndex); + } + return m_overviewModelIndex; } @@ -2194,7 +2197,7 @@ SemanticInfo SemanticHighlighter::semanticInfo(const Source &source) return semanticInfo; } -QModelIndex CPPEditor::indexForPosition(int line, int column, const QModelIndex &rootIndex) +QModelIndex CPPEditor::indexForPosition(int line, int column, const QModelIndex &rootIndex) const { QModelIndex lastIndex = rootIndex; diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index 78730998b93992ade3c7bdf416db80142de07edf..0ff2801cbc959a1b9124958ee01b4bc921036970 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -168,7 +168,7 @@ public: SemanticInfo semanticInfo() const; CPlusPlus::OverviewModel *overviewModel() const; - QModelIndex overviewModelIndex() const; + QModelIndex overviewModelIndex(); virtual void paste(); // reimplemented from BaseTextEditor virtual void cut(); // reimplemented from BaseTextEditor @@ -265,7 +265,7 @@ private: bool openLink(const Link &link) { return openCppEditorAt(link); } bool openCppEditorAt(const Link &); - QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = QModelIndex()); + QModelIndex indexForPosition(int line, int column, const QModelIndex &rootIndex = QModelIndex()) const; static Link linkToSymbol(CPlusPlus::Symbol *symbol); diff --git a/src/plugins/cppeditor/cppoutline.cpp b/src/plugins/cppeditor/cppoutline.cpp index e0202231cd029780dcada9f878a78a4bf9196435..afb9f8e5e1ec5d729b690e375e36fbff89670b7b 100644 --- a/src/plugins/cppeditor/cppoutline.cpp +++ b/src/plugins/cppeditor/cppoutline.cpp @@ -90,7 +90,6 @@ void CppOutlineWidget::setCursorSynchronization(bool syncWithCursor) void CppOutlineWidget::modelUpdated() { m_treeView->expandAll(); - updateSelectionInTree(m_editor->overviewModelIndex()); } void CppOutlineWidget::updateSelectionInTree(const QModelIndex &index) diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index d12ffd30601096021a5f02c491a3c5f669a5e09b..47c7f6c19c49161173b3a59562071e241a62793f 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -697,8 +697,12 @@ QmlOutlineModel *QmlJSTextEditor::outlineModel() const return m_outlineModel; } -QModelIndex QmlJSTextEditor::outlineModelIndex() const +QModelIndex QmlJSTextEditor::outlineModelIndex() { + if (!m_outlineModelIndex.isValid()) { + m_outlineModelIndex = indexForPosition(position()); + emit outlineModelIndexChanged(m_outlineModelIndex); + } return m_outlineModelIndex; } @@ -822,10 +826,8 @@ void QmlJSTextEditor::jumpToMethod(int /*index*/) void QmlJSTextEditor::updateMethodBoxIndex() { - m_outlineModelIndex = indexForPosition(position()); - emit outlineModelIndexChanged(m_outlineModelIndex); - - QModelIndex comboIndex = m_outlineModelIndex; + m_outlineModelIndex = QModelIndex(); // invalidate + QModelIndex comboIndex = outlineModelIndex(); if (comboIndex.isValid()) { bool blocked = m_methodCombo->blockSignals(true); @@ -1364,8 +1366,6 @@ void QmlJSTextEditor::updateSemanticInfo(const SemanticInfo &semanticInfo) QTreeView *treeView = static_cast<QTreeView*>(m_methodCombo->view()); treeView->expandAll(); - // ComboBox only let's you select top level indexes for a QAbstractItemModel! - // therefore we've to fake a treeview by listview + indentation if (m_contextPane) { Node *newNode = m_semanticInfo.declaringMember(position()); @@ -1542,3 +1542,4 @@ void SemanticHighlighter::setModelManager(QmlJS::ModelManagerInterface *modelMan { m_modelManager = modelManager; } + diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 49910dbf545c7dc980f29c8fad75dea5ca15c598..9f29b6266ddfe1f9bf09fd3012aab8340f9f0730 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -217,7 +217,7 @@ public: bool isOutdated() const; QmlOutlineModel *outlineModel() const; - QModelIndex outlineModelIndex() const; + QModelIndex outlineModelIndex(); public slots: void followSymbolUnderCursor(); diff --git a/src/plugins/qmljseditor/qmljsoutline.cpp b/src/plugins/qmljseditor/qmljsoutline.cpp index a283ed8d16a80eba76b4a434c0638351b6fd1b27..8c8d83357d34928de59741b4cd39ae201b9a98a6 100644 --- a/src/plugins/qmljseditor/qmljsoutline.cpp +++ b/src/plugins/qmljseditor/qmljsoutline.cpp @@ -67,7 +67,6 @@ void QmlJSOutlineWidget::setCursorSynchronization(bool syncWithCursor) void QmlJSOutlineWidget::modelUpdated() { m_treeView->expandAll(); - updateSelectionInTree(m_editor.data()->outlineModelIndex()); } void QmlJSOutlineWidget::updateSelectionInTree(const QModelIndex &index)