TransactionInfo: add transfers() and destinations_formatted()

This commit is contained in:
Jaquee 2016-12-03 12:07:47 +01:00
parent a4c3de9e2e
commit 7aea3d38d6
6 changed files with 46 additions and 23 deletions

View File

@ -41,7 +41,6 @@ private:
private:
friend class Wallet;
Bitmonero::TransactionHistory * m_pimpl;
mutable QList<TransactionInfo*> m_tinfo;
mutable QDateTime m_firstDateTime;

View File

@ -1,7 +1,8 @@
#include "TransactionInfo.h"
#include "WalletManager.h"
#include "Transfer.h"
#include <QDateTime>
#include <QDebug>
TransactionInfo::Direction TransactionInfo::direction() const
{
@ -71,6 +72,31 @@ QString TransactionInfo::paymentId() const
return QString::fromStdString(m_pimpl->paymentId());
}
QString TransactionInfo::destinations_formatted() const
{
QString destinations;
for (auto const& t: transfers()) {
if (!destinations.isEmpty())
destinations += "<br> ";
destinations += WalletManager::instance()->displayAmount(t->amount()) + ": " + t->address();
}
return destinations;
}
QList<Transfer*> TransactionInfo::transfers() const
{
if (!m_transfers.isEmpty()) {
return m_transfers;
}
for(auto const& t: m_pimpl->transfers()) {
TransactionInfo * parent = const_cast<TransactionInfo*>(this);
Transfer * transfer = new Transfer(t.amount, QString::fromStdString(t.address), parent);
m_transfers.append(transfer);
}
return m_transfers;
}
TransactionInfo::TransactionInfo(Bitmonero::TransactionInfo *pimpl, QObject *parent)
: QObject(parent), m_pimpl(pimpl)
{

View File

@ -5,6 +5,8 @@
#include <QObject>
#include <QDateTime>
class Transfer;
class TransactionInfo : public QObject
{
Q_OBJECT
@ -21,6 +23,7 @@ class TransactionInfo : public QObject
Q_PROPERTY(QString date READ date)
Q_PROPERTY(QString time READ time)
Q_PROPERTY(QString paymentId READ paymentId)
Q_PROPERTY(QString destinations_formatted READ destinations_formatted)
public:
enum Direction {
@ -31,14 +34,6 @@ public:
Q_ENUM(Direction)
// TODO: implement as separate class;
// struct Transfer {
// Transfer(uint64_t _amount, const std::string &address);
// const uint64_t amount;
// const std::string address;
// };
Direction direction() const;
bool isPending() const;
bool isFailed() const;
@ -53,16 +48,17 @@ public:
QString date() const;
QString time() const;
QString paymentId() const;
// TODO: implement it
//! only applicable for output transactions
// virtual const std::vector<Transfer> & transfers() const = 0;
//! used in tx details popup
QString destinations_formatted() const;
//! Could be useful later when addressbook is implemented
Q_INVOKABLE QList<Transfer*> transfers() const;
private:
explicit TransactionInfo(Bitmonero::TransactionInfo * pimpl, QObject *parent = 0);
private:
friend class TransactionHistory;
Bitmonero::TransactionInfo * m_pimpl;
mutable QList<Transfer*> m_transfers;
};
// in order to wrap it to QVariant

View File

@ -10,19 +10,15 @@ class Transfer : public QObject
Q_PROPERTY(quint64 amount READ amount)
Q_PROPERTY(QString address READ address)
private:
explicit Transfer(uint64_t _amount, const QString &_address, QObject *parent = 0): m_amount(_amount), m_address(_address), QObject(parent) {};
explicit Transfer(uint64_t _amount, const QString &_address, QObject *parent = 0): QObject(parent), m_amount(_amount), m_address(_address) {};
private:
friend class TransactionInfo;
qint64 m_amount;
quint64 m_amount;
QString m_address;
public:
qint64 amount(){ return m_amount; }
QString address(){ return m_address; };
quint64 amount() const { return m_amount; }
QString address() const { return m_address; }
};
// in order to wrap it to QVariant
Q_DECLARE_METATYPE(Transfer*)
#endif // TRANSACTIONINFO_H

View File

@ -95,6 +95,9 @@ QVariant TransactionHistoryModel::data(const QModelIndex &index, int role) const
case TransactionTimeRole:
result = tInfo->time();
break;
case TransactionDestinationsRole:
result = tInfo->destinations_formatted();
break;
}
return result;
@ -124,6 +127,7 @@ QHash<int, QByteArray> TransactionHistoryModel::roleNames() const
roleNames.insert(TransactionIsOutRole, "isOut");
roleNames.insert(TransactionDateRole, "date");
roleNames.insert(TransactionTimeRole, "time");
roleNames.insert(TransactionDestinationsRole, "destinations");
return roleNames;
}

View File

@ -33,7 +33,9 @@ public:
// extra roles for date and time (as UI wants date and time separately)
TransactionDateRole,
TransactionTimeRole,
TransactionAtomicAmountRole
TransactionAtomicAmountRole,
// only for outgoing
TransactionDestinationsRole
};
Q_ENUM(TransactionInfoRole)