From: Sakari Poussa Date: Thu, 27 May 2010 17:34:33 +0000 (+0300) Subject: Calculate and show how many shots over/under score is X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;ds=sidebyside;h=29696421b73477bde2f00ebe8fc2168c7c11e8ea;hp=d4c3c8552aae0328f8169f668b4ff0eb25ea41b1;p=scorecard Calculate and show how many shots over/under score is --- diff --git a/src/main-window.cpp b/src/main-window.cpp index 12f774a..c3c3f01 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -34,10 +34,6 @@ QString masterFile; QString logFile("/tmp/scorecard.log"); QString titleScores("ScoreCard - Scores"); QString titleCourses("ScoreCard - Courses"); -QString settingsGroup("Settings"); -QString settingsHcp("hcp"); -QString settingsHomeClub("home-club"); -QString settingsDefaultCourses("default-courses"); bool dateLessThan(const Score *s1, const Score *s2) { diff --git a/src/score-common.h b/src/score-common.h index dca5d09..a2dad65 100644 --- a/src/score-common.h +++ b/src/score-common.h @@ -10,6 +10,11 @@ #include +static QString settingsGroup("Settings"); +static QString settingsHcp("hcp"); +static QString settingsHomeClub("home-club"); +static QString settingsDefaultCourses("default-courses"); + #ifndef WANT_DEBUG #define TRACE #else @@ -37,7 +42,7 @@ class ScoreColor static QColor doubleBogey() { return Qt::red; } static QColor bad() { return Qt::red; } static QColor subTotal() { return Qt::white; } - static QColor total() { return Qt::white; } + static QColor total() { return Qt::magenta; } }; static QString statStyleSheet("QTableView {color : white;}"); diff --git a/src/table-model.cpp b/src/table-model.cpp index 24578e6..43a0afd 100644 --- a/src/table-model.cpp +++ b/src/table-model.cpp @@ -19,12 +19,14 @@ ScoreTableModel::ScoreTableModel(QObject *parent) { score = 0; course = 0; + handicap = -1; } -void ScoreTableModel::set(Score * s, Course * c) +void ScoreTableModel::set(Score * s, Course * c, int h) { score = s; course = c; + handicap = h; } int ScoreTableModel::rowCount(const QModelIndex &) const @@ -163,6 +165,13 @@ QVariant ScoreTableModel::data(const QModelIndex &index, int role) const return course->getTotal(Total); if (score && row == ROW_SCORE_2) return score->getTotal(Total); + // calculate net score + if (score && course && row == ROW_HCP_2) { + int scoreTotal = score->getTotal(Total).toInt(); + int courseTotal = course->getTotal(Total).toInt(); + int n = scoreTotal - courseTotal; + return QString("+%1").arg(n); + } } else { // data cells diff --git a/src/table-model.h b/src/table-model.h index dc3832b..b984fc5 100644 --- a/src/table-model.h +++ b/src/table-model.h @@ -23,7 +23,7 @@ class ScoreTableModel : public QAbstractTableModel public: ScoreTableModel(QObject *parent = 0); - void set(Score *, Course *); + void set(Score *, Course *, int handicap = -1); int rowCount(const QModelIndex & parent) const; int columnCount(const QModelIndex & parent) const; QVariant data(const QModelIndex & index, int role) const; @@ -48,6 +48,9 @@ private: Score *score; Club *club; Course *course; + + // Current handicap + int handicap; }; class CourseTableModel : public QAbstractTableModel