Skip to content

Commit

Permalink
[UI] - Dashboard chart load, min update time interval, not update vie…
Browse files Browse the repository at this point in the history
…w so often when node is syncing.

     - Try chart refresh when the wallet is synced.
  • Loading branch information
furszy committed Sep 9, 2019
1 parent 3c711ef commit ca046aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/qt/pivx/dashboardwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "walletmodel.h"
#include "clientmodel.h"
#include "optionsmodel.h"
#include "utiltime.h"
#include <QPainter>
#include <QModelIndex>
#include <QList>
Expand All @@ -20,6 +21,7 @@
#define NUM_ITEMS 3
#define SHOW_EMPTY_CHART_VIEW_THRESHOLD 4000
#define REQUEST_LOAD_TASK 1
#define CHART_LOAD_MIN_TIME_INTERVAL 15

#include "moc_dashboardwidget.cpp"

Expand Down Expand Up @@ -231,9 +233,8 @@ void DashboardWidget::loadWalletModel(){
void DashboardWidget::onTxArrived(const QString& hash) {
showList();
#ifdef USE_QTCHARTS
if (hasStakes() && walletModel->isCoinStakeMine(hash)) {
refreshChart();
}
if (walletModel->isCoinStakeMine(hash))
tryChartRefresh();
#endif
}

Expand Down Expand Up @@ -307,6 +308,9 @@ void DashboardWidget::walletSynced(bool sync){
if (this->isSync != sync) {
this->isSync = sync;
ui->layoutWarning->setVisible(!this->isSync);
#ifdef USE_QTCHARTS
tryChartRefresh();
#endif
}
}

Expand All @@ -315,11 +319,21 @@ void DashboardWidget::changeTheme(bool isLightTheme, QString& theme){
#ifdef USE_QTCHARTS
if (chart) this->changeChartColors();
#endif

}

#ifdef USE_QTCHARTS

void DashboardWidget::tryChartRefresh() {
if (hasStakes()) {
// Check for min update time to not reload the UI so often if the node is syncing.
int64_t now = GetTime();
if (lastRefreshTime + CHART_LOAD_MIN_TIME_INTERVAL < now) {
lastRefreshTime = now;
refreshChart();
}
}
}

void DashboardWidget::setChartShow(ChartShowType type) {
this->chartShow = type;
if (chartShow == MONTH) {
Expand Down
3 changes: 3 additions & 0 deletions src/qt/pivx/dashboardwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ private slots:

#ifdef USE_QTCHARTS

int64_t lastRefreshTime = 0;

// Chart
TransactionFilterProxy* stakesFilter = nullptr;
bool isChartInitialized = false;
Expand All @@ -166,6 +168,7 @@ private slots:
void initChart();
void showHideEmptyChart(bool show, bool loading, bool forceView = false);
bool refreshChart();
void tryChartRefresh();
QMap<int, std::pair<qint64, qint64>> getAmountBy();
ChartData loadChartData(bool withMonthNames);
void updateAxisX(const QStringList *arg = nullptr);
Expand Down

0 comments on commit ca046aa

Please sign in to comment.