- Fixed course delete crashes
[scorecard] / src / data.cpp
index 782f3da..ad0813c 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"
 
 ////////////////////////////////////////////////////////////////////////
@@ -198,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();
 }
@@ -211,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, 
@@ -227,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");
@@ -244,6 +264,7 @@ 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])
@@ -321,6 +342,22 @@ Club::Club(QString &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::isEmpty()
+{
+    bool rc = false;
+    if (courseList.count() == 0)
+        rc = true;
+    return rc;
 }
 
 QDomElement Club::toElement(QDomDocument doc)