/
dashboardwidget.h
executable file
·188 lines (149 loc) · 4.46 KB
/
dashboardwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Copyright (c) 2019 The PIVX developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASHBOARDWIDGET_H
#define DASHBOARDWIDGET_H
#include "qt/transcendence/pwidget.h"
#include "qt/transcendence/furabstractlistitemdelegate.h"
#include "qt/transcendence/furlistrow.h"
#include "transactiontablemodel.h"
#include "qt/transcendence/txviewholder.h"
#include "transactionfilterproxy.h"
#include <cstdlib>
#include <QWidget>
#include <QLineEdit>
#include <QMap>
#if defined(HAVE_CONFIG_H)
#include "config/transcendence-config.h" /* for USE_QTCHARTS */
#endif
#ifdef USE_QTCHARTS
#include <QtCharts/QChartView>
#include <QtCharts/QBarSeries>
#include <QtCharts/QBarCategoryAxis>
#include <QtCharts/QBarSet>
#include <QtCharts/QChart>
#include <QtCharts/QValueAxis>
QT_CHARTS_USE_NAMESPACE
using namespace QtCharts;
#endif
class TELOSGUI;
class WalletModel;
namespace Ui {
class DashboardWidget;
}
class SortEdit : public QLineEdit{
Q_OBJECT
public:
explicit SortEdit(QWidget* parent = nullptr) : QLineEdit(parent){}
inline void mousePressEvent(QMouseEvent *) override{
emit Mouse_Pressed();
}
~SortEdit() override{}
signals:
void Mouse_Pressed();
};
enum SortTx {
DATE_ASC = 0,
DATE_DESC = 1,
AMOUNT_ASC = 2,
AMOUNT_DESC = 3
};
enum ChartShowType {
ALL,
YEAR,
MONTH,
DAY
};
class ChartData {
public:
ChartData() {}
QMap<int, std::pair<qint64, qint64>> amountsByCache;
qreal maxValue = 0;
qint64 totalPiv = 0;
qint64 totalZTelos = 0;
QList<qreal> valuesPiv;
QList<qreal> valueszTelos;
QStringList xLabels;
};
QT_BEGIN_NAMESPACE
class QModelIndex;
QT_END_NAMESPACE
class DashboardWidget : public PWidget
{
Q_OBJECT
public:
explicit DashboardWidget(TELOSGUI* _window);
~DashboardWidget();
void loadWalletModel() override;
void loadChart();
void run(int type) override;
void onError(QString error, int type) override;
public slots:
void walletSynced(bool isSync);
/**
* Show incoming transaction notification for new transactions.
* The new items are those between start and end inclusive, under the given parent item.
*/
void processNewTransaction(const QModelIndex& parent, int start, int /*end*/);
signals:
/** Notify that a new transaction appeared */
void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address);
private slots:
void handleTransactionClicked(const QModelIndex &index);
void changeTheme(bool isLightTheme, QString &theme) override;
void onSortChanged(const QString&);
void onSortTypeChanged(const QString& value);
void updateDisplayUnit();
void showList();
void onTxArrived(const QString& hash);
#ifdef USE_QTCHARTS
void windowResizeEvent(QResizeEvent *event);
void changeChartColors();
void onChartYearChanged(const QString&);
void onChartMonthChanged(const QString&);
void onChartArrowClicked();
#endif
private:
Ui::DashboardWidget *ui;
FurAbstractListItemDelegate* txViewDelegate;
TransactionFilterProxy* filter;
TxViewHolder* txHolder;
TransactionTableModel* txModel;
int nDisplayUnit = -1;
bool isSync = false;
#ifdef USE_QTCHARTS
int64_t lastRefreshTime = 0;
std::atomic<bool> isLoading;
// Chart
TransactionFilterProxy* stakesFilter = nullptr;
bool isChartInitialized = false;
QChartView *chartView = nullptr;
QBarSeries *series = nullptr;
QBarSet *set0 = nullptr;
QBarSet *set1 = nullptr;
QBarCategoryAxis *axisX = nullptr;
QValueAxis *axisY = nullptr;
QChart *chart = nullptr;
bool isChartMin = false;
ChartShowType chartShow = YEAR;
int yearFilter = 0;
int monthFilter = 0;
int dayStart = 1;
bool hasZTelosStakes = false;
ChartData* chartData = nullptr;
void initChart();
void showHideEmptyChart(bool show, bool loading, bool forceView = false);
bool refreshChart();
void tryChartRefresh();
void updateStakeFilter();
QMap<int, std::pair<qint64, qint64>> getAmountBy();
void loadChartData(bool withMonthNames);
void updateAxisX(const QStringList *arg = nullptr);
void setChartShow(ChartShowType type);
std::pair<int, int> getChartRange(QMap<int, std::pair<qint64, qint64>> amountsBy);
bool hasStakes();
private slots:
void onChartRefreshed();
#endif
};
#endif // DASHBOARDWIDGET_H