Skip to content

Commit

Permalink
Merge pull request #157 from cristian64/scanner_result_list_context_menu
Browse files Browse the repository at this point in the history
Add context menu to results list in scanner pane.
  • Loading branch information
dreamsyntax authored May 28, 2024
2 parents fd7827f + f63aa81 commit 7e15e25
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Source/GUI/MemScanner/MemScanWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "MemScanWidget.h"

#include <QApplication>
#include <QClipboard>
#include <QFontDatabase>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QMenu>
#include <QMessageBox>
#include <QRadioButton>
#include <QRegularExpression>
Expand Down Expand Up @@ -52,6 +55,9 @@ void MemScanWidget::initialiseWidgets()
m_tblResulstList->setMinimumWidth(385);
connect(m_tblResulstList, &QAbstractItemView::doubleClicked, this,
&MemScanWidget::onResultListDoubleClicked);
m_tblResulstList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_tblResulstList, &QWidget::customContextMenuRequested, this,
&MemScanWidget::onResultsListContextMenuRequested);

m_btnAddAll = new QPushButton(tr("Add all"));
connect(m_btnAddAll, &QPushButton::clicked, this, &MemScanWidget::onAddAll);
Expand Down Expand Up @@ -597,3 +603,24 @@ void MemScanWidget::onResultListDoubleClicked(const QModelIndex& index)
m_memScanner->getIsUnsigned(), m_memScanner->getBase());
}
}

void MemScanWidget::onResultsListContextMenuRequested(const QPoint& pos)
{
const QModelIndex index{m_tblResulstList->indexAt(pos)};
if (!index.isValid())
return;

QMenu menu(this);

QAction* const addAction{menu.addAction(tr("&Add Watch"))};
connect(addAction, &QAction::triggered, this,
[this, index] { onResultListDoubleClicked(index); });

QAction* const copyAction{menu.addAction(tr("&Copy Address"))};
connect(copyAction, &QAction::triggered, [index] {
const QModelIndex addressIndex{index.siblingAtColumn(ResultsListModel::RESULT_COL_ADDRESS)};
QApplication::clipboard()->setText(addressIndex.data(Qt::DisplayRole).toString());
});

menu.exec(m_tblResulstList->viewport()->mapToGlobal(pos));
}
1 change: 1 addition & 0 deletions Source/GUI/MemScanner/MemScanWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MemScanWidget : public QWidget
void onScanMemTypeChanged();
void onCurrentValuesUpdateTimer();
void onResultListDoubleClicked(const QModelIndex& index);
void onResultsListContextMenuRequested(const QPoint& pos);
void handleScannerErrors(Common::MemOperationReturnCode errorCode);
void onFirstScan();
void onNextScan();
Expand Down

0 comments on commit 7e15e25

Please sign in to comment.