@@ -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
Cpu_Row,
32
33
Process_Row,
33
34
Tracepoint_Row,
35
+ Favorite_Row,
34
36
};
35
- constexpr auto numRows = Tracepoint_Row + 1 ;
37
+ constexpr auto numRows = Favorite_Row + 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
break ;
93
96
case Tag::Processes:
@@ -100,6 +103,8 @@ int EventModel::rowCount(const QModelIndex& parent) const
100
103
return m_processes.size ();
101
104
case OverViewRow::Tracepoint_Row:
102
105
return m_data.tracepoints .size ();
106
+ case OverViewRow::Favorite_Row:
107
+ return m_favourites.size ();
103
108
default :
104
109
Q_UNREACHABLE ();
105
110
}
@@ -168,6 +173,8 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
168
173
return tr (" Processes" );
169
174
case OverViewRow::Tracepoint_Row:
170
175
return tr (" Tracepoints" );
176
+ case OverViewRow::Favorite_Row:
177
+ return tr (" Favorites" );
171
178
}
172
179
} else if (role == Qt::ToolTipRole) {
173
180
switch (static_cast <OverViewRow>(index.row ())) {
@@ -178,6 +185,8 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
178
185
return tr (" Event timelines for the individual threads and processes." );
179
186
case OverViewRow::Tracepoint_Row:
180
187
return tr (" Event timelines for tracepoints" );
188
+ case OverViewRow::Favorite_Row:
189
+ return tr (" A list of favourites to group important events" );
181
190
}
182
191
} else if (role == SortRole) {
183
192
return index.row ();
@@ -245,6 +254,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
245
254
Q_ASSERT (thread);
246
255
} else if (tag == Tag::Tracepoints) {
247
256
tracepoint = &m_data.tracepoints [index.row ()];
257
+ } else if (tag == Tag::Favorites) {
258
+ const auto & favourite = m_favourites[index.row ()];
259
+ return data (favourite.siblingAtColumn (index.column ()), role);
248
260
}
249
261
250
262
if (role == ThreadStartRole) {
@@ -258,6 +270,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
258
270
case Tag::Processes:
259
271
case Tag::Tracepoints:
260
272
return m_time.start ;
273
+ case Tag::Favorites:
274
+ // they are handled elsewhere
275
+ Q_UNREACHABLE ();
261
276
}
262
277
} else if (role == ThreadEndRole) {
263
278
switch (tag) {
@@ -270,6 +285,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
270
285
case Tag::Processes:
271
286
case Tag::Tracepoints:
272
287
return m_time.end ;
288
+ case Tag::Favorites:
289
+ // they are handled elsewhere
290
+ Q_UNREACHABLE ();
273
291
}
274
292
} else if (role == ThreadNameRole) {
275
293
switch (tag) {
@@ -283,6 +301,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
283
301
case Tag::Processes:
284
302
case Tag::Tracepoints:
285
303
return {};
304
+ case Tag::Favorites:
305
+ // they are handled elsewhere
306
+ Q_UNREACHABLE ();
286
307
}
287
308
} else if (role == ThreadIdRole) {
288
309
switch (tag) {
@@ -295,6 +316,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
295
316
case Tag::Processes:
296
317
case Tag::Tracepoints:
297
318
return Data::INVALID_TID;
319
+ case Tag::Favorites:
320
+ // they are handled elsewhere
321
+ Q_UNREACHABLE ();
298
322
}
299
323
} else if (role == ProcessIdRole) {
300
324
switch (tag) {
@@ -307,6 +331,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
307
331
case Tag::Processes:
308
332
case Tag::Tracepoints:
309
333
return Data::INVALID_PID;
334
+ case Tag::Favorites:
335
+ // they are handled elsewhere
336
+ Q_UNREACHABLE ();
310
337
}
311
338
} else if (role == CpuIdRole) {
312
339
switch (tag) {
@@ -319,6 +346,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
319
346
case Tag::Threads:
320
347
case Tag::Tracepoints:
321
348
return Data::INVALID_CPU_ID;
349
+ case Tag::Favorites:
350
+ // they are handled elsewhere
351
+ Q_UNREACHABLE ();
322
352
}
323
353
} else if (role == EventsRole) {
324
354
switch (tag) {
@@ -333,6 +363,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
333
363
case Tag::Overview:
334
364
case Tag::Processes:
335
365
return QVariant::fromValue (Data::Events ());
366
+ case Tag::Favorites:
367
+ // they are handled elsewhere
368
+ Q_UNREACHABLE ();
336
369
}
337
370
} else if (role == SortRole) {
338
371
if (index.column () == ThreadColumn) {
@@ -348,6 +381,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
348
381
case Tag::Overview:
349
382
case Tag::Processes:
350
383
return {};
384
+ case Tag::Favorites:
385
+ // they are handled elsewhere
386
+ Q_UNREACHABLE ();
351
387
}
352
388
} else {
353
389
switch (tag) {
@@ -362,6 +398,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
362
398
case Tag::Overview:
363
399
case Tag::Processes:
364
400
return {};
401
+ case Tag::Favorites:
402
+ // they are handled elsewhere
403
+ Q_UNREACHABLE ();
365
404
}
366
405
}
367
406
}
@@ -381,6 +420,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
381
420
case Tag::Overview:
382
421
case Tag::Processes:
383
422
return {};
423
+ case Tag::Favorites:
424
+ // they are handled elsewhere
425
+ Q_UNREACHABLE ();
384
426
}
385
427
} else if (role == Qt::ToolTipRole) {
386
428
QString tooltip;
@@ -421,6 +463,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
421
463
case Tag::Overview:
422
464
case Tag::Processes:
423
465
break ;
466
+ case Tag::Favorites:
467
+ // they are handled elsewhere
468
+ Q_UNREACHABLE ();
424
469
}
425
470
426
471
tooltip += tr (" Number of Events: %1 (%2% of the total)" )
@@ -442,6 +487,9 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
442
487
case Tag::Overview:
443
488
case Tag::Processes:
444
489
return {};
490
+ case Tag::Favorites:
491
+ // they are handled elsewhere
492
+ Q_UNREACHABLE ();
445
493
}
446
494
}
447
495
break ;
@@ -456,6 +504,8 @@ QVariant EventModel::data(const QModelIndex& index, int role) const
456
504
void EventModel::setData (const Data::EventResults& data)
457
505
{
458
506
beginResetModel ();
507
+ m_favourites.clear ();
508
+
459
509
m_data = data;
460
510
m_totalEvents = 0 ;
461
511
m_maxCost = 0 ;
@@ -516,6 +566,7 @@ QModelIndex EventModel::index(int row, int column, const QModelIndex& parent) co
516
566
case Tag::Cpus:
517
567
case Tag::Tracepoints:
518
568
case Tag::Threads:
569
+ case Tag::Favorites:
519
570
break ;
520
571
case Tag::Root: // root has the 1st level children: Overview
521
572
return createIndex (row, column, static_cast <quintptr>(Tag::Overview));
@@ -527,6 +578,8 @@ QModelIndex EventModel::index(int row, int column, const QModelIndex& parent) co
527
578
return createIndex (row, column, static_cast <quintptr>(Tag::Processes));
528
579
case OverViewRow::Tracepoint_Row:
529
580
return createIndex (row, column, static_cast <quintptr>(Tag::Tracepoints));
581
+ case OverViewRow::Favorite_Row:
582
+ return createIndex (row, column, static_cast <quintptr>(Tag::Favorites));
530
583
}
531
584
Q_UNREACHABLE ();
532
585
case Tag::Processes: // 3rd level children: Threads
@@ -549,11 +602,26 @@ QModelIndex EventModel::parent(const QModelIndex& child) const
549
602
return createIndex (OverViewRow::Process_Row, 0 , static_cast <quintptr>(Tag::Overview));
550
603
case Tag::Tracepoints:
551
604
return createIndex (OverViewRow::Tracepoint_Row, 0 , static_cast <qintptr>(Tag::Overview));
552
- case Tag::Threads: {
605
+ case Tag::Favorites:
606
+ return createIndex (OverViewRow::Favorite_Row, 0 , static_cast <qintptr>(Tag::Overview));
607
+ case Tag::Threads:
553
608
const auto parentRow = tagData (child.internalId ());
554
609
return createIndex (parentRow, 0 , static_cast <quintptr>(Tag::Processes));
555
610
}
556
- }
557
611
558
612
return {};
559
613
}
614
+
615
+ void EventModel::addToFavorites (const QModelIndex& index)
616
+ {
617
+ Q_ASSERT (index.model () == this );
618
+
619
+ if (m_favourites.contains (index)) {
620
+ return ;
621
+ }
622
+
623
+ const int position = m_favourites.size ();
624
+ beginInsertRows (createIndex (Favorite_Row, 0 , static_cast <quintptr>(Tag::Overview)), position, position);
625
+ m_favourites.push_back (index);
626
+ endInsertRows ();
627
+ }
0 commit comments