TransactionHistory: firstDateTime and lastDateTime properties

This commit is contained in:
Ilya Kitaev 2016-10-08 01:22:45 +03:00
parent 99271828ae
commit e3cea8582f
2 changed files with 42 additions and 2 deletions

View file

@ -28,13 +28,33 @@ QList<TransactionInfo *> TransactionHistory::getAll() const
emit refreshStarted(); emit refreshStarted();
qDeleteAll(m_tinfo); qDeleteAll(m_tinfo);
m_tinfo.clear(); m_tinfo.clear();
QDateTime firstDateTime = QDateTime::currentDateTime();
QDateTime lastDateTime = QDateTime(QDate(1970, 1, 1));
TransactionHistory * parent = const_cast<TransactionHistory*>(this); TransactionHistory * parent = const_cast<TransactionHistory*>(this);
for (const auto i : m_pimpl->getAll()) { for (const auto i : m_pimpl->getAll()) {
TransactionInfo * ti = new TransactionInfo(i, parent); TransactionInfo * ti = new TransactionInfo(i, parent);
qDebug() << ti->hash();
m_tinfo.append(ti); m_tinfo.append(ti);
// looking for transactions timestamp scope
if (ti->timestamp() >= lastDateTime) {
lastDateTime = ti->timestamp();
}
if (ti->timestamp() <= firstDateTime) {
firstDateTime = ti->timestamp();
}
} }
emit refreshFinished(); emit refreshFinished();
if (m_firstDateTime != firstDateTime) {
m_firstDateTime = firstDateTime;
emit firstDateTimeChanged();
}
if (m_lastDateTime != lastDateTime) {
m_lastDateTime = lastDateTime;
emit lastDateTimeChanged();
}
return m_tinfo; return m_tinfo;
} }
@ -51,9 +71,20 @@ quint64 TransactionHistory::count() const
return m_tinfo.count(); return m_tinfo.count();
} }
QDateTime TransactionHistory::firstDateTime() const
{
return m_firstDateTime;
}
QDateTime TransactionHistory::lastDateTime() const
{
return m_lastDateTime;
}
TransactionHistory::TransactionHistory(Bitmonero::TransactionHistory *pimpl, QObject *parent) TransactionHistory::TransactionHistory(Bitmonero::TransactionHistory *pimpl, QObject *parent)
: QObject(parent), m_pimpl(pimpl) : QObject(parent), m_pimpl(pimpl)
{ {
// this->refresh(); m_firstDateTime = QDateTime(QDate(1970, 1, 1));
m_lastDateTime = QDateTime::currentDateTime();
} }

View file

@ -3,6 +3,7 @@
#include <QObject> #include <QObject>
#include <QList> #include <QList>
#include <QDateTime>
namespace Bitmonero { namespace Bitmonero {
class TransactionHistory; class TransactionHistory;
@ -14,6 +15,8 @@ class TransactionHistory : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int count READ count) Q_PROPERTY(int count READ count)
Q_PROPERTY(QDateTime firstDateTime READ firstDateTime NOTIFY firstDateTimeChanged)
Q_PROPERTY(QDateTime lastDateTime READ lastDateTime NOTIFY lastDateTimeChanged)
public: public:
Q_INVOKABLE TransactionInfo *transaction(int index); Q_INVOKABLE TransactionInfo *transaction(int index);
@ -21,10 +24,14 @@ public:
Q_INVOKABLE QList<TransactionInfo*> getAll() const; Q_INVOKABLE QList<TransactionInfo*> getAll() const;
Q_INVOKABLE void refresh(); Q_INVOKABLE void refresh();
quint64 count() const; quint64 count() const;
QDateTime firstDateTime() const;
QDateTime lastDateTime() const;
signals: signals:
void refreshStarted() const; void refreshStarted() const;
void refreshFinished() const; void refreshFinished() const;
void firstDateTimeChanged() const;
void lastDateTimeChanged() const;
public slots: public slots:
@ -37,6 +44,8 @@ private:
Bitmonero::TransactionHistory * m_pimpl; Bitmonero::TransactionHistory * m_pimpl;
mutable QList<TransactionInfo*> m_tinfo; mutable QList<TransactionInfo*> m_tinfo;
mutable QDateTime m_firstDateTime;
mutable QDateTime m_lastDateTime;
}; };