// Copyright (c) 2011-2015 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include "SortedTransactionsModel.h" #include "TransactionsModel.h" namespace WalletGui { SortedTransactionsModel& SortedTransactionsModel::instance() { static SortedTransactionsModel inst; return inst; } SortedTransactionsModel::SortedTransactionsModel() : QSortFilterProxyModel() { setSourceModel(&TransactionsModel::instance()); setDynamicSortFilter(true); sort(TransactionsModel::COLUMN_DATE, Qt::DescendingOrder); } SortedTransactionsModel::~SortedTransactionsModel() { } bool SortedTransactionsModel::lessThan(const QModelIndex& _left, const QModelIndex& _right) const { QDateTime leftDate = _left.data(TransactionsModel::ROLE_DATE).toDateTime(); QDateTime rightDate = _right.data(TransactionsModel::ROLE_DATE).toDateTime(); if((rightDate.isNull() || !rightDate.isValid()) && (leftDate.isNull() || !leftDate.isValid())) { return _left.row() < _right.row(); } if(leftDate.isNull() || !leftDate.isValid()) { return false; } if(rightDate.isNull() || !rightDate.isValid()) { return true; } return leftDate < rightDate; } }