23
23
******************************************************************************/
24
24
25
25
#include " PerformanceCounterSelection.h"
26
+ #include < QMenu>
26
27
#include < QSet>
27
28
#include " Code/CaptureContext.h"
28
29
#include " Code/Interface/QRDInterface.h"
30
+ #include " Code/Resources.h"
29
31
#include " ui_PerformanceCounterSelection.h"
30
32
31
33
#include < unordered_map>
@@ -87,9 +89,9 @@ QString ToString(CounterFamily family)
87
89
const int PerformanceCounterSelection::CounterDescriptionRole = Qt::UserRole + 1 ;
88
90
const int PerformanceCounterSelection::CounterIdRole = Qt::UserRole + 2 ;
89
91
90
- void PerformanceCounterSelection::expandToNode (QTreeWidgetItem *node)
92
+ void PerformanceCounterSelection::expandToNode (RDTreeWidgetItem *node)
91
93
{
92
- QTreeWidgetItem *n = node;
94
+ RDTreeWidgetItem *n = node;
93
95
while (node != NULL )
94
96
{
95
97
ui->counterTree ->expandItem (node);
@@ -107,8 +109,13 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
107
109
{
108
110
ui->setupUi (this );
109
111
110
- connect (ui->counterTree , &QTreeWidget::currentItemChanged,
111
- [this ](QTreeWidgetItem *item, QTreeWidgetItem *) -> void {
112
+ setWindowFlags (windowFlags () & ~Qt::WindowContextHelpButtonHint);
113
+
114
+ ui->counterTree ->setColumns ({QString ()});
115
+ ui->counterTree ->setHeaderHidden (true );
116
+
117
+ connect (ui->counterTree , &RDTreeWidget::currentItemChanged,
118
+ [this ](RDTreeWidgetItem *item, RDTreeWidgetItem *) -> void {
112
119
const QVariant d = item->data (0 , CounterDescriptionRole);
113
120
114
121
if (d.isValid ())
@@ -123,7 +130,7 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
123
130
connect (ui->sampleCounters , &QPushButton::pressed, this , &PerformanceCounterSelection::accept);
124
131
connect (ui->cancel , &QPushButton::pressed, this , &PerformanceCounterSelection::reject);
125
132
126
- connect (ui->counterTree , &QTreeWidget ::itemChanged, [this ](QTreeWidgetItem *item, int ) -> void {
133
+ connect (ui->counterTree , &RDTreeWidget ::itemChanged, [this ](RDTreeWidgetItem *item, int ) -> void {
127
134
const QVariant d = item->data (0 , CounterIdRole);
128
135
129
136
if (d.isValid ())
@@ -159,6 +166,10 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
159
166
SetSelectedCounters (selectedCounters);
160
167
});
161
168
});
169
+
170
+ ui->counterTree ->setContextMenuPolicy (Qt::CustomContextMenu);
171
+ QObject::connect (ui->counterTree , &RDTreeWidget::customContextMenuRequested, this ,
172
+ &PerformanceCounterSelection::counterTree_contextMenu);
162
173
}
163
174
164
175
PerformanceCounterSelection::~PerformanceCounterSelection ()
@@ -171,10 +182,10 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
171
182
ui->counterTree ->clear ();
172
183
ui->enabledCounters ->clear ();
173
184
174
- QTreeWidgetItem *currentRoot = NULL ;
185
+ RDTreeWidgetItem *currentRoot = NULL ;
175
186
CounterFamily currentFamily = CounterFamily::Unknown;
176
187
177
- std::unordered_map<std::string, QTreeWidgetItem *> categories;
188
+ std::unordered_map<std::string, RDTreeWidgetItem *> categories;
178
189
179
190
for (const CounterDescription &desc : descriptions)
180
191
{
@@ -184,23 +195,26 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
184
195
const CounterFamily family = GetCounterFamily (desc.counterID );
185
196
if (family != currentFamily)
186
197
{
187
- currentRoot = new QTreeWidgetItem (ui->counterTree );
198
+ currentRoot = new RDTreeWidgetItem ();
199
+ ui->counterTree ->addTopLevelItem (currentRoot);
188
200
currentRoot->setText (0 , ToString (family));
189
201
190
202
categories.clear ();
191
203
192
204
currentFamily = family;
193
205
}
194
206
195
- QTreeWidgetItem *categoryItem = NULL ;
207
+ RDTreeWidgetItem *categoryItem = NULL ;
196
208
197
209
const std::string category = desc.category ;
198
210
auto categoryIterator = categories.find (category);
199
211
200
212
if (categoryIterator == categories.end ())
201
213
{
202
- QTreeWidgetItem *item = new QTreeWidgetItem (currentRoot);
214
+ RDTreeWidgetItem *item = new RDTreeWidgetItem ();
215
+ currentRoot->addChild (item);
203
216
item->setText (0 , desc.category );
217
+
204
218
categories[category] = item;
205
219
categoryItem = item;
206
220
}
@@ -209,7 +223,8 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
209
223
categoryItem = categoryIterator->second ;
210
224
}
211
225
212
- QTreeWidgetItem *counterItem = new QTreeWidgetItem (categoryItem);
226
+ RDTreeWidgetItem *counterItem = new RDTreeWidgetItem ();
227
+ categoryItem->addChild (counterItem);
213
228
counterItem->setText (0 , desc.name );
214
229
counterItem->setData (0 , CounterDescriptionRole, desc.description );
215
230
counterItem->setData (0 , CounterIdRole, (uint32_t )desc.counterID );
@@ -228,7 +243,7 @@ void PerformanceCounterSelection::SetSelectedCounters(const QList<GPUCounter> &c
228
243
{
229
244
// We we walk over the complete tree, and toggle everything so it
230
245
// matches the settings
231
- QTreeWidgetItemIterator it (ui->counterTree );
246
+ RDTreeWidgetItemIterator it (ui->counterTree );
232
247
while (*it)
233
248
{
234
249
const QVariant id = (*it)->data (0 , Qt::UserRole + 2 );
@@ -327,6 +342,32 @@ void PerformanceCounterSelection::Load()
327
342
tr (" Couldn't open path %1 for reading." ).arg (filename));
328
343
}
329
344
}
345
+ void PerformanceCounterSelection::counterTree_contextMenu (const QPoint &pos)
346
+ {
347
+ RDTreeWidgetItem *item = ui->counterTree ->itemAt (pos);
348
+
349
+ QMenu contextMenu (this );
350
+
351
+ QAction expandAll (tr (" &Expand All" ), this );
352
+ QAction collapseAll (tr (" &Collapse All" ), this );
353
+
354
+ contextMenu.addAction (&expandAll);
355
+ contextMenu.addAction (&collapseAll);
356
+
357
+ expandAll.setIcon (Icons::arrow_out ());
358
+ collapseAll.setIcon (Icons::arrow_in ());
359
+
360
+ expandAll.setEnabled (item && item->childCount () > 0 );
361
+ collapseAll.setEnabled (item && item->childCount () > 0 );
362
+
363
+ QObject::connect (&expandAll, &QAction::triggered,
364
+ [this , item]() { ui->counterTree ->expandAllItems (item); });
365
+
366
+ QObject::connect (&collapseAll, &QAction::triggered,
367
+ [this , item]() { ui->counterTree ->collapseAllItems (item); });
368
+
369
+ RDDialog::show (&contextMenu, ui->counterTree ->viewport ()->mapToGlobal (pos));
370
+ }
330
371
331
372
void PerformanceCounterSelection::on_enabledCounters_activated (const QModelIndex &index)
332
373
{
@@ -343,7 +384,7 @@ void PerformanceCounterSelection::on_enabledCounters_activated(const QModelIndex
343
384
if (it != m_CounterToTreeItem.end ())
344
385
{
345
386
ui->counterTree ->setCurrentItem (it.value ());
346
- it.value ()-> setSelected ( true );
387
+ ui-> counterTree -> setSelectedItem ( it.value ());
347
388
348
389
expandToNode (it.value ());
349
390
}
0 commit comments