Skip to content

Commit 371b3b3

Browse files
committed
Change to RDTreeWidget and add context menu with expand/collapse all
1 parent 38fcc87 commit 371b3b3

File tree

3 files changed

+70
-24
lines changed

3 files changed

+70
-24
lines changed

qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.cpp

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
******************************************************************************/
2424

2525
#include "PerformanceCounterSelection.h"
26+
#include <QMenu>
2627
#include <QSet>
2728
#include "Code/CaptureContext.h"
2829
#include "Code/Interface/QRDInterface.h"
30+
#include "Code/Resources.h"
2931
#include "ui_PerformanceCounterSelection.h"
3032

3133
#include <unordered_map>
@@ -87,9 +89,9 @@ QString ToString(CounterFamily family)
8789
const int PerformanceCounterSelection::CounterDescriptionRole = Qt::UserRole + 1;
8890
const int PerformanceCounterSelection::CounterIdRole = Qt::UserRole + 2;
8991

90-
void PerformanceCounterSelection::expandToNode(QTreeWidgetItem *node)
92+
void PerformanceCounterSelection::expandToNode(RDTreeWidgetItem *node)
9193
{
92-
QTreeWidgetItem *n = node;
94+
RDTreeWidgetItem *n = node;
9395
while(node != NULL)
9496
{
9597
ui->counterTree->expandItem(node);
@@ -107,8 +109,13 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
107109
{
108110
ui->setupUi(this);
109111

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 {
112119
const QVariant d = item->data(0, CounterDescriptionRole);
113120

114121
if(d.isValid())
@@ -123,7 +130,7 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
123130
connect(ui->sampleCounters, &QPushButton::pressed, this, &PerformanceCounterSelection::accept);
124131
connect(ui->cancel, &QPushButton::pressed, this, &PerformanceCounterSelection::reject);
125132

126-
connect(ui->counterTree, &QTreeWidget::itemChanged, [this](QTreeWidgetItem *item, int) -> void {
133+
connect(ui->counterTree, &RDTreeWidget::itemChanged, [this](RDTreeWidgetItem *item, int) -> void {
127134
const QVariant d = item->data(0, CounterIdRole);
128135

129136
if(d.isValid())
@@ -159,6 +166,10 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
159166
SetSelectedCounters(selectedCounters);
160167
});
161168
});
169+
170+
ui->counterTree->setContextMenuPolicy(Qt::CustomContextMenu);
171+
QObject::connect(ui->counterTree, &RDTreeWidget::customContextMenuRequested, this,
172+
&PerformanceCounterSelection::counterTree_contextMenu);
162173
}
163174

164175
PerformanceCounterSelection::~PerformanceCounterSelection()
@@ -171,10 +182,10 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
171182
ui->counterTree->clear();
172183
ui->enabledCounters->clear();
173184

174-
QTreeWidgetItem *currentRoot = NULL;
185+
RDTreeWidgetItem *currentRoot = NULL;
175186
CounterFamily currentFamily = CounterFamily::Unknown;
176187

177-
std::unordered_map<std::string, QTreeWidgetItem *> categories;
188+
std::unordered_map<std::string, RDTreeWidgetItem *> categories;
178189

179190
for(const CounterDescription &desc : descriptions)
180191
{
@@ -184,23 +195,26 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
184195
const CounterFamily family = GetCounterFamily(desc.counterID);
185196
if(family != currentFamily)
186197
{
187-
currentRoot = new QTreeWidgetItem(ui->counterTree);
198+
currentRoot = new RDTreeWidgetItem();
199+
ui->counterTree->addTopLevelItem(currentRoot);
188200
currentRoot->setText(0, ToString(family));
189201

190202
categories.clear();
191203

192204
currentFamily = family;
193205
}
194206

195-
QTreeWidgetItem *categoryItem = NULL;
207+
RDTreeWidgetItem *categoryItem = NULL;
196208

197209
const std::string category = desc.category;
198210
auto categoryIterator = categories.find(category);
199211

200212
if(categoryIterator == categories.end())
201213
{
202-
QTreeWidgetItem *item = new QTreeWidgetItem(currentRoot);
214+
RDTreeWidgetItem *item = new RDTreeWidgetItem();
215+
currentRoot->addChild(item);
203216
item->setText(0, desc.category);
217+
204218
categories[category] = item;
205219
categoryItem = item;
206220
}
@@ -209,7 +223,8 @@ void PerformanceCounterSelection::SetCounters(const QVector<CounterDescription>
209223
categoryItem = categoryIterator->second;
210224
}
211225

212-
QTreeWidgetItem *counterItem = new QTreeWidgetItem(categoryItem);
226+
RDTreeWidgetItem *counterItem = new RDTreeWidgetItem();
227+
categoryItem->addChild(counterItem);
213228
counterItem->setText(0, desc.name);
214229
counterItem->setData(0, CounterDescriptionRole, desc.description);
215230
counterItem->setData(0, CounterIdRole, (uint32_t)desc.counterID);
@@ -228,7 +243,7 @@ void PerformanceCounterSelection::SetSelectedCounters(const QList<GPUCounter> &c
228243
{
229244
// We we walk over the complete tree, and toggle everything so it
230245
// matches the settings
231-
QTreeWidgetItemIterator it(ui->counterTree);
246+
RDTreeWidgetItemIterator it(ui->counterTree);
232247
while(*it)
233248
{
234249
const QVariant id = (*it)->data(0, Qt::UserRole + 2);
@@ -327,6 +342,32 @@ void PerformanceCounterSelection::Load()
327342
tr("Couldn't open path %1 for reading.").arg(filename));
328343
}
329344
}
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+
}
330371

331372
void PerformanceCounterSelection::on_enabledCounters_activated(const QModelIndex &index)
332373
{
@@ -343,7 +384,7 @@ void PerformanceCounterSelection::on_enabledCounters_activated(const QModelIndex
343384
if(it != m_CounterToTreeItem.end())
344385
{
345386
ui->counterTree->setCurrentItem(it.value());
346-
it.value()->setSelected(true);
387+
ui->counterTree->setSelectedItem(it.value());
347388

348389
expandToNode(it.value());
349390
}

qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PerformanceCounterSelection;
3333

3434
struct ICaptureContext;
3535
class QListWidgetItem;
36-
class QTreeWidgetItem;
36+
class RDTreeWidgetItem;
3737

3838
class PerformanceCounterSelection : public QDialog
3939
{
@@ -57,17 +57,20 @@ private slots:
5757
// automatic slots
5858
void on_enabledCounters_activated(const QModelIndex &index);
5959

60+
// manual slots
61+
void counterTree_contextMenu(const QPoint &pos);
62+
6063
private:
6164
void SetCounters(const QVector<CounterDescription> &descriptions);
62-
void expandToNode(QTreeWidgetItem *node);
65+
void expandToNode(RDTreeWidgetItem *node);
6366

6467
Ui::PerformanceCounterSelection *ui;
6568

6669
ICaptureContext &m_Ctx;
6770
QMap<GPUCounter, QListWidgetItem *> m_SelectedCounters;
6871
QMap<GPUCounter, Uuid> m_CounterToUuid;
6972
QMap<Uuid, GPUCounter> m_UuidToCounter;
70-
QMap<GPUCounter, QTreeWidgetItem *> m_CounterToTreeItem;
73+
QMap<GPUCounter, RDTreeWidgetItem *> m_CounterToTreeItem;
7174

7275
static const int CounterDescriptionRole;
7376
static const int CounterIdRole;

qrenderdoc/Windows/Dialogs/PerformanceCounterSelection.ui

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,10 @@
2424
</widget>
2525
</item>
2626
<item>
27-
<widget class="QTreeWidget" name="counterTree">
28-
<attribute name="headerVisible">
29-
<bool>false</bool>
27+
<widget class="RDTreeWidget" name="counterTree">
28+
<attribute name="headerDefaultSectionSize">
29+
<number>0</number>
3030
</attribute>
31-
<column>
32-
<property name="text">
33-
<string>1</string>
34-
</property>
35-
</column>
3631
</widget>
3732
</item>
3833
</layout>
@@ -115,6 +110,13 @@
115110
</item>
116111
</layout>
117112
</widget>
113+
<customwidgets>
114+
<customwidget>
115+
<class>RDTreeWidget</class>
116+
<extends>QTreeView</extends>
117+
<header>Widgets/Extended/RDTreeWidget.h</header>
118+
</customwidget>
119+
</customwidgets>
118120
<resources/>
119121
<connections/>
120122
</ui>

0 commit comments

Comments
 (0)