From 53aeb0d65e7b2aa779d9230a3b7cf13cfb7c0a9c Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 29 May 2020 10:28:47 +0200 Subject: [PATCH] Merge #17956: gui: Disable unavailable context menu items in transactions tab 2b18fd2242a589988fbb68205dae4afa0b8b3d34 Disable unavailable context menu items in transactions tab (Kristaps Kaupe) Pull request description: Fixes #9192. ACKs for top commit: jonatack: Re-ACK 2b18fd2242a5899 jonasschnelli: codereview utACK 2b18fd2242a589988fbb68205dae4afa0b8b3d34 Tree-SHA512: 4ea19c7b5976f1f0b1baecccb3077cf82f078af7257f92162686bcce2188efe49511a5f557853bc5fe0b10616708957d61c006944babbe60b8105e78751e865f --- src/qt/guiutil.cpp | 11 +++++++++-- src/qt/guiutil.h | 11 +++++++++-- src/qt/transactionview.cpp | 9 +++++---- src/qt/transactionview.h | 12 +++++++----- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 5d821822d3..8eb39b501d 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -455,7 +455,7 @@ QString HtmlEscape(const std::string& str, bool fMultiLine) return HtmlEscape(QString::fromStdString(str), fMultiLine); } -void copyEntryData(QAbstractItemView *view, int column, int role) +void copyEntryData(const QAbstractItemView *view, int column, int role) { if(!view || !view->selectionModel()) return; @@ -468,13 +468,20 @@ void copyEntryData(QAbstractItemView *view, int column, int role) } } -QList getEntryData(QAbstractItemView *view, int column) +QList getEntryData(const QAbstractItemView *view, int column) { if(!view || !view->selectionModel()) return QList(); return view->selectionModel()->selectedRows(column); } +bool hasEntryData(const QAbstractItemView *view, int column, int role) +{ + QModelIndexList selection = getEntryData(view, column); + if (selection.isEmpty()) return false; + return !selection.at(0).data(role).toString().isEmpty(); +} + QString getDefaultDataDirectory() { return boostPathToQString(GetDefaultDataDir()); diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 01bea89d68..4ff8002492 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -140,14 +140,21 @@ namespace GUIUtil @param[in] role Data role to extract from the model @see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress */ - void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole); + void copyEntryData(const QAbstractItemView *view, int column, int role=Qt::EditRole); /** Return a field of the currently selected entry as a QString. Does nothing if nothing is selected. @param[in] column Data column to extract from the model @see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress */ - QList getEntryData(QAbstractItemView *view, int column); + QList getEntryData(const QAbstractItemView *view, int column); + + /** Returns true if the specified field of the currently selected view entry is not empty. + @param[in] column Data column to extract from the model + @param[in] role Data role to extract from the model + @see TransactionView::contextualMenu + */ + bool hasEntryData(const QAbstractItemView *view, int column, int role); void setClipboard(const QString& str); diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 9a1d353122..195f13568f 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -44,8 +44,7 @@ static const char* PERSISTENCE_DATE_FORMAT = "yyyy-MM-dd"; TransactionView::TransactionView(QWidget* parent) : -QWidget(parent), model(nullptr), transactionProxyModel(nullptr), -transactionView(nullptr), abandonAction(nullptr), columnResizingFixer(nullptr) + QWidget(parent) { QSettings settings; // Build filter row @@ -150,8 +149,8 @@ transactionView(nullptr), abandonAction(nullptr), columnResizingFixer(nullptr) // Actions abandonAction = new QAction(tr("Abandon transaction"), this); resendAction = new QAction(tr("Resend transaction"), this); - QAction *copyAddressAction = new QAction(tr("Copy address"), this); - QAction *copyLabelAction = new QAction(tr("Copy label"), this); + copyAddressAction = new QAction(tr("Copy address"), this); + copyLabelAction = new QAction(tr("Copy label"), this); QAction *copyAmountAction = new QAction(tr("Copy amount"), this); QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this); QAction *copyTxHexAction = new QAction(tr("Copy raw transaction"), this); @@ -426,6 +425,8 @@ void TransactionView::contextualMenu(const QPoint &point) hash.SetHex(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString()); abandonAction->setEnabled(model->wallet().transactionCanBeAbandoned(hash)); resendAction->setEnabled(selection.size() == 1 && model->wallet().transactionCanBeResent(hash)); + copyAddressAction->setEnabled(GUIUtil::hasEntryData(transactionView, 0, TransactionTableModel::AddressRole)); + copyLabelAction->setEnabled(GUIUtil::hasEntryData(transactionView, 0, TransactionTableModel::LabelRole)); if (index.isValid()) { GUIUtil::PopupMenu(contextMenu, transactionView->viewport()->mapToGlobal(point)); diff --git a/src/qt/transactionview.h b/src/qt/transactionview.h index f1b42627b6..ded3f3d4b2 100644 --- a/src/qt/transactionview.h +++ b/src/qt/transactionview.h @@ -60,9 +60,9 @@ public: }; private: - WalletModel *model; - TransactionFilterProxy *transactionProxyModel; - QTableView *transactionView; + WalletModel *model{nullptr}; + TransactionFilterProxy *transactionProxyModel{nullptr}; + QTableView *transactionView{nullptr}; QComboBox *dateWidget; QComboBox *typeWidget; QComboBox *watchOnlyWidget; @@ -74,13 +74,15 @@ private: QFrame *dateRangeWidget; QDateTimeEdit *dateFrom; QDateTimeEdit *dateTo; - QAction *abandonAction; + QAction *abandonAction{nullptr}; QAction *resendAction; + QAction *copyAddressAction{nullptr}; + QAction *copyLabelAction{nullptr}; QWidget *createDateRangeWidget(); void updateCalendarWidgets(); - GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer; + GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer{nullptr}; virtual void resizeEvent(QResizeEvent* event) override; void changeEvent(QEvent* e) override;