Low level support for more details in scores including putts, sand saves, fairwayhits...
authorSakari Poussa <spoussa@gmail.com>
Wed, 21 Jul 2010 14:51:12 +0000 (17:51 +0300)
committerSakari Poussa <spoussa@gmail.com>
Wed, 21 Jul 2010 14:51:12 +0000 (17:51 +0300)
src/data.cpp
src/data.h

index 120f317..f2a348d 100644 (file)
 ////////////////////////////////////////////////////////////////////////
 // Hole
 ////////////////////////////////////////////////////////////////////////
-
-Hole::Hole(const QXmlAttributes &attrs) {
-  if (attrs.index("num") != -1)
-    num = attrs.value("num");
-  if (attrs.index("shots") != -1)
-    shots = attrs.value("shots");
-  if (attrs.index("putts") != -1)
-    putts = attrs.value("putts");
-  if (attrs.index("hcp") != -1)
-    hcp = attrs.value("hcp");
-  if (attrs.index("length") != -1)
-    length = attrs.value("length");
-  if (attrs.index("par") != -1)
-    par = attrs.value("par");
-}    
-
-Hole::Hole(const QDomElement node) {
-  num = node.attribute("num", "");
-  shots = node.attribute("shots", "");
-  putts = node.attribute("putts", "");
-  hcp = node.attribute("hcp", "");
-  length = node.attribute("length", "");
-  par = node.attribute("par", "");
-}
-
 Hole::Hole(int num, QString &par, QString &hcp)
 {
-  this->num = QString::number(num);
-  this->par = par;
-  this->hcp = hcp;
+    this->m_num = QString::number(num);
+    this->m_par = par;
+    this->m_hcp = hcp;
 }
 
 Hole::Hole(int num, QString &shots)
 {
-  this->num = QString::number(num);
-  this->shots = shots;
+    this->m_num = QString::number(num);
+    this->m_shots = shots;
 }
 
+// XML to internal converions
+Hole::Hole(const QDomElement node) 
+{
+    m_num = node.attribute("num", "");
+    m_hcp = node.attribute("hcp", "");
+    m_length = node.attribute("length", "");
+    m_par = node.attribute("par", "");
+    m_shots = node.attribute("shots", "");
+    m_putts = node.attribute("putts", "");
+    m_greenInRegulation = node.attribute("green-in-regulation", "");
+    m_fairwayHit = node.attribute("fairway-hit", "");
+    m_sandSave = node.attribute("sand-save", "");
+    m_penalty = node.attribute("penalty", "");
+}
+
+// Internal to XML conversion
 QDomElement Hole::toElement(QDomDocument doc)
 {
-  QDomElement node = doc.createElement("hole");
+    QDomElement node = doc.createElement("hole");
+
+    if (!m_num.isEmpty())
+        node.setAttribute("num", m_num);
+    if (!m_hcp.isEmpty())
+        node.setAttribute("hcp", m_hcp);
+    if (!m_length.isEmpty())
+        node.setAttribute("length", m_length);
+    if (!m_par.isEmpty())
+        node.setAttribute("par", m_par);
+    if (!m_shots.isEmpty())
+        node.setAttribute("shots", m_shots);
+    if (!m_putts.isEmpty())
+        node.setAttribute("putts", m_putts);
+    if (!m_greenInRegulation.isEmpty())
+        node.setAttribute("green-in-regulation", m_greenInRegulation);
+    if (!m_fairwayHit.isEmpty())
+        node.setAttribute("fairway-hit", m_fairwayHit);
+    if (!m_sandSave.isEmpty())
+        node.setAttribute("sand-save", m_sandSave);
+    if (!m_penalty.isEmpty())
+        node.setAttribute("penalty", m_penalty);
+
+    return node;
+}
+
+QString Hole::hcp() 
+{
+    return m_hcp;
+}
+
+void Hole::setHcp(QString& s) 
+{
+    m_hcp = s;
+}
+
+QString Hole::par() 
+{
+    return m_par;
+}
+
+void Hole::setPar(QString& s) 
+{
+    m_par = s;
+}
+
+QString Hole::shots() 
+{
+    return m_shots;
+}
+
+void Hole::setShots(QString& s) 
+{
+    m_shots = s;
+}
+
+QString Hole::putts() 
+{
+    return m_putts;
+}
+
+void Hole::setPutts(QString& s) 
+{
+    m_putts = s;
+}
 
-  if (!num.isEmpty())
-    node.setAttribute("num", num);
-  if (!shots.isEmpty())
-    node.setAttribute("shots", shots);
-  if (!putts.isEmpty())
-    node.setAttribute("putts", putts);
-  if (!hcp.isEmpty())
-    node.setAttribute("hcp", hcp);
-  if (!length.isEmpty())
-    node.setAttribute("length", length);
-  if (!par.isEmpty())
-    node.setAttribute("par", par);
+QString Hole::greenInRegulation() 
+{
+    return m_greenInRegulation;
+}
 
-  return node;
+void Hole::setGreenInRegulation(QString& s) 
+{
+    m_greenInRegulation = s;
 }
 
-QString Hole::getShots() {
-  return shots;
+QString Hole::fairwayHit() 
+{
+    return m_fairwayHit;
 }
 
-void Hole::setShots(QString& s) {
-  shots = s;
+void Hole::setFairwayHit(QString& s) 
+{
+    m_fairwayHit = s;
 }
 
-QString Hole::getHcp() {
-  return hcp;
+QString Hole::sandSave() 
+{
+    return m_sandSave;
 }
 
-void Hole::setHcp(QString& s) {
-  hcp = s;
+void Hole::setSandSave(QString& s) 
+{
+    m_sandSave = s;
 }
 
-QString Hole::getPar() {
-  return par;
+QString Hole::penalty() 
+{
+    return m_penalty;
 }
 
-void Hole::setPar(QString& s) {
-  par = s;
+void Hole::setPenalty(QString& s) 
+{
+    m_penalty = s;
 }
 
-void Hole::dump() {
-  qDebug() << num << "(" << par << ") : " << shots << "/" << putts ; 
+void Hole::dump() 
+{
+    qDebug() << m_num << "(" << m_par << ") : " << m_shots << m_putts << m_greenInRegulation << m_fairwayHit << m_sandSave << m_penalty; 
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -103,112 +159,112 @@ void Hole::dump() {
 
 Score::Score(const QXmlAttributes &attrs) 
 {
-  club = attrs.value("club");
-  course = attrs.value("course");
-  date = attrs.value("date");
+    club = attrs.value("club");
+    course = attrs.value("course");
+    date = attrs.value("date");
 }
 
 Score::Score(QString &iClub, QString &iCourse, QString &iDate) 
 {
-  club = iClub;
-  course = iCourse;
-  date = iDate;
+    club = iClub;
+    course = iCourse;
+    date = iDate;
 }
 
 Score::Score(QVector<QString> scores, QString &club, QString &course, QString &date) 
 {
-  this->club = club;
-  this->course = course;
-  this->date = date;
+    this->club = club;
+    this->course = course;
+    this->date = date;
 
-  for (int i = 0; i < scores.size(); i++) {
-    Hole *hole = new Hole(i+1, scores[i]);
-    holeList << hole;
-  }
+    for (int i = 0; i < scores.size(); i++) {
+        Hole *hole = new Hole(i+1, scores[i]);
+        holeList << hole;
+    }
 }
 
 Score::Score(const QDomElement node) {
-  club = node.attribute("club", "");
-  course = node.attribute("course", "");
-  date = node.attribute("date", "");
+    club = node.attribute("club", "");
+    course = node.attribute("course", "");
+    date = node.attribute("date", "");
 }
 
 QDomElement Score::toElement(QDomDocument doc)
 {
-  QDomElement node = doc.createElement("score");
+    QDomElement node = doc.createElement("score");
 
-  node.setAttribute("club", club);
-  node.setAttribute("course", course);
-  node.setAttribute("date", date);
+    node.setAttribute("club", club);
+    node.setAttribute("course", course);
+    node.setAttribute("date", date);
 
-  for (int i=0; i < holeList.size(); i++) {
-    Hole *hole = holeList.at(i);
-    node.appendChild(hole->toElement(doc));
-  }
-  return node;
+    for (int i=0; i < holeList.size(); i++) {
+        Hole *hole = holeList.at(i);
+        node.appendChild(hole->toElement(doc));
+    }
+    return node;
 }
 
 int Score::update(QVector<QString> &scores)
 {
-  for (int i = 0; i < scores.size(); i++) {
-    Hole *hole = holeList.at(i);
-    if (hole->getShots() != scores[i])
-      hole->setShots(scores[i]);
-  }
-  return 0;
+    for (int i = 0; i < scores.size(); i++) {
+        Hole *hole = holeList.at(i);
+        if (hole->shots() != scores[i])
+            hole->setShots(scores[i]);
+    }
+    return 0;
 }
 
 void Score::addHole(Hole *iHole) {
-  holeList << iHole;
+    holeList << iHole;
 }
   
 QString Score::getScore(int i) const 
 {
-  if (i >= 0 && i < holeList.size())
-    return holeList.at(i)->getShots();
-  else
-    return QString("-");
+    if (i >= 0 && i < holeList.size())
+        return holeList.at(i)->shots();
+    else
+        return QString("-");
 }
   
 QString Score::getTotal(int what) const
 {
-  int tot = 0;
+    int tot = 0;
 
-  if (what == Total)
-    for (int i=0; i <= 17; i++)
-      tot += holeList.at(i)->getShots().toInt();
+    if (what == Total)
+        for (int i=0; i <= 17; i++)
+            tot += holeList.at(i)->shots().toInt();
 
-  if (what == TotalOut)
-    for (int i=0; i <= 8; i++)
-      tot += holeList.at(i)->getShots().toInt();
+    if (what == TotalOut)
+        for (int i=0; i <= 8; i++)
+            tot += holeList.at(i)->shots().toInt();
  
-  if (what == TotalIn)
-    for (int i=9; i <= 17; i++)
-      tot += holeList.at(i)->getShots().toInt();
+    if (what == TotalIn)
+        for (int i=9; i <= 17; i++)
+            tot += holeList.at(i)->shots().toInt();
 
-  return QString("%1").arg(tot);
+    return QString("%1").arg(tot);
 }
 
 const QString& Score::getClubName() const
 {
-  return club;
+    return club;
 }
 
 const QString& Score::getCourseName() const
 {
-  return course;
+    return course;
 }
 
 const QString& Score::getDate() const
 {
-  return date;
+    return date;
 }
 
 void Score::dump()
 {
-  qDebug() << club << course << date ; 
-  for (int i=0; i<holeList.size(); i++)
-    holeList.at(i)->dump();
+    qDebug() << club << course << date ; 
+    for (int i=0; i<holeList.size(); i++)
+        holeList.at(i)->dump();
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -216,7 +272,7 @@ void Score::dump()
 ////////////////////////////////////////////////////////////////////////
 
 Course::Course(const QXmlAttributes &attrs) {
-  name = attrs.value("name");
+    name = attrs.value("name");
 }
 
 Course::Course(const QDomElement node, Club * parent)
@@ -229,12 +285,12 @@ Course::Course(QString &name,
               QVector<QString> &par,
               QVector<QString> &hcp)
 {
-  this->name = name;
+    this->name = name;
   
-  for (int i = 0; i < par.size(); i++) {
-    Hole *hole = new Hole(i+1, par[i], hcp[i]);
-    holeList << hole;
-  }
+    for (int i = 0; i < par.size(); i++) {
+        Hole *hole = new Hole(i+1, par[i], hcp[i]);
+        holeList << hole;
+    }
 }
 
 Club * Course::parent()
@@ -249,78 +305,78 @@ void Course::setParent(Club *parent)
 
 QDomElement Course::toElement(QDomDocument doc)
 {
-  QDomElement node = doc.createElement("course");
+    QDomElement node = doc.createElement("course");
 
-  node.setAttribute("name", name);
+    node.setAttribute("name", name);
 
-  for (int i=0; i < holeList.size(); i++) {
-    Hole *hole = holeList.at(i);
-    node.appendChild(hole->toElement(doc));
-  }
-  return node;
+    for (int i=0; i < holeList.size(); i++) {
+        Hole *hole = holeList.at(i);
+        node.appendChild(hole->toElement(doc));
+    }
+    return node;
 }
 
 int Course::update(QVector<QString> &par,
                   QVector<QString> &hcp,
                   QVector<QString> &len)
 {
-  Q_UNUSED(len);
-  for (int i = 0; i < par.size(); i++) {
-    Hole *hole = holeList.at(i);
-    if (hole->getPar() != par[i])
-      hole->setPar(par[i]);
-    if (hole->getHcp() != hcp[i])
-      hole->setHcp(hcp[i]);
-  }
-  return 0;
+    Q_UNUSED(len);
+    for (int i = 0; i < par.size(); i++) {
+        Hole *hole = holeList.at(i);
+        if (hole->par() != par[i])
+            hole->setPar(par[i]);
+        if (hole->hcp() != hcp[i])
+            hole->setHcp(hcp[i]);
+    }
+    return 0;
 }
 
 void Course::addHole(Hole *iHole) {
-  holeList << iHole;
+    holeList << iHole;
 }
 
 QString Course::getPar(int i) {
-  if (i >= 0 && i < holeList.size())
-    return holeList.at(i)->getPar();
-  else
-    return QString("-");
+    if (i >= 0 && i < holeList.size())
+        return holeList.at(i)->par();
+    else
+        return QString("-");
 }
 
 QString Course::getHcp(int i) {
-  if (i >= 0 && i < holeList.size())
-    return holeList.at(i)->getHcp();
-  else
-    return QString("-");
+    if (i >= 0 && i < holeList.size())
+        return holeList.at(i)->hcp();
+    else
+        return QString("-");
 }
   
 QString& Course::getName() 
 { 
-  return name; 
+    return name; 
 }
 
 QString Course::getTotal(int what) {
-  int tot = 0;
+    int tot = 0;
 
-  if (what == Total)
-    for (int i = 0; i < 18; i++)
-      tot += holeList.at(i)->getPar().toInt();
+    if (what == Total)
+        for (int i = 0; i < 18; i++)
+            tot += holeList.at(i)->par().toInt();
 
-  if (what == TotalOut)
-    for (int i = 0; i < 9; i++)
-      tot += holeList.at(i)->getPar().toInt();
+    if (what == TotalOut)
+        for (int i = 0; i < 9; i++)
+            tot += holeList.at(i)->par().toInt();
  
-  if (what == TotalIn)
-    for (int i = 9; i < 18; i++)
-      tot += holeList.at(i)->getPar().toInt();
+    if (what == TotalIn)
+        for (int i = 9; i < 18; i++)
+            tot += holeList.at(i)->par().toInt();
 
-  return QString("%1").arg(tot);
+    return QString("%1").arg(tot);
 }
 
 
 void Course::dump() {
-  qDebug() << " " << name;
-  for (int i=0; i<holeList.size(); i++)
-    holeList.at(i)->dump();
+    qDebug() << " " << name;
+    for (int i=0; i<holeList.size(); i++)
+        holeList.at(i)->dump();
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -328,29 +384,29 @@ void Course::dump() {
 ////////////////////////////////////////////////////////////////////////
 
 Club::Club(const QXmlAttributes &attrs, bool readOnly) 
-  : m_readOnly(readOnly)
+    : m_readOnly(readOnly)
 {
     m_homeClub = false;
     name = attrs.value("name");
 }
 
 Club::Club(const QDomElement node, bool readOnly) 
-  : m_readOnly(readOnly)
+    : m_readOnly(readOnly)
 {
     m_homeClub = false;
     name = node.attribute("name", "");
 }
 
 Club::Club(QString &name, bool readOnly)
-  : m_readOnly(readOnly)
+    : m_readOnly(readOnly)
 {
     m_homeClub = false;
     this->name = name;
 }
 
 void Club::addCourse(Course *iCourse) {
-  courseList << iCourse;
-  iCourse->setParent(this);
+    courseList << iCourse;
+    iCourse->setParent(this);
 }
 
 void Club::delCourse(Course * course) {
@@ -375,39 +431,39 @@ bool Club::isEmpty()
 
 QDomElement Club::toElement(QDomDocument doc)
 {
-  QDomElement node = doc.createElement("club");
+    QDomElement node = doc.createElement("club");
 
-  node.setAttribute("name", name);
+    node.setAttribute("name", name);
 
-  for (int i=0; i < courseList.size(); i++) {
-    Course *course = courseList.at(i);
-    node.appendChild(course->toElement(doc));
-  }
-  return node;
+    for (int i=0; i < courseList.size(); i++) {
+        Course *course = courseList.at(i);
+        node.appendChild(course->toElement(doc));
+    }
+    return node;
 }
   
 void Club::dump() {
-  qDebug() << name;
-  for (int i=0; i<courseList.size(); i++)
-    courseList.at(i)->dump();
+    qDebug() << name;
+    for (int i=0; i<courseList.size(); i++)
+        courseList.at(i)->dump();
 }
 
 QString& Club::getName() { return name; }
 
 Course *Club::getCourse(int pos) {
-  return courseList.at(pos);
+    return courseList.at(pos);
 }
 
 Course *Club::getCourse(const QString &courseName) 
 {
-  QListIterator<Course *> i(courseList);
-  Course *c = 0;
-
-  while (i.hasNext()) {
-    c = i.next();
-    if (c->getName() == courseName) {
-      return c;
+    QListIterator<Course *> i(courseList);
+    Course *c = 0;
+
+    while (i.hasNext()) {
+        c = i.next();
+        if (c->getName() == courseName) {
+            return c;
+        }
     }
-  }
-  return 0;
+    return 0;
 }
index c05c6c3..30a7a17 100644 (file)
@@ -20,21 +20,48 @@ enum { TotalOut, TotalIn, Total };
 
 class Hole {
 public:
-    Hole(const QXmlAttributes &attrs);
-    Hole(const QDomElement node);
     Hole(int num, QString &shots);
     Hole(int num, QString &par, QString &hcp);
+    Hole(const QDomElement node);
     QDomElement toElement(QDomDocument doc);
-    QString getShots();
-    void setShots(QString& shots);
-    QString getHcp();
+
+    QString hcp();
     void setHcp(QString& shots);
-    QString getPar();
+
+    QString par();
     void setPar(QString& shots);
+
+    QString shots();
+    void setShots(QString& shots);
+
+    QString putts();
+    void setPutts(QString& shots);
+
+    QString greenInRegulation();
+    void setGreenInRegulation(QString& value);
+
+    QString fairwayHit();
+    void setFairwayHit(QString& value);
+
+    QString sandSave();
+    void setSandSave(QString& value);
+
+    QString penalty();
+    void setPenalty(QString& value);
+
     void dump();
 
 private:
-    QString num, shots, putts, hcp, length, par;
+    QString m_num;               // Hole's number (1-18)
+    QString m_hcp;               // Hole's HCP value
+    QString m_length;            // Hole lenght in meters (todo: multiple)
+    QString m_par;               // Hole's par
+    QString m_shots;             // Number of shots
+    QString m_putts;             // Number of putts
+    QString m_greenInRegulation; // Green in regulation
+    QString m_fairwayHit;        // Fairway hit
+    QString m_sandSave;          // Sandsave
+    QString m_penalty;           // Other penalty
 };
 
 class Score {