Skip to content

Commit 48c9f49

Browse files
committed
allow event source combobox to select multiple costs
This patch allows the combobox in the timelinedelegate to select multiple costs as source.
1 parent 84d7904 commit 48c9f49

File tree

5 files changed

+81
-3
lines changed

5 files changed

+81
-3
lines changed

src/models/eventmodelproxy.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ EventModelProxy::EventModelProxy(QObject* parent)
2121

2222
EventModelProxy::~EventModelProxy() = default;
2323

24+
void EventModelProxy::showCostId(qint32 costId)
25+
{
26+
m_hiddenCostIds.remove(costId);
27+
invalidate();
28+
}
29+
30+
void EventModelProxy::hideCostId(qint32 costId)
31+
{
32+
m_hiddenCostIds.insert(costId);
33+
invalidate();
34+
}
35+
2436
bool EventModelProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
2537
{
2638
// index is invalid -> we are at the root node
@@ -31,6 +43,15 @@ bool EventModelProxy::filterAcceptsRow(int source_row, const QModelIndex& source
3143
return false;
3244
}
3345

46+
auto data = sourceModel()
47+
->index(source_row, EventModel::EventsColumn, source_parent)
48+
.data(EventModel::EventsRole)
49+
.value<Data::Events>();
50+
51+
if (!data.empty() && m_hiddenCostIds.contains(data[0].type)) {
52+
return false;
53+
}
54+
3455
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
3556
}
3657

src/models/eventmodelproxy.h

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

88
#pragma once
99

10+
#include <QSet>
1011
#include <QSortFilterProxyModel>
1112

1213
class EventModelProxy : public QSortFilterProxyModel
@@ -16,7 +17,13 @@ class EventModelProxy : public QSortFilterProxyModel
1617
explicit EventModelProxy(QObject* parent = nullptr);
1718
~EventModelProxy() override;
1819

20+
void showCostId(qint32 costId);
21+
void hideCostId(qint32 costId);
22+
1923
protected:
2024
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
2125
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;
26+
27+
private:
28+
QSet<qint32> m_hiddenCostIds;
2229
};

src/resultsutil.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <QTimer>
1919
#include <QTreeView>
2020

21+
#include <QStandardItemModel>
22+
2123
#include "models/costdelegate.h"
2224
#include "models/data.h"
2325
#include "models/filterandzoomstack.h"
@@ -206,6 +208,36 @@ void fillEventSourceComboBox(QComboBox* combo, const Data::Costs& costs, const Q
206208
}
207209
}
208210

211+
void fillEventSourceComboBoxMultiSelect(QComboBox* combo, const Data::Costs& costs, const QString& /*tooltipTemplate*/)
212+
{
213+
// restore selection if possible
214+
const auto oldData = combo->currentData();
215+
216+
combo->clear();
217+
218+
auto model = new QStandardItemModel(costs.numTypes(), 1, combo);
219+
int itemCounter = 0;
220+
for (int costId = 0, c = costs.numTypes(); costId < c; costId++) {
221+
if (!costs.totalCost(costId)) {
222+
continue;
223+
}
224+
225+
auto item = new QStandardItem(costs.typeName(costId));
226+
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
227+
item->setData(Qt::Checked, Qt::CheckStateRole);
228+
item->setData(costId, Qt::UserRole + 1);
229+
model->setItem(itemCounter, item);
230+
itemCounter++;
231+
}
232+
model->setRowCount(itemCounter);
233+
combo->setModel(model);
234+
235+
const auto index = combo->findData(oldData);
236+
if (index != -1) {
237+
combo->setCurrentIndex(index);
238+
}
239+
}
240+
209241
void setupResultsAggregation(QComboBox* costAggregationComboBox)
210242
{
211243
struct AggregationType

src/resultsutil.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void hideEmptyColumns(const Data::Costs& costs, QTreeView* view, int numBaseColu
9898
void hideTracepointColumns(const Data::Costs& costs, QTreeView* view, int numBaseColumns);
9999

100100
void fillEventSourceComboBox(QComboBox* combo, const Data::Costs& costs, const QString& tooltipTemplate);
101+
void fillEventSourceComboBoxMultiSelect(QComboBox* combo, const Data::Costs& costs, const QString& tooltipTemplate);
101102

102103
void setupResultsAggregation(QComboBox* costAggregationComboBox);
103104
}

src/timelinewidget.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
#include "parsers/perf/perfparser.h"
1818

1919
#include <QLabel>
20+
#include <QListView>
2021
#include <QPointer>
2122
#include <QProgressBar>
2223
#include <QSortFilterProxyModel>
24+
#include <QStandardItemModel>
2325
#include <QVBoxLayout>
2426

2527
#include <KLocalizedString>
@@ -82,9 +84,24 @@ TimeLineWidget::TimeLineWidget(PerfParser* parser, QMenu* filterMenu, FilterAndZ
8284
connect(timeLineProxy, &QAbstractItemModel::rowsInserted, this, [this]() { ui->timeLineView->expandToDepth(1); });
8385
connect(timeLineProxy, &QAbstractItemModel::modelReset, this, [this]() { ui->timeLineView->expandToDepth(1); });
8486

85-
connect(m_parser, &PerfParser::bottomUpDataAvailable, this, [this](const Data::BottomUpResults& data) {
86-
ResultsUtil::fillEventSourceComboBox(ui->timeLineEventSource, data.costs, tr("Show timeline for %1 events."));
87-
});
87+
connect(m_parser, &PerfParser::bottomUpDataAvailable, this,
88+
[this, timeLineProxy](const Data::BottomUpResults& data) {
89+
ResultsUtil::fillEventSourceComboBoxMultiSelect(ui->timeLineEventSource, data.costs,
90+
tr("Show timeline for %1 events."));
91+
92+
auto model = qobject_cast<QStandardItemModel*>(ui->timeLineEventSource->model());
93+
connect(ui->timeLineEventSource->model(), &QStandardItemModel::dataChanged, model,
94+
[timeLineProxy](const QModelIndex& topLeft, const QModelIndex& /*bottomRight*/,
95+
const QVector<int>& /*roles*/) {
96+
auto checkState = topLeft.data(Qt::CheckStateRole).value<Qt::CheckState>();
97+
98+
if (checkState == Qt::CheckState::Checked) {
99+
timeLineProxy->showCostId(topLeft.data(Qt::UserRole + 1).toUInt());
100+
} else {
101+
timeLineProxy->hideCostId(topLeft.data(Qt::UserRole + 1).toUInt());
102+
}
103+
});
104+
});
88105

89106
connect(m_parser, &PerfParser::eventsAvailable, this, [this, eventModel](const Data::EventResults& data) {
90107
eventModel->setData(data);

0 commit comments

Comments
 (0)