diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-28 21:41:56 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-29 23:09:55 +0200 |
commit | ceb6d4e11d8dab8a6778e20c433f6ed989c16221 (patch) | |
tree | 9c38a4254968ef15db820a6fac0bb8ff270957a0 /src/qt/transactiontablemodel.cpp | |
parent | 19a5975d5a024de37851524d72993f98dbdaff0c (diff) |
Implement filter row instead of tabs, allows for more expressive filters
Diffstat (limited to 'src/qt/transactiontablemodel.cpp')
-rw-r--r-- | src/qt/transactiontablemodel.cpp | 72 |
1 files changed, 44 insertions, 28 deletions
diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index e49629c9a3..28d22b8530 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -12,6 +12,7 @@ #include <QColor> #include <QTimer> #include <QIcon> +#include <QDateTime> #include <QtAlgorithms> const QString TransactionTableModel::Sent = "s"; @@ -301,27 +302,38 @@ QVariant TransactionTableModel::formatTxDate(const TransactionRecord *wtx) const } } -/* Look up address in address book, if found return - address[0:12]... (label) - otherwise just return address +/* Look up label for address in address book, if not found return empty string. + This should really move to the wallet class. */ -std::string TransactionTableModel::lookupAddress(const std::string &address) const +QString TransactionTableModel::labelForAddress(const std::string &address) const { - std::string description; CRITICAL_BLOCK(wallet->cs_mapAddressBook) { std::map<std::string, std::string>::iterator mi = wallet->mapAddressBook.find(address); - if (mi != wallet->mapAddressBook.end() && !(*mi).second.empty()) - { - std::string label = (*mi).second; - description += address.substr(0,12) + "... "; - description += "(" + label + ")"; - } - else + if (mi != wallet->mapAddressBook.end()) { - description += address; + return QString::fromStdString(mi->second); } } + return QString(); +} + +/* Look up address in address book, if found return + address[0:12]... (label) + otherwise just return address + */ +QString TransactionTableModel::lookupAddress(const std::string &address) const +{ + QString label = labelForAddress(address); + QString description; + if(label.isEmpty()) + { + description = QString::fromStdString(address); + } + else + { + description = QString::fromStdString(address.substr(0,12)) + QString("... (") + label + QString(")"); + } return description; } @@ -360,13 +372,13 @@ QVariant TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx) switch(wtx->type) { case TransactionRecord::RecvWithAddress: - description = QString::fromStdString(lookupAddress(wtx->address)); + description = lookupAddress(wtx->address); break; case TransactionRecord::RecvFromIP: description = QString::fromStdString(wtx->address); break; case TransactionRecord::SendToAddress: - description = QString::fromStdString(lookupAddress(wtx->address)); + description = lookupAddress(wtx->address); break; case TransactionRecord::SendToIP: description = QString::fromStdString(wtx->address); @@ -502,24 +514,28 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const } else if (role == TypeRole) { - /* Role for filtering tabs by type */ - switch(rec->type) - { - case TransactionRecord::RecvWithAddress: - case TransactionRecord::RecvFromIP: - return TransactionTableModel::Received; - case TransactionRecord::SendToAddress: - case TransactionRecord::SendToIP: - case TransactionRecord::SendToSelf: - return TransactionTableModel::Sent; - default: - return TransactionTableModel::Other; - } + return rec->type; + } + else if (role == DateRole) + { + return QDateTime::fromTime_t(static_cast<uint>(rec->time)); } else if (role == LongDescriptionRole) { return priv->describe(rec); } + else if (role == AddressRole) + { + return QString::fromStdString(rec->address); + } + else if (role == LabelRole) + { + return labelForAddress(rec->address); + } + else if (role == AbsoluteAmountRole) + { + return llabs(rec->credit + rec->debit); + } return QVariant(); } |