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 void Hole::setShots(QString& s) {
72 QString Hole::getHcp() {
76 void Hole::setHcp(QString& s) {
80 QString Hole::getPar() {
84 void Hole::setPar(QString& s) {
89 qDebug() << num << "(" << par << ") : " << shots << "/" << putts ;
92 ////////////////////////////////////////////////////////////////////////
94 ////////////////////////////////////////////////////////////////////////
96 Score::Score(const QXmlAttributes &attrs)
98 club = attrs.value("club");
99 course = attrs.value("course");
100 date = attrs.value("date");
103 Score::Score(QString &iClub, QString &iCourse, QString &iDate)
110 Score::Score(QVector<QString> scores, QString &club, QString &course, QString &date)
113 this->course = course;
116 for (int i = 0; i < scores.size(); i++) {
117 Hole *hole = new Hole(i+1, scores[i]);
122 Score::Score(const QDomElement node) {
123 club = node.attribute("club", "");
124 course = node.attribute("course", "");
125 date = node.attribute("date", "");
128 QDomElement Score::toElement(QDomDocument doc)
130 QDomElement node = doc.createElement("score");
132 node.setAttribute("club", club);
133 node.setAttribute("course", course);
134 node.setAttribute("date", date);
136 for (int i=0; i < holeList.size(); i++) {
137 Hole *hole = holeList.at(i);
138 node.appendChild(hole->toElement(doc));
143 int Score::update(QVector<QString> &scores)
145 for (int i = 0; i < scores.size(); i++) {
146 Hole *hole = holeList.at(i);
147 if (hole->getShots() != scores[i])
148 hole->setShots(scores[i]);
153 void Score::addHole(Hole *iHole) {
157 QString Score::getScore(int i) const
159 if (i >= 0 && i < holeList.size())
160 return holeList.at(i)->getShots();
165 QString Score::getTotal(int what) const
170 for (int i=0; i <= 17; i++)
171 tot += holeList.at(i)->getShots().toInt();
173 if (what == TotalOut)
174 for (int i=0; i <= 8; i++)
175 tot += holeList.at(i)->getShots().toInt();
178 for (int i=9; i <= 17; i++)
179 tot += holeList.at(i)->getShots().toInt();
181 return QString("%1").arg(tot);
184 const QString& Score::getClubName() const
189 const QString& Score::getCourseName() const
194 const QString& Score::getDate() const
201 qDebug() << club << course << date ;
202 for (int i=0; i<holeList.size(); i++)
203 holeList.at(i)->dump();
206 ////////////////////////////////////////////////////////////////////////
208 ////////////////////////////////////////////////////////////////////////
210 Course::Course(const QXmlAttributes &attrs) {
211 name = attrs.value("name");
214 Course::Course(const QDomElement node) {
215 name = node.attribute("name", "");
218 Course::Course(QString &name,
219 QVector<QString> &par,
220 QVector<QString> &hcp)
224 for (int i = 0; i < par.size(); i++) {
225 Hole *hole = new Hole(i+1, par[i], hcp[i]);
230 QDomElement Course::toElement(QDomDocument doc)
232 QDomElement node = doc.createElement("course");
234 node.setAttribute("name", name);
236 for (int i=0; i < holeList.size(); i++) {
237 Hole *hole = holeList.at(i);
238 node.appendChild(hole->toElement(doc));
243 int Course::update(QVector<QString> &par,
244 QVector<QString> &hcp,
245 QVector<QString> &len)
247 for (int i = 0; i < par.size(); i++) {
248 Hole *hole = holeList.at(i);
249 if (hole->getPar() != par[i])
250 hole->setPar(par[i]);
251 if (hole->getHcp() != hcp[i])
252 hole->setHcp(hcp[i]);
257 void Course::addHole(Hole *iHole) {
261 QString Course::getPar(int i) {
262 if (i >= 0 && i < holeList.size())
263 return holeList.at(i)->getPar();
268 QString Course::getHcp(int i) {
269 if (i >= 0 && i < holeList.size())
270 return holeList.at(i)->getHcp();
275 QString& Course::getName()
280 QString Course::getTotal(int what) {
284 for (int i = 0; i < 18; i++)
285 tot += holeList.at(i)->getPar().toInt();
287 if (what == TotalOut)
288 for (int i = 0; i < 9; i++)
289 tot += holeList.at(i)->getPar().toInt();
292 for (int i = 9; i < 18; i++)
293 tot += holeList.at(i)->getPar().toInt();
295 return QString("%1").arg(tot);
299 void Course::dump() {
300 qDebug() << " " << name;
301 for (int i=0; i<holeList.size(); i++)
302 holeList.at(i)->dump();
305 ////////////////////////////////////////////////////////////////////////
307 ////////////////////////////////////////////////////////////////////////
309 Club::Club(const QXmlAttributes &attrs) {
310 name = attrs.value("name");
313 Club::Club(const QDomElement node) {
314 name = node.attribute("name", "");
317 Club::Club(QString &name)
322 void Club::addCourse(Course *iCourse) {
323 courseList << iCourse;
326 QDomElement Club::toElement(QDomDocument doc)
328 QDomElement node = doc.createElement("club");
330 node.setAttribute("name", name);
332 for (int i=0; i < courseList.size(); i++) {
333 Course *course = courseList.at(i);
334 node.appendChild(course->toElement(doc));
341 for (int i=0; i<courseList.size(); i++)
342 courseList.at(i)->dump();
345 QString& Club::getName() { return name; }
347 Course *Club::getCourse(int pos) {
348 return courseList.at(pos);
351 Course *Club::getCourse(const QString &courseName)
353 QListIterator<Course *> i(courseList);
356 while (i.hasNext()) {
358 if (c->getName() == courseName) {