summaryrefslogtreecommitdiff
path: root/src/plugins/cppeditor/cppoutline.cpp
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2022-08-17 13:26:49 +0200
committerDavid Schulz <david.schulz@qt.io>2022-08-19 05:04:29 +0000
commit33001a866f400c03041ecbad2b5de630a7ca697e (patch)
tree09e1ff25c5f63fbc7fe88ff8dee273a90f42bd9f /src/plugins/cppeditor/cppoutline.cpp
parent7c7fdf6460a5bd07fa26544b48d9224dfe228427 (diff)
downloadqt-creator-33001a866f400c03041ecbad2b5de630a7ca697e.tar.gz
CppEditor: remove dependencies between different outline views
Change-Id: If371811ac236c971d21815ef8738df5a169865e3 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cppoutline.cpp')
-rw-r--r--src/plugins/cppeditor/cppoutline.cpp52
1 files changed, 39 insertions, 13 deletions
diff --git a/src/plugins/cppeditor/cppoutline.cpp b/src/plugins/cppeditor/cppoutline.cpp
index 1e298d589f..63696504b4 100644
--- a/src/plugins/cppeditor/cppoutline.cpp
+++ b/src/plugins/cppeditor/cppoutline.cpp
@@ -99,13 +99,13 @@ Qt::DropActions CppOutlineFilterModel::supportedDragActions() const
CppOutlineWidget::CppOutlineWidget(CppEditorWidget *editor) :
m_editor(editor),
m_treeView(new CppOutlineTreeView(this)),
+ m_model(&m_editor->cppEditorDocument()->outlineModel()),
+ m_proxyModel(new CppOutlineFilterModel(*m_model, this)),
m_enableCursorSync(true),
m_blockCursorSync(false),
m_sorted(false)
{
- OverviewModel *model = &m_editor->cppEditorDocument()->outlineModel();
- m_proxyModel = new CppOutlineFilterModel(*model, this);
- m_proxyModel->setSourceModel(model);
+ m_proxyModel->setSourceModel(m_model);
auto *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
@@ -117,13 +117,19 @@ CppOutlineWidget::CppOutlineWidget(CppEditorWidget *editor) :
m_treeView->setSortingEnabled(true);
setFocusProxy(m_treeView);
- connect(model, &QAbstractItemModel::modelReset, this, &CppOutlineWidget::modelUpdated);
+ connect(m_model, &QAbstractItemModel::modelReset, this, &CppOutlineWidget::modelUpdated);
modelUpdated();
- connect(m_editor->outline(), &CppEditorOutline::modelIndexChanged,
- this, &CppOutlineWidget::updateSelectionInTree);
connect(m_treeView, &QAbstractItemView::activated,
this, &CppOutlineWidget::onItemActivated);
+ connect(editor, &QPlainTextEdit::cursorPositionChanged, this, [this] {
+ if (m_model->rootItem()->hasChildren())
+ updateIndex();
+ });
+
+ m_updateIndexTimer.setSingleShot(true);
+ m_updateIndexTimer.setInterval(500);
+ connect(&m_updateIndexTimer, &QTimer::timeout, this, &CppOutlineWidget::updateIndexNow);
}
QList<QAction*> CppOutlineWidget::filterMenuActions() const
@@ -135,7 +141,7 @@ void CppOutlineWidget::setCursorSynchronization(bool syncWithCursor)
{
m_enableCursorSync = syncWithCursor;
if (m_enableCursorSync)
- updateSelectionInTree(m_editor->outline()->modelIndex());
+ updateIndexNow();
}
bool CppOutlineWidget::isSorted() const
@@ -164,17 +170,37 @@ void CppOutlineWidget::modelUpdated()
m_treeView->expandAll();
}
-void CppOutlineWidget::updateSelectionInTree(const QModelIndex &index)
+void CppOutlineWidget::updateIndex()
+{
+ m_updateIndexTimer.start();
+}
+
+void CppOutlineWidget::updateIndexNow()
{
if (!syncCursor())
return;
- QModelIndex proxyIndex = m_proxyModel->mapFromSource(index);
+ const auto revision = static_cast<unsigned>(m_editor->document()->revision());
+ if (m_model->editorRevision() != revision) {
+ m_editor->cppEditorDocument()->updateOutline();
+ m_updateIndexTimer.start();
+ return;
+ }
+
+ m_updateIndexTimer.stop();
+
+ int line = 0, column = 0;
+ m_editor->convertPosition(m_editor->position(), &line, &column);
+ QModelIndex index = m_model->indexForPosition(line, column);
+
+ if (index.isValid()) {
+ m_blockCursorSync = true;
+ QModelIndex proxyIndex = m_proxyModel->mapFromSource(index);
+ m_treeView->setCurrentIndex(proxyIndex);
+ m_treeView->scrollTo(proxyIndex);
+ m_blockCursorSync = false;
+ }
- m_blockCursorSync = true;
- m_treeView->setCurrentIndex(proxyIndex);
- m_treeView->scrollTo(proxyIndex);
- m_blockCursorSync = false;
}
void CppOutlineWidget::updateTextCursor(const QModelIndex &proxyIndex)