From 505cf1ea8600784f5e4cd7ed02876eb1b97f284c Mon Sep 17 00:00:00 2001 From: Lieven Hey Date: Wed, 4 Oct 2023 12:28:55 +0200 Subject: [PATCH] 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. --- src/models/CMakeLists.txt | 1 + src/models/eventmodelproxy.cpp | 21 +++++++++++++++++++++ src/models/eventmodelproxy.h | 22 ++++++++++++++++++++++ src/timelinewidget.cpp | 3 ++- 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/models/eventmodelproxy.cpp create mode 100644 src/models/eventmodelproxy.h diff --git a/src/models/CMakeLists.txt b/src/models/CMakeLists.txt index e0ab27021..135e29cea 100644 --- a/src/models/CMakeLists.txt +++ b/src/models/CMakeLists.txt @@ -10,6 +10,7 @@ add_library( disassemblymodel.cpp disassemblyoutput.cpp eventmodel.cpp + eventmodelproxy.cpp filterandzoomstack.cpp frequencymodel.cpp highlighter.cpp diff --git a/src/models/eventmodelproxy.cpp b/src/models/eventmodelproxy.cpp new file mode 100644 index 000000000..874ac1a49 --- /dev/null +++ b/src/models/eventmodelproxy.cpp @@ -0,0 +1,21 @@ +/* + SPDX-FileCopyrightText: Lieven Hey + SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "eventmodelproxy.h" + +EventModelProxy::EventModelProxy(QObject* parent) + : QSortFilterProxyModel(parent) +{ +} + +EventModelProxy::~EventModelProxy() = default; + +bool EventModelProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const +{ + Q_UNUSED(source_row); + return source_parent.isValid(); +} diff --git a/src/models/eventmodelproxy.h b/src/models/eventmodelproxy.h new file mode 100644 index 000000000..2c9386bf2 --- /dev/null +++ b/src/models/eventmodelproxy.h @@ -0,0 +1,22 @@ +/* + SPDX-FileCopyrightText: Lieven Hey + SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + + SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#pragma once + +#include + +class EventModelProxy : public QSortFilterProxyModel +{ + Q_OBJECT +public: +public: + EventModelProxy(QObject* parent); + ~EventModelProxy() override; + +protected: + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; +}; diff --git a/src/timelinewidget.cpp b/src/timelinewidget.cpp index c39ff066b..9db9dd611 100644 --- a/src/timelinewidget.cpp +++ b/src/timelinewidget.cpp @@ -9,6 +9,7 @@ #include "filterandzoomstack.h" #include "models/eventmodel.h" +#include "models/eventmodelproxy.h" #include "resultsutil.h" #include "timelinedelegate.h" @@ -61,7 +62,7 @@ TimeLineWidget::TimeLineWidget(PerfParser* parser, QMenu* filterMenu, FilterAndZ ui->setupUi(this); auto* eventModel = new EventModel(this); - auto* timeLineProxy = new QSortFilterProxyModel(this); + auto* timeLineProxy = new EventModelProxy(this); timeLineProxy->setRecursiveFilteringEnabled(true); timeLineProxy->setSourceModel(eventModel); timeLineProxy->setSortRole(EventModel::SortRole);