Skip to content

Commit

Permalink
Add context menu to results list in scanner pane.
Browse files Browse the repository at this point in the history
The context menu currently includes two actions:
- **Add Watch** (same as double-clicking), added for discoverability.
- **Copy Address**, as users may occasionally want to copy the address
  without first having to create the watch entry.
  • Loading branch information
cristian64 committed May 27, 2024
1 parent bafe862 commit f63aa81
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 f63aa81

Please sign in to comment.