Skip to content

Commit 2b18fd2

Browse files
committed
Disable unavailable context menu items in transactions tab
1 parent fe3b58b commit 2b18fd2

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
@@ -230,7 +230,7 @@ QString HtmlEscape(const std::string& str, bool fMultiLine)
230230
return HtmlEscape(QString::fromStdString(str), fMultiLine);
231231
}
232232

233-
void copyEntryData(QAbstractItemView *view, int column, int role)
233+
void copyEntryData(const QAbstractItemView *view, int column, int role)
234234
{
235235
if(!view || !view->selectionModel())
236236
return;
@@ -243,13 +243,20 @@ void copyEntryData(QAbstractItemView *view, int column, int role)
243243
}
244244
}
245245

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

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

src/qt/guiutil.h

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

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

8087
void setClipboard(const QString& str);
8188

src/qt/transactionview.cpp

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

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

399400
if(index.isValid())
400401
{

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);
8688

0 commit comments

Comments
 (0)