mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 00:55:09 -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 <QCheckBox>
|
||||
#include <QDateTime>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QSpinBox>
|
||||
#include <QTableWidget>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
#include <algorithm>
|
||||
#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/pending_command.h>
|
||||
|
||||
static constexpr int DEFAULT_AUTO_REFRESH_INTERVAL_SECS = 30;
|
||||
|
||||
TabDeveloper::TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_client)
|
||||
: Tab(_tabSupervisor), client(_client)
|
||||
{
|
||||
|
|
@ -45,12 +50,28 @@ TabDeveloper::TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_clien
|
|||
|
||||
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->setAutoDefault(true);
|
||||
connect(refreshButton, &QPushButton::clicked, this, &TabDeveloper::refreshClicked);
|
||||
|
||||
auto *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addWidget(statusLabel, 1, Qt::AlignLeft);
|
||||
buttonLayout->addWidget(autoRefreshCheckBox, 0, Qt::AlignRight);
|
||||
buttonLayout->addWidget(refreshIntervalSpinBox, 0, Qt::AlignRight);
|
||||
buttonLayout->addWidget(refreshButton, 0, Qt::AlignRight);
|
||||
|
||||
auto *tableLayout = new QHBoxLayout;
|
||||
|
|
@ -70,6 +91,10 @@ TabDeveloper::TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_clien
|
|||
|
||||
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"));
|
||||
statsTable->setHorizontalHeaderLabels(QString(tr("Statistic;Value")).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()
|
||||
{
|
||||
if (requestPending) {
|
||||
return;
|
||||
}
|
||||
requestPending = true;
|
||||
Command_GetServerStats cmd;
|
||||
PendingCommand *pend = client->prepareDeveloperCommand(cmd);
|
||||
connect(pend, &PendingCommand::finished, this, &TabDeveloper::serverStatsResponse);
|
||||
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)
|
||||
{
|
||||
requestPending = false;
|
||||
if (resp.response_code() != Response::RespOk) {
|
||||
statusLabel->setText(tr("No server statistics available yet."));
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,12 @@
|
|||
#include "tab.h"
|
||||
|
||||
class AbstractClient;
|
||||
class QCheckBox;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
class QSpinBox;
|
||||
class QTableWidget;
|
||||
class QTimer;
|
||||
class Response;
|
||||
|
||||
class TabDeveloper : public Tab
|
||||
|
|
@ -24,6 +27,10 @@ private:
|
|||
QTableWidget *commandTable;
|
||||
QPushButton *refreshButton;
|
||||
QLabel *statusLabel;
|
||||
QCheckBox *autoRefreshCheckBox;
|
||||
QSpinBox *refreshIntervalSpinBox;
|
||||
QTimer *autoRefreshTimer;
|
||||
bool requestPending = false;
|
||||
|
||||
void appendStatRow(const QString &name, const QString &value);
|
||||
void appendSeparatorRow(const QString §ionTitle);
|
||||
|
|
@ -33,6 +40,8 @@ private:
|
|||
private slots:
|
||||
void refreshClicked();
|
||||
void serverStatsResponse(const Response &resp);
|
||||
void autoRefreshToggled(bool checked);
|
||||
void refreshIntervalChanged();
|
||||
|
||||
public:
|
||||
explicit TabDeveloper(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue