From e9e6262c0e9ef676eb0c0c52fd1400f96b92d881 Mon Sep 17 00:00:00 2001 From: Cozz Lovan Date: Fri, 25 Oct 2013 11:13:28 -1000 Subject: [PATCH] Coin Control improvements October 25th, 2013 * code nits * introduced GUIUtil::setClipboard * calling getBalance(coinControl) now in walletmodel.cpp * replaced "WARNING" with "Warning" * added notr="true" to ui non translatable strings --- src/qt/coincontroldialog.cpp | 29 +++++++++++++++-------------- src/qt/forms/coincontroldialog.ui | 12 ++++++------ src/qt/forms/sendcoinsdialog.ui | 12 ++++++------ src/qt/guiutil.cpp | 6 ++++++ src/qt/guiutil.h | 4 +++- src/qt/sendcoinsdialog.cpp | 20 ++++++++++---------- src/qt/walletmodel.cpp | 20 +++++++++++++------- src/qt/walletmodel.h | 4 ++-- 8 files changed, 61 insertions(+), 46 deletions(-) diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index bc51e9165..e34b36b0b 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -6,6 +6,7 @@ #include "walletmodel.h" #include "addresstablemodel.h" #include "optionsmodel.h" +#include "guiutil.h" #include "coincontrol.h" #include @@ -213,31 +214,31 @@ void CoinControlDialog::showMenu(const QPoint &point) // context menu action: copy amount void CoinControlDialog::copyAmount() { - QApplication::clipboard()->setText(contextMenuItem->text(COLUMN_AMOUNT)); + GUIUtil::setClipboard(contextMenuItem->text(COLUMN_AMOUNT)); } // context menu action: copy label void CoinControlDialog::copyLabel() { if (ui->radioTreeMode->isChecked() && contextMenuItem->text(COLUMN_LABEL).length() == 0 && contextMenuItem->parent()) - QApplication::clipboard()->setText(contextMenuItem->parent()->text(COLUMN_LABEL)); + GUIUtil::setClipboard(contextMenuItem->parent()->text(COLUMN_LABEL)); else - QApplication::clipboard()->setText(contextMenuItem->text(COLUMN_LABEL)); + GUIUtil::setClipboard(contextMenuItem->text(COLUMN_LABEL)); } // context menu action: copy address void CoinControlDialog::copyAddress() { if (ui->radioTreeMode->isChecked() && contextMenuItem->text(COLUMN_ADDRESS).length() == 0 && contextMenuItem->parent()) - QApplication::clipboard()->setText(contextMenuItem->parent()->text(COLUMN_ADDRESS)); + GUIUtil::setClipboard(contextMenuItem->parent()->text(COLUMN_ADDRESS)); else - QApplication::clipboard()->setText(contextMenuItem->text(COLUMN_ADDRESS)); + GUIUtil::setClipboard(contextMenuItem->text(COLUMN_ADDRESS)); } // context menu action: copy transaction id void CoinControlDialog::copyTransactionHash() { - QApplication::clipboard()->setText(contextMenuItem->text(COLUMN_TXHASH)); + GUIUtil::setClipboard(contextMenuItem->text(COLUMN_TXHASH)); } // context menu action: lock coin @@ -266,49 +267,49 @@ void CoinControlDialog::unlockCoin() // copy label "Quantity" to clipboard void CoinControlDialog::clipboardQuantity() { - QApplication::clipboard()->setText(ui->labelCoinControlQuantity->text()); + GUIUtil::setClipboard(ui->labelCoinControlQuantity->text()); } // copy label "Amount" to clipboard void CoinControlDialog::clipboardAmount() { - QApplication::clipboard()->setText(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" "))); + GUIUtil::setClipboard(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" "))); } // copy label "Fee" to clipboard void CoinControlDialog::clipboardFee() { - QApplication::clipboard()->setText(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" "))); + GUIUtil::setClipboard(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" "))); } // copy label "After fee" to clipboard void CoinControlDialog::clipboardAfterFee() { - QApplication::clipboard()->setText(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" "))); + GUIUtil::setClipboard(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" "))); } // copy label "Bytes" to clipboard void CoinControlDialog::clipboardBytes() { - QApplication::clipboard()->setText(ui->labelCoinControlBytes->text()); + GUIUtil::setClipboard(ui->labelCoinControlBytes->text()); } // copy label "Priority" to clipboard void CoinControlDialog::clipboardPriority() { - QApplication::clipboard()->setText(ui->labelCoinControlPriority->text()); + GUIUtil::setClipboard(ui->labelCoinControlPriority->text()); } // copy label "Low output" to clipboard void CoinControlDialog::clipboardLowOutput() { - QApplication::clipboard()->setText(ui->labelCoinControlLowOutput->text()); + GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text()); } // copy label "Change" to clipboard void CoinControlDialog::clipboardChange() { - QApplication::clipboard()->setText(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" "))); + GUIUtil::setClipboard(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" "))); } // treeview: sort diff --git a/src/qt/forms/coincontroldialog.ui b/src/qt/forms/coincontroldialog.ui index 26947258f..58f6557fa 100644 --- a/src/qt/forms/coincontroldialog.ui +++ b/src/qt/forms/coincontroldialog.ui @@ -61,7 +61,7 @@ Qt::ActionsContextMenu - 0 + 0 Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -93,7 +93,7 @@ Qt::ActionsContextMenu - 0 + 0 Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -141,7 +141,7 @@ Qt::ActionsContextMenu - 0.00 BTC + 0.00 BTC Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -221,7 +221,7 @@ Qt::ActionsContextMenu - 0.00 BTC + 0.00 BTC Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -307,7 +307,7 @@ Qt::ActionsContextMenu - 0.00 BTC + 0.00 BTC Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -345,7 +345,7 @@ Qt::ActionsContextMenu - 0.00 BTC + 0.00 BTC Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse diff --git a/src/qt/forms/sendcoinsdialog.ui b/src/qt/forms/sendcoinsdialog.ui index 2d32503c0..c95efc335 100644 --- a/src/qt/forms/sendcoinsdialog.ui +++ b/src/qt/forms/sendcoinsdialog.ui @@ -232,7 +232,7 @@ Qt::ActionsContextMenu - 0 + 0 0 @@ -267,7 +267,7 @@ Qt::ActionsContextMenu - 0 + 0 Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -321,7 +321,7 @@ Qt::ActionsContextMenu - 0.00 BTC + 0.00 BTC Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -407,7 +407,7 @@ Qt::ActionsContextMenu - 0.00 BTC + 0.00 BTC Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -493,7 +493,7 @@ Qt::ActionsContextMenu - 0.00 BTC + 0.00 BTC Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse @@ -525,7 +525,7 @@ Qt::ActionsContextMenu - 0.00 BTC + 0.00 BTC Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index fc9090093..2af4606d8 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -181,6 +181,12 @@ void copyEntryData(QAbstractItemView *view, int column, int role) } } +void setClipboard(const QString& str) +{ + QApplication::clipboard()->setText(str, QClipboard::Clipboard); + QApplication::clipboard()->setText(str, QClipboard::Selection); +} + QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, const QString &filter, diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index e2c7d18aa..738c9065c 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -47,7 +47,9 @@ namespace GUIUtil @see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress */ void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole); - + + void setClipboard(const QString& str); + /** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when no suffix is provided by the user. diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index cd8560280..76445c478 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -387,49 +387,49 @@ void SendCoinsDialog::updateDisplayUnit() // Coin Control: copy label "Quantity" to clipboard void SendCoinsDialog::coinControlClipboardQuantity() { - QApplication::clipboard()->setText(ui->labelCoinControlQuantity->text()); + GUIUtil::setClipboard(ui->labelCoinControlQuantity->text()); } // Coin Control: copy label "Amount" to clipboard void SendCoinsDialog::coinControlClipboardAmount() { - QApplication::clipboard()->setText(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" "))); + GUIUtil::setClipboard(ui->labelCoinControlAmount->text().left(ui->labelCoinControlAmount->text().indexOf(" "))); } // Coin Control: copy label "Fee" to clipboard void SendCoinsDialog::coinControlClipboardFee() { - QApplication::clipboard()->setText(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" "))); + GUIUtil::setClipboard(ui->labelCoinControlFee->text().left(ui->labelCoinControlFee->text().indexOf(" "))); } // Coin Control: copy label "After fee" to clipboard void SendCoinsDialog::coinControlClipboardAfterFee() { - QApplication::clipboard()->setText(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" "))); + GUIUtil::setClipboard(ui->labelCoinControlAfterFee->text().left(ui->labelCoinControlAfterFee->text().indexOf(" "))); } // Coin Control: copy label "Bytes" to clipboard void SendCoinsDialog::coinControlClipboardBytes() { - QApplication::clipboard()->setText(ui->labelCoinControlBytes->text()); + GUIUtil::setClipboard(ui->labelCoinControlBytes->text()); } // Coin Control: copy label "Priority" to clipboard void SendCoinsDialog::coinControlClipboardPriority() { - QApplication::clipboard()->setText(ui->labelCoinControlPriority->text()); + GUIUtil::setClipboard(ui->labelCoinControlPriority->text()); } // Coin Control: copy label "Low output" to clipboard void SendCoinsDialog::coinControlClipboardLowOutput() { - QApplication::clipboard()->setText(ui->labelCoinControlLowOutput->text()); + GUIUtil::setClipboard(ui->labelCoinControlLowOutput->text()); } // Coin Control: copy label "Change" to clipboard void SendCoinsDialog::coinControlClipboardChange() { - QApplication::clipboard()->setText(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" "))); + GUIUtil::setClipboard(ui->labelCoinControlChange->text().left(ui->labelCoinControlChange->text().indexOf(" "))); } // Coin Control: settings menu - coin control enabled/disabled by user @@ -479,7 +479,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString & text) else if (!CBitcoinAddress(text.toStdString()).IsValid()) { ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); - ui->labelCoinControlChangeLabel->setText(tr("WARNING: Invalid Bitcoin address")); + ui->labelCoinControlChangeLabel->setText(tr("Warning: Invalid Bitcoin address")); } else { @@ -496,7 +496,7 @@ void SendCoinsDialog::coinControlChangeEdited(const QString & text) else { ui->labelCoinControlChangeLabel->setStyleSheet("QLabel{color:red;}"); - ui->labelCoinControlChangeLabel->setText(tr("WARNING: unknown change address")); + ui->labelCoinControlChangeLabel->setText(tr("Warning: Unknown change address")); } } } diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index bbf20a419..a95df8194 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -36,8 +36,19 @@ WalletModel::~WalletModel() unsubscribeFromCoreSignals(); } -qint64 WalletModel::getBalance() const +qint64 WalletModel::getBalance(const CCoinControl *coinControl) const { + if (coinControl) + { + int64 nBalance = 0; + std::vector vCoins; + wallet->AvailableCoins(vCoins, true, coinControl); + BOOST_FOREACH(const COutput& out, vCoins) + nBalance += out.tx->vout[out.i].nValue; + + return nBalance; + } + return wallet->GetBalance(); } @@ -156,12 +167,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList vCoins; - wallet->AvailableCoins(vCoins, true, coinControl); - BOOST_FOREACH(const COutput& out, vCoins) - nBalance += out.tx->vout[out.i].nValue; + int64 nBalance = getBalance(coinControl); if(total > nBalance) { diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index f6bf7a8eb..4d61da994 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -62,8 +62,8 @@ public: OptionsModel *getOptionsModel(); AddressTableModel *getAddressTableModel(); TransactionTableModel *getTransactionTableModel(); - - qint64 getBalance() const; + + qint64 getBalance(const CCoinControl *coinControl=NULL) const; qint64 getUnconfirmedBalance() const; qint64 getImmatureBalance() const; int getNumTransactions() const;