3 ////////////////////////////////////////////////////////////////////////
5 ////////////////////////////////////////////////////////////////////////
7 Hole::Hole(const QXmlAttributes &attrs) {
8 if (attrs.index("num") != -1)
9 num = attrs.value("num");
10 if (attrs.index("shots") != -1)
11 shots = attrs.value("shots");
12 if (attrs.index("putts") != -1)
13 putts = attrs.value("putts");
14 if (attrs.index("hcp") != -1)
15 hcp = attrs.value("hcp");
16 if (attrs.index("length") != -1)
17 length = attrs.value("length");
18 if (attrs.index("par") != -1)
19 par = attrs.value("par");
22 Hole::Hole(const QDomElement node) {
23 num = node.attribute("num", "");
24 shots = node.attribute("shots", "");
25 putts = node.attribute("putts", "");
26 hcp = node.attribute("hcp", "");
27 length = node.attribute("length", "");
28 par = node.attribute("par", "");
31 Hole::Hole(int num, QString &par, QString &hcp)
33 this->num = QString::number(num);
38 Hole::Hole(int num, QString &shots)
40 this->num = QString::number(num);
44 QDomElement Hole::toElement(QDomDocument doc)
46 QDomElement node = doc.createElement("hole");
49 node.setAttribute("num", num);
51 node.setAttribute("shots", shots);
53 node.setAttribute("putts", putts);
55 node.setAttribute("hcp", hcp);
56 if (!length.isEmpty())
57 node.setAttribute("length", length);
59 node.setAttribute("par", par);
64 QString Hole::getShots() {
68 QString Hole::getHcp() {
72 QString Hole::getPar() {
77 qDebug() << num << "(" << par << ") : " << shots << "/" << putts ;
80 ////////////////////////////////////////////////////////////////////////
82 ////////////////////////////////////////////////////////////////////////
84 Score::Score(const QXmlAttributes &attrs)
86 club = attrs.value("club");
87 course = attrs.value("course");
88 date = attrs.value("date");
91 Score::Score(QString &iClub, QString &iCourse, QString &iDate)
98 Score::Score(QVector<QString> scores, QString &club, QString &course, QString &date)
101 this->course = course;
104 for (int i = 0; i < scores.size(); i++) {
105 Hole *hole = new Hole(i+1, scores[i]);
110 Score::Score(const QDomElement node) {
111 club = node.attribute("club", "");
112 course = node.attribute("course", "");
113 date = node.attribute("date", "");
116 QDomElement Score::toElement(QDomDocument doc)
118 QDomElement node = doc.createElement("score");
120 node.setAttribute("club", club);
121 node.setAttribute("course", course);
122 node.setAttribute("date", date);
124 for (int i=0; i < holeList.size(); i++) {
125 Hole *hole = holeList.at(i);
126 node.appendChild(hole->toElement(doc));
131 void Score::addHole(Hole *iHole) {
135 QString Score::getScore(int i) {
136 if (i >= 0 && i < holeList.size())
137 return holeList.at(i)->getShots();
142 QString Score::getTotal(int what) {
146 for (int i=0; i <= 17; i++)
147 tot += holeList.at(i)->getShots().toInt();
149 if (what == TotalOut)
150 for (int i=0; i <= 8; i++)
151 tot += holeList.at(i)->getShots().toInt();
154 for (int i=9; i <= 17; i++)
155 tot += holeList.at(i)->getShots().toInt();
157 return QString("%1").arg(tot);
160 QString& Score::getClubName() {
164 QString& Score::getCourseName() {
168 QString& Score::getDate() {
173 qDebug() << club << " " << course << " " << date ;
174 for (int i=0; i<holeList.size(); i++)
175 holeList.at(i)->dump();
178 ////////////////////////////////////////////////////////////////////////
180 ////////////////////////////////////////////////////////////////////////
182 Course::Course(const QXmlAttributes &attrs) {
183 name = attrs.value("name");
186 Course::Course(const QDomElement node) {
187 name = node.attribute("name", "");
190 Course::Course(QString &name,
191 QVector<QString> &par,
192 QVector<QString> &hcp)
196 for (int i = 0; i < par.size(); i++) {
197 Hole *hole = new Hole(i+1, par[i], hcp[i]);
202 QDomElement Course::toElement(QDomDocument doc)
204 QDomElement node = doc.createElement("course");
206 node.setAttribute("name", name);
208 for (int i=0; i < holeList.size(); i++) {
209 Hole *hole = holeList.at(i);
210 node.appendChild(hole->toElement(doc));
215 void Course::addHole(Hole *iHole) {
219 QString Course::getPar(int i) {
220 if (i >= 0 && i < holeList.size())
221 return holeList.at(i)->getPar();
226 QString Course::getHcp(int i) {
227 if (i >= 0 && i < holeList.size())
228 return holeList.at(i)->getHcp();
233 QString& Course::getName()
238 QString Course::getTotal(int what) {
242 for (int i = 0; i < 18; i++)
243 tot += holeList.at(i)->getPar().toInt();
245 if (what == TotalOut)
246 for (int i = 0; i < 9; i++)
247 tot += holeList.at(i)->getPar().toInt();
250 for (int i = 9; i < 18; i++)
251 tot += holeList.at(i)->getPar().toInt();
253 return QString("%1").arg(tot);
257 void Course::dump() {
258 qDebug() << " " << name;
259 for (int i=0; i<holeList.size(); i++)
260 holeList.at(i)->dump();
263 ////////////////////////////////////////////////////////////////////////
265 ////////////////////////////////////////////////////////////////////////
267 Club::Club(const QXmlAttributes &attrs) {
268 name = attrs.value("name");
271 Club::Club(const QDomElement node) {
272 name = node.attribute("name", "");
275 Club::Club(QString &name)
280 void Club::addCourse(Course *iCourse) {
281 courseList << iCourse;
284 QDomElement Club::toElement(QDomDocument doc)
286 QDomElement node = doc.createElement("club");
288 node.setAttribute("name", name);
290 for (int i=0; i < courseList.size(); i++) {
291 Course *course = courseList.at(i);
292 node.appendChild(course->toElement(doc));
299 for (int i=0; i<courseList.size(); i++)
300 courseList.at(i)->dump();
303 QString& Club::getName() { return name; }
305 Course *Club::getCourse(int pos) {
306 return courseList.at(pos);
309 Course *Club::getCourse(QString &courseName)
311 QListIterator<Course *> i(courseList);
314 while (i.hasNext()) {
316 if (c->getName() == courseName) {