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) const
137 if (i >= 0 && i < holeList.size())
138 return holeList.at(i)->getShots();
143 QString Score::getTotal(int what) const
148 for (int i=0; i <= 17; i++)
149 tot += holeList.at(i)->getShots().toInt();
151 if (what == TotalOut)
152 for (int i=0; i <= 8; i++)
153 tot += holeList.at(i)->getShots().toInt();
156 for (int i=9; i <= 17; i++)
157 tot += holeList.at(i)->getShots().toInt();
159 return QString("%1").arg(tot);
162 const QString& Score::getClubName() const
167 const QString& Score::getCourseName() const
172 const QString& Score::getDate() const
179 qDebug() << club << " " << course << " " << date ;
180 for (int i=0; i<holeList.size(); i++)
181 holeList.at(i)->dump();
184 ////////////////////////////////////////////////////////////////////////
186 ////////////////////////////////////////////////////////////////////////
188 Course::Course(const QXmlAttributes &attrs) {
189 name = attrs.value("name");
192 Course::Course(const QDomElement node) {
193 name = node.attribute("name", "");
196 Course::Course(QString &name,
197 QVector<QString> &par,
198 QVector<QString> &hcp)
202 for (int i = 0; i < par.size(); i++) {
203 Hole *hole = new Hole(i+1, par[i], hcp[i]);
208 QDomElement Course::toElement(QDomDocument doc)
210 QDomElement node = doc.createElement("course");
212 node.setAttribute("name", name);
214 for (int i=0; i < holeList.size(); i++) {
215 Hole *hole = holeList.at(i);
216 node.appendChild(hole->toElement(doc));
221 void Course::addHole(Hole *iHole) {
225 QString Course::getPar(int i) {
226 if (i >= 0 && i < holeList.size())
227 return holeList.at(i)->getPar();
232 QString Course::getHcp(int i) {
233 if (i >= 0 && i < holeList.size())
234 return holeList.at(i)->getHcp();
239 QString& Course::getName()
244 QString Course::getTotal(int what) {
248 for (int i = 0; i < 18; i++)
249 tot += holeList.at(i)->getPar().toInt();
251 if (what == TotalOut)
252 for (int i = 0; i < 9; i++)
253 tot += holeList.at(i)->getPar().toInt();
256 for (int i = 9; i < 18; i++)
257 tot += holeList.at(i)->getPar().toInt();
259 return QString("%1").arg(tot);
263 void Course::dump() {
264 qDebug() << " " << name;
265 for (int i=0; i<holeList.size(); i++)
266 holeList.at(i)->dump();
269 ////////////////////////////////////////////////////////////////////////
271 ////////////////////////////////////////////////////////////////////////
273 Club::Club(const QXmlAttributes &attrs) {
274 name = attrs.value("name");
277 Club::Club(const QDomElement node) {
278 name = node.attribute("name", "");
281 Club::Club(QString &name)
286 void Club::addCourse(Course *iCourse) {
287 courseList << iCourse;
290 QDomElement Club::toElement(QDomDocument doc)
292 QDomElement node = doc.createElement("club");
294 node.setAttribute("name", name);
296 for (int i=0; i < courseList.size(); i++) {
297 Course *course = courseList.at(i);
298 node.appendChild(course->toElement(doc));
305 for (int i=0; i<courseList.size(); i++)
306 courseList.at(i)->dump();
309 QString& Club::getName() { return name; }
311 Course *Club::getCourse(int pos) {
312 return courseList.at(pos);
315 Course *Club::getCourse(const QString &courseName)
317 QListIterator<Course *> i(courseList);
320 while (i.hasNext()) {
322 if (c->getName() == courseName) {