From db358f9ebcdc3751346d63acbf0f4a11140dac92 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Wed, 25 Jun 2014 17:06:55 -0400 Subject: CppEditor: Fix jump behavior in outline sidebar Before, we jumped to a symbol as soon as the selection changed, which was problematic: * It was inconsistent to other outlines (e.g. class view, project explorer) * Using the Up/Down keys in the sidebar immediately jumped to the symbol in the editor, thus polluting the editor history. Now we jump to a symbol if the corresponding item was explicitly activated (QAbstractItemView::activated() signal). There was also another strange issue: If "Synchronize with Editor" was de-activated, nothing happened upon activation/selection of an item. Now "Synchronize with Editor" means to update the selection in the side bar if the cursor position changes in the editor (one direction only). Task-number: QTCREATORBUG-12412 Change-Id: I8d9191d5fa8e229723194dcf30081e144debecbb Reviewed-by: Eike Ziller Reviewed-by: Erik Verbruggen --- src/plugins/cppeditor/cppoutline.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/plugins/cppeditor/cppoutline.cpp') diff --git a/src/plugins/cppeditor/cppoutline.cpp b/src/plugins/cppeditor/cppoutline.cpp index 31c6cdee69..145d9606cf 100644 --- a/src/plugins/cppeditor/cppoutline.cpp +++ b/src/plugins/cppeditor/cppoutline.cpp @@ -113,10 +113,8 @@ CppOutlineWidget::CppOutlineWidget(CPPEditorWidget *editor) : connect(m_editor->outline(), SIGNAL(modelIndexChanged(QModelIndex)), this, SLOT(updateSelectionInTree(QModelIndex))); - connect(m_treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SLOT(updateSelectionInText(QItemSelection))); connect(m_treeView, SIGNAL(activated(QModelIndex)), - this, SLOT(focusEditor())); + this, SLOT(onItemActivated(QModelIndex))); } QList CppOutlineWidget::filterMenuActions() const @@ -152,17 +150,6 @@ void CppOutlineWidget::updateSelectionInTree(const QModelIndex &index) m_blockCursorSync = false; } -void CppOutlineWidget::updateSelectionInText(const QItemSelection &selection) -{ - if (!syncCursor()) - return; - - if (!selection.indexes().isEmpty()) { - QModelIndex proxyIndex = selection.indexes().first(); - updateTextCursor(proxyIndex); - } -} - void CppOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex) { QModelIndex index = m_proxyModel->mapToSource(proxyIndex); @@ -182,8 +169,12 @@ void CppOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex) } } -void CppOutlineWidget::focusEditor() +void CppOutlineWidget::onItemActivated(const QModelIndex &index) { + if (!index.isValid()) + return; + + updateTextCursor(index); m_editor->setFocus(); } -- cgit v1.2.1