Calculate and show how many shots over/under score is
authorSakari Poussa <spoussa@gmail.com>
Thu, 27 May 2010 17:34:33 +0000 (20:34 +0300)
committerSakari Poussa <spoussa@gmail.com>
Thu, 27 May 2010 17:34:33 +0000 (20:34 +0300)
src/main-window.cpp
src/score-common.h
src/table-model.cpp
src/table-model.h

index 12f774a..c3c3f01 100644 (file)
@@ -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)
 {
index dca5d09..a2dad65 100644 (file)
 
 #include <QColor>
 
+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;}");
index 24578e6..43a0afd 100644 (file)
@@ -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
index dc3832b..b984fc5 100644 (file)
@@ -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