33#include " qt/pivx/sendconfirmdialog.h"
44#include " qt/pivx/txrow.h"
55#include " qt/pivx/qtutils.h"
6+ #include " guiutil.h"
67#include " walletmodel.h"
78#include " optionsmodel.h"
89#include " qt/pivx/settings/settingsfaqwidget.h"
1516#include < QPaintEngine>
1617#include < QGraphicsDropShadowEffect>
1718#include < iostream>
19+ #include < cstdlib>
20+
21+ #include < QMap>
1822
19- /*
2023// Chart
2124#include < QtCharts/QChartView>
2225#include < QtCharts/QBarSeries>
2326#include < QtCharts/QBarSet>
2427#include < QtCharts/QLegend>
2528#include < QtCharts/QBarCategoryAxis>
2629#include < QtCharts/QValueAxis>
27- */
2830#include < QGraphicsLayout>
2931
3032#define DECORATION_SIZE 65
@@ -158,13 +160,11 @@ DashboardWidget::DashboardWidget(PIVXGUI* _window, QWidget *parent) :
158160 // ui->pushImgEmptyChart->setProperty("cssClass", "img-empty-staking-off");
159161 // ui->labelEmptyChart->setText("Staking off");
160162
161- ui->labelEmptyChart ->setText (" Staking on " );
163+ ui->labelEmptyChart ->setText (" Staking off " );
162164 ui->labelEmptyChart ->setProperty (" cssClass" , " text-empty" );
163165
164166 ui->labelMessageEmpty ->setText (" You can activate and deactivate the Staking mode in the status bar at the top right of the wallet" );
165167 ui->labelMessageEmpty ->setProperty (" cssClass" , " text-subtitle" );
166- // load chart
167- loadChart ();
168168
169169 // Chart State
170170 ui->layoutChart ->setVisible (false );
@@ -192,68 +192,117 @@ void DashboardWidget::handleTransactionClicked(const QModelIndex &index){
192192
193193}
194194
195- void DashboardWidget::loadChart (){
196- /*
195+ void DashboardWidget::initChart () {
197196 set0 = new QBarSet (" PIV" );
198197 set0->setColor (QColor (176 ,136 ,255 ));
199198
200199 set1 = new QBarSet (" zPIV" );
201200 set1->setColor (QColor (92 ,75 ,125 ));
202201
203- *set0 << 4 << 2 << 4 << 6;
204- *set1 << 6 << 9 << 3 << 6;
202+ chart = new QChart ();
203+ }
204+
205+ const char * monthsNames[12 ] = {" Jan" , " Feb" , " Mar" , " Apr" , " May" , " Jun" , " Jul" , " Aug" , " Sep" , " Oct" , " Nov" , " Dec" };
205206
206- QBarSeries *series = new QBarSeries();
207- series->append(set0);
208- series->append(set1);
207+ void DashboardWidget::loadChart (){
209208
210- // bar width
211- series->setBarWidth(0.8);
209+ int size = stakesFilter->rowCount ();
210+ if (size > 0 ) {
211+ ui->layoutChart ->setVisible (true );
212+ ui->emptyContainerChart ->setVisible (false );
213+ initChart ();
214+
215+ // pair PIV, zPIV
216+ QMap<int , std::pair<qint64, qint64>> amountByMonths;
217+ // get all of the stakes
218+ for (int i = 0 ; i < size; ++i) {
219+ QModelIndex modelIndex = stakesFilter->index (i, TransactionTableModel::ToAddress);
220+ qint64 amount = llabs (modelIndex.data (TransactionTableModel::AmountRole).toLongLong ());
221+ QDateTime datetime = modelIndex.data (TransactionTableModel::DateRole).toDateTime ();
222+ bool isPiv = modelIndex.data (TransactionTableModel::TypeRole).toInt () != TransactionRecord::StakeZPIV;
223+ int month = datetime.date ().month ();
224+ if (amountByMonths.contains (month)) {
225+ if (isPiv) {
226+ amountByMonths[month].first += amount;
227+ } else
228+ amountByMonths[month].second += amount;
229+ } else {
230+ if (isPiv) {
231+ amountByMonths[month] = std::make_pair (amount, 0 );
232+ } else {
233+ amountByMonths[month] = std::make_pair (0 , amount);
234+ }
235+ }
212236
213- chart = new QChart();
214- chart->addSeries(series);
215- // title
216- //chart->setTitle("Simple barchart example");
217- chart->setAnimationOptions(QChart::SeriesAnimations);
218-
219- QStringList categories;
220- categories << "Jan" << "Feb" << "Mar" << "Apr";
221- axisX = new QBarCategoryAxis();
222- axisX->append(categories);
223- chart->addAxis(axisX, Qt::AlignBottom);
224- series->attachAxis(axisX);
225-
226- axisY = new QValueAxis();
227- axisY->setRange(0,12);
228- chart->addAxis(axisY, Qt::AlignRight);
229- series->attachAxis(axisY);
230-
231- // Legend
232- chart->legend()->setVisible(false);
233- chart->legend()->setAlignment(Qt::AlignTop);
234-
235- QChartView *chartView = new QChartView(chart);
236- chartView->setRenderHint(QPainter::Antialiasing);
237-
238- QVBoxLayout *baseScreensContainer = new QVBoxLayout(this);
239- baseScreensContainer->setMargin(0);
240- ui->chartContainer->setLayout(baseScreensContainer);
241-
242- ui->chartContainer->layout()->addWidget(chartView);
243- ui->chartContainer->setProperty("cssClass", "container-chart");
237+ }
238+
239+ QStringList months;
240+ qreal maxValue = 0 ;
241+ for (int j = 12 ; j > 6 ; j--) {
242+ qreal piv = 0 ;
243+ qreal zpiv = 0 ;
244+ if (amountByMonths.contains (j)) {
245+ std::pair<qint64, qint64> pair = amountByMonths[j];
246+ piv = (pair.first != 0 ) ? pair.first / 100000000 : 0 ;
247+ zpiv = (pair.second != 0 ) ? pair.second / 100000000 : 0 ;
248+ }
249+ months << monthsNames[j - 1 ];
250+ set0->append (piv);
251+ set1->append (zpiv);
252+
253+ int max = std::max (piv, zpiv);
254+ if (max > maxValue) {
255+ maxValue = max;
256+ }
257+ }
244258
245- // Set colors
246- changeChartColors();
259+ QBarSeries *series = new QtCharts::QBarSeries ();
260+ series->append (set0);
261+ series->append (set1);
247262
248- // Chart margin removed.
249- chart->layout()->setContentsMargins(0, 0, 0, 0);
250- chart->setBackgroundRoundness(0);
251- */
263+ // bar width
264+ series->setBarWidth (0.8 );
265+
266+ chart->addSeries (series);
267+ chart->setAnimationOptions (QChart::SeriesAnimations);
268+
269+ axisX = new QBarCategoryAxis ();
270+ axisX->append (months);
271+ chart->addAxis (axisX, Qt::AlignBottom);
272+ series->attachAxis (axisX);
273+
274+ axisY = new QValueAxis ();
275+ axisY->setRange (0 ,maxValue);
276+ chart->addAxis (axisY, Qt::AlignRight);
277+ series->attachAxis (axisY);
278+
279+ // Legend
280+ chart->legend ()->setVisible (false );
281+ chart->legend ()->setAlignment (Qt::AlignTop);
282+
283+ QChartView *chartView = new QChartView (chart);
284+ chartView->setRenderHint (QPainter::Antialiasing);
285+
286+ QVBoxLayout *baseScreensContainer = new QVBoxLayout (this );
287+ baseScreensContainer->setMargin (0 );
288+ ui->chartContainer ->setLayout (baseScreensContainer);
289+
290+ ui->chartContainer ->layout ()->addWidget (chartView);
291+ ui->chartContainer ->setProperty (" cssClass" , " container-chart" );
292+
293+ // Set colors
294+ changeChartColors ();
295+
296+ // Chart margin removed.
297+ chart->layout ()->setContentsMargins (0 , 0 , 0 , 0 );
298+ chart->setBackgroundRoundness (0 );
299+ } else {
300+ ui->layoutChart ->setVisible (false );
301+ ui->emptyContainerChart ->setVisible (true );
302+ }
252303}
253304
254305void DashboardWidget::changeChartColors (){
255- /*
256- // Colors
257306 QColor gridLineColorX;
258307 QColor linePenColorY;
259308 QColor backgroundColor;
@@ -275,7 +324,6 @@ void DashboardWidget::changeChartColors(){
275324 chart->setBackgroundBrush (QBrush (backgroundColor));
276325 set0->setBorderColor (gridLineColorX);
277326 set1->setBorderColor (gridLineColorX);
278- */
279327}
280328
281329void DashboardWidget::loadWalletModel (){
@@ -300,6 +348,13 @@ void DashboardWidget::loadWalletModel(){
300348 connect (ui->pushImgEmpty , SIGNAL (clicked ()), this , SLOT (openFAQ ()));
301349 connect (ui->btnHowTo , SIGNAL (clicked ()), this , SLOT (openFAQ ()));
302350 }
351+
352+ // chart filter
353+ stakesFilter = new TransactionFilterProxy ();
354+ stakesFilter->setSourceModel (txModel);
355+ stakesFilter->sort (TransactionTableModel::Date, Qt::DescendingOrder);
356+ stakesFilter->setOnlyStakes (true );
357+ loadChart ();
303358 }
304359 // update the display unit, to not use the default ("PIV")
305360 updateDisplayUnit ();
0 commit comments