GPLv2 license
[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   QDomElement toElement(QDomDocument doc);
54   int update(QVector<QString> &scores);
55   void addHole(Hole *iHole);
56   QString getScore(int i) const;
57   QString getTotal(int what) const;
58   const QString& getClubName() const;
59   const QString& getCourseName() const;
60   const QString& getDate() const;
61   void dump();
62
63  private:
64   QList <Hole *> holeList;
65   QString club, course, date;
66 };
67
68 class Course {
69  public:
70   Course(const QXmlAttributes &attrs);
71   Course(const QDomElement node);
72   Course(QString &name, QVector<QString> &, QVector<QString> &);
73   QDomElement toElement(QDomDocument doc);
74   int update(QVector<QString> &, QVector<QString> &, QVector<QString> &);
75   void addHole(Hole *iHole);
76   QString getPar(int i);
77   QString getHcp(int i);
78   QString& getName();
79   QString getTotal(int what);
80   void dump();
81
82  private:
83   QList <Hole *> holeList;
84   QString name;
85 };
86
87 class Club {
88  public:
89
90   Club(const QXmlAttributes &attrs);
91   Club(const QDomElement node);
92   Club(QString &name);
93
94   QDomElement toElement(QDomDocument doc);
95   void addCourse(Course *iCourse);
96   void dump();
97   QString& getName();
98   Course *getCourse(int pos);
99   Course *getCourse(const QString &courseName);
100
101   QList <Course *> getCourseList() { return courseList; } // HACK: fixme
102
103  private:
104   QList <Course *> courseList;
105   QString name;
106
107 };
108 #endif