Cavoke  1.1.0
A Platform for creating and hosting multiplayer turn-based board games
Loading...
Searching...
No Matches
statisticsview.cpp
1#include "statisticsview.h"
2#include <QFileDialog>
3#include "authdialog.h"
4#include "ui_statisticsview.h"
5
6StatisticsView::StatisticsView(QWidget *parent)
7 : QMainWindow(parent), ui(new Ui::StatisticsView) {
8 ui->setupUi(this);
9 connect(ui->games_combobox, SIGNAL(currentIndexChanged(int)), this,
10 SLOT(repeaterCurrentIndexChanged(int)));
11}
12
13void StatisticsView::repeaterCurrentIndexChanged(int index) {
14 if (index == -1) {
15 displayEmpty();
16 return;
17 }
18 emit statisticsGameChanged(ui->games_combobox->itemData(index).toString());
19}
20
21void StatisticsView::displayEmpty() {
22 ui->time_played_label->setText("0");
23 ui->games_played_label->setText("0");
24 ui->win_rate_label->setText("0");
25}
26
27void StatisticsView::gotUserGameStatisticsUpdate(
28 const UserGameStatistics &userGameStatistics) {
29 ui->time_played_label->setText(
30 QString::number(userGameStatistics.time_played_sec));
31 ui->games_played_label->setText(
32 QString::number(userGameStatistics.games_played));
33 ui->win_rate_label->setText(QString::number(userGameStatistics.win_rate));
34}
35
36StatisticsView::~StatisticsView() {
37 delete ui;
38}
39
40void StatisticsView::on_backButton_clicked() {
41 this->close();
42 emit shownStartView();
43}
44
45void StatisticsView::gotGamesListUpdate(
46 const std::vector<GameInfo> &newGamesList) {
47 ui->games_combobox->clear();
48 for (const auto &gameInfo : newGamesList) {
49 ui->games_combobox->addItem(gameInfo.display_name, gameInfo.id);
50 }
51}
52void StatisticsView::gotUserStatisticsUpdate(
53 const UserStatistics &userStatistics) {
54 ui->total_time_played_label->setText(
55 QString::number(userStatistics.total_time_played_sec));
56 ui->total_games_played_label->setText(
57 QString::number(userStatistics.total_games_played));
58}
59
60void StatisticsView::requestUpdates() {
61 emit requestedRefresh();
62 emit statisticsGameChanged(
63 ui->games_combobox->itemData(ui->games_combobox->currentIndex())
64 .toString());
65}
66
67void StatisticsView::on_refreshButton_clicked() {
68 requestUpdates();
69}