- Fixed course delete crashes
[scorecard] / src / data.h
1 /*
2  * Copyright (C) 2009 Sakari Poussa
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 2.
7  */
8
9 #ifndef __SCORE_DATA_H
10 #define __SCORE_DATA_H
11
12 #include <QDebug>
13 #include <QVector>
14 #include <QXmlAttributes>
15 #include <QDomElement>
16 #include <QDomDocument>
17
18 enum { TotalOut, TotalIn, Total };
19
20
21 class Hole {
22  public:
23   Hole(const QXmlAttributes &attrs);
24   Hole(const QDomElement node);
25   Hole(int num, QString &shots);
26   Hole(int num, QString &par, QString &hcp);
27   QDomElement toElement(QDomDocument doc);
28   QString getShots();
29   void setShots(QString& shots);
30   QString getHcp();
31   void setHcp(QString& shots);
32   QString getPar();
33   void setPar(QString& shots);
34   void dump();
35
36  private:
37   QString num, shots, putts, hcp, length, par;
38 };
39
40 class Score {
41  public:
42
43   Score(const QXmlAttributes &attrs);
44   Score(QString &iClub, QString &iCourse, QString &iDate);
45   Score(const QDomElement node);
46   Score(QVector<QString> scores, QString &club, QString &course, QString &date);
47
48   bool operator< (const Score& val) const 
49   { 
50     return date < val.getDate();
51   }
52
53   bool operator> (const Score& val) const 
54   { 
55     return date > val.getDate();
56   }
57
58   QDomElement toElement(QDomDocument doc);
59   int update(QVector<QString> &scores);
60   void addHole(Hole *iHole);
61   QString getScore(int i) const;
62   QString getTotal(int what) const;
63   const QString& getClubName() const;
64   const QString& getCourseName() const;
65   const QString& getDate() const;
66   void dump();
67
68  private:
69   QList <Hole *> holeList;
70   QString club, course, date;
71 };
72
73 class Club;
74
75 class Course {
76  public:
77   Course(const QXmlAttributes &attrs);
78   Course(const QDomElement node, Club * parent = 0);
79   Course(QString &name, QVector<QString> &, QVector<QString> &);
80   QDomElement toElement(QDomDocument doc);
81   int update(QVector<QString> &, QVector<QString> &, QVector<QString> &);
82   void addHole(Hole *iHole);
83   QString getPar(int i);
84   QString getHcp(int i);
85   QString& getName();
86   QString getTotal(int what);
87   void dump();
88   Club * parent();
89   void setParent(Club *parent);
90
91  private:
92   QList <Hole *> holeList;
93   QString name;
94   Club *club;
95 };
96
97 class Club {
98  public:
99
100   Club(const QXmlAttributes &attrs);
101   Club(const QDomElement node);
102   Club(QString &name);
103
104   QDomElement toElement(QDomDocument doc);
105   void addCourse(Course *iCourse);
106   void delCourse(Course *iCourse);
107   void dump();
108   QString& getName();
109   Course *getCourse(int pos);
110   Course *getCourse(const QString &courseName);
111   bool isEmpty();
112
113   QList <Course *> getCourseList() { return courseList; } // HACK: fixme
114
115  private:
116   QList <Course *> courseList;
117   QString name;
118
119 };
120 #endif