File: classwidget.cpp

package info (click to toggle)
kdevelop 4%3A5.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 57,892 kB
  • sloc: cpp: 278,773; javascript: 3,558; python: 3,385; sh: 1,317; ansic: 689; xml: 273; php: 95; makefile: 40; lisp: 13; sed: 12
file content (110 lines) | stat: -rw-r--r-- 3,466 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * KDevelop Class viewer
 *
 * Copyright 2006 Adam Treat <treat@kde.org>
 * Copyright (c) 2006-2007 Hamish Rodda <rodda@kde.org>
 * Copyright 2009 Lior Mualem <lior.m.kde@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Library General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "classwidget.h"

#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QHeaderView>

#include <KLocalizedString>
#include <QLineEdit>
#include <QTimer>

#include "language/classmodel/classmodel.h"
#include "classtree.h"
#include "classbrowserplugin.h"

using namespace KDevelop;

ClassWidget::ClassWidget(QWidget* parent, ClassBrowserPlugin* plugin)
    : QWidget(parent)
    , m_plugin(plugin)
    , m_model(new ClassModel())
    , m_tree(new ClassTree(this, plugin))
    , m_searchLine(new QLineEdit(this))
    , m_filterTimer(new QTimer(this))
{
    setObjectName(QStringLiteral("Class Browser Tree"));
    setWindowTitle(i18nc("@title:window", "Classes"));
    setWindowIcon(QIcon::fromTheme(QStringLiteral("code-class"), windowIcon()));

    // Set tree in the plugin
    m_plugin->setActiveClassTree(m_tree);

    // Set model in the tree view
    m_tree->setModel(m_model);
    m_tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
    m_tree->header()->setStretchLastSection(false);

    // We need notification in the model for the collapse/expansion of nodes.
    connect(m_tree, &ClassTree::collapsed,
            m_model, &ClassModel::collapsed);
    connect(m_tree, &ClassTree::expanded,
            m_model, &ClassModel::expanded);

    // Init filter timer
    m_filterTimer->setSingleShot(true);
    m_filterTimer->setInterval(500);
    connect(m_filterTimer, &QTimer::timeout, this, [this]() {
        m_tree->setCurrentIndex(QModelIndex());
        m_model->updateFilterString(m_filterText);

        if (m_filterText.isEmpty())
            m_tree->collapseAll();
        else
            m_tree->expandToDepth(0);
    });

    // Init search box
    m_searchLine->setClearButtonEnabled(true);
    connect(m_searchLine, &QLineEdit::textChanged, this, [this](const QString& newFilter) {
        m_filterText = newFilter;
        m_filterTimer->start();
    });

    auto* searchLabel = new QLabel(i18nc("@label:textbox", "S&earch:"), this);
    searchLabel->setBuddy(m_searchLine);

    auto* layout = new QHBoxLayout();
    layout->setSpacing(5);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(searchLabel);
    layout->addWidget(m_searchLine);

    setFocusProxy(m_searchLine);

    auto* vbox = new QVBoxLayout(this);
    vbox->setContentsMargins(0, 0, 0, 0);
    vbox->addLayout(layout);
    vbox->addWidget(m_tree);
    setLayout(vbox);

    setWhatsThis(i18nc("@info:whatsthis", "Class Browser"));
}

ClassWidget::~ClassWidget()
{
    delete m_model;
}