File indexing completed on 2024-04-14 04:31:20

0001 /* This file is part of KDevelop
0002  *  Copyright 2011 Sebastien Rannou <mxs@sbrk.org>
0003  *  Copyright 2008 Hamish Rodda <rodda@kde.org>
0004  *  Copyright 2011 Lucas Sarie <lucas.sarie@gmail.com>
0005  *  Copyright 2017 Anton Anikin <anton@anikin.xyz>
0006 
0007  This program is free software; you can redistribute it and/or
0008  modify it under the terms of the GNU General Public
0009  License as published by the Free Software Foundation; either
0010  version 2 of the License, or (at your option) any later version.
0011 
0012  This program is distributed in the hope that it will be useful,
0013  but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  General Public License for more details.
0016 
0017  You should have received a copy of the GNU General Public License
0018  along with this program; see the file COPYING.  If not, write to
0019  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #include "cachegrind_view.h"
0024 #include "ui_cachegrind_view.h"
0025 
0026 #include "cachegrind_model.h"
0027 #include "debug.h"
0028 #include "utils.h"
0029 
0030 #include <interfaces/icore.h>
0031 #include <interfaces/idocumentcontroller.h>
0032 
0033 #include <QSortFilterProxyModel>
0034 
0035 namespace Valgrind
0036 {
0037 
0038 CachegrindView::CachegrindView(CachegrindFunctionsModel* model, QWidget* parent)
0039     : QWidget(parent)
0040     , ui(new Ui::CachegrindView)
0041 {
0042     ui->setupUi(this);
0043 
0044     Q_ASSERT(model);
0045     model->setParent(this);
0046 
0047     connect(ui->percenageValues, &QCheckBox::stateChanged,
0048             model, &CachegrindFunctionsModel::setPercentageValues);
0049     model->setPercentageValues(ui->percenageValues->checkState());
0050 
0051     auto functionsProxyModel = new QSortFilterProxyModel(this);
0052     functionsProxyModel->setSourceModel(model);
0053     functionsProxyModel->setSortRole(SortRole);
0054     functionsProxyModel->setFilterKeyColumn(-1);
0055     ui->functionsView->setModel(functionsProxyModel);
0056     ui->functionsView->setSortingEnabled(true);
0057     ui->functionsView->sortByColumn(1);
0058 
0059     ui->functionsView->header()->resizeSections(QHeaderView::ResizeToContents);
0060     ui->functionsView->header()->setStretchLastSection(false);
0061     ui->functionsView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
0062 
0063     connect(ui->searchEdit, &QLineEdit::textChanged,
0064             functionsProxyModel, &QSortFilterProxyModel::setFilterWildcard);
0065 
0066     connect(ui->functionsView->selectionModel(), &QItemSelectionModel::currentChanged,
0067             this, [=](const QModelIndex& currentProxyIndex, const QModelIndex&) {
0068 
0069         auto sourceIndex = functionsProxyModel->mapToSource(currentProxyIndex);
0070         auto item = static_cast<CachegrindFunction*>(sourceIndex.internalPointer());
0071 
0072         if (item) {
0073             ui->nameLabel->setText(item->functionName);
0074             ui->sourceLabel->setText(item->fileNames.join("\n\n"));
0075         } else {
0076             ui->nameLabel->clear();
0077             ui->sourceLabel->clear();
0078         }
0079     });
0080     ui->nameLabel->clear();
0081     ui->sourceLabel->clear();
0082 }
0083 
0084 CachegrindView::~CachegrindView() = default;
0085 
0086 }