Skip to content

Commit 9fabf70

Browse files
committed
Add checkboxes for counter groups to allow enable/disabling in batch
1 parent c0065a7 commit 9fabf70

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,58 @@ QString ToString(CounterFamily family)
8888

8989
const int PerformanceCounterSelection::CounterDescriptionRole = Qt::UserRole + 1;
9090
const int PerformanceCounterSelection::CounterIdRole = Qt::UserRole + 2;
91+
const int PerformanceCounterSelection::PreviousCheckStateRole = Qt::UserRole + 3;
92+
93+
void PerformanceCounterSelection::uncheckAllChildren(RDTreeWidgetItem *item)
94+
{
95+
for(int i = 0; i < item->childCount(); i++)
96+
{
97+
uncheckAllChildren(item->child(i));
98+
99+
item->child(i)->setCheckState(0, Qt::Unchecked);
100+
item->child(i)->setData(0, PreviousCheckStateRole, Qt::Unchecked);
101+
}
102+
}
103+
104+
void PerformanceCounterSelection::checkAllChildren(RDTreeWidgetItem *item)
105+
{
106+
for(int i = 0; i < item->childCount(); i++)
107+
{
108+
checkAllChildren(item->child(i));
109+
110+
item->child(i)->setCheckState(0, Qt::Checked);
111+
item->child(i)->setData(0, PreviousCheckStateRole, Qt::Checked);
112+
}
113+
}
114+
115+
void PerformanceCounterSelection::updateParentCheckState(RDTreeWidgetItem *item)
116+
{
117+
if(!item)
118+
return;
119+
120+
int numChecked = 0;
121+
int numPartial = 0;
122+
123+
for(int i = 0; i < item->childCount(); i++)
124+
{
125+
Qt::CheckState state = item->child(i)->checkState(0);
126+
if(state == Qt::PartiallyChecked)
127+
numPartial++;
128+
else if(state == Qt::Checked)
129+
numChecked++;
130+
}
131+
132+
if(numChecked == item->childCount())
133+
item->setCheckState(0, Qt::Checked);
134+
else if(numChecked > 0 || numPartial > 0)
135+
item->setCheckState(0, Qt::PartiallyChecked);
136+
else
137+
item->setCheckState(0, Qt::Unchecked);
138+
139+
item->setData(0, PreviousCheckStateRole, item->checkState(0));
140+
141+
updateParentCheckState(item->parent());
142+
}
91143

92144
void PerformanceCounterSelection::expandToNode(RDTreeWidgetItem *node)
93145
{
@@ -133,6 +185,8 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
133185
connect(ui->counterTree, &RDTreeWidget::itemChanged, [this](RDTreeWidgetItem *item, int) -> void {
134186
const QVariant d = item->data(0, CounterIdRole);
135187

188+
static bool recurse = false;
189+
136190
if(d.isValid())
137191
{
138192
if(item->checkState(0) == Qt::Checked)
@@ -149,6 +203,37 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
149203
QListWidgetItem *listItem = m_SelectedCounters.take((GPUCounter)d.toUInt());
150204
delete listItem;
151205
}
206+
207+
if(!recurse)
208+
{
209+
recurse = true;
210+
updateParentCheckState(item->parent());
211+
recurse = false;
212+
}
213+
}
214+
else if(!recurse)
215+
{
216+
Qt::CheckState prev = item->data(0, PreviousCheckStateRole).value<Qt::CheckState>();
217+
218+
if(item->checkState(0) != prev)
219+
{
220+
recurse = true;
221+
222+
if(item->checkState(0) == Qt::Checked)
223+
{
224+
checkAllChildren(item);
225+
}
226+
else
227+
{
228+
uncheckAllChildren(item);
229+
}
230+
231+
item->setData(0, PreviousCheckStateRole, item->checkState(0));
232+
233+
updateParentCheckState(item);
234+
235+
recurse = false;
236+
}
152237
}
153238
});
154239

@@ -198,6 +283,8 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
198283
currentRoot = new RDTreeWidgetItem();
199284
ui->counterTree->addTopLevelItem(currentRoot);
200285
currentRoot->setText(0, ToString(family));
286+
currentRoot->setCheckState(0, Qt::Unchecked);
287+
currentRoot->setData(0, PreviousCheckStateRole, Qt::Unchecked);
201288

202289
categories.clear();
203290

@@ -214,6 +301,8 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
214301
RDTreeWidgetItem *item = new RDTreeWidgetItem();
215302
currentRoot->addChild(item);
216303
item->setText(0, desc.category);
304+
item->setCheckState(0, Qt::Unchecked);
305+
item->setData(0, PreviousCheckStateRole, Qt::Unchecked);
217306

218307
categories[category] = item;
219308
categoryItem = item;
@@ -229,6 +318,7 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
229318
counterItem->setData(0, CounterDescriptionRole, desc.description);
230319
counterItem->setData(0, CounterIdRole, (uint32_t)desc.counterID);
231320
counterItem->setCheckState(0, Qt::Unchecked);
321+
counterItem->setData(0, PreviousCheckStateRole, Qt::Unchecked);
232322

233323
m_CounterToTreeItem[desc.counterID] = counterItem;
234324
}

qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ private slots:
6363
private:
6464
void SetCounters(const QVector<CounterDescription> &descriptions);
6565
void expandToNode(RDTreeWidgetItem *node);
66+
void updateParentCheckState(RDTreeWidgetItem *item);
6667

6768
Ui::PerformanceCounterSelection *ui;
6869

@@ -74,4 +75,7 @@ private slots:
7475

7576
static const int CounterDescriptionRole;
7677
static const int CounterIdRole;
78+
static const int PreviousCheckStateRole;
79+
void uncheckAllChildren(RDTreeWidgetItem *item);
80+
void checkAllChildren(RDTreeWidgetItem *item);
7781
};

0 commit comments

Comments
 (0)