Browse Source

Copy amount to clipboard (implements #657)

- Also, unify similar code related to copying transaction fields to clipboard
0.8
Wladimir J. van der Laan 13 years ago
parent
commit
c58e7d4e01
  1. 16
      src/qt/guiutil.cpp
  2. 10
      src/qt/guiutil.h
  3. 31
      src/qt/transactionview.cpp
  4. 9
      src/qt/transactionview.h

16
src/qt/guiutil.cpp

@ -12,6 +12,9 @@
#include <QLineEdit> #include <QLineEdit>
#include <QUrl> #include <QUrl>
#include <QTextDocument> // For Qt::escape #include <QTextDocument> // For Qt::escape
#include <QAbstractItemView>
#include <QApplication>
#include <QClipboard>
QString GUIUtil::dateTimeStr(qint64 nTime) QString GUIUtil::dateTimeStr(qint64 nTime)
{ {
@ -88,3 +91,16 @@ QString GUIUtil::HtmlEscape(const std::string& str, bool fMultiLine)
{ {
return HtmlEscape(QString::fromStdString(str), fMultiLine); return HtmlEscape(QString::fromStdString(str), fMultiLine);
} }
void GUIUtil::copyEntryData(QAbstractItemView *view, int column, int role)
{
if(!view || !view->selectionModel())
return;
QModelIndexList selection = view->selectionModel()->selectedRows(column);
if(!selection.isEmpty())
{
// Copy first item
QApplication::clipboard()->setText(selection.at(0).data(role).toString());
}
}

10
src/qt/guiutil.h

@ -9,6 +9,7 @@ class QLineEdit;
class QWidget; class QWidget;
class QDateTime; class QDateTime;
class QUrl; class QUrl;
class QAbstractItemView;
QT_END_NAMESPACE QT_END_NAMESPACE
class SendCoinsRecipient; class SendCoinsRecipient;
@ -35,6 +36,15 @@ public:
// HTML escaping for rich text controls // HTML escaping for rich text controls
static QString HtmlEscape(const QString& str, bool fMultiLine=false); static QString HtmlEscape(const QString& str, bool fMultiLine=false);
static QString HtmlEscape(const std::string& str, bool fMultiLine=false); static QString HtmlEscape(const std::string& str, bool fMultiLine=false);
/** Copy a field of the currently selected entry of a view to the clipboard. Does nothing if nothing
is selected.
@param[in] column Data column to extract from the model
@param[in] role Data role to extract from the model
@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
*/
static void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole);
}; };
#endif // GUIUTIL_H #endif // GUIUTIL_H

31
src/qt/transactionview.cpp

@ -10,6 +10,7 @@
#include "transactiondescdialog.h" #include "transactiondescdialog.h"
#include "editaddressdialog.h" #include "editaddressdialog.h"
#include "optionsmodel.h" #include "optionsmodel.h"
#include "guiutil.h"
#include <QScrollBar> #include <QScrollBar>
#include <QComboBox> #include <QComboBox>
@ -123,12 +124,14 @@ TransactionView::TransactionView(QWidget *parent) :
// Actions // Actions
QAction *copyAddressAction = new QAction(tr("Copy address"), this); QAction *copyAddressAction = new QAction(tr("Copy address"), this);
QAction *copyLabelAction = new QAction(tr("Copy label"), this); QAction *copyLabelAction = new QAction(tr("Copy label"), this);
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
QAction *editLabelAction = new QAction(tr("Edit label"), this); QAction *editLabelAction = new QAction(tr("Edit label"), this);
QAction *showDetailsAction = new QAction(tr("Show details..."), this); QAction *showDetailsAction = new QAction(tr("Show details..."), this);
contextMenu = new QMenu(); contextMenu = new QMenu();
contextMenu->addAction(copyAddressAction); contextMenu->addAction(copyAddressAction);
contextMenu->addAction(copyLabelAction); contextMenu->addAction(copyLabelAction);
contextMenu->addAction(copyAmountAction);
contextMenu->addAction(editLabelAction); contextMenu->addAction(editLabelAction);
contextMenu->addAction(showDetailsAction); contextMenu->addAction(showDetailsAction);
@ -139,14 +142,11 @@ TransactionView::TransactionView(QWidget *parent) :
connect(amountWidget, SIGNAL(textChanged(QString)), this, SLOT(changedAmount(QString))); connect(amountWidget, SIGNAL(textChanged(QString)), this, SLOT(changedAmount(QString)));
connect(view, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(doubleClicked(QModelIndex))); connect(view, SIGNAL(doubleClicked(QModelIndex)), this, SIGNAL(doubleClicked(QModelIndex)));
connect(view, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextualMenu(QPoint)));
connect(view,
SIGNAL(customContextMenuRequested(QPoint)),
this,
SLOT(contextualMenu(QPoint)));
connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(copyAddress())); connect(copyAddressAction, SIGNAL(triggered()), this, SLOT(copyAddress()));
connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel())); connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel())); connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel()));
connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails())); connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails()));
} }
@ -302,24 +302,17 @@ void TransactionView::contextualMenu(const QPoint &point)
void TransactionView::copyAddress() void TransactionView::copyAddress()
{ {
if(!transactionView->selectionModel()) GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::AddressRole);
return;
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
if(!selection.isEmpty())
{
QApplication::clipboard()->setText(selection.at(0).data(TransactionTableModel::AddressRole).toString());
}
} }
void TransactionView::copyLabel() void TransactionView::copyLabel()
{ {
if(!transactionView->selectionModel()) GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::LabelRole);
return; }
QModelIndexList selection = transactionView->selectionModel()->selectedRows();
if(!selection.isEmpty()) void TransactionView::copyAmount()
{ {
QApplication::clipboard()->setText(selection.at(0).data(TransactionTableModel::LabelRole).toString()); GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::FormattedAmountRole);
}
} }
void TransactionView::editLabel() void TransactionView::editLabel()

9
src/qt/transactionview.h

@ -60,6 +60,11 @@ private:
private slots: private slots:
void contextualMenu(const QPoint &); void contextualMenu(const QPoint &);
void dateRangeChanged(); void dateRangeChanged();
void showDetails();
void copyAddress();
void editLabel();
void copyLabel();
void copyAmount();
signals: signals:
void doubleClicked(const QModelIndex&); void doubleClicked(const QModelIndex&);
@ -70,10 +75,6 @@ public slots:
void changedPrefix(const QString &prefix); void changedPrefix(const QString &prefix);
void changedAmount(const QString &amount); void changedAmount(const QString &amount);
void exportClicked(); void exportClicked();
void showDetails();
void copyAddress();
void editLabel();
void copyLabel();
}; };

Loading…
Cancel
Save