Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to copy pointer addresses (or base address) of a watch entry #167

Merged
merged 21 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
17ed8bf
feat: Added right click menu to copy pointer address in Edit Address …
jahorta Jul 7, 2024
edcf1d5
feat: Added right click option to copy pointer address from a watch e…
jahorta Jul 7, 2024
9a71205
fix: fixed CMake errors in Linux and macOS CI
jahorta Jul 7, 2024
17be2b6
fix: sprintf depreciated and no more implicit captures in lambda fxns
jahorta Jul 7, 2024
d7ac0e6
fix: type mismatch in comparison
jahorta Jul 7, 2024
8224672
imports are now in alphabetical order
jahorta Jul 11, 2024
f6ac8d8
Context menu in Edit Address Widget now tied to pointer address label
jahorta Jul 11, 2024
b86d544
now use isValid to check if index is a valid QModelIndex
jahorta Jul 11, 2024
1c3306a
context menu now copies the address to clipboard without a separate m…
jahorta Jul 11, 2024
df62c53
removed check for selection is of size zero.
jahorta Jul 11, 2024
bb9d84e
now checks against numerical address instead the string version
jahorta Jul 11, 2024
b199251
removed QString::number since .arg takes numbers
jahorta Jul 11, 2024
1e9bee5
made variables const where applicable and changed variable name for c…
jahorta Jul 11, 2024
86a36a7
changed static_cast to qobject_cast
jahorta Jul 13, 2024
b766803
added const to pointers which should not change
jahorta Jul 13, 2024
635357c
fixed indentation
jahorta Jul 13, 2024
9eac5df
removed unnecessary variable assignment
jahorta Jul 13, 2024
7b8d015
changed static_cast to qobject_cast
jahorta Jul 13, 2024
3f88e06
fix: clang format errors
jahorta Jul 13, 2024
95c8bbc
removed junk at start of line
jahorta Jul 13, 2024
d36266e
formatted for clang
jahorta Jul 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "DlgAddWatchEntry.h"

#include <QApplication>
#include <QClipboard>
#include <QDialogButtonBox>
#include <QFontDatabase>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QMenu>
#include <QMessageBox>
#include <QVBoxLayout>
#include <sstream>
Expand Down Expand Up @@ -167,6 +170,10 @@ void DlgAddWatchEntry::fillFields(MemWatchEntry* entry)
QLabel* lblAddressOfPath = new QLabel();
lblAddressOfPath->setText(
QString::fromStdString(" -> " + m_entry->getAddressStringForPointerLevel(i + 1)));
lblAddressOfPath->setProperty("addr", m_entry->getAddressForPointerLevel(i + 1));
lblAddressOfPath->setContextMenuPolicy(Qt::CustomContextMenu);
connect(lblAddressOfPath, &QWidget::customContextMenuRequested, this,
&DlgAddWatchEntry::onPointerOffsetContextMenuRequested);
m_addressPath.append(lblAddressOfPath);
m_offsetsLayout->addWidget(lblLevel, i, 0);
m_offsetsLayout->addWidget(txbOffset, i, 1);
Expand All @@ -190,6 +197,12 @@ void DlgAddWatchEntry::addPointerOffset()
QLineEdit* txbOffset = new QLineEdit();
m_offsets.append(txbOffset);
QLabel* lblAddressOfPath = new QLabel(" -> ");
lblAddressOfPath->setText(
QString::fromStdString(" -> " + m_entry->getAddressStringForPointerLevel(level + 1)));
lblAddressOfPath->setProperty("addr", m_entry->getAddressForPointerLevel(level + 1));
lblAddressOfPath->setContextMenuPolicy(Qt::CustomContextMenu);
connect(lblAddressOfPath, &QWidget::customContextMenuRequested, this,
&DlgAddWatchEntry::onPointerOffsetContextMenuRequested);
m_addressPath.append(lblAddressOfPath);
m_offsetsLayout->addWidget(lblLevel, level, 0);
m_offsetsLayout->addWidget(txbOffset, level, 1);
Expand Down Expand Up @@ -385,9 +398,10 @@ void DlgAddWatchEntry::updatePreview()
for (int i = 0; i < level; ++i)
{
QLabel* lblAddressOfPath =
static_cast<QLabel*>(m_offsetsLayout->itemAtPosition(i, 2)->widget());
qobject_cast<QLabel*>(m_offsetsLayout->itemAtPosition(i, 2)->widget());
lblAddressOfPath->setText(
QString::fromStdString(" -> " + m_entry->getAddressStringForPointerLevel(i + 1)));
lblAddressOfPath->setProperty("addr", m_entry->getAddressForPointerLevel(i + 1));
}
}
}
Expand Down Expand Up @@ -424,3 +438,23 @@ MemWatchEntry* DlgAddWatchEntry::stealEntry()
m_entry = nullptr;
return entry;
}

void DlgAddWatchEntry::onPointerOffsetContextMenuRequested(const QPoint& pos)
{
QLabel* const lbl = qobject_cast<QLabel*>(sender());

QMenu* const contextMenu = new QMenu(this);
QAction* const copyAddr = new QAction(tr("&Copy Address"), this);

const QString text{QString::number(lbl->property("addr").toUInt(), 16).toUpper()};
connect(copyAddr, &QAction::triggered, this,
[text] { QApplication::clipboard()->setText(text); });
contextMenu->addAction(copyAddr);

if (!lbl->property("addr").toUInt())
{
copyAddr->setEnabled(false);
}

contextMenu->popup(lbl->mapToGlobal(pos));
}
1 change: 1 addition & 0 deletions Source/GUI/MemWatcher/Dialogs/DlgAddWatchEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class DlgAddWatchEntry : public QDialog
void addPointerOffset();
void removePointerOffset();
void removeAllPointerOffset();
void onPointerOffsetContextMenuRequested(const QPoint& pos);

MemWatchEntry* m_entry{};
AddressInputWidget* m_txbAddress{};
Expand Down
34 changes: 34 additions & 0 deletions Source/GUI/MemWatcher/MemWatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,40 @@ void MemWatchWidget::onMemWatchContextMenuRequested(const QPoint& pos)
connect(copy, &QAction::triggered, this, [this] { copySelectedWatchesToClipBoard(); });
contextMenu->addAction(copy);

if (index.isValid())
{
MemWatchEntry* const entry = m_watchModel->getEntryFromIndex(index);
if (entry->isBoundToPointer())
{
QMenu* const copyAddrSubmenu = contextMenu->addMenu(tr("Copy add&ress..."));
QAction* const copyPointer = new QAction(tr("Copy &base address..."), this);
const QString addrString{QString::number(entry->getConsoleAddress(), 16).toUpper()};
connect(copyPointer, &QAction::triggered, this,
[addrString] { QApplication::clipboard()->setText(addrString); });
copyAddrSubmenu->addAction(copyPointer);
for (int i = 0; i < static_cast<int>(entry->getPointerLevel()); ++i)
{
if (!entry->getAddressForPointerLevel(i + 1))
break;
QAction* const copyAddrOfPointer =
new QAction(tr("Copy pointed address at &level %1...").arg(i + 1), this);
const QString addrString{
QString::number(entry->getAddressForPointerLevel(i + 1), 16).toUpper()};
connect(copyAddrOfPointer, &QAction::triggered, this,
[addrString] { QApplication::clipboard()->setText(addrString); });
copyAddrSubmenu->addAction(copyAddrOfPointer);
}
}
else
{
QAction* const copyPointer = new QAction(tr("Copy add&ress"), this);
const QString addrString{QString::number(entry->getConsoleAddress(), 16).toUpper()};
connect(copyPointer, &QAction::triggered, this,
[addrString] { QApplication::clipboard()->setText(addrString); });
contextMenu->addAction(copyPointer);
}
}

QAction* paste = new QAction(tr("&Paste"), this);
connect(paste, &QAction::triggered, this, [this, index] { pasteWatchFromClipBoard(index); });
contextMenu->addAction(paste);
Expand Down
Loading