www updates
[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     Score(const QXmlAttributes &attrs);
43     Score(QString &iClub, QString &iCourse, QString &iDate);
44     Score(const QDomElement node);
45     Score(QVector<QString> scores, QString &club, QString &course, QString &date);
46
47     bool operator< (const Score& val) const 
48     { 
49         return date < val.getDate();
50     }
51     
52     bool operator> (const Score& val) const 
53     { 
54         return date > val.getDate();
55     }
56
57     QDomElement toElement(QDomDocument doc);
58     int update(QVector<QString> &scores);
59     void addHole(Hole *iHole);
60     QString getScore(int i) const;
61     QString getTotal(int what) const;
62     const QString& getClubName() const;
63     const QString& getCourseName() const;
64     const QString& getDate() const;
65     void dump();
66
67 private:
68     QList <Hole *> holeList;
69     QString club, course, date;
70 };
71
72 class Club;
73
74 class Course {
75 public:
76     Course(const QXmlAttributes &attrs);
77     Course(const QDomElement node, Club * parent = 0);
78     Course(QString &name, QVector<QString> &, QVector<QString> &);
79     QDomElement toElement(QDomDocument doc);
80     int update(QVector<QString> &, QVector<QString> &, QVector<QString> &);
81     void addHole(Hole *iHole);
82     QString getPar(int i);
83     QString getHcp(int i);
84     QString& getName();
85     QString getTotal(int what);
86     void dump();
87     Club * parent();
88     void setParent(Club *parent);
89
90 private:
91     QList <Hole *> holeList;
92     QString name;
93     Club *club;
94 };
95
96 class Club {
97 public:
98     Club(const QXmlAttributes &attrs, bool readOnly = false);
99     Club(const QDomElement node, bool readOnly = false);
100     Club(QString &name, bool readOnly = false);
101
102     QDomElement toElement(QDomDocument doc);
103     void addCourse(Course *iCourse);
104     void delCourse(Course *iCourse);
105     void dump();
106     QString& getName();
107     Course *getCourse(int pos);
108     Course *getCourse(const QString &courseName);
109     bool isEmpty();
110     bool isReadOnly();
111     void setHomeClub(bool value) { m_homeClub = value; }
112     bool isHomeClub() { return m_homeClub; }
113
114     QList <Course *> getCourseList() { return courseList; } // HACK: fixme
115
116 private:
117     bool m_readOnly;
118     bool m_homeClub;
119     QList <Course *> courseList;
120     QString name;
121 };
122 #endif