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 Oct 6, 2021
1 parent a94991b commit ed32d25
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/diffviewwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#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 @@ -31,11 +33,13 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
, m_timelineA(new TimeLineWidget(m_parserA, m_filterMenu, m_filterAndZoomStackA, this))
, m_timelineB(new TimeLineWidget(m_parserB, m_filterMenu, m_filterAndZoomStackB, this))
{
auto diffProxy = new DiffViewProxy(this);
diffProxy->setSourceModel(m_model);

ui->setupUi(this);
ui->diffTreeView->setModel(m_model);
ui->bottomUpVerticalLayout->addWidget(m_contents);

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

auto dockify = [](QWidget* widget, const QString& id, const QString& title, const QString& shortcut) {
Expand All @@ -51,6 +55,20 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
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->setThreshhold(threshold); });

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

auto repositionFilterBusyIndicator = [this] {
auto geometry = m_filterBusyIndicator->geometry();
geometry.setWidth(width() / 2);
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
27 changes: 27 additions & 0 deletions src/models/diffviewproxy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "diffviewproxy.h"
#include "treemodel.h"

DiffViewProxy::DiffViewProxy(QObject* parent)
: QSortFilterProxyModel(parent)
{
setRecursiveFilteringEnabled(true);
}

void DiffViewProxy::setThreshhold(double threshhold)
{
m_threshhold = threshhold;
invalidateFilter();
}

bool DiffViewProxy::filterAcceptsRow(int source_row, const QModelIndex& parent) const
{
Q_UNUSED(parent);

const auto model = qobject_cast<DiffViewModel*>(sourceModel());

const auto cost =
model->data(model->index(source_row, DiffViewModel::NUM_BASE_COLUMNS), DiffViewModel::SortRole).toLongLong();
const auto t = std::abs(cost / 10'000.f);

return t > m_threshhold;
}
20 changes: 20 additions & 0 deletions src/models/diffviewproxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef DIFFVIEWPROXY_H
#define DIFFVIEWPROXY_H

#include <QSortFilterProxyModel>

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

void setThreshhold(double threshhold);

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

private:
double m_threshhold = 0.01;
};

#endif // DIFFVIEWPROXY_H

0 comments on commit ed32d25

Please sign in to comment.