return AddressToHash160(address.toStdString(), hash160);
}
+
+/* Look up label for address in address book, if not found return empty string.
+ */
+QString AddressTableModel::labelForAddress(const QString &address) const
+{
+ CRITICAL_BLOCK(wallet->cs_mapAddressBook)
+ {
+ std::map<std::string, std::string>::iterator mi = wallet->mapAddressBook.find(address.toStdString());
+ if (mi != wallet->mapAddressBook.end())
+ {
+ return QString::fromStdString(mi->second);
+ }
+ }
+ return QString();
+}
+
+int AddressTableModel::lookupAddress(const QString &address) const
+{
+ QModelIndexList lst = match(index(0, Address, QModelIndex()),
+ Qt::EditRole, address, 1, Qt::MatchExactly);
+ if(lst.isEmpty())
+ {
+ return -1;
+ }
+ else
+ {
+ return lst.at(0).row();
+ }
+}
+
*/
bool validateAddress(const QString &address);
+ /* Look up label for address in address book, if not found return empty string.
+ */
+ QString labelForAddress(const QString &address) const;
+
+ /* Look up row index of an address in the model.
+ Return -1 if not found.
+ */
+ int lookupAddress(const QString &address) const;
+
private:
CWallet *wallet;
AddressTablePriv *priv;
QVBoxLayout *vbox = new QVBoxLayout();
transactionView = new TransactionView(this);
- connect(transactionView, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(transactionDetails(const QModelIndex&)));
+ connect(transactionView, SIGNAL(doubleClicked(const QModelIndex&)), transactionView, SLOT(transactionDetails()));
vbox->addWidget(transactionView);
transactionsPage = new QWidget(this);
connect(walletModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString)));
// Put transaction list in tabs
- transactionView->setModel(walletModel->getTransactionTableModel());
+ transactionView->setModel(walletModel);
addressBookPage->setModel(walletModel->getAddressTableModel());
receiveCoinsPage->setModel(walletModel->getAddressTableModel());
default: icon = ":/icons/connect_4"; break;
}
labelConnections->setTextFormat(Qt::RichText);
- labelConnections->setText("<img src=\""+icon+"\">" + tr("%n connection(s)", "", count));
+ labelConnections->setText("<img src=\""+icon+"\"> " + tr("%n connection(s)", "", count));
}
void BitcoinGUI::setNumBlocks(int count)
*payFee = (retval == QMessageBox::Yes);
}
-void BitcoinGUI::transactionDetails(const QModelIndex& idx)
-{
- // A transaction is doubleclicked
- TransactionDescDialog dlg(idx);
- dlg.exec();
-}
-
void BitcoinGUI::incomingTransaction(const QModelIndex & parent, int start, int end)
{
TransactionTableModel *ttm = walletModel->getTransactionTableModel();
void optionsClicked();
void aboutClicked();
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
- void transactionDetails(const QModelIndex& idx);
void incomingTransaction(const QModelIndex & parent, int start, int end);
void exportClicked();
};
#include "sendcoinsdialog.h"
#include "ui_sendcoinsdialog.h"
#include "walletmodel.h"
+#include "addresstablemodel.h"
#include "guiutil.h"
#include "addressbookpage.h"
void SendCoinsDialog::on_payTo_textChanged(const QString &address)
{
- ui->addAsLabel->setText(model->labelForAddress(address));
+ ui->addAsLabel->setText(model->getAddressTableModel()->labelForAddress(address));
}
void SendCoinsDialog::clear()
#include "guiconstants.h"
#include "transactiondesc.h"
#include "walletmodel.h"
+#include "addresstablemodel.h"
#include "headers.h"
*/
QString TransactionTableModel::lookupAddress(const std::string &address) const
{
- QString label = walletModel->labelForAddress(QString::fromStdString(address));
+ QString label = walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(address));
QString description;
if(label.isEmpty())
{
}
else if (role == LabelRole)
{
- return walletModel->labelForAddress(QString::fromStdString(rec->address));
+ return walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(rec->address));
}
else if (role == AbsoluteAmountRole)
{
#include "transactionfilterproxy.h"
#include "transactionrecord.h"
+#include "walletmodel.h"
+#include "addresstablemodel.h"
#include "transactiontablemodel.h"
#include "guiutil.h"
#include "csvmodelwriter.h"
+#include "transactiondescdialog.h"
+#include "editaddressdialog.h"
#include <QScrollBar>
#include <QComboBox>
#include <QPushButton>
#include <QFileDialog>
#include <QMessageBox>
+#include <QPoint>
+#include <QMenu>
+#include <QApplication>
+#include <QClipboard>
#include <QDebug>
// Always show scroll bar
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
view->setTabKeyNavigation(false);
+ view->setContextMenuPolicy(Qt::CustomContextMenu);
transactionView = view;
+ // Actions
+ QAction *copyAddressAction = new QAction("Copy address", this);
+ QAction *copyLabelAction = new QAction("Copy label", this);
+ QAction *editLabelAction = new QAction("Edit label", this);
+ QAction *showDetailsAction = new QAction("Show details...", this);
+
+ contextMenu = new QMenu();
+ contextMenu->addAction(copyAddressAction);
+ contextMenu->addAction(copyLabelAction);
+ contextMenu->addAction(editLabelAction);
+ contextMenu->addAction(showDetailsAction);
+
+ // Connect actions
connect(dateWidget, SIGNAL(activated(int)), this, SLOT(chooseDate(int)));
connect(typeWidget, SIGNAL(activated(int)), this, SLOT(chooseType(int)));
connect(addressWidget, SIGNAL(textChanged(const QString&)), this, SLOT(changedPrefix(const QString&)));
connect(amountWidget, SIGNAL(textChanged(const QString&)), this, SLOT(changedAmount(const QString&)));
connect(view, SIGNAL(doubleClicked(const QModelIndex&)), this, SIGNAL(doubleClicked(const QModelIndex&)));
+
+ connect(view,
+ SIGNAL(customContextMenuRequested(const QPoint &)),
+ this,
+ SLOT(contextualMenu(const QPoint &)));
+
+ connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(copyAddress()));
+ connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
+ connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel()));
+ connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails()));
}
-void TransactionView::setModel(TransactionTableModel *model)
+void TransactionView::setModel(WalletModel *model)
{
this->model = model;
transactionProxyModel = new TransactionFilterProxy(this);
- transactionProxyModel->setSourceModel(model);
+ transactionProxyModel->setSourceModel(model->getTransactionTableModel());
transactionProxyModel->setDynamicSortFilter(true);
transactionProxyModel->setSortRole(Qt::EditRole);
}
}
+void TransactionView::contextualMenu(const QPoint &point)
+{
+ QModelIndex index = transactionView->indexAt(point);
+ if(index.isValid())
+ {
+ contextMenu->exec(QCursor::pos());
+ }
+}
+
+void TransactionView::copyAddress()
+{
+ QModelIndexList selection = transactionView->selectionModel()->selectedRows();
+ if(!selection.isEmpty())
+ {
+ QApplication::clipboard()->setText(selection.at(0).data(TransactionTableModel::AddressRole).toString());
+ }
+}
+
+void TransactionView::copyLabel()
+{
+ QModelIndexList selection = transactionView->selectionModel()->selectedRows();
+ if(!selection.isEmpty())
+ {
+ QApplication::clipboard()->setText(selection.at(0).data(TransactionTableModel::LabelRole).toString());
+ }
+}
+
+void TransactionView::editLabel()
+{
+ QModelIndexList selection = transactionView->selectionModel()->selectedRows();
+ if(!selection.isEmpty())
+ {
+ AddressTableModel *addressBook = model->getAddressTableModel();
+ QString address = selection.at(0).data(TransactionTableModel::AddressRole).toString();
+ if(address.isEmpty())
+ {
+ // If this transaction has no associated address, exit
+ return;
+ }
+ int idx = addressBook->lookupAddress(address);
+ if(idx != -1)
+ {
+ // Edit sending / receiving address
+ QModelIndex modelIdx = addressBook->index(idx, 0, QModelIndex());
+ // Determine type of address, launch appropriate editor dialog type
+ QString type = modelIdx.data(AddressTableModel::TypeRole).toString();
+
+ EditAddressDialog dlg(type==AddressTableModel::Receive
+ ? EditAddressDialog::EditReceivingAddress
+ : EditAddressDialog::EditSendingAddress,
+ this);
+ dlg.setModel(addressBook);
+ dlg.loadRow(idx);
+ dlg.exec();
+ }
+ else
+ {
+ // Add sending address
+ EditAddressDialog dlg(EditAddressDialog::NewSendingAddress,
+ this);
+ dlg.exec();
+ }
+ }
+}
+
+void TransactionView::showDetails()
+{
+ QModelIndexList selection = transactionView->selectionModel()->selectedRows();
+ if(!selection.isEmpty())
+ {
+ TransactionDescDialog dlg(selection.at(0));
+ dlg.exec();
+ }
+}
#include <QWidget>
-class TransactionTableModel;
+class WalletModel;
class TransactionFilterProxy;
QT_BEGIN_NAMESPACE
class QComboBox;
class QLineEdit;
class QModelIndex;
+class QMenu;
QT_END_NAMESPACE
class TransactionView : public QWidget
public:
explicit TransactionView(QWidget *parent = 0);
- void setModel(TransactionTableModel *model);
+ void setModel(WalletModel *model);
enum DateEnum
{
};
private:
- TransactionTableModel *model;
+ WalletModel *model;
TransactionFilterProxy *transactionProxyModel;
QTableView *transactionView;
QLineEdit *addressWidget;
QLineEdit *amountWidget;
+ QMenu *contextMenu;
+
+private slots:
+ void contextualMenu(const QPoint &);
+
signals:
void doubleClicked(const QModelIndex&);
void changedPrefix(const QString &prefix);
void changedAmount(const QString &amount);
void exportClicked();
+ void showDetails();
+ void copyAddress();
+ void editLabel();
+ void copyLabel();
};
return transactionTableModel;
}
-/* Look up label for address in address book, if not found return empty string.
- */
-QString WalletModel::labelForAddress(const QString &address) const
-{
- CRITICAL_BLOCK(wallet->cs_mapAddressBook)
- {
- std::map<std::string, std::string>::iterator mi = wallet->mapAddressBook.find(address.toStdString());
- if (mi != wallet->mapAddressBook.end())
- {
- return QString::fromStdString(mi->second);
- }
- }
- return QString();
-}
qint64 getBalance() const;
int getNumTransactions() const;
- /* Look up label for address in address book, if not found return empty string.
- */
- QString labelForAddress(const QString &address) const;
-
/* Send coins */
StatusCode sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs=QString());
private: