@@ -83,6 +83,7 @@ DashboardWidget::DashboardWidget(PIVXGUI* _window, QWidget *parent) :
8383 ui->comboBoxYears ->setView (new QListView ());
8484 ui->comboBoxYears ->setStyleSheet (" selection-background-color:transparent; selection-color:transparent;" );
8585 ui->pushButtonYear ->setChecked (true );
86+ setChartShow (YEAR);
8687
8788 connect (ui->comboBoxYears , SIGNAL (currentIndexChanged (const QString&)), this ,SLOT (onChartYearChanged (const QString&)));
8889
@@ -151,16 +152,17 @@ DashboardWidget::DashboardWidget(PIVXGUI* _window, QWidget *parent) :
151152
152153 connect (ui->pushButtonYear , &QPushButton::clicked, [this ](){setChartShow (YEAR);});
153154 connect (ui->pushButtonMonth , &QPushButton::clicked, [this ](){setChartShow (MONTH);});
154- connect (ui->pushButtonAll , &QPushButton::clicked, [this ](){
155- yearFilter = 0 ;
156- monthFilter = 0 ;
157- setChartShow (ALL);
158- });
155+ connect (ui->pushButtonAll , &QPushButton::clicked, [this ](){setChartShow (ALL);});
159156}
160157
161158void DashboardWidget::setChartShow (ChartShowType type) {
162159 this ->chartShow = type;
163- refreshChart ();
160+ if (chartShow == MONTH) {
161+ ui->containerChartArrow ->setVisible (true );
162+ } else {
163+ ui->containerChartArrow ->setVisible (false );
164+ }
165+ if (isChartInitialized) refreshChart ();
164166}
165167
166168void DashboardWidget::handleTransactionClicked (const QModelIndex &index){
@@ -177,6 +179,7 @@ void DashboardWidget::handleTransactionClicked(const QModelIndex &index){
177179 ui->listTransactions ->scrollTo (index);
178180 ui->listTransactions ->clearSelection ();
179181 ui->listTransactions ->setFocus ();
182+ dialog->deleteLater ();
180183}
181184
182185void DashboardWidget::loadWalletModel (){
@@ -278,10 +281,13 @@ void DashboardWidget::loadChart(){
278281 ui->layoutChart ->setVisible (true );
279282 ui->emptyContainerChart ->setVisible (false );
280283 initChart ();
281- monthFilter = QDate::currentDate ().month ();
284+ QDate currentDate = QDate::currentDate ();
285+ monthFilter = currentDate.month ();
286+ yearFilter = currentDate.year ();
282287 for (int i = 1 ; i < 13 ; ++i) ui->comboBoxMonths ->addItem (QString (monthsNames[i-1 ]), QVariant (i));
283288 ui->comboBoxMonths ->setCurrentIndex (monthFilter - 1 );
284- connect (ui->comboBoxMonths , SIGNAL (currentIndexChanged (const QString&)), this ,SLOT (onChartMonthChanged (const QString&)));
289+ connect (ui->comboBoxMonths , SIGNAL (currentIndexChanged (const QString&)), this , SLOT (onChartMonthChanged (const QString&)));
290+ connect (ui->pushButtonChartArrow , SIGNAL (clicked ()), this , SLOT (onChartArrowClicked ()));
285291 }
286292 refreshChart ();
287293 changeChartColors ();
@@ -301,6 +307,7 @@ void DashboardWidget::initChart() {
301307 chart->legend ()->setVisible (false );
302308 chart->legend ()->setAlignment (Qt::AlignTop);
303309 chart->layout ()->setContentsMargins (0 , 0 , 0 , 0 );
310+ chart->setMargins ({0 , 0 , 0 , 0 });
304311 chart->setBackgroundRoundness (0 );
305312 // Axis
306313 chart->addAxis (axisX, Qt::AlignBottom);
@@ -309,11 +316,14 @@ void DashboardWidget::initChart() {
309316
310317 chartView = new QChartView (chart);
311318 chartView->setRenderHint (QPainter::Antialiasing);
319+ chartView->setRubberBand ( QChartView::HorizontalRubberBand );
320+ chartView->setContentsMargins (0 ,0 ,0 ,0 );
312321
313- QVBoxLayout *baseScreensContainer = new QVBoxLayout (this );
322+ QHBoxLayout *baseScreensContainer = new QHBoxLayout (this );
314323 baseScreensContainer->setMargin (0 );
324+ baseScreensContainer->addWidget (chartView);
315325 ui->chartContainer ->setLayout (baseScreensContainer);
316- ui->chartContainer ->layout ()-> addWidget (chartView );
326+ ui->chartContainer ->setContentsMargins ( 0 , 0 , 0 , 0 );
317327 ui->chartContainer ->setProperty (" cssClass" , " container-chart" );
318328}
319329
@@ -343,32 +353,36 @@ void DashboardWidget::changeChartColors(){
343353
344354// pair PIV, zPIV
345355QMap<int , std::pair<qint64, qint64>> DashboardWidget::getAmountBy () {
346- bool filterByMonth = false ;
347- if (monthFilter != 0 && chartShow == MONTH) {
348- filterByMonth = true ;
349- }
350- if (yearFilter != 0 ) {
351- if (filterByMonth) {
352- QDate monthFirst = QDate (yearFilter, monthFilter, 1 );
356+ if (chartShow != ALL) {
357+ bool filterByMonth = false ;
358+ if (monthFilter != 0 && chartShow == MONTH) {
359+ filterByMonth = true ;
360+ }
361+ if (yearFilter != 0 ) {
362+ if (filterByMonth) {
363+ QDate monthFirst = QDate (yearFilter, monthFilter, 1 );
364+ stakesFilter->setDateRange (
365+ QDateTime (monthFirst),
366+ QDateTime (QDate (yearFilter, monthFilter, monthFirst.daysInMonth ()))
367+ );
368+ } else {
369+ stakesFilter->setDateRange (
370+ QDateTime (QDate (yearFilter, 1 , 1 )),
371+ QDateTime (QDate (yearFilter, 12 , 31 ))
372+ );
373+ }
374+ } else if (filterByMonth) {
375+ QDate currentDate = QDate::currentDate ();
376+ QDate monthFirst = QDate (currentDate.year (), monthFilter, 1 );
353377 stakesFilter->setDateRange (
354378 QDateTime (monthFirst),
355- QDateTime (QDate (yearFilter , monthFilter, monthFirst.daysInMonth ()))
379+ QDateTime (QDate (currentDate. year () , monthFilter, monthFirst.daysInMonth ()))
356380 );
381+ ui->comboBoxYears ->setCurrentText (QString::number (currentDate.year ()));
357382 } else {
358- stakesFilter->setDateRange (
359- QDateTime (QDate (yearFilter, 1 , 1 )),
360- QDateTime (QDate (yearFilter, 12 , 31 ))
361- );
383+ stakesFilter->clearDateRange ();
362384 }
363- } else if (filterByMonth){
364- QDate currentDate = QDate::currentDate ();
365- QDate monthFirst = QDate (currentDate.year (), monthFilter, 1 );
366- stakesFilter->setDateRange (
367- QDateTime (monthFirst),
368- QDateTime (QDate (currentDate.year (), monthFilter, monthFirst.daysInMonth ()))
369- );
370- ui->comboBoxYears ->setCurrentText (QString::number (currentDate.year ()));
371- } else {
385+ } else {
372386 stakesFilter->clearDateRange ();
373387 }
374388 int size = stakesFilter->rowCount ();
@@ -380,28 +394,6 @@ QMap<int, std::pair<qint64, qint64>> DashboardWidget::getAmountBy() {
380394 QDateTime datetime = modelIndex.data (TransactionTableModel::DateRole).toDateTime ();
381395 bool isPiv = modelIndex.data (TransactionTableModel::TypeRole).toInt () != TransactionRecord::StakeZPIV;
382396
383- /* *
384- * If this is ALL, order this by years.
385- * To do that, the amountBy map is a map of:
386- * year --> pair<PIV,zPIV>
387- * ---
388- * If this is YEAR, show the 12 months of the year (need a filter by year).
389- * To do that, the amountBy map is a map of:
390- * month --> pair<PIV,zPIV>
391- * ---
392- * If this is MONTH, order this by days (need a filter by month and year).
393- * To do that, then amountBy map is a map of:
394- * day --> pair<PIV,zPIV>
395- * ---
396- * If this is WEEK, order this by weeks (need a filter by year, month and week number).
397- * To do that, the amountBy map is a map of:
398- * week num --> pair<PIV,zPIV>
399- * ---
400- * If this is DAY, order this by hours (need a filter by year, month and day).
401- * To do that, the amountBy map is a map of:
402- * day --> pair<PIV,zPIV>
403- */
404-
405397 int time = 0 ;
406398 switch (chartShow) {
407399 case YEAR: {
@@ -477,7 +469,7 @@ void DashboardWidget::refreshChart(){
477469 amountsByCache = getAmountBy ();
478470
479471 QStringList months;
480- isChartMin = width () < 1350 ;
472+ isChartMin = width () < 1300 ;
481473 bool withMonthNames = !isChartMin && (chartShow == YEAR);
482474
483475 qreal maxValue = 0 ;
@@ -488,18 +480,22 @@ void DashboardWidget::refreshChart(){
488480 QList<qreal> valueszPiv;
489481
490482 std::pair<int ,int > range = getChartRange (amountsByCache);
483+ bool isOrderedByMonth = chartShow == MONTH;
484+ int daysInMonth = QDate (yearFilter, monthFilter, 1 ).daysInMonth ();
485+
491486 for (int j = range.first ; j < range.second ; j++) {
487+ int num = (isOrderedByMonth && j > daysInMonth) ? (j % daysInMonth) : j;
492488 qreal piv = 0 ;
493489 qreal zpiv = 0 ;
494- if (amountsByCache.contains (j )) {
495- std::pair<qint64, qint64> pair = amountsByCache[j ];
490+ if (amountsByCache.contains (num )) {
491+ std::pair <qint64, qint64> pair = amountsByCache[num ];
496492 piv = (pair.first != 0 ) ? pair.first / 100000000 : 0 ;
497493 zpiv = (pair.second != 0 ) ? pair.second / 100000000 : 0 ;
498494 totalPiv += pair.first ;
499495 totalZpiv += pair.second ;
500496 }
501497
502- months << ((withMonthNames) ? monthsNames[j- 1 ] : QString::number (j ));
498+ months << ((withMonthNames) ? monthsNames[num - 1 ] : QString::number (num ));
503499 valuesPiv.append (piv);
504500 valueszPiv.append (zpiv);
505501
@@ -594,7 +590,7 @@ std::pair<int, int> DashboardWidget::getChartRange(QMap<int, std::pair<qint64, q
594590 return std::make_pair (keys.first (), keys.last () + 1 );
595591 }
596592 case MONTH:
597- return std::make_pair (1 , 32 );
593+ return std::make_pair (dayStart, dayStart + 9 );
598594 default :
599595 inform (tr (" Error loading chart, invalid show option" ));
600596 return std::make_pair (0 , 0 );
@@ -613,9 +609,17 @@ void DashboardWidget::updateAxisX(const QStringList* args) {
613609 axisX->append (months);
614610}
615611
612+ void DashboardWidget::onChartArrowClicked () {
613+ dayStart--;
614+ if (dayStart == 0 ) {
615+ dayStart = QDate (yearFilter, monthFilter, 1 ).daysInMonth ();
616+ }
617+ refreshChart ();
618+ }
619+
616620void DashboardWidget::windowResizeEvent (QResizeEvent *event){
617621 if (stakesFilter->rowCount () > 0 && axisX) {
618- if (width () > 1350 ) {
622+ if (width () > 1300 ) {
619623 if (isChartMin) {
620624 isChartMin = false ;
621625 switch (chartShow) {
@@ -640,6 +644,7 @@ void DashboardWidget::windowResizeEvent(QResizeEvent *event){
640644 } else {
641645 if (!isChartMin) {
642646 updateAxisX ();
647+ isChartMin = true ;
643648 }
644649 }
645650 }
0 commit comments