Skip to content

Commit 0d5c182

Browse files
committed
Merge #17956: gui: Disable unavailable context menu items in transactions tab
2b18fd2 Disable unavailable context menu items in transactions tab (Kristaps Kaupe) Pull request description: Fixes #9192. ACKs for top commit: jonatack: Re-ACK 2b18fd2 jonasschnelli: codereview utACK 2b18fd2 Tree-SHA512: 4ea19c7b5976f1f0b1baecccb3077cf82f078af7257f92162686bcce2188efe49511a5f557853bc5fe0b10616708957d61c006944babbe60b8105e78751e865f
2 parents a9024a4 + 2b18fd2 commit 0d5c182

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

src/qt/guiutil.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ QString HtmlEscape(const std::string& str, bool fMultiLine)
232232
return HtmlEscape(QString::fromStdString(str), fMultiLine);
233233
}
234234

235-
void copyEntryData(QAbstractItemView *view, int column, int role)
235+
void copyEntryData(const QAbstractItemView *view, int column, int role)
236236
{
237237
if(!view || !view->selectionModel())
238238
return;
@@ -245,13 +245,20 @@ void copyEntryData(QAbstractItemView *view, int column, int role)
245245
}
246246
}
247247

248-
QList<QModelIndex> getEntryData(QAbstractItemView *view, int column)
248+
QList<QModelIndex> getEntryData(const QAbstractItemView *view, int column)
249249
{
250250
if(!view || !view->selectionModel())
251251
return QList<QModelIndex>();
252252
return view->selectionModel()->selectedRows(column);
253253
}
254254

255+
bool hasEntryData(const QAbstractItemView *view, int column, int role)
256+
{
257+
QModelIndexList selection = getEntryData(view, column);
258+
if (selection.isEmpty()) return false;
259+
return !selection.at(0).data(role).toString().isEmpty();
260+
}
261+
255262
QString getDefaultDataDirectory()
256263
{
257264
return boostPathToQString(GetDefaultDataDir());

src/qt/guiutil.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,21 @@ namespace GUIUtil
7171
@param[in] role Data role to extract from the model
7272
@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
7373
*/
74-
void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole);
74+
void copyEntryData(const QAbstractItemView *view, int column, int role=Qt::EditRole);
7575

7676
/** Return a field of the currently selected entry as a QString. Does nothing if nothing
7777
is selected.
7878
@param[in] column Data column to extract from the model
7979
@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
8080
*/
81-
QList<QModelIndex> getEntryData(QAbstractItemView *view, int column);
81+
QList<QModelIndex> getEntryData(const QAbstractItemView *view, int column);
82+
83+
/** Returns true if the specified field of the currently selected view entry is not empty.
84+
@param[in] column Data column to extract from the model
85+
@param[in] role Data role to extract from the model
86+
@see TransactionView::contextualMenu
87+
*/
88+
bool hasEntryData(const QAbstractItemView *view, int column, int role);
8289

8390
void setClipboard(const QString& str);
8491

src/qt/transactionview.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
#include <QVBoxLayout>
3838

3939
TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *parent) :
40-
QWidget(parent), model(nullptr), transactionProxyModel(nullptr),
41-
transactionView(nullptr), abandonAction(nullptr), bumpFeeAction(nullptr), columnResizingFixer(nullptr)
40+
QWidget(parent)
4241
{
4342
// Build filter row
4443
setContentsMargins(0,0,0,0);
@@ -153,8 +152,8 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
153152
abandonAction = new QAction(tr("Abandon transaction"), this);
154153
bumpFeeAction = new QAction(tr("Increase transaction fee"), this);
155154
bumpFeeAction->setObjectName("bumpFeeAction");
156-
QAction *copyAddressAction = new QAction(tr("Copy address"), this);
157-
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
155+
copyAddressAction = new QAction(tr("Copy address"), this);
156+
copyLabelAction = new QAction(tr("Copy label"), this);
158157
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
159158
QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this);
160159
QAction *copyTxHexAction = new QAction(tr("Copy raw transaction"), this);
@@ -396,6 +395,8 @@ void TransactionView::contextualMenu(const QPoint &point)
396395
hash.SetHex(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString());
397396
abandonAction->setEnabled(model->wallet().transactionCanBeAbandoned(hash));
398397
bumpFeeAction->setEnabled(model->wallet().transactionCanBeBumped(hash));
398+
copyAddressAction->setEnabled(GUIUtil::hasEntryData(transactionView, 0, TransactionTableModel::AddressRole));
399+
copyLabelAction->setEnabled(GUIUtil::hasEntryData(transactionView, 0, TransactionTableModel::LabelRole));
399400

400401
if (index.isValid()) {
401402
GUIUtil::PopupMenu(contextMenu, transactionView->viewport()->mapToGlobal(point));

src/qt/transactionview.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class TransactionView : public QWidget
6060
};
6161

6262
private:
63-
WalletModel *model;
64-
TransactionFilterProxy *transactionProxyModel;
65-
QTableView *transactionView;
63+
WalletModel *model{nullptr};
64+
TransactionFilterProxy *transactionProxyModel{nullptr};
65+
QTableView *transactionView{nullptr};
6666

6767
QComboBox *dateWidget;
6868
QComboBox *typeWidget;
@@ -75,12 +75,14 @@ class TransactionView : public QWidget
7575
QFrame *dateRangeWidget;
7676
QDateTimeEdit *dateFrom;
7777
QDateTimeEdit *dateTo;
78-
QAction *abandonAction;
79-
QAction *bumpFeeAction;
78+
QAction *abandonAction{nullptr};
79+
QAction *bumpFeeAction{nullptr};
80+
QAction *copyAddressAction{nullptr};
81+
QAction *copyLabelAction{nullptr};
8082

8183
QWidget *createDateRangeWidget();
8284

83-
GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer;
85+
GUIUtil::TableViewLastColumnResizingFixer *columnResizingFixer{nullptr};
8486

8587
virtual void resizeEvent(QResizeEvent* event) override;
8688

0 commit comments

Comments
 (0)