Added Context Menu to Strings Widget (#817)

* Added Context Menu to Strigns Widget

* Fixed slot getting called twice without Qt::UniqueConnection
This commit is contained in:
Ankur Saini 2018-10-15 14:36:15 +05:30 committed by Florian Märkl
parent 781235ba87
commit 3dc71c90d2
3 changed files with 81 additions and 0 deletions

View File

@ -6,7 +6,10 @@
#include "MainWindow.h"
#include "utils/Helpers.h"
#include "dialogs/XrefsDialog.h"
#include <QMenu>
#include <QClipboard>
StringsModel::StringsModel(QList<StringDescription> *strings, QObject *parent)
: QAbstractListModel(parent),
@ -142,6 +145,17 @@ StringsWidget::StringsWidget(MainWindow *main, QAction *action) :
connect(clear_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::clearFilter);
clear_shortcut->setContext(Qt::WidgetWithChildrenShortcut);
connect(ui->actionFilter, SIGNAL(triggered()), ui->quickFilterView, SLOT(showFilter()));
connect(ui->actionCopy_String, SIGNAL(triggered()), this, SLOT(on_actionCopy()));
connect(ui->actionCopy_Address, SIGNAL(triggered()), this, SLOT(on_actionCopy()));
connect(ui->stringsTreeView, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showStringsContextMenu(const QPoint &)));
ui->actionFilter->setShortcut(QKeySequence::Find);
ui->stringsTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
model = new StringsModel(&strings, this);
proxy_model = new StringsSortFilterProxyModel(model, this);
ui->stringsTreeView->setModel(proxy_model);
@ -195,3 +209,46 @@ void StringsWidget::stringSearchFinished(const QList<StringDescription> &strings
task = nullptr;
}
void StringsWidget::showStringsContextMenu(const QPoint &pt)
{
QMenu *menu = new QMenu(ui->stringsTreeView);
menu->clear();
menu->addAction(ui->actionCopy_String);
menu->addAction(ui->actionCopy_Address);
menu->addAction(ui->actionFilter);
menu->addSeparator();
menu->addAction(ui->actionX_refs);
menu->exec(ui->stringsTreeView->mapToGlobal(pt));
delete menu;
}
void StringsWidget::on_actionX_refs_triggered()
{
StringDescription str = ui->stringsTreeView->selectionModel()->currentIndex().data(
StringsModel::StringDescriptionRole).value<StringDescription>();
XrefsDialog *x = new XrefsDialog(this);
x->fillRefsForAddress(str.vaddr, RAddressString(str.vaddr), false);
x->setAttribute(Qt::WA_DeleteOnClose);
x->exec();
}
void StringsWidget::on_actionCopy()
{
QModelIndex current_item = ui->stringsTreeView->currentIndex();
int row = current_item.row();
QModelIndex index;
if(sender() == ui->actionCopy_String)
index = ui->stringsTreeView->model()->index(row, 1);
else if(sender() == ui->actionCopy_Address)
index = ui->stringsTreeView->model()->index(row, 0);
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(index.data().toString());
}

View File

@ -70,6 +70,10 @@ private slots:
void refreshStrings();
void stringSearchFinished(const QList<StringDescription> &strings);
void showStringsContextMenu(const QPoint &pt);
void on_actionX_refs_triggered();
void on_actionCopy();
private:
std::unique_ptr<Ui::StringsWidget> ui;

View File

@ -71,6 +71,26 @@
</item>
</layout>
</widget>
<action name="actionCopy_Address">
<property name="text">
<string>Copy Address</string>
</property>
</action>
<action name="actionCopy_String">
<property name="text">
<string>Copy String</string>
</property>
</action>
<action name="actionX_refs">
<property name="text">
<string>Xrefs</string>
</property>
</action>
<action name="actionFilter">
<property name="text">
<string>Filter</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>