2015-12-13 17:58:29 +01:00
|
|
|
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-05 18:03:05 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#ifndef BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
|
|
|
|
#define BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
|
2013-11-05 18:03:05 +01:00
|
|
|
|
2013-12-10 11:57:57 +01:00
|
|
|
#include "walletmodel.h"
|
|
|
|
|
2013-11-05 18:03:05 +01:00
|
|
|
#include <QAbstractTableModel>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
|
|
class CWallet;
|
|
|
|
|
2014-01-14 05:05:43 +01:00
|
|
|
class RecentRequestEntry
|
2013-11-05 18:03:05 +01:00
|
|
|
{
|
2014-01-14 05:05:43 +01:00
|
|
|
public:
|
|
|
|
RecentRequestEntry() : nVersion(RecentRequestEntry::CURRENT_VERSION), id(0) { }
|
|
|
|
|
2014-01-22 09:46:15 +01:00
|
|
|
static const int CURRENT_VERSION = 1;
|
2014-01-14 05:05:43 +01:00
|
|
|
int nVersion;
|
|
|
|
int64_t id;
|
2013-11-05 18:03:05 +01:00
|
|
|
QDateTime date;
|
|
|
|
SendCoinsRecipient recipient;
|
2014-01-14 05:05:43 +01:00
|
|
|
|
2014-09-02 09:58:09 +02:00
|
|
|
ADD_SERIALIZE_METHODS;
|
2014-01-14 05:05:43 +01:00
|
|
|
|
2014-08-20 22:44:38 +02:00
|
|
|
template <typename Stream, typename Operation>
|
2014-08-21 00:49:32 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
2014-08-20 22:44:38 +02:00
|
|
|
unsigned int nDate = date.toTime_t();
|
2014-01-14 05:05:43 +01:00
|
|
|
|
2014-09-01 21:36:46 +02:00
|
|
|
READWRITE(this->nVersion);
|
|
|
|
nVersion = this->nVersion;
|
2014-08-20 22:44:38 +02:00
|
|
|
READWRITE(id);
|
2014-01-14 05:05:43 +01:00
|
|
|
READWRITE(nDate);
|
2014-08-20 22:44:38 +02:00
|
|
|
READWRITE(recipient);
|
2014-01-14 05:05:43 +01:00
|
|
|
|
2014-09-01 21:36:46 +02:00
|
|
|
if (ser_action.ForRead())
|
2014-08-21 00:49:32 +02:00
|
|
|
date = QDateTime::fromTime_t(nDate);
|
overhaul serialization code
The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:
template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
size_t nSerSize = 0;
/* CODE */
return nSerSize;
}
In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();
The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.
2014-08-20 08:42:31 +02:00
|
|
|
}
|
2013-11-05 18:03:05 +01:00
|
|
|
};
|
|
|
|
|
2014-01-18 00:01:14 +01:00
|
|
|
class RecentRequestEntryLessThan
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RecentRequestEntryLessThan(int nColumn, Qt::SortOrder fOrder):
|
|
|
|
column(nColumn), order(fOrder) {}
|
2014-01-22 09:46:15 +01:00
|
|
|
bool operator()(RecentRequestEntry &left, RecentRequestEntry &right) const;
|
2014-01-18 00:01:14 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
int column;
|
|
|
|
Qt::SortOrder order;
|
|
|
|
};
|
|
|
|
|
2014-01-28 10:48:41 +01:00
|
|
|
/** Model for list of recently generated payment requests / bitcoin: URIs.
|
2013-11-05 18:03:05 +01:00
|
|
|
* Part of wallet model.
|
|
|
|
*/
|
|
|
|
class RecentRequestsTableModel: public QAbstractTableModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2013-12-10 11:57:57 +01:00
|
|
|
explicit RecentRequestsTableModel(CWallet *wallet, WalletModel *parent);
|
2013-11-05 18:03:05 +01:00
|
|
|
~RecentRequestsTableModel();
|
|
|
|
|
|
|
|
enum ColumnIndex {
|
|
|
|
Date = 0,
|
|
|
|
Label = 1,
|
|
|
|
Message = 2,
|
2014-01-18 00:01:14 +01:00
|
|
|
Amount = 3,
|
|
|
|
NUMBER_OF_COLUMNS
|
2013-11-05 18:03:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @name Methods overridden from QAbstractTableModel
|
|
|
|
@{*/
|
|
|
|
int rowCount(const QModelIndex &parent) const;
|
|
|
|
int columnCount(const QModelIndex &parent) const;
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent) const;
|
|
|
|
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
/*@}*/
|
|
|
|
|
|
|
|
const RecentRequestEntry &entry(int row) const { return list[row]; }
|
|
|
|
void addNewRequest(const SendCoinsRecipient &recipient);
|
2014-01-14 05:05:43 +01:00
|
|
|
void addNewRequest(const std::string &recipient);
|
|
|
|
void addNewRequest(RecentRequestEntry &recipient);
|
2013-11-05 18:03:05 +01:00
|
|
|
|
2015-07-14 13:59:05 +02:00
|
|
|
public Q_SLOTS:
|
2014-01-18 00:01:14 +01:00
|
|
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
2014-06-07 08:20:22 +02:00
|
|
|
void updateDisplayUnit();
|
2014-01-18 00:01:14 +01:00
|
|
|
|
2013-11-05 18:03:05 +01:00
|
|
|
private:
|
|
|
|
WalletModel *walletModel;
|
|
|
|
QStringList columns;
|
|
|
|
QList<RecentRequestEntry> list;
|
2014-01-14 05:05:43 +01:00
|
|
|
int64_t nReceiveRequestsMaxId;
|
2014-06-07 08:20:22 +02:00
|
|
|
|
|
|
|
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */
|
|
|
|
void updateAmountColumnTitle();
|
|
|
|
/** Gets title for amount column including current display unit if optionsModel reference available. */
|
|
|
|
QString getAmountTitle();
|
2013-11-05 18:03:05 +01:00
|
|
|
};
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#endif // BITCOIN_QT_RECENTREQUESTSTABLEMODEL_H
|