-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 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.
- Loading branch information
Showing
5 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
SPDX-FileCopyrightText: Lieven Hey <lieven.hey@kdab.com> | ||
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" | ||
#include "eventmodel.h" | ||
|
||
EventModelProxy::EventModelProxy(QObject* parent) | ||
: QSortFilterProxyModel(parent) | ||
{ | ||
setDynamicSortFilter(true); | ||
setRecursiveFilteringEnabled(true); | ||
setSortRole(EventModel::SortRole); | ||
setFilterKeyColumn(EventModel::ThreadColumn); | ||
setFilterRole(Qt::DisplayRole); | ||
} | ||
|
||
EventModelProxy::~EventModelProxy() = default; | ||
|
||
bool EventModelProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const | ||
{ | ||
// index is invalid -> we are at the root node | ||
// hide categories that have no children (e.g. favorites, tracepoints) | ||
if (!source_parent.isValid()) { | ||
const auto model = sourceModel(); | ||
if (!model->hasChildren(model->index(source_row, 0))) | ||
return false; | ||
} | ||
|
||
auto data = sourceModel() | ||
->index(source_row, EventModel::EventsColumn, source_parent) | ||
.data(EventModel::EventsRole) | ||
.value<Data::Events>(); | ||
|
||
if (data.empty()) { | ||
return false; | ||
} | ||
|
||
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
SPDX-FileCopyrightText: Lieven Hey <lieven.hey@kdab.com> | ||
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 <QSortFilterProxyModel> | ||
|
||
class EventModelProxy : public QSortFilterProxyModel | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit EventModelProxy(QObject* parent = nullptr); | ||
~EventModelProxy() override; | ||
|
||
protected: | ||
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters