<commit_before>// Copyright (c) 2011-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "overviewpage.h"
#include "ui_overviewpage.h"

#include "bitcoinunits.h"
#include "clientmodel.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "transactionfilterproxy.h"
#include "transactiontablemodel.h"
#include "walletmodel.h"

#include "omnicore/notifications.h"
#include "omnicore/omnicore.h"
#include "omnicore/sp.h"
#include "omnicore/tx.h"
#include "omnicore/pending.h"

#include "main.h"

#include <sstream>
#include <string>

#include <QAbstractItemDelegate>
#include <QBrush>
#include <QColor>
#include <QDateTime>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QListWidgetItem>
#include <QPainter>
#include <QRect>
#include <QString>
#include <QStyleOptionViewItem>
#include <QVariant>
#include <QVBoxLayout>
#include <QWidget>

using std::ostringstream;
using std::string;

using namespace mastercore;

#define DECORATION_SIZE 64
#define NUM_ITEMS 6 // 3 - number of recent transactions to display

class TxViewDelegate : public QAbstractItemDelegate
{
    Q_OBJECT
public:
    TxViewDelegate(): QAbstractItemDelegate(), unit(BitcoinUnits::BTC)
    {

    }

    inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
                      const QModelIndex &index ) const
    {
        painter->save();

        QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime();
        QString address = index.data(Qt::DisplayRole).toString();
        qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong();
        bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool();
        QVariant value = index.data(Qt::ForegroundRole);

        QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
        QRect mainRect = option.rect;
        QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE));
        int xspace = DECORATION_SIZE + 8;
        int ypad = 6;
        int halfheight = (mainRect.height() - 2*ypad)/2;
        QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight);
        QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight);

        // Rather ugly way to provide recent transaction display support - each time we paint a transaction we will check if
        // it's Omni and override the values if so.  This will not scale at all, but since we're only ever doing 6 txns via the occasional
        // repaint performance should be a non-issue and it'll provide the functionality short term while a better approach is devised.
        uint256 hash = 0;
        hash.SetHex(index.data(TransactionTableModel::TxIDRole).toString().toStdString());
        bool omniOverride = false;
        bool omniOutbound = true;
        bool omniSendToSelf = false;
        bool valid = false;
        std::string omniAmountStr;

        // check pending
        for(PendingMap::iterator it = my_pending.begin(); it != my_pending.end(); ++it) {
            uint256 txid = it->first;
            if (txid != hash) continue;
            omniOverride = true;
            // grab pending object & extract details
            CMPPending *p_pending = &(it->second);
            address = QString::fromStdString(p_pending->src);
            uint64_t omniPropertyId = p_pending->prop;
            int64_t omniAmount = p_pending->amount;
            valid = true;
            if (isPropertyDivisible(omniPropertyId)) {
                omniAmountStr = FormatDivisibleShortMP(omniAmount) + getTokenLabel(omniPropertyId);
            } else {
                omniAmountStr = FormatIndivisibleMP(omniAmount) + getTokenLabel(omniPropertyId);
            }
            break;
        }

        // check wallet
        if (p_txlistdb->exists(hash)) {
            omniOverride = true;
            amount = 0;
            CTransaction wtx;
            uint256 blockHash = 0;
            if (GetTransaction(hash, wtx, blockHash, true)) {
                if ((0 != blockHash) || (NULL != GetBlockIndex(blockHash))) {
                    CBlockIndex* pBlockIndex = GetBlockIndex(blockHash);
                    if (NULL != pBlockIndex) {
                        int blockHeight = pBlockIndex->nHeight;
                        CMPTransaction mp_obj;
                        int parseRC = ParseTransaction(wtx, blockHeight, 0, mp_obj);
                        if (0 < parseRC) { //positive RC means DEx payment
                            std::string tmpBuyer, tmpSeller;<commit_msg>UI: tidy up overview changes<commit_after>// Copyright (c) 2011-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "overviewpage.h"
#include "ui_overviewpage.h"

#include "bitcoinunits.h"
#include "clientmodel.h"
#include "guiconstants.h"
#include "guiutil.h"
#include "optionsmodel.h"
#include "transactionfilterproxy.h"
#include "transactiontablemodel.h"
#include "walletmodel.h"

#include "omnicore/notifications.h"
#include "omnicore/omnicore.h"
#include "omnicore/sp.h"
#include "omnicore/tx.h"
#include "omnicore/pending.h"

#include "main.h"

#include <sstream>
#include <string>

#include <QAbstractItemDelegate>
#include <QBrush>
#include <QColor>
#include <QDateTime>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QListWidgetItem>
#include <QPainter>
#include <QRect>
#include <QString>
#include <QStyleOptionViewItem>
#include <QVariant>
#include <QVBoxLayout>
#include <QWidget>

using std::ostringstream;
using std::string;

using namespace mastercore;

#define DECORATION_SIZE 64
#define NUM_ITEMS 6 // 3 - number of recent transactions to display

class TxViewDelegate : public QAbstractItemDelegate
{
    Q_OBJECT
public:
    TxViewDelegate(): QAbstractItemDelegate(), unit(BitcoinUnits::BTC)
    {

    }

    inline void paint(QPainter *painter, const QStyleOptionViewItem &option,
                      const QModelIndex &index ) const
    {
        painter->save();

        QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime();
        QString address = index.data(Qt::DisplayRole).toString();
        qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong();
        bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool();
        QVariant value = index.data(Qt::ForegroundRole);

        QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
        QRect mainRect = option.rect;
        QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE));
        int xspace = DECORATION_SIZE + 8;
        int ypad = 6;
        int halfheight = (mainRect.height() - 2*ypad)/2;
        QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight);
        QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight);

        // Rather ugly way to provide recent transaction display support - each time we paint a transaction we will check if
        // it's Omni and override the values if so.  This will not scale at all, but since we're only ever doing 6 txns via the occasional
        // repaint performance should be a non-issue and it'll provide the functionality short term while a better approach is devised.
        uint256 hash = 0;
        hash.SetHex(index.data(TransactionTableModel::TxIDRole).toString().toStdString());
        bool omniOverride = false, omniSendToSelf = false, valid = false, omniOutbound = true;
        std::string omniAmountStr;

        // check pending
        PendingMap::iterator it = my_pending.find(hash);
        if (it != my_pending.end()) {
            omniOverride = true;
            valid = true; // assume all outbound pending are valid prior to confirmation
            CMPPending *p_pending = &(it->second);
            address = QString::fromStdString(p_pending->src);
            if (isPropertyDivisible(p_pending->prop)) {
                omniAmountStr = FormatDivisibleShortMP(p_pending->amount) + getTokenLabel(p_pending->prop);
            } else {
                omniAmountStr = FormatIndivisibleMP(p_pending->amount) + getTokenLabel(p_pending->prop);
            }
        }

        // check database
        if (p_txlistdb->exists(hash)) {
            omniOverride = true;
            amount = 0;
            CTransaction wtx;
            uint256 blockHash = 0;
            if (GetTransaction(hash, wtx, blockHash, true)) {
                if ((0 != blockHash) || (NULL != GetBlockIndex(blockHash))) {
                    CBlockIndex* pBlockIndex = GetBlockIndex(blockHash);
                    if (NULL != pBlockIndex) {
                        int blockHeight = pBlockIndex->nHeight;
                        CMPTransaction mp_obj;
                        int parseRC = ParseTransaction(wtx, blockHeight, 0, mp_obj);
                        if (0 < parseRC) { //positive RC means DEx payment
                            std::string tmpBuyer, tmpSeller;
{'fraction_non_alphanumeric': 0.10674518201284797, 'fraction_numerical': 0.007815845824411135, 'mean_word_length': 2.896954526491448, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3676022', 'n_tokens_mistral': 2792, 'n_tokens_neox': 2678, 'n_words': 698}