mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[Client] Togglable auto-refresh for Developer stats tab
This commit is contained in:
parent
b855b279a7
commit
8989390dc6
2 changed files with 57 additions and 0 deletions
|
|
@ -6,12 +6,15 @@
|
||||||
|
|
||||||
#include "tab_developer.h"
|
#include "tab_developer.h"
|
||||||
|
|
||||||
|
#include <QCheckBox>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QSpinBox>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
|
#include <QTimer>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <libcockatrice/network/client/abstract/abstract_client.h>
|
#include <libcockatrice/network/client/abstract/abstract_client.h>
|
||||||
|
|
@ -19,6 +22,8 @@
|
||||||
#include <libcockatrice/protocol/pb/response_get_server_stats.pb.h>
|
#include <libcockatrice/protocol/pb/response_get_server_stats.pb.h>
|
||||||
#include <libcockatrice/protocol/pending_command.h>
|
#include <libcockatrice/protocol/pending_command.h>
|
||||||
|
|
||||||
|
static constexpr int DEFAULT_AUTO_REFRESH_INTERVAL_SECS = 30;
|
||||||
|
|
||||||
TabDeveloper::TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_client)
|
TabDeveloper::TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_client)
|
||||||
: Tab(_tabSupervisor), client(_client)
|
: Tab(_tabSupervisor), client(_client)
|
||||||
{
|
{
|
||||||
|
|
@ -45,12 +50,28 @@ TabDeveloper::TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_clien
|
||||||
|
|
||||||
statusLabel = new QLabel;
|
statusLabel = new QLabel;
|
||||||
|
|
||||||
|
autoRefreshCheckBox = new QCheckBox;
|
||||||
|
autoRefreshCheckBox->setChecked(false);
|
||||||
|
|
||||||
|
refreshIntervalSpinBox = new QSpinBox;
|
||||||
|
refreshIntervalSpinBox->setRange(5, 3600);
|
||||||
|
refreshIntervalSpinBox->setValue(DEFAULT_AUTO_REFRESH_INTERVAL_SECS);
|
||||||
|
refreshIntervalSpinBox->setEnabled(false);
|
||||||
|
|
||||||
|
autoRefreshTimer = new QTimer(this);
|
||||||
|
connect(autoRefreshTimer, &QTimer::timeout, this, &TabDeveloper::refreshClicked);
|
||||||
|
connect(autoRefreshCheckBox, &QCheckBox::toggled, this, &TabDeveloper::autoRefreshToggled);
|
||||||
|
connect(refreshIntervalSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this,
|
||||||
|
&TabDeveloper::refreshIntervalChanged);
|
||||||
|
|
||||||
refreshButton = new QPushButton;
|
refreshButton = new QPushButton;
|
||||||
refreshButton->setAutoDefault(true);
|
refreshButton->setAutoDefault(true);
|
||||||
connect(refreshButton, &QPushButton::clicked, this, &TabDeveloper::refreshClicked);
|
connect(refreshButton, &QPushButton::clicked, this, &TabDeveloper::refreshClicked);
|
||||||
|
|
||||||
auto *buttonLayout = new QHBoxLayout;
|
auto *buttonLayout = new QHBoxLayout;
|
||||||
buttonLayout->addWidget(statusLabel, 1, Qt::AlignLeft);
|
buttonLayout->addWidget(statusLabel, 1, Qt::AlignLeft);
|
||||||
|
buttonLayout->addWidget(autoRefreshCheckBox, 0, Qt::AlignRight);
|
||||||
|
buttonLayout->addWidget(refreshIntervalSpinBox, 0, Qt::AlignRight);
|
||||||
buttonLayout->addWidget(refreshButton, 0, Qt::AlignRight);
|
buttonLayout->addWidget(refreshButton, 0, Qt::AlignRight);
|
||||||
|
|
||||||
auto *tableLayout = new QHBoxLayout;
|
auto *tableLayout = new QHBoxLayout;
|
||||||
|
|
@ -70,6 +91,10 @@ TabDeveloper::TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_clien
|
||||||
|
|
||||||
void TabDeveloper::retranslateUi()
|
void TabDeveloper::retranslateUi()
|
||||||
{
|
{
|
||||||
|
autoRefreshCheckBox->setText(tr("Auto-refresh"));
|
||||||
|
autoRefreshCheckBox->setToolTip(tr("Automatically request fresh server statistics at a fixed interval."));
|
||||||
|
refreshIntervalSpinBox->setSuffix(tr(" s"));
|
||||||
|
refreshIntervalSpinBox->setToolTip(tr("Seconds between automatic refreshes."));
|
||||||
refreshButton->setText(tr("Refresh server stats"));
|
refreshButton->setText(tr("Refresh server stats"));
|
||||||
statsTable->setHorizontalHeaderLabels(QString(tr("Statistic;Value")).split(";"));
|
statsTable->setHorizontalHeaderLabels(QString(tr("Statistic;Value")).split(";"));
|
||||||
commandTable->setHorizontalHeaderLabels(QString(tr("Command;Count;Total ms;Avg ms")).split(";"));
|
commandTable->setHorizontalHeaderLabels(QString(tr("Command;Count;Total ms;Avg ms")).split(";"));
|
||||||
|
|
@ -126,14 +151,37 @@ void TabDeveloper::appendSeparatorRow(const QString §ionTitle)
|
||||||
|
|
||||||
void TabDeveloper::refreshClicked()
|
void TabDeveloper::refreshClicked()
|
||||||
{
|
{
|
||||||
|
if (requestPending) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
requestPending = true;
|
||||||
Command_GetServerStats cmd;
|
Command_GetServerStats cmd;
|
||||||
PendingCommand *pend = client->prepareDeveloperCommand(cmd);
|
PendingCommand *pend = client->prepareDeveloperCommand(cmd);
|
||||||
connect(pend, &PendingCommand::finished, this, &TabDeveloper::serverStatsResponse);
|
connect(pend, &PendingCommand::finished, this, &TabDeveloper::serverStatsResponse);
|
||||||
client->sendCommand(pend);
|
client->sendCommand(pend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabDeveloper::autoRefreshToggled(bool checked)
|
||||||
|
{
|
||||||
|
refreshIntervalSpinBox->setEnabled(checked);
|
||||||
|
if (checked) {
|
||||||
|
refreshIntervalChanged();
|
||||||
|
refreshClicked();
|
||||||
|
} else {
|
||||||
|
autoRefreshTimer->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabDeveloper::refreshIntervalChanged()
|
||||||
|
{
|
||||||
|
if (autoRefreshCheckBox->isChecked()) {
|
||||||
|
autoRefreshTimer->start(refreshIntervalSpinBox->value() * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TabDeveloper::serverStatsResponse(const Response &resp)
|
void TabDeveloper::serverStatsResponse(const Response &resp)
|
||||||
{
|
{
|
||||||
|
requestPending = false;
|
||||||
if (resp.response_code() != Response::RespOk) {
|
if (resp.response_code() != Response::RespOk) {
|
||||||
statusLabel->setText(tr("No server statistics available yet."));
|
statusLabel->setText(tr("No server statistics available yet."));
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,12 @@
|
||||||
#include "tab.h"
|
#include "tab.h"
|
||||||
|
|
||||||
class AbstractClient;
|
class AbstractClient;
|
||||||
|
class QCheckBox;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
class QSpinBox;
|
||||||
class QTableWidget;
|
class QTableWidget;
|
||||||
|
class QTimer;
|
||||||
class Response;
|
class Response;
|
||||||
|
|
||||||
class TabDeveloper : public Tab
|
class TabDeveloper : public Tab
|
||||||
|
|
@ -24,6 +27,10 @@ private:
|
||||||
QTableWidget *commandTable;
|
QTableWidget *commandTable;
|
||||||
QPushButton *refreshButton;
|
QPushButton *refreshButton;
|
||||||
QLabel *statusLabel;
|
QLabel *statusLabel;
|
||||||
|
QCheckBox *autoRefreshCheckBox;
|
||||||
|
QSpinBox *refreshIntervalSpinBox;
|
||||||
|
QTimer *autoRefreshTimer;
|
||||||
|
bool requestPending = false;
|
||||||
|
|
||||||
void appendStatRow(const QString &name, const QString &value);
|
void appendStatRow(const QString &name, const QString &value);
|
||||||
void appendSeparatorRow(const QString §ionTitle);
|
void appendSeparatorRow(const QString §ionTitle);
|
||||||
|
|
@ -33,6 +40,8 @@ private:
|
||||||
private slots:
|
private slots:
|
||||||
void refreshClicked();
|
void refreshClicked();
|
||||||
void serverStatsResponse(const Response &resp);
|
void serverStatsResponse(const Response &resp);
|
||||||
|
void autoRefreshToggled(bool checked);
|
||||||
|
void refreshIntervalChanged();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
explicit TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue