@@ -88,6 +88,58 @@ QString ToString(CounterFamily family)
88
88
89
89
const int PerformanceCounterSelection::CounterDescriptionRole = Qt::UserRole + 1 ;
90
90
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
+ }
91
143
92
144
void PerformanceCounterSelection::expandToNode (RDTreeWidgetItem *node)
93
145
{
@@ -133,6 +185,8 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
133
185
connect (ui->counterTree , &RDTreeWidget::itemChanged, [this ](RDTreeWidgetItem *item, int ) -> void {
134
186
const QVariant d = item->data (0 , CounterIdRole);
135
187
188
+ static bool recurse = false ;
189
+
136
190
if (d.isValid ())
137
191
{
138
192
if (item->checkState (0 ) == Qt::Checked)
@@ -149,6 +203,37 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
149
203
QListWidgetItem *listItem = m_SelectedCounters.take ((GPUCounter)d.toUInt ());
150
204
delete listItem;
151
205
}
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
+ }
152
237
}
153
238
});
154
239
@@ -198,6 +283,8 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
198
283
currentRoot = new RDTreeWidgetItem ();
199
284
ui->counterTree ->addTopLevelItem (currentRoot);
200
285
currentRoot->setText (0 , ToString (family));
286
+ currentRoot->setCheckState (0 , Qt::Unchecked);
287
+ currentRoot->setData (0 , PreviousCheckStateRole, Qt::Unchecked);
201
288
202
289
categories.clear ();
203
290
@@ -214,6 +301,8 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
214
301
RDTreeWidgetItem *item = new RDTreeWidgetItem ();
215
302
currentRoot->addChild (item);
216
303
item->setText (0 , desc.category );
304
+ item->setCheckState (0 , Qt::Unchecked);
305
+ item->setData (0 , PreviousCheckStateRole, Qt::Unchecked);
217
306
218
307
categories[category] = item;
219
308
categoryItem = item;
@@ -229,6 +318,7 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
229
318
counterItem->setData (0 , CounterDescriptionRole, desc.description );
230
319
counterItem->setData (0 , CounterIdRole, (uint32_t )desc.counterID );
231
320
counterItem->setCheckState (0 , Qt::Unchecked);
321
+ counterItem->setData (0 , PreviousCheckStateRole, Qt::Unchecked);
232
322
233
323
m_CounterToTreeItem[desc.counterID ] = counterItem;
234
324
}
0 commit comments