mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-25 21:59:30 +01:00
Stats: allow flipping the table
This commit is contained in:
parent
63c7128d3e
commit
3f2568db5d
2 changed files with 28 additions and 9 deletions
|
@ -49,11 +49,9 @@ const QColor StatsWidget::PassBrush(210, 210, 210);
|
|||
const QColor StatsWidget::InvalidBrush(255, 0, 0);
|
||||
|
||||
|
||||
const bool HORIZONTAL = false;
|
||||
|
||||
|
||||
StatsWidget::StatsWidget(QWidget *parent, const PublicGame *iGame)
|
||||
: QWidget(parent), m_game(iGame), m_autoResizeColumns(true)
|
||||
: QWidget(parent), m_game(iGame), m_autoResizeColumns(true),
|
||||
m_isHorizontal(false)
|
||||
{
|
||||
// Layout
|
||||
setLayout(new QVBoxLayout);
|
||||
|
@ -82,6 +80,15 @@ StatsWidget::StatsWidget(QWidget *parent, const PublicGame *iGame)
|
|||
QObject::connect(lockSizesAction, SIGNAL(toggled(bool)),
|
||||
this, SLOT(lockSizesChanged(bool)));
|
||||
|
||||
// Add a context menu option to flip the table
|
||||
QAction *flipAction = new QAction(_q("Flip the table"), this);
|
||||
flipAction->setStatusTip(_q("Flip the table so that rows and columns are exchanged.\n"
|
||||
"This allows sorting the players by ranking, for example."));
|
||||
m_table->addAction(flipAction);
|
||||
m_table->setContextMenuPolicy(Qt::ActionsContextMenu);
|
||||
QObject::connect(flipAction, SIGNAL(triggered()),
|
||||
this, SLOT(flipTable()));
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
@ -242,7 +249,7 @@ void StatsWidget::refresh()
|
|||
|
||||
QModelIndex StatsWidget::getIndex(int row, int col) const
|
||||
{
|
||||
if (HORIZONTAL)
|
||||
if (m_isHorizontal)
|
||||
return m_model->index(row, col);
|
||||
else
|
||||
return m_model->index(col, row);
|
||||
|
@ -251,7 +258,7 @@ QModelIndex StatsWidget::getIndex(int row, int col) const
|
|||
|
||||
void StatsWidget::setSectionHidden(int index, bool iHide)
|
||||
{
|
||||
if (HORIZONTAL)
|
||||
if (m_isHorizontal)
|
||||
m_table->setColumnHidden(index, iHide);
|
||||
else
|
||||
m_table->setRowHidden(index, iHide);
|
||||
|
@ -260,15 +267,15 @@ void StatsWidget::setSectionHidden(int index, bool iHide)
|
|||
|
||||
void StatsWidget::setModelSize(int rowCount, int colCount)
|
||||
{
|
||||
m_model->setRowCount(HORIZONTAL ? rowCount : colCount);
|
||||
m_model->setColumnCount(HORIZONTAL ? colCount : rowCount);
|
||||
m_model->setRowCount(m_isHorizontal ? rowCount : colCount);
|
||||
m_model->setColumnCount(m_isHorizontal ? colCount : rowCount);
|
||||
}
|
||||
|
||||
|
||||
void StatsWidget::setModelHeader(int index, const QString &iText, bool iPlayerNames)
|
||||
{
|
||||
Qt::Orientation orientation;
|
||||
if ((HORIZONTAL && iPlayerNames) || (!HORIZONTAL && !iPlayerNames))
|
||||
if ((m_isHorizontal && iPlayerNames) || (!m_isHorizontal && !iPlayerNames))
|
||||
orientation = Qt::Vertical;
|
||||
else
|
||||
orientation = Qt::Horizontal;
|
||||
|
@ -402,3 +409,10 @@ void StatsWidget::lockSizesChanged(bool checked)
|
|||
}
|
||||
|
||||
|
||||
void StatsWidget::flipTable()
|
||||
{
|
||||
m_isHorizontal = !m_isHorizontal;
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ public slots:
|
|||
|
||||
private slots:
|
||||
void lockSizesChanged(bool checked);
|
||||
void flipTable();
|
||||
|
||||
private:
|
||||
/// Encapsulated game, can be NULL
|
||||
|
@ -62,6 +63,10 @@ private:
|
|||
/// Indicate whether the columns should be resized automatically
|
||||
bool m_autoResizeColumns;
|
||||
|
||||
/// Orientation of the table (horizontal means the players are displayed as rows)
|
||||
bool m_isHorizontal;
|
||||
|
||||
|
||||
static const QColor WarningBrush;
|
||||
static const QColor PenaltyBrush;
|
||||
static const QColor SoloBrush;
|
||||
|
|
Loading…
Reference in a new issue