| 24 | using namespace KDevelop; |
| 25 | |
| 26 | ClassWidget::ClassWidget(QWidget* parent, ClassBrowserPlugin* plugin) |
| 27 | : QWidget(parent) |
| 28 | , m_plugin(plugin) |
| 29 | , m_model(new ClassModel()) |
| 30 | , m_tree(new ClassTree(this, plugin)) |
| 31 | , m_searchLine(new QLineEdit(this)) |
| 32 | , m_filterTimer(new QTimer(this)) |
| 33 | { |
| 34 | setObjectName(QStringLiteral("Class Browser Tree")); |
| 35 | setWindowTitle(i18nc("@title:window", "Classes")); |
| 36 | setWindowIcon(QIcon::fromTheme(QStringLiteral("code-class"), windowIcon())); |
| 37 | |
| 38 | // Set tree in the plugin |
| 39 | m_plugin->setActiveClassTree(m_tree); |
| 40 | |
| 41 | // Set model in the tree view |
| 42 | m_tree->setModel(m_model); |
| 43 | m_tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); |
| 44 | m_tree->header()->setStretchLastSection(false); |
| 45 | |
| 46 | // We need notification in the model for the collapse/expansion of nodes. |
| 47 | connect(m_tree, &ClassTree::collapsed, |
| 48 | m_model, &ClassModel::collapsed); |
| 49 | connect(m_tree, &ClassTree::expanded, |
| 50 | m_model, &ClassModel::expanded); |
| 51 | |
| 52 | // Init filter timer |
| 53 | m_filterTimer->setSingleShot(true); |
| 54 | m_filterTimer->setInterval(500); |
| 55 | connect(m_filterTimer, &QTimer::timeout, this, [this]() { |
| 56 | m_tree->setCurrentIndex(QModelIndex()); |
| 57 | m_model->updateFilterString(m_filterText); |
| 58 | |
| 59 | if (m_filterText.isEmpty()) |
| 60 | m_tree->collapseAll(); |
| 61 | else |
| 62 | m_tree->expandToDepth(0); |
| 63 | }); |
| 64 | |
| 65 | // Init search box |
| 66 | m_searchLine->setClearButtonEnabled(true); |
| 67 | connect(m_searchLine, &QLineEdit::textChanged, this, [this](const QString& newFilter) { |
| 68 | m_filterText = newFilter; |
| 69 | m_filterTimer->start(); |
| 70 | }); |
| 71 | |
| 72 | auto* searchLabel = new QLabel(i18nc("@label:textbox", "S&earch:"), this); |
| 73 | searchLabel->setBuddy(m_searchLine); |
| 74 | |
| 75 | auto* layout = new QHBoxLayout(); |
| 76 | layout->setSpacing(5); |
| 77 | layout->setContentsMargins(0, 0, 0, 0); |
| 78 | layout->addWidget(searchLabel); |
| 79 | layout->addWidget(m_searchLine); |
| 80 | |
| 81 | setFocusProxy(m_searchLine); |
| 82 | |
| 83 | auto* vbox = new QVBoxLayout(this); |
nothing calls this directly
no test coverage detected