Skip to content

Commit 4f7a309

Browse files
committed
add filtering to diff view
1 parent 82ce41e commit 4f7a309

File tree

4 files changed

+104
-2
lines changed

4 files changed

+104
-2
lines changed

src/diffviewwidget.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@
2727

2828
#include "diffviewwidget.h"
2929

30+
#include <QAction>
31+
#include <QDoubleSpinBox>
3032
#include <QLabel>
33+
#include <QMenu>
3134
#include <QProgressBar>
3235

36+
#include <kddockwidgets/DockWidget.h>
37+
#include <kddockwidgets/MainWindow.h>
38+
39+
#include "diffviewproxy.h"
3340
#include "dockwidgetsetup.h"
3441
#include "filterandzoomstack.h"
3542
#include "models/treemodel.h"
@@ -45,14 +52,50 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
4552
, ui(new Ui::ResultsDiffPage)
4653
, m_parserA(new PerfParser(this))
4754
, m_parserB(new PerfParser(this))
55+
, m_filterAndZoomStackA(new FilterAndZoomStack(this))
56+
, m_filterAndZoomStackB(new FilterAndZoomStack(this))
57+
, m_filterMenu(new QMenu(this))
4858
, m_model(new DiffViewModel(this))
59+
, m_contents(createDockingArea(QStringLiteral("diffview"), this))
60+
, m_timelineA(new TimeLineWidget(m_parserA, m_filterMenu, m_filterAndZoomStackA, this))
61+
, m_timelineB(new TimeLineWidget(m_parserB, m_filterMenu, m_filterAndZoomStackB, this))
4962
{
5063
ui->setupUi(this);
51-
;
52-
ui->diffTreeView->setModel(m_model);
64+
auto diffProxy = new DiffViewProxy(this);
65+
diffProxy->setSourceModel(m_model);
66+
67+
ResultsUtil::setupTreeView(ui->diffTreeView, ui->diffSearch, diffProxy, DiffViewModel::InitialSortColumn,
68+
DiffViewModel::SortRole);
5369
ui->diffTreeView->sortByColumn(DiffViewModel::InitialSortColumn, Qt::DescendingOrder);
5470
ResultsUtil::setupCostDelegate<DiffViewModel>(m_model, ui->diffTreeView);
5571

72+
auto dockify = [](QWidget* widget, const QString& id, const QString& title, const QString& shortcut) {
73+
auto* dock = new KDDockWidgets::DockWidget(id);
74+
dock->setWidget(widget);
75+
dock->setTitle(title);
76+
dock->toggleAction()->setShortcut(shortcut);
77+
return dock;
78+
};
79+
80+
m_timelineDockA = dockify(m_timelineA, QStringLiteral("timelinea"), tr("Timeline A"), tr("Ctrl+A"));
81+
m_contents->addDockWidget(m_timelineDockA, KDDockWidgets::Location_OnBottom);
82+
m_timelineDockB = dockify(m_timelineB, QStringLiteral("timelineb"), tr("Timeline B"), tr("Ctrl+B"));
83+
m_timelineDockA->addDockWidgetAsTab(m_timelineDockB);
84+
85+
auto costThreshold = new QDoubleSpinBox(this);
86+
costThreshold->setDecimals(2);
87+
costThreshold->setMinimum(0);
88+
costThreshold->setMaximum(99.90);
89+
costThreshold->setPrefix(tr("Cost Threshold: "));
90+
costThreshold->setSuffix(QStringLiteral("%"));
91+
costThreshold->setValue(0.01);
92+
costThreshold->setSingleStep(0.01);
93+
connect(costThreshold, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
94+
[diffProxy](double threshold) { diffProxy->setThreshold(threshold); });
95+
96+
ui->bottomUpVerticalLayout->addWidget(costThreshold);
97+
ui->bottomUpVerticalLayout->addWidget(m_contents);
98+
5699
auto repositionFilterBusyIndicator = [this] {
57100
auto geometry = m_filterBusyIndicator->geometry();
58101
geometry.setWidth(width() / 2);
@@ -104,6 +147,15 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
104147
}
105148
});
106149

150+
connect(m_filterAndZoomStackA, &FilterAndZoomStack::filterChanged, this, [this](const Data::FilterAction& action) {
151+
m_bFinished = true;
152+
m_parserA->filterResults(action);
153+
});
154+
connect(m_filterAndZoomStackB, &FilterAndZoomStack::filterChanged, this, [this](const Data::FilterAction& action) {
155+
m_aFinished = true;
156+
m_parserB->filterResults(action);
157+
});
158+
107159
{
108160
m_filterBusyIndicator = new QWidget(this);
109161
m_filterBusyIndicator->setMinimumHeight(100);

src/diffviewwidget.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "data.h"
3131
#include <QWidget>
3232

33+
class QMenu;
3334
class PerfParser;
3435
class DiffViewModel;
3536
class TimeLineWidget;
@@ -58,6 +59,9 @@ public slots:
5859
QScopedPointer<Ui::ResultsDiffPage> ui;
5960
PerfParser* m_parserA;
6061
PerfParser* m_parserB;
62+
FilterAndZoomStack* m_filterAndZoomStackA;
63+
FilterAndZoomStack* m_filterAndZoomStackB;
64+
QMenu* m_filterMenu;
6165
DiffViewModel* m_model;
6266
KDDockWidgets::MainWindow* m_contents;
6367
KDDockWidgets::DockWidget* m_timelineDockA;

src/models/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_library(models STATIC
1616
../settings.cpp
1717
../util.cpp
1818
callercalleeproxy.cpp
19+
diffviewproxy.cpp
1920
)
2021

2122
target_link_libraries(models

src/models/diffviewproxy.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
diffviewproxy.h
3+
4+
This file is part of Hotspot, the Qt GUI for performance analysis.
5+
6+
Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
7+
Author: Lieven Hey <[email protected]>
8+
9+
Licensees holding valid commercial KDAB Hotspot licenses may use this file in
10+
accordance with Hotspot Commercial License Agreement provided with the Software.
11+
12+
Contact [email protected] if any conditions of this licensing are not clear to you.
13+
14+
This program is free software; you can redistribute it and/or modify
15+
it under the terms of the GNU General Public License as published by
16+
the Free Software Foundation, either version 2 of the License, or
17+
(at your option) any later version.
18+
19+
This program is distributed in the hope that it will be useful,
20+
but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
GNU General Public License for more details.
23+
24+
You should have received a copy of the GNU General Public License
25+
along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
*/
27+
28+
#pragma once
29+
30+
#include <QSortFilterProxyModel>
31+
32+
class DiffViewProxy : public QSortFilterProxyModel
33+
{
34+
public:
35+
explicit DiffViewProxy(QObject* parent = nullptr);
36+
~DiffViewProxy();
37+
38+
void setThreshold(double threshold);
39+
40+
protected:
41+
bool filterAcceptsRow(int source_row, const QModelIndex& parent) const override;
42+
43+
private:
44+
double m_threshold = 0.01;
45+
};

0 commit comments

Comments
 (0)