Calculate and show how many shots over/under score is
[scorecard] / src / table-model.cpp
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