Skip to content

Commit

Permalink
dashboard tx list included in a good degree
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Aug 28, 2019
1 parent 498d890 commit 98d84f8
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 15 deletions.
15 changes: 14 additions & 1 deletion src/qt/bitcoinunits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <QSettings>
#include <QStringList>

#include <iostream>

BitcoinUnits::BitcoinUnits(QObject* parent) : QAbstractListModel(parent),
unitlist(availableUnits())
{
Expand Down Expand Up @@ -164,7 +166,18 @@ QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, Separator
if (num_decimals <= 0)
return quotient_str;

return quotient_str + QString(".") + remainder_str;
// Clean remainder
QString cleanRemainder = remainder_str;
for(int i = (remainder_str.length() -1); i > 1; i--)
{
if (remainder_str.at(i) == "0") {
cleanRemainder = cleanRemainder.left(cleanRemainder.lastIndexOf("0"));
}else
break;
}


return quotient_str + QString(".") + cleanRemainder;
}


Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/addresseswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ContactsHolder : public FurListRow<QWidget*>
return new AddressLabelRow(isLightTheme, false);
}

void init(QWidget* holder, bool isHovered, bool isSelected) const override{
void init(QWidget* holder,const QModelIndex &index, bool isHovered, bool isSelected) const override{
static_cast<AddressLabelRow*>(holder)->updateState(isLightTheme, isHovered, isSelected);
}

Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/contactsdropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ContViewHolder : public FurListRow<QWidget*>
return new ContactDropdownRow(true, false);
}

void init(QWidget* holder, bool isHovered, bool isSelected) const override{
void init(QWidget* holder,const QModelIndex &index, bool isHovered, bool isSelected) const override{
static_cast<ContactDropdownRow*>(holder)->update(isLightTheme, isHovered, isSelected);
}

Expand Down
30 changes: 23 additions & 7 deletions src/qt/pivx/dashboardwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
#include "qt/pivx/txdetaildialog.h"
#include "qt/pivx/txrow.h"
#include "qt/pivx/qtutils.h"
#include "qt/pivx/txviewholder.h"
#include "walletmodel.h"
#include "optionsmodel.h"
#include <QFile>
#include <QAbstractItemDelegate>
#include <QPainter>
#include <QSettings>
#include <QModelIndex>
#include <QObject>
#include <QPaintEngine>

#include "QGraphicsDropShadowEffect"
#include <QGraphicsDropShadowEffect>
#include <iostream>

/*
Expand All @@ -39,11 +38,12 @@ DashboardWidget::DashboardWidget(PIVXGUI* _window, QWidget *parent) :
{
ui->setupUi(this);

txHolder = new TxViewHolder(isLightTheme());
txViewDelegate = new FurAbstractListItemDelegate(
DECORATION_SIZE,
new TxViewHolder(isLightTheme()),
txHolder,
this
);
);

// Load css.
this->setStyleSheet(parent->styleSheet());
Expand Down Expand Up @@ -250,8 +250,24 @@ void DashboardWidget::changeChartColors(){
}

void DashboardWidget::setWalletModel(WalletModel* model){
txModel = model->getTransactionTableModel();
ui->listTransactions->setModel(this->txModel);
walletModel = model;
if (model && model->getOptionsModel()) {
txModel = model->getTransactionTableModel();
ui->listTransactions->setModel(this->txModel);
ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress);
}
// update the display unit, to not use the default ("PIV")
updateDisplayUnit();
}

void DashboardWidget::updateDisplayUnit()
{
if (walletModel && walletModel->getOptionsModel()) {
nDisplayUnit = walletModel->getOptionsModel()->getDisplayUnit();

txHolder->setDisplayUnit(nDisplayUnit);
ui->listTransactions->update();
}
}

void DashboardWidget::onSortTxPressed(){
Expand Down
6 changes: 5 additions & 1 deletion src/qt/pivx/dashboardwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "qt/pivx/furabstractlistitemdelegate.h"
#include "qt/pivx/furlistrow.h"
#include "transactiontablemodel.h"
#include "qt/pivx/txrow.h"
#include "qt/pivx/txviewholder.h"

#include <QWidget>
#include <QLineEdit>
Expand Down Expand Up @@ -60,13 +60,17 @@ private slots:
void changeTheme(bool isLightTheme, QString &theme);
void changeChartColors();
void onSortTxPressed();
void updateDisplayUnit();
private:
Ui::DashboardWidget *ui;
PIVXGUI* window;
// Painter delegate
FurAbstractListItemDelegate* txViewDelegate;
TxViewHolder* txHolder;
// Model
WalletModel* walletModel;
TransactionTableModel* txModel;
int nDisplayUnit = -1;

/*
// Chart
Expand Down
1 change: 1 addition & 0 deletions src/qt/pivx/furabstractlistitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void FurAbstractListItemDelegate::paint(QPainter *painter, const QStyleOptionVie

painter->translate(option.rect.topLeft());
QWidget *row = this->row->createHolder(index.row());
this->row->init(row, index, isStateHovered, isStateSelected);
row->setStyleSheet(qobject_cast<QWidget*>(parent())->styleSheet());
row->setAttribute(Qt::WA_DontShowOnScreen, true);
row->setGeometry(option.rect);
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/furlistrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FurListRow{
return nullptr;
}

virtual inline void init(T, bool isHovered, bool isSelected) const{
virtual inline void init(T, const QModelIndex&, bool isHovered, bool isSelected) const{

}

Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/receivewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AddressHolder : public FurListRow<QWidget*>
return new MyAddressRow();
}

void init(QWidget* holder, bool isHovered, bool isSelected) const override{
void init(QWidget* holder,const QModelIndex &index, bool isHovered, bool isSelected) const override{
//static_cast<MyAddressRow*>(holder)->update(isLightTheme, isHovered, isSelected);
}

Expand Down
17 changes: 17 additions & 0 deletions src/qt/pivx/txrow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "qt/pivx/txrow.h"
#include "qt/pivx/forms/ui_txrow.h"

#include "guiutil.h"


TxRow::TxRow(bool isLightTheme, QWidget *parent) :
QWidget(parent),
ui(new Ui::TxRow)
Expand All @@ -10,13 +13,27 @@ TxRow::TxRow(bool isLightTheme, QWidget *parent) :
ui->lblAddress->setProperty("cssClass", "text-list-body1");
ui->lblDate->setProperty("cssClass", "text-list-caption");

updateStatus(isLightTheme, false, false);
}

void TxRow::updateStatus(bool isLightTheme, bool isHover, bool isSelected){
if(isLightTheme)
ui->lblDivisory->setStyleSheet("background-color:#bababa");
else
ui->lblDivisory->setStyleSheet("background-color:#40ffffff");
}

void TxRow::setDate(QDateTime date){
ui->lblDate->setText(GUIUtil::dateTimeStr(date));
}

void TxRow::setLabel(QString str){
ui->lblAddress->setText(str);
}

void TxRow::setAmount(QString str){
ui->lblAmount->setText(str);
}

TxRow::~TxRow()
{
Expand Down
7 changes: 7 additions & 0 deletions src/qt/pivx/txrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define TXROW_H

#include <QWidget>
#include <QDateTime>

namespace Ui {
class TxRow;
Expand All @@ -15,12 +16,18 @@ class TxRow : public QWidget
explicit TxRow(bool isLightTheme, QWidget *parent = nullptr);
~TxRow();

void updateStatus(bool isLightTheme, bool isHover, bool isSelected);

void sendRow(bool isLightTheme);
void receiveRow(bool isLightTheme);
void stakeRow(bool isLightTheme);
void zPIVStakeRow(bool isLightTheme);
void mintRow(bool isLightTheme);

void setDate(QDateTime);
void setLabel(QString);
void setAmount(QString);

private:
Ui::TxRow *ui;
};
Expand Down
23 changes: 23 additions & 0 deletions src/qt/pivx/txviewholder.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "qt/pivx/txviewholder.h"
#include "qt/pivx/txrow.h"

#include "transactiontablemodel.h"
#include "bitcoingui.h"
#include <QModelIndex>

QWidget* TxViewHolder::createHolder(int pos){
TxRow *row = new TxRow(isLightTheme);
// TODO: move this to other class
Expand All @@ -17,6 +21,25 @@ QWidget* TxViewHolder::createHolder(int pos){
}
return row;
}

void TxViewHolder::init(QWidget* holder,const QModelIndex &index, bool isHovered, bool isSelected) const{
TxRow *txRow = static_cast<TxRow*>(holder);
txRow->updateStatus(isLightTheme, isHovered, isSelected);

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

QModelIndex indexType = index.siblingAtColumn(TransactionTableModel::Type);
QString label = indexType.data(Qt::DisplayRole).toString() + " " + address;
QString amountText = BitcoinUnits::formatWithUnit(nDisplayUnit, amount, true, BitcoinUnits::separatorAlways);

txRow->setDate(date);
txRow->setLabel(label);
txRow->setAmount(amountText);
}

QColor TxViewHolder::rectColor(bool isHovered, bool isSelected){
// TODO: Move this to other class
if(isLightTheme){
Expand Down
11 changes: 10 additions & 1 deletion src/qt/pivx/txviewholder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define TXVIEWHOLDER_H

#include "qt/pivx/furlistrow.h"

#include "bitcoinunits.h"

class TxViewHolder : public FurListRow<QWidget*>
{
Expand All @@ -13,11 +13,20 @@ class TxViewHolder : public FurListRow<QWidget*>

QWidget* createHolder(int pos) override;

void init(QWidget* holder,const QModelIndex &index, bool isHovered, bool isSelected) const override;

QColor rectColor(bool isHovered, bool isSelected) override;

~TxViewHolder() override{};

bool isLightTheme;

void setDisplayUnit(int displayUnit){
nDisplayUnit = displayUnit;
}

private:
int nDisplayUnit;
};

#endif // TXVIEWHOLDER_H
2 changes: 1 addition & 1 deletion src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ QString TransactionTableModel::lookupAddress(const std::string& address, bool to
description += label;
}
if (label.isEmpty() || tooltip) {
description += QString(" (") + QString::fromStdString(address) + QString(")");
description += QString::fromStdString(address);
}
return description;
}
Expand Down

0 comments on commit 98d84f8

Please sign in to comment.