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);
}
+2 -1
View File
@@ -48,7 +48,8 @@ public:
void setAnnotationObject(const SDObject *annotation);
signals:
private slots:
void customContextMenu(QModelIndex index, QMenu *menu);
protected:
@@ -360,6 +360,8 @@ void RDTreeView::contextMenuEvent(QContextMenuEvent *event)
QObject::connect(&copy, &QAction::triggered, [this, index, pos]() { copyIndex(pos, index); });
emit customContextMenu(index, &contextMenu);
RDDialog::show(&contextMenu, viewport()->mapToGlobal(pos));
}
+1
View File
@@ -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;