Add a right-click handle to show an annotation in the event browser

This commit is contained in:
baldurk
2025-09-17 15:37:27 +01:00
parent 13ad7875f2
commit 4afe5017b0
4 changed files with 40 additions and 1 deletions
+35
View File
@@ -23,7 +23,9 @@
******************************************************************************/
#include "AnnotationDisplay.h"
#include <QAction>
#include <QHeaderView>
#include <QMenu>
#include <QVBoxLayout>
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<void *>();
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);
}