diff --git a/qt/stats_widget.cpp b/qt/stats_widget.cpp index d657559..f3e0750 100644 --- a/qt/stats_widget.cpp +++ b/qt/stats_widget.cpp @@ -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(); +} + + diff --git a/qt/stats_widget.h b/qt/stats_widget.h index c1bd167..1ea0e40 100644 --- a/qt/stats_widget.h +++ b/qt/stats_widget.h @@ -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;