Changeset View
Changeset View
Standalone View
Standalone View
src/qt/coincontroldialog.cpp
Show First 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | CoinControlDialog::CoinControlDialog(const PlatformStyle *_platformStyle, | ||||
ui->treeWidget->setColumnWidth(COLUMN_CHECKBOX, 84); | ui->treeWidget->setColumnWidth(COLUMN_CHECKBOX, 84); | ||||
ui->treeWidget->setColumnWidth(COLUMN_AMOUNT, 110); | ui->treeWidget->setColumnWidth(COLUMN_AMOUNT, 110); | ||||
ui->treeWidget->setColumnWidth(COLUMN_LABEL, 190); | ui->treeWidget->setColumnWidth(COLUMN_LABEL, 190); | ||||
ui->treeWidget->setColumnWidth(COLUMN_ADDRESS, 320); | ui->treeWidget->setColumnWidth(COLUMN_ADDRESS, 320); | ||||
ui->treeWidget->setColumnWidth(COLUMN_DATE, 130); | ui->treeWidget->setColumnWidth(COLUMN_DATE, 130); | ||||
ui->treeWidget->setColumnWidth(COLUMN_CONFIRMATIONS, 110); | ui->treeWidget->setColumnWidth(COLUMN_CONFIRMATIONS, 110); | ||||
// store transaction hash in this column, but don't show it | // store transaction hash in this column, but don't show it | ||||
ui->treeWidget->setColumnHidden(COLUMN_TXHASH, true); | ui->treeWidget->setColumnHidden(COLUMN_TXID, true); | ||||
// store vout index in this column, but don't show it | // store vout index in this column, but don't show it | ||||
ui->treeWidget->setColumnHidden(COLUMN_VOUT_INDEX, true); | ui->treeWidget->setColumnHidden(COLUMN_VOUT_INDEX, true); | ||||
// default view is sorted by amount desc | // default view is sorted by amount desc | ||||
sortView(COLUMN_AMOUNT, Qt::DescendingOrder); | sortView(COLUMN_AMOUNT, Qt::DescendingOrder); | ||||
// restore list mode and sortorder as a convenience feature | // restore list mode and sortorder as a convenience feature | ||||
QSettings settings; | QSettings settings; | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
// context menu | // context menu | ||||
void CoinControlDialog::showMenu(const QPoint &point) { | void CoinControlDialog::showMenu(const QPoint &point) { | ||||
QTreeWidgetItem *item = ui->treeWidget->itemAt(point); | QTreeWidgetItem *item = ui->treeWidget->itemAt(point); | ||||
if (item) { | if (item) { | ||||
contextMenuItem = item; | contextMenuItem = item; | ||||
// disable some items (like Copy Transaction ID, lock, unlock) for tree | // disable some items (like Copy Transaction ID, lock, unlock) for tree | ||||
// roots in context menu | // roots in context menu | ||||
if (item->text(COLUMN_TXHASH).length() == 64) { | if (item->text(COLUMN_TXID).length() == 64) { | ||||
TxId txid; | COutPoint outpoint = buildOutPoint(item); | ||||
txid.SetHex(item->text(COLUMN_TXHASH).toStdString()); | |||||
// transaction hash is 64 characters (this means its a child node, | // transaction hash is 64 characters (this means its a child node, | ||||
// so its not a parent node in tree mode) | // so its not a parent node in tree mode) | ||||
copyTransactionHashAction->setEnabled(true); | copyTransactionHashAction->setEnabled(true); | ||||
if (model->wallet().isLockedCoin( | if (model->wallet().isLockedCoin(outpoint)) { | ||||
COutPoint(txid, item->text(COLUMN_VOUT_INDEX).toUInt()))) { | |||||
lockAction->setEnabled(false); | lockAction->setEnabled(false); | ||||
unlockAction->setEnabled(true); | unlockAction->setEnabled(true); | ||||
} else { | } else { | ||||
lockAction->setEnabled(true); | lockAction->setEnabled(true); | ||||
unlockAction->setEnabled(false); | unlockAction->setEnabled(false); | ||||
} | } | ||||
} else { | } else { | ||||
// this means click on parent node in tree mode -> disable all | // this means click on parent node in tree mode -> disable all | ||||
Show All 32 Lines | if (ui->radioTreeMode->isChecked() && | ||||
GUIUtil::setClipboard(contextMenuItem->parent()->text(COLUMN_ADDRESS)); | GUIUtil::setClipboard(contextMenuItem->parent()->text(COLUMN_ADDRESS)); | ||||
} else { | } else { | ||||
GUIUtil::setClipboard(contextMenuItem->text(COLUMN_ADDRESS)); | GUIUtil::setClipboard(contextMenuItem->text(COLUMN_ADDRESS)); | ||||
} | } | ||||
} | } | ||||
// context menu action: copy transaction id | // context menu action: copy transaction id | ||||
void CoinControlDialog::copyTransactionHash() { | void CoinControlDialog::copyTransactionHash() { | ||||
GUIUtil::setClipboard(contextMenuItem->text(COLUMN_TXHASH)); | GUIUtil::setClipboard(contextMenuItem->text(COLUMN_TXID)); | ||||
} | } | ||||
// context menu action: lock coin | // context menu action: lock coin | ||||
void CoinControlDialog::lockCoin() { | void CoinControlDialog::lockCoin() { | ||||
if (contextMenuItem->checkState(COLUMN_CHECKBOX) == Qt::Checked) { | if (contextMenuItem->checkState(COLUMN_CHECKBOX) == Qt::Checked) { | ||||
contextMenuItem->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked); | contextMenuItem->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked); | ||||
} | } | ||||
COutPoint outpt( | COutPoint outpoint = buildOutPoint(contextMenuItem); | ||||
uint256S(contextMenuItem->text(COLUMN_TXHASH).toStdString()), | model->wallet().lockCoin(outpoint); | ||||
contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt()); | |||||
model->wallet().lockCoin(outpt); | |||||
contextMenuItem->setDisabled(true); | contextMenuItem->setDisabled(true); | ||||
contextMenuItem->setIcon( | contextMenuItem->setIcon( | ||||
COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed")); | COLUMN_CHECKBOX, platformStyle->SingleColorIcon(":/icons/lock_closed")); | ||||
updateLabelLocked(); | updateLabelLocked(); | ||||
} | } | ||||
// context menu action: unlock coin | // context menu action: unlock coin | ||||
void CoinControlDialog::unlockCoin() { | void CoinControlDialog::unlockCoin() { | ||||
COutPoint outpt( | COutPoint outpoint = buildOutPoint(contextMenuItem); | ||||
uint256S(contextMenuItem->text(COLUMN_TXHASH).toStdString()), | model->wallet().unlockCoin(outpoint); | ||||
contextMenuItem->text(COLUMN_VOUT_INDEX).toUInt()); | |||||
model->wallet().unlockCoin(outpt); | |||||
contextMenuItem->setDisabled(false); | contextMenuItem->setDisabled(false); | ||||
contextMenuItem->setIcon(COLUMN_CHECKBOX, QIcon()); | contextMenuItem->setIcon(COLUMN_CHECKBOX, QIcon()); | ||||
updateLabelLocked(); | updateLabelLocked(); | ||||
} | } | ||||
// copy label "Quantity" to clipboard | // copy label "Quantity" to clipboard | ||||
void CoinControlDialog::clipboardQuantity() { | void CoinControlDialog::clipboardQuantity() { | ||||
GUIUtil::setClipboard(ui->labelCoinControlQuantity->text()); | GUIUtil::setClipboard(ui->labelCoinControlQuantity->text()); | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if (checked && model) { | ||||
updateView(); | updateView(); | ||||
} | } | ||||
} | } | ||||
// checkbox clicked by user | // checkbox clicked by user | ||||
void CoinControlDialog::viewItemChanged(QTreeWidgetItem *item, int column) { | void CoinControlDialog::viewItemChanged(QTreeWidgetItem *item, int column) { | ||||
// transaction hash is 64 characters (this means its a child node, so its | // transaction hash is 64 characters (this means its a child node, so its | ||||
// not a parent node in tree mode) | // not a parent node in tree mode) | ||||
if (column == COLUMN_CHECKBOX && item->text(COLUMN_TXHASH).length() == 64) { | if (column == COLUMN_CHECKBOX && item->text(COLUMN_TXID).length() == 64) { | ||||
COutPoint outpt(uint256S(item->text(COLUMN_TXHASH).toStdString()), | COutPoint outpoint = buildOutPoint(item); | ||||
item->text(COLUMN_VOUT_INDEX).toUInt()); | |||||
if (item->checkState(COLUMN_CHECKBOX) == Qt::Unchecked) { | if (item->checkState(COLUMN_CHECKBOX) == Qt::Unchecked) { | ||||
coinControl()->UnSelect(outpt); | coinControl()->UnSelect(outpoint); | ||||
} else if (item->isDisabled()) { | } else if (item->isDisabled()) { | ||||
// locked (this happens if "check all" through parent node) | // locked (this happens if "check all" through parent node) | ||||
item->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked); | item->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked); | ||||
} else { | } else { | ||||
coinControl()->Select(outpt); | coinControl()->Select(outpoint); | ||||
} | } | ||||
// selection changed -> update labels | // selection changed -> update labels | ||||
if (ui->treeWidget->isEnabled()) { | if (ui->treeWidget->isEnabled()) { | ||||
// do not update on every click for (un)select all | // do not update on every click for (un)select all | ||||
CoinControlDialog::updateLabels(model, this); | CoinControlDialog::updateLabels(model, this); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 231 Lines • ▼ Show 20 Lines | void CoinControlDialog::updateLabels(WalletModel *model, QDialog *dialog) { | ||||
} | } | ||||
} | } | ||||
CCoinControl *CoinControlDialog::coinControl() { | CCoinControl *CoinControlDialog::coinControl() { | ||||
static CCoinControl coin_control; | static CCoinControl coin_control; | ||||
return &coin_control; | return &coin_control; | ||||
} | } | ||||
COutPoint CoinControlDialog::buildOutPoint(const QTreeWidgetItem *item) { | |||||
TxId txid; | |||||
txid.SetHex(item->text(COLUMN_TXID).toStdString()); | |||||
return COutPoint(txid, item->text(COLUMN_VOUT_INDEX).toUInt()); | |||||
} | |||||
void CoinControlDialog::updateView() { | void CoinControlDialog::updateView() { | ||||
if (!model || !model->getOptionsModel() || !model->getAddressTableModel()) { | if (!model || !model->getOptionsModel() || !model->getAddressTableModel()) { | ||||
return; | return; | ||||
} | } | ||||
bool treeMode = ui->radioTreeMode->isChecked(); | bool treeMode = ui->radioTreeMode->isChecked(); | ||||
ui->treeWidget->clear(); | ui->treeWidget->clear(); | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | for (const auto &coins : model->wallet().listCoins()) { | ||||
// confirmations | // confirmations | ||||
itemOutput->setText(COLUMN_CONFIRMATIONS, | itemOutput->setText(COLUMN_CONFIRMATIONS, | ||||
QString::number(out.depth_in_main_chain)); | QString::number(out.depth_in_main_chain)); | ||||
itemOutput->setData(COLUMN_CONFIRMATIONS, Qt::UserRole, | itemOutput->setData(COLUMN_CONFIRMATIONS, Qt::UserRole, | ||||
QVariant((qlonglong)out.depth_in_main_chain)); | QVariant((qlonglong)out.depth_in_main_chain)); | ||||
// transaction id | // transaction id | ||||
itemOutput->setText(COLUMN_TXHASH, QString::fromStdString( | itemOutput->setText( | ||||
output.GetTxId().GetHex())); | COLUMN_TXID, QString::fromStdString(output.GetTxId().GetHex())); | ||||
// vout index | // vout index | ||||
itemOutput->setText(COLUMN_VOUT_INDEX, | itemOutput->setText(COLUMN_VOUT_INDEX, | ||||
QString::number(output.GetN())); | QString::number(output.GetN())); | ||||
// disable locked coins | // disable locked coins | ||||
if (model->wallet().isLockedCoin(output)) { | if (model->wallet().isLockedCoin(output)) { | ||||
// just to be sure | // just to be sure | ||||
Show All 38 Lines |