PIVX Core  5.6.99
P2P Digital Currency
txviewholder.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "txviewholder.h"
6 
7 #include "qtutils.h"
9 
10 #include <QModelIndex>
11 
12 #define ADDRESS_SIZE 12
13 
14 QWidget* TxViewHolder::createHolder(int pos)
15 {
16  if (!txRow) txRow = new TxRow();
18  return txRow;
19 }
20 
21 void TxViewHolder::init(QWidget* holder, const QModelIndex &index, bool isHovered, bool isSelected) const
22 {
23  QModelIndex rIndex = (filter) ? filter->mapToSource(index) : index;
24  int type = rIndex.data(TransactionTableModel::TypeRole).toInt();
25 
26  TxRow *txRow = static_cast<TxRow*>(holder);
27  txRow->updateStatus(isLightTheme, isHovered, isSelected);
28 
29  QDateTime date = rIndex.data(TransactionTableModel::DateRole).toDateTime();
30  QModelIndex indexType = rIndex.sibling(rIndex.row(),TransactionTableModel::Type);
31  QString label = indexType.data(Qt::DisplayRole).toString();
32 
34  txRow->showHideSecondAmount(hasDoubleAmount);
35 
36  if (type != TransactionRecord::ZerocoinMint &&
39  type != TransactionRecord::Other) {
40 
41  QString address = rIndex.data(Qt::DisplayRole).toString();
42  if (!address.isEmpty()) {
43  if (type == TransactionRecord::SendToNobody) {
44  // OP_RETURN record with a valid utf-8 string to show
45  label.clear();
46  label += address;
47  } else {
48  // Regular addresses
49  if (address.length() > 20) {
50  address = address.left(ADDRESS_SIZE) + "..." + address.right(ADDRESS_SIZE);
51  }
52  label += " " + address;
53  }
54  }
55  } else if (type == TransactionRecord::Other) {
56  label += rIndex.data(Qt::DisplayRole).toString();
57  }
58 
59  qint64 amountTop = rIndex.data(TransactionTableModel::AmountRole).toLongLong();
60  int status = rIndex.data(TransactionTableModel::StatusRole).toInt();
61  bool isUnconfirmed = (status == TransactionStatus::Unconfirmed) || (status == TransactionStatus::Immature)
63 
64  txRow->setDate(date);
65  txRow->setLabel(label);
66  QString amountText = BitcoinUnits::formatWithUnit(nDisplayUnit, amountTop, true, BitcoinUnits::separatorAlways);
67  if (hasDoubleAmount) {
68  qint64 amountBottom = rIndex.data(TransactionTableModel::ShieldedCreditAmountRole).toLongLong();
69  QString amountBottomText = BitcoinUnits::formatWithUnit(nDisplayUnit, amountBottom, true, BitcoinUnits::separatorAlways);
70  txRow->setAmount(amountBottomText + (type == TransactionRecord::SendToSelfShieldedAddress ? " shielded" : ""),
71  amountText + " fee");
72  } else {
73  txRow->setAmount(amountText, "");
74  }
75  txRow->setType(isLightTheme, type, !isUnconfirmed);
76 }
77 
78 QColor TxViewHolder::rectColor(bool isHovered, bool isSelected)
79 {
80  return getRowColor(isLightTheme, isHovered, isSelected);
81 }
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
@ Unconfirmed
Not yet mined into a block.
@ Immature
Generated (mined) transactions.
@ NotAccepted
Mined but not accepted.
@ Conflicted
Conflicts with other transaction or mempool.
@ TypeRole
Type of transaction.
@ StatusRole
Transaction status (TransactionRecord::Status)
@ DateRole
Date and time this transaction was created.
@ ShieldedCreditAmountRole
Credit amount of transaction.
@ AmountRole
Net amount of transaction.
Definition: txrow.h:17
void showHideSecondAmount(bool show)
Definition: txrow.cpp:25
void init(bool isLightTheme)
Definition: txrow.cpp:19
void setDate(QDateTime)
Definition: txrow.cpp:50
void updateStatus(bool isLightTheme, bool isHover, bool isSelected)
Definition: txrow.cpp:42
void setLabel(QString)
Definition: txrow.cpp:55
void setAmount(QString top, QString bottom)
Definition: txrow.cpp:60
void setType(bool isLightTheme, int type, bool isConfirmed)
Definition: txrow.cpp:66
bool isLightTheme
Definition: txviewholder.h:30
TxRow * txRow
Definition: txviewholder.h:45
TransactionFilterProxy * filter
Definition: txviewholder.h:44
void init(QWidget *holder, const QModelIndex &index, bool isHovered, bool isSelected) const override
QColor rectColor(bool isHovered, bool isSelected) override
QWidget * createHolder(int pos) override
QColor getRowColor(bool isLightTheme, bool isHovered, bool isSelected)
Definition: qtutils.cpp:233
#define ADDRESS_SIZE