Skip to content

Commit 0506b95

Browse files
committed
add QSFP to hide empty rows in eventmodel
The favourites and tracepoint patches include some rows in the model that may be empty. To keep the code simple an readable all rows will be shown. Then a proxy model is put ontop to remove empty rows.
1 parent f0e8581 commit 0506b95

File tree

5 files changed

+79
-5
lines changed

5 files changed

+79
-5
lines changed

src/models/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_library(
1010
disassemblymodel.cpp
1111
disassemblyoutput.cpp
1212
eventmodel.cpp
13+
eventmodelproxy.cpp
1314
filterandzoomstack.cpp
1415
frequencymodel.cpp
1516
highlighter.cpp

src/models/eventmodelproxy.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
SPDX-FileCopyrightText: Lieven Hey <[email protected]>
3+
SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
4+
5+
SPDX-License-Identifier: GPL-2.0-or-later
6+
*/
7+
8+
#include "eventmodelproxy.h"
9+
#include "eventmodel.h"
10+
11+
EventModelProxy::EventModelProxy(QObject* parent)
12+
: QSortFilterProxyModel(parent)
13+
{
14+
setRecursiveFilteringEnabled(true);
15+
setSortRole(EventModel::SortRole);
16+
setFilterKeyColumn(EventModel::ThreadColumn);
17+
setFilterRole(Qt::DisplayRole);
18+
}
19+
20+
EventModelProxy::~EventModelProxy() = default;
21+
22+
bool EventModelProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
23+
{
24+
// index is invalid -> we are at the root node
25+
if (!source_parent.isValid()) {
26+
const auto model = sourceModel();
27+
return model->rowCount(model->index(source_row, 0));
28+
}
29+
30+
return true;
31+
}

src/models/eventmodelproxy.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
SPDX-FileCopyrightText: Lieven Hey <[email protected]>
3+
SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
4+
5+
SPDX-License-Identifier: GPL-2.0-or-later
6+
*/
7+
8+
#pragma once
9+
10+
#include <QSortFilterProxyModel>
11+
12+
class EventModelProxy : public QSortFilterProxyModel
13+
{
14+
Q_OBJECT
15+
public:
16+
EventModelProxy(QObject* parent = nullptr);
17+
~EventModelProxy() override;
18+
19+
protected:
20+
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
21+
};

src/timelinewidget.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "filterandzoomstack.h"
1111
#include "models/eventmodel.h"
12+
#include "models/eventmodelproxy.h"
1213
#include "resultsutil.h"
1314
#include "timelinedelegate.h"
1415

@@ -61,12 +62,8 @@ TimeLineWidget::TimeLineWidget(PerfParser* parser, QMenu* filterMenu, FilterAndZ
6162
ui->setupUi(this);
6263

6364
auto* eventModel = new EventModel(this);
64-
auto* timeLineProxy = new QSortFilterProxyModel(this);
65-
timeLineProxy->setRecursiveFilteringEnabled(true);
65+
auto* timeLineProxy = new EventModelProxy(this);
6666
timeLineProxy->setSourceModel(eventModel);
67-
timeLineProxy->setSortRole(EventModel::SortRole);
68-
timeLineProxy->setFilterKeyColumn(EventModel::ThreadColumn);
69-
timeLineProxy->setFilterRole(Qt::DisplayRole);
7067
ResultsUtil::connectFilter(ui->timeLineSearch, timeLineProxy);
7168
ui->timeLineView->setModel(timeLineProxy);
7269
ui->timeLineView->setSortingEnabled(true);

tests/modeltests/tst_models.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <models/disassemblymodel.h>
2020
#include <models/eventmodel.h>
21+
#include <models/eventmodelproxy.h>
2122
#include <models/sourcecodemodel.h>
2223

2324
namespace {
@@ -586,6 +587,29 @@ private slots:
586587
QCOMPARE(model.rowCount(favoritesIndex), 0);
587588
}
588589

590+
void testEventModelProxy()
591+
{
592+
const auto events = createEventModelTestData();
593+
EventModel model;
594+
QAbstractItemModelTester tester(&model);
595+
model.setData(events);
596+
597+
EventModelProxy proxy;
598+
proxy.setSourceModel(&model);
599+
600+
const auto favoritesIndex = model.index(3, 0);
601+
const auto processesIndex = model.index(1, 0);
602+
603+
QCOMPARE(model.rowCount(), 4);
604+
QCOMPARE(proxy.rowCount(), 2);
605+
606+
model.addToFavorites(model.index(0, 0, processesIndex));
607+
QCOMPARE(proxy.rowCount(), 3);
608+
609+
model.removeFromFavorites(model.index(0, 0, favoritesIndex));
610+
QCOMPARE(proxy.rowCount(), 2);
611+
}
612+
589613
void testPrettySymbol_data()
590614
{
591615
QTest::addColumn<QString>("prettySymbol");

0 commit comments

Comments
 (0)