Merge branch 'master' of /opt/src/sb1/qt/scorecard
[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(int num, QString &shots);
24     Hole(int num, QString &par, QString &hcp);
25     Hole(const QDomElement node);
26     QDomElement toElement(QDomDocument doc);
27
28     QString hcp();
29     void setHcp(QString& shots);
30
31     QString par();
32     void setPar(QString& shots);
33
34     QString shots();
35     void setShots(QString& shots);
36
37     QString putts();
38     void setPutts(QString& shots);
39
40     QString greenInRegulation();
41     void setGreenInRegulation(QString& value);
42
43     QString fairwayHit();
44     void setFairwayHit(QString& value);
45
46     QString sandSave();
47     void setSandSave(QString& value);
48
49     QString penalty();
50     void setPenalty(QString& value);
51
52     void dump();
53
54 private:
55     QString m_num;               // Hole's number (1-18)
56     QString m_hcp;               // Hole's HCP value
57     QString m_length;            // Hole lenght in meters (todo: multiple)
58     QString m_par;               // Hole's par
59     QString m_shots;             // Number of shots
60     QString m_putts;             // Number of putts
61     QString m_greenInRegulation; // Green in regulation
62     QString m_fairwayHit;        // Fairway hit
63     QString m_sandSave;          // Sandsave
64     QString m_penalty;           // Other penalty
65 };
66
67 class Score {
68 public:
69     Score(const QXmlAttributes &attrs);
70     Score(QString &iClub, QString &iCourse, QString &iDate);
71     Score(const QDomElement node);
72     Score(QVector<QString> scores, QString &club, QString &course, QString &date);
73
74     bool operator< (const Score& val) const 
75     { 
76         return date < val.getDate();
77     }
78     
79     bool operator> (const Score& val) const 
80     { 
81         return date > val.getDate();
82     }
83
84     QDomElement toElement(QDomDocument doc);
85     int update(QVector<QString> &scores);
86     void addHole(Hole *iHole);
87     QString getScore(int i) const;
88     QString getTotal(int what) const;
89     const QString& getClubName() const;
90     const QString& getCourseName() const;
91     const QString& getDate() const;
92     void dump();
93
94 private:
95     QList <Hole *> holeList;
96     QString club, course, date;
97 };
98
99 class Club;
100
101 class Course {
102 public:
103     Course(const QXmlAttributes &attrs);
104     Course(const QDomElement node, Club * parent = 0);
105     Course(QString &name, QVector<QString> &, QVector<QString> &);
106     QDomElement toElement(QDomDocument doc);
107     int update(QVector<QString> &, QVector<QString> &, QVector<QString> &);
108     void addHole(Hole *iHole);
109     QString getPar(int i);
110     QString getHcp(int i);
111     QString& getName();
112     QString getTotal(int what);
113     void dump();
114     Club * parent();
115     void setParent(Club *parent);
116
117 private:
118     QList <Hole *> holeList;
119     QString name;
120     Club *club;
121 };
122
123 class Club {
124 public:
125     Club(const QXmlAttributes &attrs, bool readOnly = false);
126     Club(const QDomElement node, bool readOnly = false);
127     Club(QString &name, bool readOnly = false);
128
129     QDomElement toElement(QDomDocument doc);
130     void addCourse(Course *iCourse);
131     void delCourse(Course *iCourse);
132     void dump();
133     QString& getName();
134     Course *getCourse(int pos);
135     Course *getCourse(const QString &courseName);
136     bool isEmpty();
137     bool isReadOnly();
138     void setHomeClub(bool value) { m_homeClub = value; }
139     bool isHomeClub() { return m_homeClub; }
140
141     QList <Course *> getCourseList() { return courseList; } // HACK: fixme
142
143 private:
144     bool m_readOnly;
145     bool m_homeClub;
146     QList <Course *> courseList;
147     QString name;
148 };
149 #endif