Skip to content

Commit 786e577

Browse files
committed
add filtering to diff view
1 parent 1dc1b2d commit 786e577

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

src/diffviewwidget.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#include "diffviewwidget.h"
22

33
#include <QAction>
4+
#include <QDoubleSpinBox>
45
#include <QLabel>
56
#include <QMenu>
67
#include <QProgressBar>
78

89
#include <kddockwidgets/DockWidget.h>
910
#include <kddockwidgets/MainWindow.h>
1011

12+
#include "diffviewproxy.h"
1113
#include "dockwidgetsetup.h"
1214
#include "filterandzoomstack.h"
1315
#include "models/treemodel.h"
@@ -31,11 +33,13 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
3133
, m_timelineA(new TimeLineWidget(m_parserA, m_filterMenu, m_filterAndZoomStackA, this))
3234
, m_timelineB(new TimeLineWidget(m_parserB, m_filterMenu, m_filterAndZoomStackB, this))
3335
{
36+
auto diffProxy = new DiffViewProxy(this);
37+
diffProxy->setSourceModel(m_model);
38+
3439
ui->setupUi(this);
35-
ui->diffTreeView->setModel(m_model);
36-
ui->bottomUpVerticalLayout->addWidget(m_contents);
3740

38-
ResultsUtil::setupTreeView(ui->diffTreeView, ui->diffSearch, m_model);
41+
ResultsUtil::setupTreeView(ui->diffTreeView, ui->diffSearch, diffProxy, DiffViewModel::InitialSortColumn,
42+
DiffViewModel::SortRole);
3943
ResultsUtil::setupCostDelegate<DiffViewModel>(m_model, ui->diffTreeView);
4044

4145
auto dockify = [](QWidget* widget, const QString& id, const QString& title, const QString& shortcut) {
@@ -51,6 +55,20 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
5155
m_timelineDockB = dockify(m_timelineB, QStringLiteral("timelineb"), tr("Timeline B"), tr("Ctrl+B"));
5256
m_timelineDockA->addDockWidgetAsTab(m_timelineDockB);
5357

58+
auto costThreshold = new QDoubleSpinBox(this);
59+
costThreshold->setDecimals(2);
60+
costThreshold->setMinimum(0);
61+
costThreshold->setMaximum(99.90);
62+
costThreshold->setPrefix(tr("Cost Threshold: "));
63+
costThreshold->setSuffix(QStringLiteral("%"));
64+
costThreshold->setValue(0.01);
65+
costThreshold->setSingleStep(0.01);
66+
connect(costThreshold, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
67+
[diffProxy](double threshold) { diffProxy->setThreshhold(threshold); });
68+
69+
ui->bottomUpVerticalLayout->addWidget(costThreshold);
70+
ui->bottomUpVerticalLayout->addWidget(m_contents);
71+
5472
auto repositionFilterBusyIndicator = [this] {
5573
auto geometry = m_filterBusyIndicator->geometry();
5674
geometry.setWidth(width() / 2);

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.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "diffviewproxy.h"
2+
#include "treemodel.h"
3+
4+
DiffViewProxy::DiffViewProxy(QObject* parent)
5+
: QSortFilterProxyModel(parent)
6+
{
7+
setRecursiveFilteringEnabled(true);
8+
}
9+
10+
void DiffViewProxy::setThreshhold(double threshhold)
11+
{
12+
m_threshhold = threshhold;
13+
invalidateFilter();
14+
}
15+
16+
bool DiffViewProxy::filterAcceptsRow(int source_row, const QModelIndex& parent) const
17+
{
18+
Q_UNUSED(parent);
19+
20+
const auto model = qobject_cast<DiffViewModel*>(sourceModel());
21+
22+
const auto cost =
23+
model->data(model->index(source_row, DiffViewModel::NUM_BASE_COLUMNS), DiffViewModel::SortRole).toLongLong();
24+
const auto t = std::abs(cost / 10'000.f);
25+
26+
return t > m_threshhold;
27+
}

src/models/diffviewproxy.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef DIFFVIEWPROXY_H
2+
#define DIFFVIEWPROXY_H
3+
4+
#include <QSortFilterProxyModel>
5+
6+
class DiffViewProxy : public QSortFilterProxyModel
7+
{
8+
public:
9+
explicit DiffViewProxy(QObject* parent = nullptr);
10+
11+
void setThreshhold(double threshhold);
12+
13+
protected:
14+
bool filterAcceptsRow(int source_row, const QModelIndex& parent) const override;
15+
16+
private:
17+
double m_threshhold = 0.01;
18+
};
19+
20+
#endif // DIFFVIEWPROXY_H

0 commit comments

Comments
 (0)