File indexing completed on 2024-05-05 05:51:37
0001 /* 0002 SPDX-FileCopyrightText: 2020 Waqar Ahmed <waqar.17a@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "gotosymboltreeview.h" 0007 0008 #include <KTextEditor/Cursor> 0009 #include <KTextEditor/MainWindow> 0010 #include <KTextEditor/View> 0011 0012 GotoSymbolTreeView::GotoSymbolTreeView(KTextEditor::MainWindow *mainWindow, QWidget *parent) 0013 : QTreeView(parent) 0014 , m_mainWindow(mainWindow) 0015 { 0016 setSelectionBehavior(QAbstractItemView::SelectRows); 0017 setSelectionMode(QAbstractItemView::SingleSelection); 0018 setTextElideMode(Qt::ElideRight); 0019 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 0020 0021 setHeaderHidden(true); 0022 setRootIsDecorated(false); 0023 } 0024 0025 int GotoSymbolTreeView::sizeHintWidth() const 0026 { 0027 return sizeHintForColumn(0); 0028 } 0029 0030 void GotoSymbolTreeView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) 0031 { 0032 if (globalMode) { 0033 return QTreeView::currentChanged(current, previous); 0034 } 0035 0036 int line = current.data(Qt::UserRole).toInt(); 0037 KTextEditor::Cursor c(--line, 0); 0038 if (c.isValid()) { 0039 auto view = m_mainWindow->activeView(); 0040 if (view) { 0041 view->setCursorPosition(c); 0042 } 0043 } 0044 0045 return QTreeView::currentChanged(current, previous); 0046 } 0047 0048 #include "moc_gotosymboltreeview.cpp"