+/*
+ * Copyright (C) 2009 Sakari Poussa
+ *
+ * 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, version 2.
+ */
#include <QColor>
#include <QBrush>
#include <QFont>
#include "table-model.h"
-Qt::ItemFlags ScoreTableModel::flags ( const QModelIndex & index )
+QString empty("");
+#define SC_BLUE_THEME
+QColor colorHoleBg(26, 26, 26);
+QColor colorHoleFg(Qt::yellow);
+QColor colorBirdie(138, 226, 52);
+QColor colorPar(Qt::black);
+#ifdef SC_ORANGE_THEME
+QColor colorBogey(0xfc, 0xaf, 0x3e);
+QColor colorDoubleBogey(0xf5, 0x79, 0x00);
+QColor colorBad(0xce, 0x5c, 0x00);
+#endif
+#ifdef SC_BLUE_THEME
+QColor colorBogey(0x72, 0x9f, 0xcf);
+QColor colorDoubleBogey(0x34, 0x65, 0xa4);
+QColor colorBad(0x20, 0x4a, 0x87);
+#endif
+QColor colorSubTotal(Qt::black);
+QColor colorTotal(Qt::black);
+
+Qt::ItemFlags ScoreTableModel::flags (const QModelIndex & index)
{
- return Qt::NoItemFlags;
+ return 0;
+}
+
+void ScoreTableModel::setMode(int m)
+{
+ currentMode = m;
+}
+
+int ScoreTableModel::mode(void)
+{
+ return currentMode;
}
// Assign the 'sList' to internal 'scoreList'. Set the current score
return str;
}
+QString& ScoreTableModel::clubName(void)
+{
+ if (club)
+ return club->getName();
+
+ return empty;
+}
+
+QString& ScoreTableModel::courseName(void)
+{
+ if (course)
+ return course->getName();
+
+ return empty;
+}
+
Course *ScoreTableModel::findCourse(const QString &clubName,
const QString &courseName)
{
return 0;
}
+Club *ScoreTableModel::getClub(void)
+{
+ return club;
+}
+
+Course *ScoreTableModel::getCourse(void)
+{
+ return course;
+}
+
+Score *ScoreTableModel::getScore(void)
+{
+ return score;
+}
+
void ScoreTableModel::first()
{
if (score && course) {
int ScoreTableModel::rowCount(const QModelIndex & parent) const
{
- return ROW_COUNT;
+ return 8;
}
int ScoreTableModel::columnCount(const QModelIndex & parent) const
{
- return COL_COUNT + 2; // 2 for in/out and tot columns
+ return 9 + 2; // 2 for in/out and tot columns
}
QModelIndex ScoreTableModel::index(int row, int column, const QModelIndex &parent) const
{
if (hasIndex(row, column, parent)) {
int flag = (parent.column() > 0) ? parent.column() : 0;
- //qDebug() << "index() " << row << "/" << column << "/ flag: " << flag <<"//" << parent;
return createIndex(row, column, flag);
}
else {
}
}
-#define ROW_PAR 0
-#define ROW_HCP 1
-#define ROW_SCORE 2
-
QVariant ScoreTableModel::data(const QModelIndex &index, int role) const
{
- if (!index.isValid())
- return QVariant();
+ // TODO: move away from the stack
- if (!course || !score)
+ if (!index.isValid())
return QVariant();
int row = index.row();
return Qt::AlignCenter;
}
- // Does this item belog to front or back nine
- int offset = index.internalId() ? 9 : 0;
if (index.column() > 10)
return QVariant();
//
// COLORS
//
- QColor colorBirdie(Qt::yellow);
- QColor colorPar(Qt::green);
- QColor colorBogey(Qt::darkGreen);
- QColor colorDoubleBogey(Qt::cyan);
- QColor colorBad(Qt::white);
- QColor colorSubTotal(Qt::lightGray);
- QColor colorTotal(Qt::gray);
-
if (role == Qt::BackgroundRole) {
- int par = (course->getPar(index.column() + offset)).toInt();
- int shots = (score->getScore(index.column() + offset)).toInt();
+ // Hole numbers 1-18. All hole nums, in, out and tot cell but not
+ // the empty cell.
+ if ((row == ROW_HOLE && col != 10) || row == ROW_HOLE_2) {
+ QBrush brush(colorHoleBg);
+ return brush;
+ }
+ if (score && course && (row == ROW_SCORE || row == ROW_SCORE_2)) {
+ int par;
+ int shots;
+ if (row == ROW_SCORE) {
+ par = course->getPar(col).toInt();
+ shots = score->getScore(col).toInt();
+ }
+ else {
+ par = course->getPar(col + 9).toInt();
+ shots = score->getScore(col + 9).toInt();
+ }
- if (index.row() == ROW_SCORE) {
- if (index.column() == 10 && offset == 9) {
+ if (col == 10 && row == ROW_SCORE_2) {
// Total score
QBrush brush(colorTotal);
- //brush.setStyle(Qt::Dense6Pattern);
return brush;
}
- if (col == 9 && row == 2) {
+ if (col == 9) {
// In and Out scores
QBrush brush(colorSubTotal);
- //brush.setStyle(Qt::Dense7Pattern);
return brush;
}
- if (index.column() < 9) {
+ if (col < 9) {
if (shots == par) {
// Par
QBrush brush(colorPar);
QBrush brush(colorDoubleBogey);
return brush;
}
+ if (shots > (par+2)) {
+ // Very bad
+ QBrush brush(colorBad);
+ return brush;
+ }
}
}
return QVariant();
// FONT
//
if (role == Qt::FontRole) {
- if (index.row() == ROW_SCORE) {
- if (index.column() == 10 && offset == 9) {
+ if (row == ROW_SCORE_2 && col == 10) {
QFont font;
font.setBold(true);
return font;
- }
}
}
//
- // DATA
+ // NUMBERS
//
if (role == Qt::DisplayRole) {
- // In/Out column
- if (index.column() == 9) {
- if (index.row() == ROW_PAR)
- if (offset == 0)
- return course->getTotal(TotalOut);
- else
- return course->getTotal(TotalIn);
- else if (index.row() == ROW_SCORE) {
- if (offset == 0)
- return score->getTotal(TotalOut);
- else
- return score->getTotal(TotalIn);
- }
- else
- return QVariant();
- }
- // Tot column
- if (index.column() == 10) {
- if (index.row() == ROW_PAR && offset == 9)
+ if (col == 9) {
+ // In/out label
+ if (row == ROW_HOLE)
+ return QString("Out");
+ if (row == ROW_HOLE_2)
+ return QString("In");
+
+ // In/Out for par
+ if (score && course && row == ROW_PAR)
+ return course->getTotal(TotalOut);
+ if (score && course && row == ROW_PAR_2)
+ return course->getTotal(TotalIn);
+
+ // In/Out for score
+ if (score && row == ROW_SCORE)
+ return score->getTotal(TotalOut);
+ if (score && row == ROW_SCORE_2)
+ return score->getTotal(TotalIn);
+
+ }
+ else if (col == 10) {
+ // Total label
+ if (row == ROW_HOLE_2)
+ return QString("Tot");
+ // Total score
+ if (score && course && row == ROW_PAR_2)
return course->getTotal(Total);
- else if (index.row() == ROW_SCORE && offset == 9)
+ if (score && row == ROW_SCORE_2)
return score->getTotal(Total);
- else
- return QVariant();
}
-
- //qDebug() << "data() " << index << "/" << offset;
- switch(index.row()) {
- case ROW_PAR:
- return course->getPar(index.column() + offset);
- case ROW_HCP:
- return course->getHcp(index.column() + offset);
- case ROW_SCORE:
- return score->getScore(index.column() + offset);
+ else {
+ // data cells
+ switch(row) {
+ case ROW_HOLE:
+ return col + 1;
+ case ROW_HOLE_2:
+ return col + 10;
+ case ROW_PAR:
+ if (score && course)
+ return course->getPar(col);
+ case ROW_PAR_2:
+ if (score && course)
+ return course->getPar(col + 9);
+ case ROW_HCP:
+ if (score && course)
+ return course->getHcp(col);
+ case ROW_HCP_2:
+ if (score && course)
+ return course->getHcp(col + 9);
+ case ROW_SCORE:
+ if (score)
+ return score->getScore(col);
+ case ROW_SCORE_2:
+ if (score)
+ return score->getScore(col + 9);
+ }
}
}
return QVariant();
QVariant ScoreTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
- if (role != Qt::DisplayRole)
- return QVariant();
-
- // TODO: how to diff between the two table views (no index?)
-
- if (orientation == Qt::Horizontal)
- if (section >= 0 && section <= 8)
- return QString("%1").arg(section+1);
- else if (section == 9)
- return QString(""); // was: I/O
- else
- return QString(""); // was: Tot
- else {
- switch(section) {
- case 0:
- return QString("Par");
- case 1:
- return QString("HCP");
- case 2:
- return QString("Score");
- }
+ // Only vertical header -- horizontal is hidden
+ if (orientation == Qt::Horizontal)
+ return QVariant();
+
+#if 0
+ if (role == Qt::BackgroundRole) {
+ QColor colorHoleBg(Qt::darkGray);
+ QBrush brush(colorHoleBg);
+ return brush;
+ }
+#endif
+ if (role == Qt::DisplayRole) {
+ switch(section) {
+ case ROW_PAR:
+ case ROW_PAR_2:
+ return QString("Par");
+ case ROW_HCP:
+ case ROW_HCP_2:
+ return QString("HCP");
+ case ROW_SCORE:
+ case ROW_SCORE_2:
+ return QString("Score");
}
return QVariant();
+ }
+
+ return QVariant();
}
-
+