From ceb6d4e11d8dab8a6778e20c433f6ed989c16221 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 28 Jun 2011 21:41:56 +0200 Subject: Implement filter row instead of tabs, allows for more expressive filters --- src/qt/transactiontablemodel.cpp | 72 ++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 28 deletions(-) (limited to 'src/qt/transactiontablemodel.cpp') 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 #include #include +#include #include 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::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(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(); } -- cgit v1.2.3