From 8e1c55c79d17dc1893cf0ab81291cd0d95504a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Mon, 18 Jun 2012 23:00:41 +0200 Subject: [PATCH] StatsWidget: use the player name for the title of the columns. Also hide some rows depending on the game type. --- qt/stats_widget.cpp | 103 +++++++++++++++++++++++++++----------------- qt/stats_widget.h | 3 +- 2 files changed, 65 insertions(+), 41 deletions(-) diff --git a/qt/stats_widget.cpp b/qt/stats_widget.cpp index e14d88b..b182688 100644 --- a/qt/stats_widget.cpp +++ b/qt/stats_widget.cpp @@ -31,6 +31,8 @@ #include "player.h" #include "history.h" #include "turn.h" +#include "game_params.h" +#include "settings.h" using namespace std; @@ -45,7 +47,7 @@ const QColor StatsWidget::PassBrush(210, 210, 210); const QColor StatsWidget::InvalidBrush(255, 0, 0); -const bool HORIZONTAL = true; +const bool HORIZONTAL = false; StatsWidget::StatsWidget(QWidget *parent, const PublicGame *iGame) @@ -57,12 +59,10 @@ StatsWidget::StatsWidget(QWidget *parent, const PublicGame *iGame) // Create the table m_table = new QTableView(this); m_table->setEditTriggers(QAbstractItemView::NoEditTriggers); + m_table->horizontalHeader()->setHighlightSections(false); + m_table->verticalHeader()->setHighlightSections(false); m_table->horizontalHeader()->setMinimumSectionSize(15); m_table->verticalHeader()->setMinimumSectionSize(15); - if (HORIZONTAL) - m_table->verticalHeader()->setVisible(false); - else - m_table->horizontalHeader()->setVisible(false); //m_table->setSortingEnabled(true); layout()->addWidget(m_table); @@ -89,20 +89,38 @@ void StatsWidget::refresh() unsigned histSize = m_game == NULL ? 0 : m_game->getHistory().getSize(); unsigned nbPlayers = m_game == NULL ? 0 : m_game->getNbPlayers(); - setModelSize(nbPlayers + 1, histSize + 9); + setModelSize(nbPlayers + 1, histSize + 8); + // Some fields are displayed only in some cases + const bool isArbit = m_game != NULL && + m_game->getParams().getMode() == GameParams::kARBITRATION; + const bool canHaveSolos = m_game != NULL && + m_game->getParams().getMode() == GameParams::kDUPLICATE && + Settings::Instance().getInt("duplicate.solo-players") <= (int)m_game->getNbPlayers(); + + // Define columns (or rows, depending on the orientation) int col = 0; - setModelHeader(col++, _q("Table")); - setModelHeader(col++, _q("Player")); + setSectionHidden(col, !isArbit); + setModelHeader(col++, _q("Table"), false); + for (unsigned i = 1; i <= histSize; ++i) - setModelHeader(col++, QString("#%1").arg(i)); - setModelHeader(col++, _q("Sub-total")); - setModelHeader(col++, _q("Warnings")); - setModelHeader(col++, _q("Penalties")); - setModelHeader(col++, _q("Solo points")); - setModelHeader(col++, _q("Total")); - setModelHeader(col++, _q("Diff")); - setModelHeader(col++, _q("Game %")); + setModelHeader(col++, QString("#%1").arg(i), false); + + setSectionHidden(col, !isArbit && !canHaveSolos); + setModelHeader(col++, _q("Sub-total"), false); + setSectionHidden(col, !isArbit); + setModelHeader(col++, _q("Warnings"), false); + setSectionHidden(col, !isArbit); + setModelHeader(col++, _q("Penalties"), false); + setSectionHidden(col, !isArbit && !canHaveSolos); + setModelHeader(col++, _q("Solo points"), false); + + setModelHeader(col++, _q("Total"), false); + setModelHeader(col++, _q("Diff"), false); + setModelHeader(col++, _q("Game %"), false); + + // Define the header for the Game pseudo-player + setModelHeader(0, _q("Game"), true); if (m_game == NULL) return; @@ -117,7 +135,6 @@ void StatsWidget::refresh() int col = 0; // Skip the table number ++col; - setModelText(getIndex(row, col++), _q("Game")); int score = 0; for (unsigned j = 0; j < gHistory.getSize(); ++j) { @@ -140,13 +157,11 @@ void StatsWidget::refresh() { const Player &player = m_game->getPlayer(i); int col = 0; + setModelHeader(i + 1, qfw(player.getName()), true); // Table number setModelText(getIndex(i + 1, col++), player.getTableNb()); - // Player name - setModelText(getIndex(i + 1, col++), qfw(player.getName())); - int score = 0; // Normal turns for (unsigned j = 0; j < gHistory.getSize(); ++j) @@ -179,18 +194,8 @@ void StatsWidget::refresh() } // Resize - for (int i = 0; i < m_model->columnCount(); ++i) - { - if (i > 0) - { - m_table->horizontalHeader()->resizeSection(i, 30); - } - m_table->resizeColumnToContents(i); - } - for (int i = 0; i < m_model->rowCount(); ++i) - { - m_table->resizeRowToContents(i); - } + m_table->resizeRowsToContents(); + m_table->resizeColumnsToContents(); } @@ -203,6 +208,15 @@ QModelIndex StatsWidget::getIndex(int row, int col) const } +void StatsWidget::setSectionHidden(int index, bool iHide) +{ + if (HORIZONTAL) + m_table->setColumnHidden(index, iHide); + else + m_table->setRowHidden(index, iHide); +} + + void StatsWidget::setModelSize(int rowCount, int colCount) { m_model->setRowCount(HORIZONTAL ? rowCount : colCount); @@ -210,11 +224,15 @@ void StatsWidget::setModelSize(int rowCount, int colCount) } -void StatsWidget::setModelHeader(int col, const QString &iText) +void StatsWidget::setModelHeader(int index, const QString &iText, bool iPlayerNames) { - Qt::Orientation orientation = HORIZONTAL ? Qt::Horizontal : Qt::Vertical; - m_model->setHeaderData(col, orientation, iText); - m_model->setHeaderData(col, orientation, Qt::AlignCenter, Qt::TextAlignmentRole); + Qt::Orientation orientation; + if ((HORIZONTAL && iPlayerNames) || (!HORIZONTAL && !iPlayerNames)) + orientation = Qt::Vertical; + else + orientation = Qt::Horizontal; + m_model->setHeaderData(index, orientation, iText); + m_model->setHeaderData(index, orientation, Qt::AlignCenter, Qt::TextAlignmentRole); } @@ -308,11 +326,16 @@ QString StatsWidget::getTooltip(const Turn &iTurn, const Turn &iGameTurn) const // Points int score = move.getScore(); int gameScore = iGameTurn.getMove().getScore(); - QString scoreString = _q("Points: %1 (%2)").arg(score); - if (score == gameScore) - tooltip += "\n" + scoreString.arg(_q("max")); + if (move.isNull()) + tooltip += _q("Points: %1").arg(score); else - tooltip += "\n" + scoreString.arg(score - gameScore); + { + QString scoreString = _q("Points: %1 (%2)").arg(score); + if (score == gameScore) + tooltip += "\n" + scoreString.arg(_q("max")); + else + tooltip += "\n" + scoreString.arg(score - gameScore); + } if (iTurn.getWarningsNb()) { diff --git a/qt/stats_widget.h b/qt/stats_widget.h index 08b24c4..6e8aff0 100644 --- a/qt/stats_widget.h +++ b/qt/stats_widget.h @@ -66,8 +66,9 @@ private: QModelIndex getIndex(int row, int col) const; QString getTooltip(const Turn &iTurn, const Turn &iGameTurn) const; + void setSectionHidden(int index, bool iHide); void setModelSize(int rowCount, int colCount); - void setModelHeader(int col, const QString &iText); + void setModelHeader(int index, const QString &iText, bool iPlayerNames); void setModelText(const QModelIndex &iIndex, const QVariant &iData, bool useBoldFont = false); void setModelTurnData(const QModelIndex &iIndex,