mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-23 06:56:40 +00:00
Add custom context menu for all tree views with expand/collapse and copy
This commit is contained in:
@@ -25,13 +25,16 @@
|
||||
#include "RDTreeView.h"
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QProxyStyle>
|
||||
#include <QStylePainter>
|
||||
#include <QToolTip>
|
||||
#include <QWheelEvent>
|
||||
#include "Code/Resources.h"
|
||||
|
||||
static int GetDepth(const QAbstractItemModel *model, const QModelIndex &idx)
|
||||
{
|
||||
@@ -225,6 +228,67 @@ void RDTreeView::keyPressEvent(QKeyEvent *e)
|
||||
emit(keyPress(e));
|
||||
}
|
||||
|
||||
void RDTreeView::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QPoint pos = event->pos();
|
||||
|
||||
QModelIndex index = indexAt(pos);
|
||||
|
||||
QMenu contextMenu(this);
|
||||
|
||||
QAction expandAllAction(tr("&Expand All"), this);
|
||||
QAction collapseAllAction(tr("&Collapse All"), this);
|
||||
QAction copy(tr("&Copy"), this);
|
||||
|
||||
if(rootIsDecorated())
|
||||
{
|
||||
contextMenu.addAction(&expandAllAction);
|
||||
contextMenu.addAction(&collapseAllAction);
|
||||
contextMenu.addSeparator();
|
||||
}
|
||||
contextMenu.addAction(©);
|
||||
|
||||
expandAllAction.setIcon(Icons::arrow_out());
|
||||
collapseAllAction.setIcon(Icons::arrow_in());
|
||||
|
||||
expandAllAction.setEnabled(index.isValid() && model()->rowCount(index) > 0);
|
||||
collapseAllAction.setEnabled(index.isValid() && model()->rowCount(index) > 0);
|
||||
|
||||
QObject::connect(&expandAllAction, &QAction::triggered, [this, index]() { expandAll(index); });
|
||||
|
||||
QObject::connect(&collapseAllAction, &QAction::triggered, [this, index]() { collapseAll(index); });
|
||||
|
||||
QObject::connect(©, &QAction::triggered, [this, index, pos]() {
|
||||
bool clearsel = false;
|
||||
if(selectionModel()->selectedRows().empty())
|
||||
{
|
||||
setSelection(QRect(pos, QSize(1, 1)), selectionCommand(index));
|
||||
clearsel = true;
|
||||
}
|
||||
copySelection();
|
||||
if(clearsel)
|
||||
selectionModel()->clear();
|
||||
});
|
||||
|
||||
RDDialog::show(&contextMenu, viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void RDTreeView::expandAll(QModelIndex index)
|
||||
{
|
||||
expand(index);
|
||||
|
||||
for(int r = 0, rows = model()->rowCount(index); r < rows; r++)
|
||||
expandAll(model()->index(r, 0, index));
|
||||
}
|
||||
|
||||
void RDTreeView::collapseAll(QModelIndex index)
|
||||
{
|
||||
collapse(index);
|
||||
|
||||
for(int r = 0, rows = model()->rowCount(index); r < rows; r++)
|
||||
collapseAll(model()->index(r, 0, index));
|
||||
}
|
||||
|
||||
bool RDTreeView::viewportEvent(QEvent *event)
|
||||
{
|
||||
if(m_TooltipElidedItems && event->type() == QEvent::ToolTip)
|
||||
|
||||
@@ -127,6 +127,11 @@ public:
|
||||
void clearInternalExpansions() { m_Expansions.clear(); }
|
||||
virtual void copySelection();
|
||||
|
||||
void expandAll(QModelIndex index);
|
||||
void collapseAll(QModelIndex index);
|
||||
using QTreeView::expandAll;
|
||||
using QTreeView::collapseAll;
|
||||
|
||||
signals:
|
||||
void leave(QEvent *e);
|
||||
void keyPress(QKeyEvent *e);
|
||||
@@ -137,6 +142,7 @@ protected:
|
||||
void leaveEvent(QEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
bool viewportEvent(QEvent *event) override;
|
||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||
|
||||
void drawRow(QPainter *painter, const QStyleOptionViewItem &options,
|
||||
const QModelIndex &index) const override;
|
||||
|
||||
@@ -714,15 +714,10 @@ void RDTreeWidget::expandItem(RDTreeWidgetItem *item)
|
||||
{
|
||||
expand(m_model->indexForItem(item, 0));
|
||||
}
|
||||
|
||||
void RDTreeWidget::expandAllItems(RDTreeWidgetItem *item)
|
||||
{
|
||||
expandItem(item);
|
||||
|
||||
for(int c = 0; c < item->childCount(); c++)
|
||||
{
|
||||
RDTreeWidgetItem *child = item->child(c);
|
||||
expandAllItems(child);
|
||||
}
|
||||
expandAll(m_model->indexForItem(item, 0));
|
||||
}
|
||||
|
||||
void RDTreeWidget::collapseItem(RDTreeWidgetItem *item)
|
||||
@@ -732,13 +727,7 @@ void RDTreeWidget::collapseItem(RDTreeWidgetItem *item)
|
||||
|
||||
void RDTreeWidget::collapseAllItems(RDTreeWidgetItem *item)
|
||||
{
|
||||
collapseItem(item);
|
||||
|
||||
for(int c = 0; c < item->childCount(); c++)
|
||||
{
|
||||
RDTreeWidgetItem *child = item->child(c);
|
||||
collapseAllItems(child);
|
||||
}
|
||||
collapseAll(m_model->indexForItem(item, 0));
|
||||
}
|
||||
|
||||
void RDTreeWidget::scrollToItem(RDTreeWidgetItem *node)
|
||||
|
||||
@@ -265,10 +265,6 @@ PerformanceCounterSelection::PerformanceCounterSelection(ICaptureContext &ctx,
|
||||
SetSelectedCounters(selectedCounters);
|
||||
});
|
||||
});
|
||||
|
||||
ui->counterTree->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
QObject::connect(ui->counterTree, &RDTreeWidget::customContextMenuRequested, this,
|
||||
&PerformanceCounterSelection::counterTree_contextMenu);
|
||||
}
|
||||
|
||||
PerformanceCounterSelection::~PerformanceCounterSelection()
|
||||
@@ -458,32 +454,6 @@ void PerformanceCounterSelection::Load()
|
||||
tr("Couldn't open path %1 for reading.").arg(filename));
|
||||
}
|
||||
}
|
||||
void PerformanceCounterSelection::counterTree_contextMenu(const QPoint &pos)
|
||||
{
|
||||
RDTreeWidgetItem *item = ui->counterTree->itemAt(pos);
|
||||
|
||||
QMenu contextMenu(this);
|
||||
|
||||
QAction expandAll(tr("&Expand All"), this);
|
||||
QAction collapseAll(tr("&Collapse All"), this);
|
||||
|
||||
contextMenu.addAction(&expandAll);
|
||||
contextMenu.addAction(&collapseAll);
|
||||
|
||||
expandAll.setIcon(Icons::arrow_out());
|
||||
collapseAll.setIcon(Icons::arrow_in());
|
||||
|
||||
expandAll.setEnabled(item && item->childCount() > 0);
|
||||
collapseAll.setEnabled(item && item->childCount() > 0);
|
||||
|
||||
QObject::connect(&expandAll, &QAction::triggered,
|
||||
[this, item]() { ui->counterTree->expandAllItems(item); });
|
||||
|
||||
QObject::connect(&collapseAll, &QAction::triggered,
|
||||
[this, item]() { ui->counterTree->collapseAllItems(item); });
|
||||
|
||||
RDDialog::show(&contextMenu, ui->counterTree->viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void PerformanceCounterSelection::on_enabledCounters_activated(const QModelIndex &index)
|
||||
{
|
||||
|
||||
@@ -57,9 +57,6 @@ private slots:
|
||||
// automatic slots
|
||||
void on_enabledCounters_activated(const QModelIndex &index);
|
||||
|
||||
// manual slots
|
||||
void counterTree_contextMenu(const QPoint &pos);
|
||||
|
||||
private:
|
||||
void SetCounters(const QVector<CounterDescription> &descriptions);
|
||||
void expandToNode(RDTreeWidgetItem *node);
|
||||
|
||||
@@ -130,10 +130,6 @@ ResourceInspector::ResourceInspector(ICaptureContext &ctx, QWidget *parent)
|
||||
ui->relatedResources->setFont(Formatter::PreferredFont());
|
||||
ui->resourceUsage->setFont(Formatter::PreferredFont());
|
||||
|
||||
ui->initChunks->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
QObject::connect(ui->initChunks, &RDTreeWidget::customContextMenuRequested, this,
|
||||
&ResourceInspector::initChunks_contextMenu);
|
||||
|
||||
{
|
||||
RDHeaderView *header = new RDHeaderView(Qt::Horizontal, this);
|
||||
ui->relatedResources->setHeader(header);
|
||||
@@ -463,33 +459,6 @@ void ResourceInspector::resource_doubleClicked(const QModelIndex &index)
|
||||
HighlightUsage();
|
||||
}
|
||||
|
||||
void ResourceInspector::initChunks_contextMenu(const QPoint &pos)
|
||||
{
|
||||
RDTreeWidgetItem *item = ui->initChunks->itemAt(pos);
|
||||
|
||||
QMenu contextMenu(this);
|
||||
|
||||
QAction expandAll(tr("&Expand All"), this);
|
||||
QAction collapseAll(tr("&Collapse All"), this);
|
||||
|
||||
contextMenu.addAction(&expandAll);
|
||||
contextMenu.addAction(&collapseAll);
|
||||
|
||||
expandAll.setIcon(Icons::arrow_out());
|
||||
collapseAll.setIcon(Icons::arrow_in());
|
||||
|
||||
expandAll.setEnabled(item && item->childCount() > 0);
|
||||
collapseAll.setEnabled(item && item->childCount() > 0);
|
||||
|
||||
QObject::connect(&expandAll, &QAction::triggered,
|
||||
[this, item]() { ui->initChunks->expandAllItems(item); });
|
||||
|
||||
QObject::connect(&collapseAll, &QAction::triggered,
|
||||
[this, item]() { ui->initChunks->collapseAllItems(item); });
|
||||
|
||||
RDDialog::show(&contextMenu, ui->initChunks->viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void ResourceInspector::on_viewContents_clicked()
|
||||
{
|
||||
TextureDescription *tex = m_Ctx.GetTexture(m_Resource);
|
||||
|
||||
@@ -65,7 +65,6 @@ public slots:
|
||||
|
||||
// manual slots
|
||||
void resource_doubleClicked(const QModelIndex &index);
|
||||
void initChunks_contextMenu(const QPoint &pos);
|
||||
|
||||
private slots:
|
||||
void on_viewContents_clicked();
|
||||
|
||||
Reference in New Issue
Block a user