Skip to content

Commit

Permalink
[GUI] Dashboard hasStakes variable set when the view is loaded and/or…
Browse files Browse the repository at this point in the history
… when the first stake is received. Don't use the stake filter proxy which can or can't have stakes (always changing and being filtered).
  • Loading branch information
furszy committed Oct 1, 2019
1 parent 6f91049 commit 38c654b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
32 changes: 19 additions & 13 deletions src/qt/pivx/dashboardwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ void DashboardWidget::loadWalletModel(){
stakesFilter->setOnlyStakes(true);
stakesFilter->setSourceModel(txModel);
stakesFilter->sort(TransactionTableModel::Date, Qt::AscendingOrder);
hasStakes = stakesFilter->rowCount() > 0;
loadChart();
#endif
}
Expand All @@ -236,8 +237,12 @@ void DashboardWidget::loadWalletModel(){
void DashboardWidget::onTxArrived(const QString& hash) {
showList();
#ifdef USE_QTCHARTS
if (walletModel->isCoinStakeMine(hash))
if (walletModel->isCoinStakeMine(hash)) {
// Update value if this is our first stake
if (!hasStakes)
hasStakes = stakesFilter->rowCount() > 0;
tryChartRefresh();
}
#endif
}

Expand Down Expand Up @@ -327,12 +332,17 @@ void DashboardWidget::changeTheme(bool isLightTheme, QString& theme){
#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();
if (hasStakes) {
// First check that everything was loaded properly.
if (!chart) {
loadChart();
} else {
// 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();
}
}
}
}
Expand All @@ -350,7 +360,7 @@ void DashboardWidget::setChartShow(ChartShowType type) {
const QStringList monthsNames = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

void DashboardWidget::loadChart(){
if (hasStakes()) {
if (hasStakes) {
if (!chart) {
showHideEmptyChart(false, false);
initChart();
Expand Down Expand Up @@ -743,7 +753,7 @@ void DashboardWidget::onChartArrowClicked() {
}

void DashboardWidget::windowResizeEvent(QResizeEvent *event){
if (hasStakes() > 0 && axisX) {
if (hasStakes && axisX) {
if (width() > 1300) {
if (isChartMin) {
isChartMin = false;
Expand Down Expand Up @@ -772,10 +782,6 @@ void DashboardWidget::windowResizeEvent(QResizeEvent *event){
}
}

bool DashboardWidget::hasStakes() {
return stakesFilter->rowCount() > 0;
}

#endif

void DashboardWidget::run(int type) {
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/dashboardwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private slots:
bool hasZpivStakes = false;

ChartData* chartData = nullptr;
bool hasStakes = false;

void initChart();
void showHideEmptyChart(bool show, bool loading, bool forceView = false);
Expand All @@ -177,7 +178,6 @@ private slots:
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();
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/settings/settingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void SettingsWidget::loadClientModel(){
settingsDisplayOptionsWidget->setClientModel(clientModel);
settingsWalletOptionsWidget->setClientModel(clientModel);
/* keep consistency for action triggered elsewhere */
connect(optionsModel, SIGNAL(hideOrphansChanged(bool)), this, SLOT(updateHideOrphans(bool)));
//connect(optionsModel, SIGNAL(hideOrphansChanged(bool)), this, SLOT(updateHideOrphans(bool)));

// TODO: Connect show restart needed and apply changes.
}
Expand Down

0 comments on commit 38c654b

Please sign in to comment.