mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-16 07:47:39 +01:00
New statistics window, still quite unpolished.
This commit is contained in:
parent
f7a7eab3a3
commit
a07d39fc22
5 changed files with 368 additions and 2 deletions
|
@ -78,6 +78,7 @@ eliot_SOURCES = \
|
|||
dic_wizard.cpp dic_wizard.h \
|
||||
board_widget.cpp board_widget.h \
|
||||
history_widget.cpp history_widget.h \
|
||||
stats_widget.cpp stats_widget.h \
|
||||
play_word_mediator.cpp play_word_mediator.h \
|
||||
tables_dialog.cpp tables_dialog.h \
|
||||
training_widget.cpp training_widget.h \
|
||||
|
@ -120,6 +121,7 @@ nodist_eliot_SOURCES = \
|
|||
dic_wizard.moc.cpp \
|
||||
board_widget.moc.cpp \
|
||||
history_widget.moc.cpp \
|
||||
stats_widget.moc.cpp \
|
||||
play_word_mediator.moc.cpp \
|
||||
player_widget.moc.cpp \
|
||||
tables_dialog.moc.cpp \
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "training_widget.h"
|
||||
#include "arbitration_widget.h"
|
||||
#include "history_widget.h"
|
||||
#include "stats_widget.h"
|
||||
#include "dic_tools_widget.h"
|
||||
#include "players_table_helper.h"
|
||||
#include "timer_widget.h"
|
||||
|
@ -77,7 +78,7 @@ MainWindow::MainWindow(QWidget *iParent)
|
|||
m_playersWidget(NULL), m_trainingWidget(NULL),
|
||||
m_arbitrationWidget(NULL), m_scoresWidget(NULL),
|
||||
m_bagWindow(NULL), m_boardWindow(NULL),
|
||||
m_historyWindow(NULL), m_timerWindow(NULL),
|
||||
m_historyWindow(NULL), m_statsWindow(NULL), m_timerWindow(NULL),
|
||||
m_dicToolsWindow(NULL), m_dicNameLabel(NULL), m_timerModel(NULL),
|
||||
m_currentTurn(0)
|
||||
{
|
||||
|
@ -202,6 +203,7 @@ MainWindow::~MainWindow()
|
|||
delete m_bagWindow;
|
||||
delete m_boardWindow;
|
||||
delete m_historyWindow;
|
||||
delete m_statsWindow;
|
||||
delete m_timerWindow;
|
||||
delete m_dicToolsWindow;
|
||||
delete m_game;
|
||||
|
@ -532,6 +534,8 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
|||
m_boardWindow->close();
|
||||
if (m_historyWindow)
|
||||
m_historyWindow->close();
|
||||
if (m_statsWindow)
|
||||
m_statsWindow->close();
|
||||
if (m_timerWindow)
|
||||
m_timerWindow->close();
|
||||
if (m_dicToolsWindow)
|
||||
|
@ -712,7 +716,9 @@ void MainWindow::createMenu()
|
|||
m_actionWindowsHistory = addMenuAction(menuWindows, _q("&History"), _q("Ctrl+H"),
|
||||
_q("Show/hide the game history"), SLOT(onWindowsHistory()),
|
||||
true, QIcon(":/images/playlist_16px.png"));
|
||||
m_actionWindowsTimer = addMenuAction(menuWindows, _q("&Timer"), QString(""),
|
||||
m_actionWindowsStats = addMenuAction(menuWindows, _q("&Statistics"), QString(""),
|
||||
_q("Show/hide the statistics"), SLOT(onWindowsStatistics()), true);
|
||||
m_actionWindowsTimer = addMenuAction(menuWindows, _q("Ti&mer"), QString(""),
|
||||
_q("Show/hide the timer"), SLOT(onWindowsTimer()), true);
|
||||
m_actionWindowsDicTools = addMenuAction(menuWindows, _q("&Dictionary tools"), _q("Ctrl+D"),
|
||||
_q("Show/hide the dictionary tools"), SLOT(onWindowsDicTools()), true);
|
||||
|
@ -1217,6 +1223,24 @@ void MainWindow::onWindowsHistory()
|
|||
}
|
||||
|
||||
|
||||
void MainWindow::onWindowsStatistics()
|
||||
{
|
||||
if (m_statsWindow == NULL)
|
||||
{
|
||||
// Create the window
|
||||
StatsWidget *stats = new StatsWidget;
|
||||
stats->setGame(m_game);
|
||||
m_statsWindow = new AuxWindow(*stats, _q("Statistiques"), "StatsWindow",
|
||||
m_actionWindowsStats);
|
||||
QObject::connect(this, SIGNAL(gameChanged(const PublicGame*)),
|
||||
stats, SLOT(setGame(const PublicGame*)));
|
||||
QObject::connect(this, SIGNAL(gameUpdated()),
|
||||
stats, SLOT(refresh()));
|
||||
}
|
||||
m_statsWindow->toggleVisibility();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::onWindowsTimer()
|
||||
{
|
||||
if (m_timerWindow == NULL)
|
||||
|
|
|
@ -88,6 +88,7 @@ private slots:
|
|||
void onWindowsBag();
|
||||
void onWindowsBoard();
|
||||
void onWindowsHistory();
|
||||
void onWindowsStatistics();
|
||||
void onWindowsTimer();
|
||||
void onWindowsDicTools();
|
||||
void onHelpAbout();
|
||||
|
@ -173,6 +174,8 @@ private:
|
|||
AuxWindow *m_boardWindow;
|
||||
QAction *m_actionWindowsHistory;
|
||||
AuxWindow *m_historyWindow;
|
||||
QAction *m_actionWindowsStats;
|
||||
AuxWindow *m_statsWindow;
|
||||
QAction *m_actionWindowsTimer;
|
||||
AuxWindow *m_timerWindow;
|
||||
QAction *m_actionWindowsDicTools;
|
||||
|
|
273
qt/stats_widget.cpp
Normal file
273
qt/stats_widget.cpp
Normal file
|
@ -0,0 +1,273 @@
|
|||
/*****************************************************************************
|
||||
* Eliot
|
||||
* Copyright (C) 2012 Olivier Teulière
|
||||
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*****************************************************************************/
|
||||
|
||||
#include <QtGui/QTableWidget>
|
||||
#include <QtGui/QHeaderView>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QLabel>
|
||||
|
||||
#include "stats_widget.h"
|
||||
#include "qtcommon.h"
|
||||
#include "public_game.h"
|
||||
#include "player.h"
|
||||
#include "history.h"
|
||||
#include "turn.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
INIT_LOGGER(qt, StatsWidget);
|
||||
|
||||
|
||||
StatsWidget::StatsWidget(QWidget *parent, const PublicGame *iGame)
|
||||
: QWidget(parent), m_game(iGame)
|
||||
{
|
||||
// Layout
|
||||
setLayout(new QVBoxLayout);
|
||||
|
||||
// Create the table
|
||||
m_table = new QTableWidget(this);
|
||||
m_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
// m_table->setSortingEnabled(true);
|
||||
//m_table->setAlternatingRowColors(true);
|
||||
m_table->horizontalHeader()->setMinimumSectionSize(15);
|
||||
layout()->addWidget(m_table);
|
||||
|
||||
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
setSizePolicy(policy);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void StatsWidget::setGame(const PublicGame *iGame)
|
||||
{
|
||||
m_game = iGame;
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void StatsWidget::refresh()
|
||||
{
|
||||
m_table->clear();
|
||||
if (m_game == NULL)
|
||||
return;
|
||||
|
||||
const History &gHistory = m_game->getHistory();
|
||||
m_table->setColumnCount(gHistory.getSize() + 8);
|
||||
|
||||
int col = 0;
|
||||
m_table->setHorizontalHeaderItem(col++, createItem(_q("Player")));
|
||||
for (unsigned i = 1; i <= gHistory.getSize(); ++i)
|
||||
m_table->setHorizontalHeaderItem(col++, createItem(QString("%1").arg(i)));
|
||||
m_table->setHorizontalHeaderItem(col++, createItem(_q("Sub-total")));
|
||||
m_table->setHorizontalHeaderItem(col++, createItem(_q("Warnings")));
|
||||
m_table->setHorizontalHeaderItem(col++, createItem(_q("Penalties")));
|
||||
m_table->setHorizontalHeaderItem(col++, createItem(_q("Bonuses")));
|
||||
m_table->setHorizontalHeaderItem(col++, createItem(_q("Total")));
|
||||
m_table->setHorizontalHeaderItem(col++, createItem(_q("Diff")));
|
||||
m_table->setHorizontalHeaderItem(col++, createItem(_q("Game %")));
|
||||
|
||||
unsigned nbPlayers = m_game->getNbPlayers();
|
||||
m_table->setRowCount(nbPlayers + 1);
|
||||
|
||||
// Game data
|
||||
int gameTotal = 0;
|
||||
{
|
||||
int col = 0;
|
||||
m_table->setItem(0, col++, createItem(_q("Game")));
|
||||
int score = 0;
|
||||
for (unsigned j = 0; j < gHistory.getSize(); ++j)
|
||||
{
|
||||
m_table->setCellWidget(0, col++, createCell(gHistory.getTurn(j), gHistory.getTurn(j)));
|
||||
score += gHistory.getTurn(j).getMove().getScore();
|
||||
}
|
||||
m_table->setItem(0, col++, createItem(QString("%1").arg(score)));
|
||||
// Skip the events columns
|
||||
col += 3;
|
||||
m_table->setItem(0, col++, createItem(QString("%1").arg(score)));
|
||||
// Skip the diff column
|
||||
col += 1;
|
||||
m_table->setItem(0, col++, createItem("100%"));
|
||||
|
||||
gameTotal = score;
|
||||
}
|
||||
|
||||
// Players data
|
||||
for (unsigned i = 0; i < nbPlayers; ++i)
|
||||
{
|
||||
const Player &player = m_game->getPlayer(i);
|
||||
int col = 0;
|
||||
|
||||
// Player name
|
||||
m_table->setItem(i + 1, col++, createItem(qfw(player.getName())));
|
||||
|
||||
int score = 0;
|
||||
// Normal turns
|
||||
for (unsigned j = 0; j < gHistory.getSize(); ++j)
|
||||
{
|
||||
const History &pHistory = player.getHistory();
|
||||
m_table->setCellWidget(i + 1, col++, createCell(pHistory.getTurn(j), gHistory.getTurn(j)));
|
||||
score += pHistory.getTurn(j).getMove().getScore();
|
||||
}
|
||||
|
||||
// Sub-total
|
||||
m_table->setItem(i + 1, col++, createItem(QString("%1").arg(score)));
|
||||
|
||||
// Events columns
|
||||
for (int j = 0; j <= 2; ++j)
|
||||
{
|
||||
m_table->setCellWidget(i + 1, col++, createEventCell(j, player));
|
||||
}
|
||||
|
||||
// Final score
|
||||
score += player.getSoloPoints() + player.getPenaltyPoints();
|
||||
m_table->setItem(i + 1, col++, createItem(QString("%1").arg(score)));
|
||||
|
||||
// Diff with game total
|
||||
m_table->setItem(i + 1, col++, createItem(QString("%1").arg(gameTotal - score)));
|
||||
// Global score percentage
|
||||
m_table->setItem(i + 1, col++, createItem(QString("%1%").arg(100. * score / gameTotal)));
|
||||
}
|
||||
|
||||
// Resize
|
||||
for (int i = 0; i < m_table->columnCount(); ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
m_table->horizontalHeader()->resizeSection(i, 30);
|
||||
}
|
||||
m_table->resizeColumnToContents(i);
|
||||
}
|
||||
for (int i = 0; i < m_table->rowCount(); ++i)
|
||||
{
|
||||
m_table->resizeRowToContents(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QTableWidgetItem * StatsWidget::createItem(QString iText)
|
||||
{
|
||||
QTableWidgetItem *item = new QTableWidgetItem(iText);
|
||||
item->setTextAlignment(Qt::AlignCenter);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
QString StatsWidget::getScore(const Turn &iTurn)
|
||||
{
|
||||
if (iTurn.getMove().isNull())
|
||||
return "";
|
||||
return QString("%1").arg(iTurn.getMove().getScore());
|
||||
}
|
||||
|
||||
|
||||
QString StatsWidget::getFlags(const Turn &iTurn)
|
||||
{
|
||||
QString flags(iTurn.getWarningsNb(), QChar('W'));
|
||||
if (iTurn.getPenaltyPoints() != 0)
|
||||
{
|
||||
if (flags != "")
|
||||
flags += "-";
|
||||
flags += "P";
|
||||
}
|
||||
if (iTurn.getSoloPoints() != 0)
|
||||
{
|
||||
if (flags != "")
|
||||
flags += "-";
|
||||
flags += "S";
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
QString StatsWidget::getTooltip(const Turn &iTurn, const Turn &iGameTurn)
|
||||
{
|
||||
QString tooltip = _q("Rack: %1").arg(qfw(iTurn.getPlayedRack().toString()));
|
||||
if (iTurn.getMove().isValid())
|
||||
{
|
||||
tooltip += "\n" + _q("Word: %1").arg(qfw(iTurn.getMove().getRound().getWord()));
|
||||
tooltip += "\n" + _q("Ref: %1").arg(qfw(iTurn.getMove().getRound().getCoord().toString()));
|
||||
}
|
||||
if (&iTurn != &iGameTurn)
|
||||
{
|
||||
unsigned score = iTurn.getMove().getScore();
|
||||
unsigned gameScore = iGameTurn.getMove().getScore();
|
||||
tooltip += "\n" + _q("Points: %1 (%2%)").arg(score).arg(score * 100 / gameScore);
|
||||
}
|
||||
if (iTurn.getWarningsNb())
|
||||
{
|
||||
tooltip += "\n" + _q("Warnings: %1").arg(iTurn.getWarningsNb());
|
||||
}
|
||||
if (iTurn.getPenaltyPoints())
|
||||
{
|
||||
tooltip += "\n" + _q("Penalties: %1").arg(iTurn.getPenaltyPoints());
|
||||
}
|
||||
if (iTurn.getSoloPoints())
|
||||
{
|
||||
tooltip += "\n" + _q("Solo: %1").arg(iTurn.getSoloPoints());
|
||||
}
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
|
||||
QWidget * StatsWidget::createCell(const Turn &iTurn, const Turn &iGameTurn)
|
||||
{
|
||||
QWidget *widget = new QWidget;
|
||||
QLayout *layout = new QVBoxLayout;
|
||||
layout->setContentsMargins(2, 2, 2, 2);
|
||||
widget->setLayout(layout);
|
||||
|
||||
QLabel *label1 = new QLabel;
|
||||
layout->addWidget(label1);
|
||||
QString score = getScore(iTurn);
|
||||
label1->setText(score);
|
||||
label1->setAlignment(Qt::AlignCenter);
|
||||
|
||||
QString flags = getFlags(iTurn);
|
||||
if (flags != "")
|
||||
{
|
||||
QLabel *label2 = new QLabel;
|
||||
layout->addWidget(label2);
|
||||
label2->setText(flags);
|
||||
label2->setAlignment(Qt::AlignCenter);
|
||||
}
|
||||
|
||||
QString tooltip = getTooltip(iTurn, iGameTurn);
|
||||
widget->setToolTip(tooltip);
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
||||
QWidget * StatsWidget::createEventCell(int iEvent, const Player &iPlayer)
|
||||
{
|
||||
QLabel * label = new QLabel;
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
if (iEvent == 0 && iPlayer.getWarningsNb() != 0)
|
||||
label->setText(QString("%1").arg(iPlayer.getWarningsNb()));
|
||||
else if (iEvent == 1 && iPlayer.getPenaltyPoints() != 0)
|
||||
label->setText(QString("%1").arg(iPlayer.getPenaltyPoints()));
|
||||
else if (iEvent == 2 && iPlayer.getSoloPoints() != 0)
|
||||
label->setText(QString("%1").arg(iPlayer.getSoloPoints()));
|
||||
return label;
|
||||
}
|
||||
|
||||
|
64
qt/stats_widget.h
Normal file
64
qt/stats_widget.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*****************************************************************************
|
||||
* Eliot
|
||||
* Copyright (C) 2012 Olivier Teulière
|
||||
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef STATS_WIDGET_H_
|
||||
#define STATS_WIDGET_H_
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
|
||||
class PublicGame;
|
||||
class Player;
|
||||
class Turn;
|
||||
class QTableWidget;
|
||||
class QTableWidgetItem;
|
||||
|
||||
class StatsWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT;
|
||||
DEFINE_LOGGER();
|
||||
|
||||
public:
|
||||
explicit StatsWidget(QWidget *parent = 0, const PublicGame *iGame = NULL);
|
||||
|
||||
public slots:
|
||||
void setGame(const PublicGame *iGame = NULL);
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
/// Encapsulated game, can be NULL
|
||||
const PublicGame *m_game;
|
||||
|
||||
/// Model of the game
|
||||
QTableWidget *m_table;
|
||||
|
||||
static QTableWidgetItem *createItem(QString iText);
|
||||
|
||||
static QString getScore(const Turn &iTurn);
|
||||
static QString getFlags(const Turn &iTurn);
|
||||
static QString getTooltip(const Turn &iTurn, const Turn &iGameTurn);
|
||||
static QWidget * createCell(const Turn &iTurn, const Turn &iGameTurn);
|
||||
static QWidget * createEventCell(int event, const Player &iPlayer);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in a new issue