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 &shots)
33 this->num = QString::number(num);
37 QDomElement Hole::toElement(QDomDocument doc)
39 QDomElement node = doc.createElement("hole");
42 node.setAttribute("num", num);
44 node.setAttribute("shots", shots);
46 node.setAttribute("putts", putts);
48 node.setAttribute("hcp", hcp);
49 if (!length.isEmpty())
50 node.setAttribute("length", length);
52 node.setAttribute("par", par);
57 QString Hole::getShots() {
61 QString Hole::getHcp() {
65 QString Hole::getPar() {
70 qDebug() << num << "(" << par << ") : " << shots << "/" << putts ;
73 ////////////////////////////////////////////////////////////////////////
75 ////////////////////////////////////////////////////////////////////////
77 Score::Score(const QXmlAttributes &attrs)
79 club = attrs.value("club");
80 course = attrs.value("course");
81 date = attrs.value("date");
84 Score::Score(QString &iClub, QString &iCourse, QString &iDate)
91 Score::Score(QVector<QString> scores, QString &club, QString &course, QString &date)
94 this->course = course;
97 for (int i=0; i<scores.size(); i++) {
98 Hole *hole = new Hole(i+1, scores[i]);
104 Score::Score(const QDomElement node) {
105 club = node.attribute("club", "");
106 course = node.attribute("course", "");
107 date = node.attribute("date", "");
110 QDomElement Score::toElement(QDomDocument doc)
112 QDomElement node = doc.createElement("score");
114 node.setAttribute("club", club);
115 node.setAttribute("course", course);
116 node.setAttribute("date", date);
118 for (int i=0; i < holeList.size(); i++) {
119 Hole *hole = holeList.at(i);
120 node.appendChild(hole->toElement(doc));
125 void Score::addHole(Hole *iHole) {
129 QString Score::getScore(int i) {
130 if (i >= 0 && i < holeList.size())
131 return holeList.at(i)->getShots();
136 QString Score::getTotal(int what) {
140 for (int i=0; i <= 17; i++)
141 tot += holeList.at(i)->getShots().toInt();
143 if (what == TotalOut)
144 for (int i=0; i <= 8; i++)
145 tot += holeList.at(i)->getShots().toInt();
148 for (int i=9; i <= 17; i++)
149 tot += holeList.at(i)->getShots().toInt();
151 return QString("%1").arg(tot);
154 QString& Score::getClubName() {
158 QString& Score::getCourseName() {
162 QString& Score::getDate() {
167 qDebug() << club << " " << course << " " << date ;
168 for (int i=0; i<holeList.size(); i++)
169 holeList.at(i)->dump();
172 ////////////////////////////////////////////////////////////////////////
174 ////////////////////////////////////////////////////////////////////////
176 Course::Course(const QXmlAttributes &attrs) {
177 name = attrs.value("name");
180 Course::Course(const QDomElement node) {
181 name = node.attribute("name", "");
184 QDomElement Course::toElement(QDomDocument doc)
186 QDomElement node = doc.createElement("course");
188 node.setAttribute("name", name);
190 for (int i=0; i < holeList.size(); i++) {
191 Hole *hole = holeList.at(i);
192 node.appendChild(hole->toElement(doc));
197 void Course::addHole(Hole *iHole) {
201 QString Course::getPar(int i) {
202 if (i >= 0 && i < holeList.size())
203 return holeList.at(i)->getPar();
208 QString Course::getHcp(int i) {
209 if (i >= 0 && i < holeList.size())
210 return holeList.at(i)->getHcp();
215 QString& Course::getName()
220 QString Course::getTotal(int what) {
224 for (int i = 0; i < 18; i++)
225 tot += holeList.at(i)->getPar().toInt();
227 if (what == TotalOut)
228 for (int i = 0; i < 9; i++)
229 tot += holeList.at(i)->getPar().toInt();
232 for (int i = 9; i < 18; i++)
233 tot += holeList.at(i)->getPar().toInt();
235 return QString("%1").arg(tot);
239 void Course::dump() {
240 qDebug() << " " << name;
241 for (int i=0; i<holeList.size(); i++)
242 holeList.at(i)->dump();
245 ////////////////////////////////////////////////////////////////////////
247 ////////////////////////////////////////////////////////////////////////
249 Club::Club(const QXmlAttributes &attrs) {
250 name = attrs.value("name");
253 Club::Club(const QDomElement node) {
254 name = node.attribute("name", "");
257 void Club::addCourse(Course *iCourse) {
258 courseList << iCourse;
261 QDomElement Club::toElement(QDomDocument doc)
263 QDomElement node = doc.createElement("club");
265 node.setAttribute("name", name);
267 for (int i=0; i < courseList.size(); i++) {
268 Course *course = courseList.at(i);
269 node.appendChild(course->toElement(doc));
276 for (int i=0; i<courseList.size(); i++)
277 courseList.at(i)->dump();
280 QString& Club::getName() { return name; }
282 Course *Club::getCourse(int pos) {
283 return courseList.at(pos);
286 Course *Club::getCourse(QString &courseName) {
287 QListIterator<Course *> i(courseList);
290 while (i.hasNext()) {
292 if (c->getName() == courseName) {
293 qDebug() << "Match " << courseName;