Skip to content

Commit

Permalink
Add context menu to create breakpoints on Function browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
epasveer committed Mar 30, 2024
1 parent 422d061 commit 30d21fe
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 12 deletions.
49 changes: 45 additions & 4 deletions src/SeerFunctionBrowserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include <QtWidgets/QTreeWidgetItemIterator>
#include <QtWidgets/QLabel>
#include <QtWidgets/QApplication>
#include <QtCore/QFileInfo>
#include <QtWidgets/QMenu>
#include <QtGui/QAction>
#include <QtCore/Qt>
#include <QtCore/QMap>
#include <QtCore/QDebug>
Expand All @@ -20,6 +21,7 @@ SeerFunctionBrowserWidget::SeerFunctionBrowserWidget (QWidget* parent) : QWidget
// Setup the widgets
functionSearchLineEdit->setPlaceholderText("Search regex...");
functionSearchLineEdit->setClearButtonEnabled(true);
functionTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
functionTreeWidget->setMouseTracking(true);
//functionTreeWidget->resizeColumnToContents(0);
functionTreeWidget->resizeColumnToContents(1);
Expand All @@ -31,9 +33,10 @@ SeerFunctionBrowserWidget::SeerFunctionBrowserWidget (QWidget* parent) : QWidget
functionTreeWidget->setSortingEnabled(false);

// Connect things.
QObject::connect(functionTreeWidget, &QTreeWidget::itemDoubleClicked, this, &SeerFunctionBrowserWidget::handleItemDoubleClicked);
QObject::connect(functionTreeWidget, &QTreeWidget::itemEntered, this, &SeerFunctionBrowserWidget::handleItemEntered);
QObject::connect(functionSearchLineEdit, &QLineEdit::returnPressed, this, &SeerFunctionBrowserWidget::handleSearchLineEdit);
QObject::connect(functionTreeWidget, &QTreeWidget::customContextMenuRequested, this, &SeerFunctionBrowserWidget::handleContextMenu);
QObject::connect(functionTreeWidget, &QTreeWidget::itemDoubleClicked, this, &SeerFunctionBrowserWidget::handleItemDoubleClicked);
QObject::connect(functionTreeWidget, &QTreeWidget::itemEntered, this, &SeerFunctionBrowserWidget::handleItemEntered);
QObject::connect(functionSearchLineEdit, &QLineEdit::returnPressed, this, &SeerFunctionBrowserWidget::handleSearchLineEdit);
}

SeerFunctionBrowserWidget::~SeerFunctionBrowserWidget () {
Expand Down Expand Up @@ -171,6 +174,44 @@ void SeerFunctionBrowserWidget::handleSearchLineEdit () {
}
}

void SeerFunctionBrowserWidget::handleContextMenu (const QPoint& pos) {

// Get the item at the cursor.
QTreeWidgetItem* item = functionTreeWidget->itemAt(pos);

if (item == 0) {
return;
}

// Construct the menu.
QMenu menu ("Options", this);
QAction* openAction = menu.addAction(QString("Open '%1'").arg(item->text(1)));
QAction* breakpointSourceAction = menu.addAction(QString("Create breakpoint on '%1:%2'").arg(item->text(1)).arg(item->text(2)));
QAction* breakpointFunctionAction = menu.addAction(QString("Create breakpoint in '%1'").arg(item->text(0)));

// Execute the menu. Return if nothing.
QAction* action = menu.exec(functionTreeWidget->viewport()->mapToGlobal(pos));

if (action == 0) {
return;
}

if (action == openAction) {
emit selectedFile(item->text(1), item->text(3), item->text(2).toInt());
return;
}

if (action == breakpointSourceAction) {
emit insertBreakpoint(QString("--source %1 --line %2").arg(item->text(3)).arg(item->text(2)));
return;
}

if (action == breakpointFunctionAction) {
emit insertBreakpoint(QString("--function \"%1\"").arg(item->text(0)));
return;
}
}

void SeerFunctionBrowserWidget::refresh () {
handleSearchLineEdit();
}
Expand Down
2 changes: 2 additions & 0 deletions src/SeerFunctionBrowserWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SeerFunctionBrowserWidget : public QWidget, protected Ui::SeerFunctionBrow

public slots:
void handleText (const QString& text);
void handleContextMenu (const QPoint& pos);
void refresh ();

protected slots:
Expand All @@ -24,6 +25,7 @@ class SeerFunctionBrowserWidget : public QWidget, protected Ui::SeerFunctionBrow
signals:
void refreshFunctionList (int id, const QString& functionRegex);
void selectedFile (QString file, QString fullname, int lineno);
void insertBreakpoint (QString breakpoint);

protected:
private:
Expand Down
1 change: 1 addition & 0 deletions src/SeerGdbWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ SeerGdbWidget::SeerGdbWidget (QWidget* parent) : QWidget(parent) {
QObject::connect(sourceLibraryManagerWidget->sourceBrowserWidget(), &SeerSourceBrowserWidget::selectedFile, editorManagerWidget, &SeerEditorManagerWidget::handleOpenFile);
QObject::connect(sourceLibraryManagerWidget->functionBrowserWidget(), &SeerFunctionBrowserWidget::refreshFunctionList, this, &SeerGdbWidget::handleGdbExecutableFunctions);
QObject::connect(sourceLibraryManagerWidget->functionBrowserWidget(), &SeerFunctionBrowserWidget::selectedFile, editorManagerWidget, &SeerEditorManagerWidget::handleOpenFile);
QObject::connect(sourceLibraryManagerWidget->functionBrowserWidget(), &SeerFunctionBrowserWidget::insertBreakpoint, this, &SeerGdbWidget::handleGdbBreakpointInsert);
QObject::connect(sourceLibraryManagerWidget->typeBrowserWidget(), &SeerTypeBrowserWidget::refreshTypeList, this, &SeerGdbWidget::handleGdbExecutableTypes);
QObject::connect(sourceLibraryManagerWidget->typeBrowserWidget(), &SeerTypeBrowserWidget::selectedFile, editorManagerWidget, &SeerEditorManagerWidget::handleOpenFile);
QObject::connect(sourceLibraryManagerWidget->staticBrowserWidget(), &SeerStaticBrowserWidget::refreshVariableList, this, &SeerGdbWidget::handleGdbExecutableVariables);
Expand Down
15 changes: 10 additions & 5 deletions src/SeerRegisterValuesBrowserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QtWidgets/QMessageBox>
#include <QtGui/QFontDatabase>
#include <QtGui/QClipboard>
#include <QtGui/QAction>
#include <QtCore/QSettings>
#include <QtCore/QVector>
#include <QtCore/QByteArray>
Expand Down Expand Up @@ -286,11 +287,15 @@ void SeerRegisterValuesBrowserWidget::handleContextMenu (const QPoint& pos) {
// Get the item at the cursor.
QTreeWidgetItem* item = registersTreeWidget->itemAt(pos);

if (item == 0) {
return;
}

// Construct the menu.
QMenu* menu = new QMenu("Options", this);
QAction* editAction = menu->addAction("Edit selected");
QAction* copyAction = menu->addAction("Copy selected");
QAction* copyAllAction = menu->addAction("Copy all");
QMenu menu("Options", this);
QAction* editAction = menu.addAction("Edit selected");
QAction* copyAction = menu.addAction("Copy selected");
QAction* copyAllAction = menu.addAction("Copy all");

// If no selected item, disable 'selected' copy but allow 'all'.
if (item == 0) {
Expand All @@ -299,7 +304,7 @@ void SeerRegisterValuesBrowserWidget::handleContextMenu (const QPoint& pos) {
}

// Execute the menu. Return if nothing.
QAction* action = menu->exec(registersTreeWidget->mapToGlobal(pos));
QAction* action = menu.exec(registersTreeWidget->viewport()->mapToGlobal(pos));

if (action == 0) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/SeerStackLocalsBrowserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <QtWidgets/QApplication>
#include <QtWidgets/QMenu>
#include <QtGui/QFontDatabase>
#include <QtGui/QAction>
#include <QtCore/QRegularExpressionMatch>
#include <QAction>
#include <QtCore/QDebug>
#include <QtGlobal>

Expand Down
2 changes: 1 addition & 1 deletion src/SeerVariableLoggerBrowserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ void SeerVariableLoggerBrowserWidget::handleContextMenu (const QPoint& pos) {
}

// Execute the menu. Return if nothing.
QAction* action = menu.exec(variablesTreeWidget->mapToGlobal(pos));
QAction* action = menu.exec(variablesTreeWidget->viewport()->mapToGlobal(pos));

if (action == 0) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/SeerVariableTrackerBrowserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ void SeerVariableTrackerBrowserWidget::handleContextMenu (const QPoint& pos) {
}

// Execute the menu. Return if nothing.
QAction* action = menu.exec(variablesTreeWidget->mapToGlobal(pos));
QAction* action = menu.exec(variablesTreeWidget->viewport()->mapToGlobal(pos));

if (action == 0) {
return;
Expand Down

0 comments on commit 30d21fe

Please sign in to comment.