Add club-master.xml r/o file for distributed courses. User added courses go to club...
[scorecard] / src / data.cpp
index edfff01..19e52f0 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * 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 "data.h"
 
 ////////////////////////////////////////////////////////////////////////
@@ -73,10 +81,18 @@ QString Hole::getHcp() {
   return hcp;
 }
 
+void Hole::setHcp(QString& s) {
+  hcp = s;
+}
+
 QString Hole::getPar() {
   return par;
 }
 
+void Hole::setPar(QString& s) {
+  par = s;
+}
+
 void Hole::dump() {
   qDebug() << num << "(" << par << ") : " << shots << "/" << putts ; 
 }
@@ -132,7 +148,7 @@ QDomElement Score::toElement(QDomDocument doc)
   return node;
 }
 
-int Score::update(QVector<QString> scores)
+int Score::update(QVector<QString> &scores)
 {
   for (int i = 0; i < scores.size(); i++) {
     Hole *hole = holeList.at(i);
@@ -190,7 +206,7 @@ const QString& Score::getDate() const
 
 void Score::dump()
 {
-  qDebug() << club << " " << course << " " << date ; 
+  qDebug() << club << course << date ; 
   for (int i=0; i<holeList.size(); i++)
     holeList.at(i)->dump();
 }
@@ -203,8 +219,10 @@ Course::Course(const QXmlAttributes &attrs) {
   name = attrs.value("name");
 }
 
-Course::Course(const QDomElement node) {
-  name = node.attribute("name", "");
+Course::Course(const QDomElement node, Club * parent)
+    : club(parent)
+{
+    name = node.attribute("name", "");
 }
 
 Course::Course(QString &name, 
@@ -219,6 +237,16 @@ Course::Course(QString &name,
   }
 }
 
+Club * Course::parent()
+{
+    return club;
+}
+
+void Course::setParent(Club *parent)
+{
+    club = parent;
+}
+
 QDomElement Course::toElement(QDomDocument doc)
 {
   QDomElement node = doc.createElement("course");
@@ -232,6 +260,21 @@ QDomElement Course::toElement(QDomDocument 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;
+}
+
 void Course::addHole(Hole *iHole) {
   holeList << iHole;
 }
@@ -284,21 +327,47 @@ void Course::dump() {
 // Club
 ////////////////////////////////////////////////////////////////////////
 
-Club::Club(const QXmlAttributes &attrs) {
-  name = attrs.value("name");
+Club::Club(const QXmlAttributes &attrs, bool readOnly) 
+  : m_readOnly(readOnly)
+{
+    name = attrs.value("name");
 }
 
-Club::Club(const QDomElement node) {
-  name = node.attribute("name", "");
+Club::Club(const QDomElement node, bool readOnly) 
+  : m_readOnly(readOnly)
+{
+    name = node.attribute("name", "");
 }
 
-Club::Club(QString &name)
+Club::Club(QString &name, bool readOnly)
+  : m_readOnly(readOnly)
 {
-  this->name = name;
+    this->name = name;
 }
 
 void Club::addCourse(Course *iCourse) {
   courseList << iCourse;
+  iCourse->setParent(this);
+}
+
+void Club::delCourse(Course * course) {
+    int index = courseList.indexOf(course);
+
+    if (index != -1)
+        courseList.removeAt(index);
+}
+
+bool Club::isReadOnly()
+{
+    return m_readOnly;
+}
+
+bool Club::isEmpty()
+{
+    bool rc = false;
+    if (courseList.count() == 0)
+        rc = true;
+    return rc;
 }
 
 QDomElement Club::toElement(QDomDocument doc)