Added context menu to register refs

This commit is contained in:
mandlebro 2018-07-25 23:15:21 +01:00 committed by xarkes
parent 6f88ebc020
commit a4d160dd3d
2 changed files with 36 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "utils/Helpers.h" #include "utils/Helpers.h"
#include <QMenu> #include <QMenu>
#include <QClipboard>
RegisterRefModel::RegisterRefModel(QList<RegisterRefDescription> *registerRefs, QObject *parent) RegisterRefModel::RegisterRefModel(QList<RegisterRefDescription> *registerRefs, QObject *parent)
: QAbstractListModel(parent), : QAbstractListModel(parent),
@ -121,6 +122,9 @@ RegisterRefsWidget::RegisterRefsWidget(MainWindow *main, QAction *action) :
ui->registerRefTreeView->setModel(registerRefProxyModel); ui->registerRefTreeView->setModel(registerRefProxyModel);
ui->registerRefTreeView->sortByColumn(RegisterRefModel::RegColumn, Qt::AscendingOrder); ui->registerRefTreeView->sortByColumn(RegisterRefModel::RegColumn, Qt::AscendingOrder);
actionCopyValue = new QAction(tr("Copy register value"));
actionCopyRef = new QAction(tr("Copy register reference"));
// Ctrl-F to show/hide the filter entry // Ctrl-F to show/hide the filter entry
QShortcut *search_shortcut = new QShortcut(QKeySequence::Find, this); QShortcut *search_shortcut = new QShortcut(QKeySequence::Find, this);
connect(search_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter); connect(search_shortcut, &QShortcut::activated, ui->quickFilterView, &QuickFilterView::showFilter);
@ -132,6 +136,15 @@ RegisterRefsWidget::RegisterRefsWidget(MainWindow *main, QAction *action) :
setScrollMode(); setScrollMode();
connect(Core(), &CutterCore::refreshAll, this, &RegisterRefsWidget::refreshRegisterRef); connect(Core(), &CutterCore::refreshAll, this, &RegisterRefsWidget::refreshRegisterRef);
connect(Core(), &CutterCore::registersChanged, this, &RegisterRefsWidget::refreshRegisterRef); connect(Core(), &CutterCore::registersChanged, this, &RegisterRefsWidget::refreshRegisterRef);
connect(actionCopyValue, &QAction::triggered, [=] () {
copyClip(RegisterRefModel::ValueColumn);
});
connect(actionCopyRef, &QAction::triggered, [=] () {
copyClip(RegisterRefModel::RefColumn);
});
ui->registerRefTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->registerRefTreeView, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showRegRefContextMenu(const QPoint &)));
} }
RegisterRefsWidget::~RegisterRefsWidget() {} RegisterRefsWidget::~RegisterRefsWidget() {}
@ -158,3 +171,22 @@ void RegisterRefsWidget::on_registerRefTreeView_doubleClicked(const QModelIndex
RegisterRefModel::RegisterRefDescriptionRole).value<RegisterRefDescription>(); RegisterRefModel::RegisterRefDescriptionRole).value<RegisterRefDescription>();
Core()->seek(item.value); Core()->seek(item.value);
} }
void RegisterRefsWidget::showRegRefContextMenu(const QPoint &pt)
{
QMenu *menu = new QMenu(ui->registerRefTreeView);
menu->clear();
menu->addAction(actionCopyValue);
menu->addAction(actionCopyRef);
menu->exec(ui->registerRefTreeView->viewport()->mapToGlobal(pt));
delete menu;
}
void RegisterRefsWidget::copyClip(int column)
{
int row = ui->registerRefTreeView->selectionModel()->currentIndex().row();
QString value = ui->registerRefTreeView->selectionModel()->currentIndex().sibling(row, column).data().toString();
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(value);
}

View File

@ -69,6 +69,8 @@ public:
private slots: private slots:
void on_registerRefTreeView_doubleClicked(const QModelIndex &index); void on_registerRefTreeView_doubleClicked(const QModelIndex &index);
void refreshRegisterRef(); void refreshRegisterRef();
void copyClip(int column);
void showRegRefContextMenu(const QPoint &pt);
private: private:
std::unique_ptr<Ui::RegisterRefsWidget> ui; std::unique_ptr<Ui::RegisterRefsWidget> ui;
@ -76,6 +78,7 @@ private:
RegisterRefModel *registerRefModel; RegisterRefModel *registerRefModel;
RegisterRefProxyModel *registerRefProxyModel; RegisterRefProxyModel *registerRefProxyModel;
QList<RegisterRefDescription> registerRefs; QList<RegisterRefDescription> registerRefs;
QAction *actionCopyValue;
QAction *actionCopyRef;
void setScrollMode(); void setScrollMode();
}; };