| 22 | using namespace KDevelop; |
| 23 | |
| 24 | OutlineWidget::OutlineWidget(QWidget* parent, OutlineViewPlugin* plugin) |
| 25 | : QWidget(parent) |
| 26 | , m_plugin(plugin) |
| 27 | , m_model(new OutlineModel(this)) |
| 28 | , m_tree(new QTreeView(this)) |
| 29 | , m_proxy(new QSortFilterProxyModel(this)) |
| 30 | , m_filter(new QLineEdit(this)) |
| 31 | { |
| 32 | setObjectName(QStringLiteral("Outline View")); |
| 33 | setWindowTitle(i18nc("@title:window", "Outline")); |
| 34 | setWindowIcon(QIcon::fromTheme(QStringLiteral("code-class"), windowIcon())); //TODO: better icon? |
| 35 | |
| 36 | m_proxy->setRecursiveFilteringEnabled(true); |
| 37 | m_proxy->setSourceModel(m_model); |
| 38 | m_proxy->setFilterCaseSensitivity(Qt::CaseInsensitive); |
| 39 | m_proxy->setSortCaseSensitivity(Qt::CaseInsensitive); |
| 40 | m_proxy->setDynamicSortFilter(false); |
| 41 | |
| 42 | m_tree->setModel(m_proxy); |
| 43 | m_tree->setHeaderHidden(true); |
| 44 | |
| 45 | // sort action |
| 46 | m_sortAlphabeticallyAction = new QAction(QIcon::fromTheme(QStringLiteral("view-sort-ascending")), |
| 47 | i18nc("@action", "Sort Alphabetically"), this); |
| 48 | m_sortAlphabeticallyAction->setToolTip(i18nc("@info:tooltip", "Sort items alphabetically")); |
| 49 | m_sortAlphabeticallyAction->setCheckable(true); |
| 50 | connect(m_sortAlphabeticallyAction, &QAction::triggered, this, [this](bool sort) { |
| 51 | // calling sort with -1 will restore the original order |
| 52 | m_proxy->sort(sort ? 0 : -1, Qt::AscendingOrder); |
| 53 | m_sortAlphabeticallyAction->setChecked(sort); |
| 54 | }); |
| 55 | addAction(m_sortAlphabeticallyAction); |
| 56 | |
| 57 | // filter |
| 58 | connect(m_filter, &QLineEdit::textChanged, m_proxy, &QSortFilterProxyModel::setFilterFixedString); |
| 59 | connect(m_tree, &QTreeView::activated, this, &OutlineWidget::activated); |
| 60 | m_filter->setPlaceholderText(i18nc("@info:placeholder", "Filter...")); |
| 61 | auto filterAction = new QWidgetAction(this); |
| 62 | filterAction->setDefaultWidget(m_filter); |
| 63 | addAction(filterAction); |
| 64 | |
| 65 | setFocusProxy(m_filter); |
| 66 | |
| 67 | auto* vbox = new QVBoxLayout(this); |
| 68 | vbox->setContentsMargins(0, 0, 0, 0); |
| 69 | vbox->addWidget(m_tree); |
| 70 | setLayout(vbox); |
| 71 | expandFirstLevel(); |
| 72 | connect(m_model, &QAbstractItemModel::modelReset, this, &OutlineWidget::expandFirstLevel); |
| 73 | } |
| 74 | |
| 75 | void OutlineWidget::activated(const QModelIndex& index) |
| 76 | { |
nothing calls this directly
no test coverage detected