From 4afe5017b0aacef32f5bf3fc4e146eea3d0b1352 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 17 Sep 2025 15:37:27 +0100 Subject: [PATCH] Add a right-click handle to show an annotation in the event browser --- qrenderdoc/Widgets/AnnotationDisplay.cpp | 35 ++++++++++++++++++++++ qrenderdoc/Widgets/AnnotationDisplay.h | 3 +- qrenderdoc/Widgets/Extended/RDTreeView.cpp | 2 ++ qrenderdoc/Widgets/Extended/RDTreeView.h | 1 + 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/qrenderdoc/Widgets/AnnotationDisplay.cpp b/qrenderdoc/Widgets/AnnotationDisplay.cpp index e3b66b9d9..f90d4582a 100644 --- a/qrenderdoc/Widgets/AnnotationDisplay.cpp +++ b/qrenderdoc/Widgets/AnnotationDisplay.cpp @@ -23,7 +23,9 @@ ******************************************************************************/ #include "AnnotationDisplay.h" +#include #include +#include #include AnnotationDisplay::AnnotationDisplay(ICaptureContext &ctx, bool standalone, QWidget *parent) @@ -49,6 +51,9 @@ AnnotationDisplay::AnnotationDisplay(ICaptureContext &ctx, bool standalone, QWid setWindowTitle(tr("Annotation Viewer")); + QObject::connect(m_Tree, &RDTreeWidget::customContextMenu, this, + &AnnotationDisplay::customContextMenu); + if(m_Standalone) m_Ctx.AddCaptureViewer(this); } @@ -141,3 +146,33 @@ void AnnotationDisplay::setAnnotationObject(const SDObject *annotation) m_Tree->applyExpansion(m_Expansion, 0); } + +void AnnotationDisplay::customContextMenu(QModelIndex index, QMenu *menu) +{ + RDTreeWidgetItem *item = m_Tree->itemForIndex(index); + const SDObject *obj = (const SDObject *)item->tag().value(); + + rdcstr path; + // don't include the root node, it's not part of the path, so only iterate over nodes that have + // parents themselves + while(obj && obj->GetParent()) + { + if(path.empty()) + path = obj->name; + else + path = obj->name + rdcstr(".") + path; + obj = obj->GetParent(); + } + + if(path.empty()) + return; + + QAction *sep = menu->insertSeparator(menu->actions()[0]); + + QAction *showInEventBrowser = new QAction(tr("&Highlight in Event Browser"), menu); + + QObject::connect(showInEventBrowser, &QAction::triggered, + [this, path]() { m_Ctx.GetEventBrowser()->SetHighlightedAnnotation(path); }); + + menu->insertAction(sep, showInEventBrowser); +} diff --git a/qrenderdoc/Widgets/AnnotationDisplay.h b/qrenderdoc/Widgets/AnnotationDisplay.h index 554d69e71..348ebb4dc 100644 --- a/qrenderdoc/Widgets/AnnotationDisplay.h +++ b/qrenderdoc/Widgets/AnnotationDisplay.h @@ -48,7 +48,8 @@ public: void setAnnotationObject(const SDObject *annotation); -signals: +private slots: + void customContextMenu(QModelIndex index, QMenu *menu); protected: diff --git a/qrenderdoc/Widgets/Extended/RDTreeView.cpp b/qrenderdoc/Widgets/Extended/RDTreeView.cpp index 60a654e51..006837477 100644 --- a/qrenderdoc/Widgets/Extended/RDTreeView.cpp +++ b/qrenderdoc/Widgets/Extended/RDTreeView.cpp @@ -360,6 +360,8 @@ void RDTreeView::contextMenuEvent(QContextMenuEvent *event) QObject::connect(©, &QAction::triggered, [this, index, pos]() { copyIndex(pos, index); }); + emit customContextMenu(index, &contextMenu); + RDDialog::show(&contextMenu, viewport()->mapToGlobal(pos)); } diff --git a/qrenderdoc/Widgets/Extended/RDTreeView.h b/qrenderdoc/Widgets/Extended/RDTreeView.h index 87407e247..086c5fc63 100644 --- a/qrenderdoc/Widgets/Extended/RDTreeView.h +++ b/qrenderdoc/Widgets/Extended/RDTreeView.h @@ -183,6 +183,7 @@ public: signals: void leave(QEvent *e); void keyPress(QKeyEvent *e); + void customContextMenu(QModelIndex index, QMenu *menu); protected: void mouseMoveEvent(QMouseEvent *e) override;