@@ -24,17 +24,19 @@ enum class Tag : quint8
24
24
Processes,
25
25
Threads,
26
26
Tracepoints,
27
+ Favorites,
27
28
};
28
29
29
30
enum OverviewRow : quint8
30
31
{
31
32
CpuRow,
32
33
ProcessRow,
33
34
TracepointRow,
35
+ FavoriteRow,
34
36
};
35
- constexpr auto numRows = TracepointRow + 1 ;
37
+ constexpr auto numRows = FavoriteRow + 1 ;
36
38
37
- constexpr auto LAST_TAG = Tag::Tracepoints ;
39
+ constexpr auto LAST_TAG = Tag::Favorites ;
38
40
39
41
const auto DATATAG_SHIFT = sizeof (Tag) * 8 ;
40
42
const auto DATATAG_UNSHIFT = (sizeof (quintptr) - sizeof (Tag)) * 8 ;
@@ -88,6 +90,7 @@ int EventModel::rowCount(const QModelIndex& parent) const
88
90
case Tag::Cpus:
89
91
case Tag::Threads:
90
92
case Tag::Tracepoints:
93
+ case Tag::Favorites:
91
94
return 0 ;
92
95
case Tag::Processes:
93
96
return m_processes.value (parent.row ()).threads .size ();
@@ -99,6 +102,8 @@ int EventModel::rowCount(const QModelIndex& parent) const
99
102
return m_processes.size ();
100
103
case OverviewRow::TracepointRow:
101
104
return m_data.tracepoints .size ();
105
+ case OverviewRow::FavoriteRow:
106
+ return m_favourites.size ();
102
107
}
103
108
Q_UNREACHABLE ();
104
109
case Tag::Root:
@@ -166,6 +171,8 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
166
171
return tr (" Processes" );
167
172
case OverviewRow::TracepointRow:
168
173
return tr (" Tracepoints" );
174
+ case OverviewRow::FavoriteRow:
175
+ return tr (" Favorites" );
169
176
}
170
177
} else if (role == Qt::ToolTipRole) {
171
178
switch (static_cast <OverviewRow>(index.row ())) {
@@ -176,6 +183,8 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
176
183
return tr (" Event timelines for the individual threads and processes." );
177
184
case OverviewRow::TracepointRow:
178
185
return tr (" Event timelines for tracepoints" );
186
+ case OverviewRow::FavoriteRow:
187
+ return tr (" A list of favourites to group important events" );
179
188
}
180
189
} else if (role == SortRole) {
181
190
return index.row ();
@@ -243,6 +252,13 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
243
252
Q_ASSERT (thread);
244
253
} else if (tag == Tag::Tracepoints) {
245
254
tracepoint = &m_data.tracepoints [index.row ()];
255
+ } else if (tag == Tag::Favorites) {
256
+ if (role == IsFavoriteRole) {
257
+ return true ;
258
+ }
259
+
260
+ const auto & favourite = m_favourites[index.row ()];
261
+ return data (favourite.siblingAtColumn (index.column ()), role);
246
262
}
247
263
248
264
if (role == ThreadStartRole) {
@@ -256,6 +272,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
256
272
case Tag::Processes:
257
273
case Tag::Tracepoints:
258
274
return m_time.start ;
275
+ case Tag::Favorites:
276
+ // they are handled elsewhere
277
+ Q_UNREACHABLE ();
259
278
}
260
279
} else if (role == ThreadEndRole) {
261
280
switch (tag) {
@@ -268,6 +287,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
268
287
case Tag::Processes:
269
288
case Tag::Tracepoints:
270
289
return m_time.end ;
290
+ case Tag::Favorites:
291
+ // they are handled elsewhere
292
+ Q_UNREACHABLE ();
271
293
}
272
294
} else if (role == ThreadNameRole) {
273
295
switch (tag) {
@@ -281,6 +303,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
281
303
case Tag::Processes:
282
304
case Tag::Tracepoints:
283
305
return {};
306
+ case Tag::Favorites:
307
+ // they are handled elsewhere
308
+ Q_UNREACHABLE ();
284
309
}
285
310
} else if (role == ThreadIdRole) {
286
311
switch (tag) {
@@ -293,6 +318,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
293
318
case Tag::Processes:
294
319
case Tag::Tracepoints:
295
320
return Data::INVALID_TID;
321
+ case Tag::Favorites:
322
+ // they are handled elsewhere
323
+ Q_UNREACHABLE ();
296
324
}
297
325
} else if (role == ProcessIdRole) {
298
326
switch (tag) {
@@ -305,6 +333,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
305
333
case Tag::Processes:
306
334
case Tag::Tracepoints:
307
335
return Data::INVALID_PID;
336
+ case Tag::Favorites:
337
+ // they are handled elsewhere
338
+ Q_UNREACHABLE ();
308
339
}
309
340
} else if (role == CpuIdRole) {
310
341
switch (tag) {
@@ -317,6 +348,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
317
348
case Tag::Threads:
318
349
case Tag::Tracepoints:
319
350
return Data::INVALID_CPU_ID;
351
+ case Tag::Favorites:
352
+ // they are handled elsewhere
353
+ Q_UNREACHABLE ();
320
354
}
321
355
} else if (role == EventsRole) {
322
356
switch (tag) {
@@ -331,6 +365,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
331
365
case Tag::Overview:
332
366
case Tag::Processes:
333
367
return {};
368
+ case Tag::Favorites:
369
+ // they are handled elsewhere
370
+ Q_UNREACHABLE ();
334
371
}
335
372
} else if (role == SortRole) {
336
373
if (index.column () == ThreadColumn) {
@@ -346,6 +383,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
346
383
case Tag::Overview:
347
384
case Tag::Processes:
348
385
return {};
386
+ case Tag::Favorites:
387
+ // they are handled elsewhere
388
+ Q_UNREACHABLE ();
349
389
}
350
390
} else {
351
391
switch (tag) {
@@ -360,8 +400,13 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
360
400
case Tag::Overview:
361
401
case Tag::Processes:
362
402
return {};
403
+ case Tag::Favorites:
404
+ // they are handled elsewhere
405
+ Q_UNREACHABLE ();
363
406
}
364
407
}
408
+ } else if (role == IsFavoriteRole) {
409
+ return false ;
365
410
}
366
411
367
412
switch (static_cast <Columns>(index.column ())) {
@@ -379,6 +424,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
379
424
case Tag::Overview:
380
425
case Tag::Processes:
381
426
return {};
427
+ case Tag::Favorites:
428
+ // they are handled elsewhere
429
+ Q_UNREACHABLE ();
382
430
}
383
431
} else if (role == Qt::ToolTipRole) {
384
432
QString tooltip;
@@ -419,6 +467,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
419
467
case Tag::Overview:
420
468
case Tag::Processes:
421
469
return {};
470
+ case Tag::Favorites:
471
+ // they are handled elsewhere
472
+ Q_UNREACHABLE ();
422
473
}
423
474
424
475
tooltip += tr (" Number of Events: %1 (%2% of the total)" )
@@ -440,6 +491,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
440
491
case Tag::Overview:
441
492
case Tag::Processes:
442
493
return {};
494
+ case Tag::Favorites:
495
+ // they are handled elsewhere
496
+ Q_UNREACHABLE ();
443
497
}
444
498
}
445
499
break ;
@@ -454,6 +508,8 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
454
508
void EventModel::setData (const Data::EventResults& data)
455
509
{
456
510
beginResetModel ();
511
+ m_favourites.clear ();
512
+
457
513
m_data = data;
458
514
m_totalEvents = 0 ;
459
515
m_maxCost = 0 ;
@@ -514,6 +570,7 @@ QModelIndex EventModel::index(int row, int column, const QModelIndex& parent) co
514
570
case Tag::Cpus:
515
571
case Tag::Tracepoints:
516
572
case Tag::Threads:
573
+ case Tag::Favorites:
517
574
break ;
518
575
case Tag::Root: // root has the 1st level children: Overview
519
576
return createIndex (row, column, static_cast <quintptr>(Tag::Overview));
@@ -525,6 +582,8 @@ QModelIndex EventModel::index(int row, int column, const QModelIndex& parent) co
525
582
return createIndex (row, column, static_cast <quintptr>(Tag::Processes));
526
583
case OverviewRow::TracepointRow:
527
584
return createIndex (row, column, static_cast <quintptr>(Tag::Tracepoints));
585
+ case OverviewRow::FavoriteRow:
586
+ return createIndex (row, column, static_cast <quintptr>(Tag::Favorites));
528
587
}
529
588
Q_UNREACHABLE ();
530
589
case Tag::Processes: // 3rd level children: Threads
@@ -546,12 +605,48 @@ QModelIndex EventModel::parent(const QModelIndex& child) const
546
605
case Tag::Processes:
547
606
return createIndex (OverviewRow::ProcessRow, 0 , static_cast <quintptr>(Tag::Overview));
548
607
case Tag::Tracepoints:
549
- return createIndex (OverviewRow::TracepointRow, 0 , static_cast <qintptr>(Tag::Overview));
550
- case Tag::Threads: {
608
+ return createIndex (OverviewRow::TracepointRow, 0 , static_cast <quintptr>(Tag::Overview));
609
+ case Tag::Favorites:
610
+ return createIndex (OverviewRow::FavoriteRow, 0 , static_cast <quintptr>(Tag::Overview));
611
+ case Tag::Threads:
551
612
const auto parentRow = tagData (child.internalId ());
552
613
return createIndex (parentRow, 0 , static_cast <quintptr>(Tag::Processes));
553
614
}
554
- }
555
615
556
616
return {};
557
617
}
618
+
619
+ void EventModel::addToFavorites (const QModelIndex& index)
620
+ {
621
+ Q_ASSERT (index.model () == this );
622
+
623
+ if (index.column () != 0 ) {
624
+ // we only want one index per row, so we force it to be column zero
625
+ // this way we can easily check if we have duplicate rows
626
+ addToFavorites (index.siblingAtColumn (0 ));
627
+ return ;
628
+ }
629
+
630
+ if (m_favourites.contains (index)) {
631
+ return ;
632
+ }
633
+
634
+ const auto row = m_favourites.size ();
635
+
636
+ beginInsertRows (createIndex (FavoriteRow, 0 , static_cast <quintptr>(Tag::Overview)), row, row);
637
+ m_favourites.push_back (index);
638
+ endInsertRows ();
639
+ }
640
+
641
+ void EventModel::removeFromFavorites (const QModelIndex& index)
642
+ {
643
+ Q_ASSERT (index.model () == this );
644
+ Q_ASSERT (dataTag (index) == Tag::Favorites);
645
+
646
+ const auto row = index.row ();
647
+ Q_ASSERT (row >= 0 && row < m_favourites.size ());
648
+
649
+ beginRemoveRows (createIndex (FavoriteRow, 0 , static_cast <quintptr>(Tag::Overview)), row, row);
650
+ m_favourites.remove (row);
651
+ endRemoveRows ();
652
+ }
0 commit comments