Coins: add Edit Label to context menu

This commit is contained in:
tobtoht 2021-07-02 17:27:26 +02:00
parent 4489d50b72
commit 5d89931f9d
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
3 changed files with 17 additions and 1 deletions

View file

@ -38,6 +38,9 @@ CoinsWidget::CoinsWidget(QSharedPointer<AppContext> ctx, QWidget *parent)
// context menu
ui->coins->setContextMenuPolicy(Qt::CustomContextMenu);
m_editLabelAction = new QAction("Edit Label", this);
connect(m_editLabelAction, &QAction::triggered, this, &CoinsWidget::editLabel);
m_thawOutputAction = new QAction("Thaw output", this);
m_freezeOutputAction = new QAction("Freeze output", this);
@ -47,6 +50,7 @@ CoinsWidget::CoinsWidget(QSharedPointer<AppContext> ctx, QWidget *parent)
m_viewOutputAction = new QAction(icons()->icon("info2.svg"), "Details", this);
m_sweepOutputAction = new QAction("Sweep output", this);
m_sweepOutputsAction = new QAction("Sweep selected outputs", this);
connect(m_freezeOutputAction, &QAction::triggered, this, &CoinsWidget::freezeOutput);
connect(m_thawOutputAction, &QAction::triggered, this, &CoinsWidget::thawOutput);
connect(m_viewOutputAction, &QAction::triggered, this, &CoinsWidget::viewOutput);
@ -116,6 +120,7 @@ void CoinsWidget::showContextMenu(const QPoint &point) {
bool isUnlocked = c->unlocked();
menu->addMenu(m_copyMenu);
menu->addAction(m_editLabelAction);
if (!isSpent) {
isFrozen ? menu->addAction(m_thawOutputAction) : menu->addAction(m_freezeOutputAction);
@ -303,4 +308,10 @@ void CoinsWidget::thawCoins(const QVector<int> &indexes) {
m_ctx->updateBalance();
}
void CoinsWidget::editLabel() {
QModelIndex index = ui->coins->currentIndex().siblingAtColumn(m_model->ModelColumn::Label);
ui->coins->setCurrentIndex(index);
ui->coins->edit(index);
}
CoinsWidget::~CoinsWidget() = default;

View file

@ -41,6 +41,7 @@ private slots:
void onSweepOutput();
void onSweepMulti();
void setSearchFilter(const QString &filter);
void editLabel();
private:
void freezeCoins(const QVector<int>& indexes);
@ -70,6 +71,7 @@ private:
QAction *m_viewOutputAction;
QAction *m_sweepOutputAction;
QAction *m_sweepOutputsAction;
QAction *m_editLabelAction;
Coins *m_coins;
CoinsModel * m_model;
CoinsProxyModel * m_proxyModel;

View file

@ -61,7 +61,7 @@ QVariant CoinsModel::data(const QModelIndex &index, int role) const
QVariant result;
bool found = m_coins->coin(index.row(), [this, &index, &result, &role](const CoinsInfo &cInfo) {
if(role == Qt::DisplayRole || role == Qt::UserRole) {
if(role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole) {
result = parseTransactionInfo(cInfo, index.column(), role);
}
else if (role == Qt::BackgroundRole) {
@ -119,6 +119,9 @@ QVariant CoinsModel::data(const QModelIndex &index, int role) const
else if (!cInfo.unlocked()) {
result = "Output is locked (needs more confirmations)";
}
else if (cInfo.spent()) {
result = "Output is spent";
}
}
});
if (!found) {