TxConfAdv: allow copy context menus

This commit is contained in:
tobtoht 2024-01-03 17:22:26 +01:00
parent 002d7d3353
commit a8eac7efeb
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
2 changed files with 44 additions and 1 deletions

View file

@ -48,7 +48,16 @@ TxConfAdvDialog::TxConfAdvDialog(Wallet *wallet, const QString &description, QWi
ui->txid->hide();
ui->label_txid->hide();
}
ui->treeInputs->setContextMenuPolicy(Qt::CustomContextMenu);
ui->treeOutputs->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->treeInputs, &QTreeView::customContextMenuRequested, [this](const QPoint &point){
this->setupContextMenu(point, ui->treeInputs);
});
connect(ui->treeOutputs, &QTreeView::customContextMenuRequested, [this](const QPoint &point){
this->setupContextMenu(point, ui->treeOutputs);
});
this->adjustSize();
}
@ -217,4 +226,35 @@ void TxConfAdvDialog::closeDialog() {
QDialog::reject();
}
void TxConfAdvDialog::setupContextMenu(const QPoint &point, QTreeWidget *tree) {
if (!tree) {
return;
}
QTreeWidgetItem *header = tree->headerItem();
if (!header) {
return;
}
auto* menu = new QMenu(this);
for (int column = 0; column < tree->columnCount(); column++)
{
menu->addAction(QString("Copy %1").arg(header->text(column)), this, [this, column, point, tree]{
this->copyFromTree(point, column, tree);
});
}
menu->popup(tree->viewport()->mapToGlobal(point));
}
void TxConfAdvDialog::copyFromTree(const QPoint &point, int column, QTreeWidget *tree) {
QModelIndex index = tree->indexAt(point);
if (!index.isValid()) {
return;
}
QModelIndex dataIndex = index.sibling(index.row(), column);
Utils::copyToClipboard(dataIndex.data().toString());
}
TxConfAdvDialog::~TxConfAdvDialog() = default;

View file

@ -8,6 +8,7 @@
#include <QMenu>
#include <QStandardItemModel>
#include <QTextCharFormat>
#include <QTreeWidget>
#include "components.h"
#include "libwalletqt/PendingTransaction.h"
@ -34,6 +35,8 @@ private:
void broadcastTransaction();
void closeDialog();
void setAmounts(quint64 amount, quint64 fee);
void setupContextMenu(const QPoint &point, QTreeWidget *tree);
void copyFromTree(const QPoint &point, int column, QTreeWidget *tree);
void signedCopy();
void signedSaveFile();