Skip to content

Commit

Permalink
add filtering to diff view
Browse files Browse the repository at this point in the history
  • Loading branch information
lievenhey committed Nov 5, 2021
1 parent 50d15b4 commit 04a1546
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/diffviewwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@

#include "diffviewwidget.h"

#include <QAction>
#include <QDoubleSpinBox>
#include <QLabel>
#include <QMenu>
#include <QProgressBar>

#include <kddockwidgets/DockWidget.h>
#include <kddockwidgets/MainWindow.h>

#include "diffviewproxy.h"
#include "dockwidgetsetup.h"
#include "filterandzoomstack.h"
#include "models/treemodel.h"
Expand All @@ -45,14 +52,50 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
, ui(new Ui::ResultsDiffPage)
, m_parserA(new PerfParser(this))
, m_parserB(new PerfParser(this))
, m_filterAndZoomStackA(new FilterAndZoomStack(this))
, m_filterAndZoomStackB(new FilterAndZoomStack(this))
, m_filterMenu(new QMenu(this))
, m_model(new DiffViewModel(this))
, m_contents(createDockingArea(QStringLiteral("diffview"), this))
, m_timelineA(new TimeLineWidget(m_parserA, m_filterMenu, m_filterAndZoomStackA, this))
, m_timelineB(new TimeLineWidget(m_parserB, m_filterMenu, m_filterAndZoomStackB, this))
{
ui->setupUi(this);
;
ui->diffTreeView->setModel(m_model);
auto diffProxy = new DiffViewProxy(this);
diffProxy->setSourceModel(m_model);

ResultsUtil::setupTreeView(ui->diffTreeView, ui->diffSearch, diffProxy, DiffViewModel::InitialSortColumn,
DiffViewModel::SortRole);
ui->diffTreeView->sortByColumn(DiffViewModel::InitialSortColumn, Qt::DescendingOrder);
ResultsUtil::setupCostDelegate<DiffViewModel>(m_model, ui->diffTreeView);

auto dockify = [](QWidget* widget, const QString& id, const QString& title, const QString& shortcut) {
auto* dock = new KDDockWidgets::DockWidget(id);
dock->setWidget(widget);
dock->setTitle(title);
dock->toggleAction()->setShortcut(shortcut);
return dock;
};

m_timelineDockA = dockify(m_timelineA, QStringLiteral("timelinea"), tr("Timeline A"), tr("Ctrl+A"));
m_contents->addDockWidget(m_timelineDockA, KDDockWidgets::Location_OnBottom);
m_timelineDockB = dockify(m_timelineB, QStringLiteral("timelineb"), tr("Timeline B"), tr("Ctrl+B"));
m_timelineDockA->addDockWidgetAsTab(m_timelineDockB);

auto costThreshold = new QDoubleSpinBox(this);
costThreshold->setDecimals(2);
costThreshold->setMinimum(0);
costThreshold->setMaximum(99.90);
costThreshold->setPrefix(tr("Cost Threshold: "));
costThreshold->setSuffix(QStringLiteral("%"));
costThreshold->setValue(0.01);
costThreshold->setSingleStep(0.01);
connect(costThreshold, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
[diffProxy](double threshold) { diffProxy->setThreshold(threshold); });

ui->bottomUpVerticalLayout->addWidget(costThreshold);
ui->bottomUpVerticalLayout->addWidget(m_contents);

auto repositionFilterBusyIndicator = [this] {
auto geometry = m_filterBusyIndicator->geometry();
geometry.setWidth(width() / 2);
Expand Down Expand Up @@ -104,6 +147,15 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
}
});

connect(m_filterAndZoomStackA, &FilterAndZoomStack::filterChanged, this, [this](const Data::FilterAction& action) {
m_bFinished = true;
m_parserA->filterResults(action);
});
connect(m_filterAndZoomStackB, &FilterAndZoomStack::filterChanged, this, [this](const Data::FilterAction& action) {
m_aFinished = true;
m_parserB->filterResults(action);
});

{
m_filterBusyIndicator = new QWidget(this);
m_filterBusyIndicator->setMinimumHeight(100);
Expand Down
4 changes: 4 additions & 0 deletions src/diffviewwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "data.h"
#include <QWidget>

class QMenu;
class PerfParser;
class DiffViewModel;
class TimeLineWidget;
Expand Down Expand Up @@ -58,6 +59,9 @@ public slots:
QScopedPointer<Ui::ResultsDiffPage> ui;
PerfParser* m_parserA;
PerfParser* m_parserB;
FilterAndZoomStack* m_filterAndZoomStackA;
FilterAndZoomStack* m_filterAndZoomStackB;
QMenu* m_filterMenu;
DiffViewModel* m_model;
KDDockWidgets::MainWindow* m_contents;
KDDockWidgets::DockWidget* m_timelineDockA;
Expand Down
1 change: 1 addition & 0 deletions src/models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_library(models STATIC
../settings.cpp
../util.cpp
callercalleeproxy.cpp
diffviewproxy.cpp
)

target_link_libraries(models
Expand Down
1 change: 1 addition & 0 deletions src/models/costdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <cmath>

// TODO: c++17 move to std clamp
float clamp(float value, float low, float high)
{
if (value < low)
Expand Down
45 changes: 45 additions & 0 deletions src/models/diffviewproxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
diffviewproxy.h
This file is part of Hotspot, the Qt GUI for performance analysis.
Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
Author: Lieven Hey <[email protected]>
Licensees holding valid commercial KDAB Hotspot licenses may use this file in
accordance with Hotspot Commercial License Agreement provided with the Software.
Contact [email protected] if any conditions of this licensing are not clear to you.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU 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, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <QSortFilterProxyModel>

class DiffViewProxy : public QSortFilterProxyModel
{
public:
explicit DiffViewProxy(QObject* parent = nullptr);
~DiffViewProxy();

void setThreshold(double threshold);

protected:
bool filterAcceptsRow(int source_row, const QModelIndex& parent) const override;

private:
double m_threshold = 0.01;
};

0 comments on commit 04a1546

Please sign in to comment.