PIVX Core  5.6.99
P2P Digital Currency
dashboardwidget.h
Go to the documentation of this file.
1 // Copyright (c) 2019-2021 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 #ifndef PIVX_QT_DASHBOARDWIDGET_H
6 #define PIVX_QT_DASHBOARDWIDGET_H
7 
9 #include "furlistrow.h"
10 #include "pwidget.h"
11 #include "transactionfilterproxy.h"
12 #include "transactiontablemodel.h"
13 #include "txviewholder.h"
14 
15 #include <atomic>
16 #include <cstdlib>
17 #include <QWidget>
18 #include <QLineEdit>
19 #include <QMap>
20 
21 #if defined(HAVE_CONFIG_H)
22 #include "config/pivx-config.h" /* for USE_QTCHARTS */
23 #endif
24 
25 #ifdef USE_QTCHARTS
26 
27 #include <QtCharts/QChartView>
28 #include <QtCharts/QBarSeries>
29 #include <QtCharts/QBarCategoryAxis>
30 #include <QtCharts/QBarSet>
31 #include <QtCharts/QChart>
32 #include <QtCharts/QValueAxis>
33 
34 QT_CHARTS_USE_NAMESPACE
35 
36 using namespace QtCharts;
37 
38 #endif
39 
40 class PIVXGUI;
41 class WalletModel;
42 
43 namespace Ui {
44 class DashboardWidget;
45 }
46 
47 class SortEdit : public QLineEdit{
48  Q_OBJECT
49 public:
50  explicit SortEdit(QWidget* parent = nullptr) : QLineEdit(parent){}
51 
52  inline void mousePressEvent(QMouseEvent *) override{
53  Q_EMIT Mouse_Pressed();
54  }
55 
56  ~SortEdit() override{}
57 
58 Q_SIGNALS:
59  void Mouse_Pressed();
60 
61 };
62 
63 enum SortTx {
64  DATE_DESC = 0,
65  DATE_ASC = 1,
67  AMOUNT_ASC = 3
68 };
69 
71  ALL,
74  DAY
75 };
76 
77 class ChartData {
78 public:
79  ChartData() {}
80 
81  QMap<int, std::pair<qint64, qint64>> amountsByCache;
82  qreal maxValue = 0;
83  qint64 totalPiv = 0;
84  qint64 totalMN = 0;
85  QList<qreal> valuesPiv;
86  QList<qreal> valuesMN;
87  QStringList xLabels;
88 };
89 
90 QT_BEGIN_NAMESPACE
91 class QModelIndex;
92 QT_END_NAMESPACE
93 
94 class DashboardWidget : public PWidget
95 {
96  Q_OBJECT
97 
98 public:
99  explicit DashboardWidget(PIVXGUI* _window);
100  ~DashboardWidget();
101 
102  void loadWalletModel() override;
103  void loadChart();
104 
105  void run(int type) override;
106  void onError(QString error, int type) override;
107 
108 public Q_SLOTS:
109  void walletSynced(bool isSync);
114  void processNewTransaction(const QModelIndex& parent, int start, int /*end*/);
115 Q_SIGNALS:
117  void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address);
118 private Q_SLOTS:
119  void handleTransactionClicked(const QModelIndex &index);
120  void changeTheme(bool isLightTheme, QString &theme) override;
121  void onSortChanged(const QString&);
122  void onSortTypeChanged(const QString& value);
123  void updateDisplayUnit();
124  void showList();
125  void onTxArrived(const QString& hash, const bool isCoinStake, const bool isMNReward, const bool isCSAnyType);
126 
127 #ifdef USE_QTCHARTS
128  void windowResizeEvent(QResizeEvent* event);
129  void changeChartColors();
130  void onChartYearChanged(const QString&);
131  void onChartMonthChanged(const QString&);
132  void onChartArrowClicked(bool goLeft);
133 #endif
134 
135 private:
136  Ui::DashboardWidget *ui{nullptr};
137  FurAbstractListItemDelegate* txViewDelegate{nullptr};
138  TransactionFilterProxy* filter{nullptr};
139  TxViewHolder* txHolder{nullptr};
140  TransactionTableModel* txModel{nullptr};
141  int nDisplayUnit{-1};
142  bool isSync{false};
143 
144  void changeSort(int nSortIndex);
145 
146 #ifdef USE_QTCHARTS
147 
148  int64_t lastRefreshTime{0};
149  std::atomic<bool> isLoading;
150 
151  // Chart
152  TransactionFilterProxy* stakesFilter{nullptr};
153  bool isChartInitialized{false};
154  QChartView *chartView{nullptr};
155  QBarSeries *series{nullptr};
156  QBarSet *set0{nullptr};
157  QBarSet *set1{nullptr};
158 
159  QBarCategoryAxis *axisX{nullptr};
160  QValueAxis *axisY{nullptr};
161 
162  QChart *chart{nullptr};
163  bool isChartMin{false};
164  ChartShowType chartShow{YEAR};
165  int yearFilter{0};
166  int monthFilter{0};
167  int dayStart{1};
168  bool hasMNRewards{false};
169 
170  ChartData* chartData{nullptr};
171  bool hasStakes{false};
172  bool fShowCharts{true};
173  std::atomic<bool> filterUpdateNeeded{false};
174 
175  void initChart();
176  void showHideEmptyChart(bool show, bool loading, bool forceView = false);
177  bool refreshChart();
178  void tryChartRefresh();
179  void updateStakeFilter();
180  QMap<int, std::pair<qint64, qint64>> getAmountBy();
181  bool loadChartData(bool withMonthNames);
182  void updateAxisX(const QStringList *arg = nullptr);
183  void setChartShow(ChartShowType type);
184  std::pair<int, int> getChartRange(const QMap<int, std::pair<qint64, qint64>>& amountsBy);
185 
186 private Q_SLOTS:
187  void onChartRefreshed();
188  void onHideChartsChanged(bool fHide);
189 
190 #endif
191 
192 };
193 
194 #endif // PIVX_QT_DASHBOARDWIDGET_H
int64_t CAmount
Amount in PIV (Can be negative)
Definition: amount.h:13
QList< qreal > valuesMN
QMap< int, std::pair< qint64, qint64 > > amountsByCache
QList< qreal > valuesPiv
QStringList xLabels
void incomingTransaction(const QString &date, int unit, const CAmount &amount, const QString &type, const QString &address)
Notify that a new transaction appeared.
PIVX GUI main class.
Definition: pivxgui.h:46
void mousePressEvent(QMouseEvent *) override
~SortEdit() override
SortEdit(QWidget *parent=nullptr)
void Mouse_Pressed()
Filter the transaction list according to pre-specified rules.
UI model for the transaction table of a wallet.
Interface to PIVX wallet from Qt view code.
Definition: walletmodel.h:109
ChartShowType
@ DAY
@ MONTH
@ ALL
@ YEAR
SortTx
@ AMOUNT_ASC
@ DATE_DESC
@ DATE_ASC
@ AMOUNT_DESC
bool isLightTheme()
Definition: qtutils.cpp:210
bool error(const char *fmt, const Args &... args)
Definition: system.h:77