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 QString Hole::getPar() {
81 qDebug() << num << "(" << par << ") : " << shots << "/" << putts ;
84 ////////////////////////////////////////////////////////////////////////
86 ////////////////////////////////////////////////////////////////////////
88 Score::Score(const QXmlAttributes &attrs)
90 club = attrs.value("club");
91 course = attrs.value("course");
92 date = attrs.value("date");
95 Score::Score(QString &iClub, QString &iCourse, QString &iDate)
102 Score::Score(QVector<QString> scores, QString &club, QString &course, QString &date)
105 this->course = course;
108 for (int i = 0; i < scores.size(); i++) {
109 Hole *hole = new Hole(i+1, scores[i]);
114 Score::Score(const QDomElement node) {
115 club = node.attribute("club", "");
116 course = node.attribute("course", "");
117 date = node.attribute("date", "");
120 QDomElement Score::toElement(QDomDocument doc)
122 QDomElement node = doc.createElement("score");
124 node.setAttribute("club", club);
125 node.setAttribute("course", course);
126 node.setAttribute("date", date);
128 for (int i=0; i < holeList.size(); i++) {
129 Hole *hole = holeList.at(i);
130 node.appendChild(hole->toElement(doc));
135 int Score::update(QVector<QString> scores)
137 for (int i = 0; i < scores.size(); i++) {
138 Hole *hole = holeList.at(i);
139 if (hole->getShots() != scores[i])
140 hole->setShots(scores[i]);
145 void Score::addHole(Hole *iHole) {
149 QString Score::getScore(int i) const
151 if (i >= 0 && i < holeList.size())
152 return holeList.at(i)->getShots();
157 QString Score::getTotal(int what) const
162 for (int i=0; i <= 17; i++)
163 tot += holeList.at(i)->getShots().toInt();
165 if (what == TotalOut)
166 for (int i=0; i <= 8; i++)
167 tot += holeList.at(i)->getShots().toInt();
170 for (int i=9; i <= 17; i++)
171 tot += holeList.at(i)->getShots().toInt();
173 return QString("%1").arg(tot);
176 const QString& Score::getClubName() const
181 const QString& Score::getCourseName() const
186 const QString& Score::getDate() const
193 qDebug() << club << " " << course << " " << date ;
194 for (int i=0; i<holeList.size(); i++)
195 holeList.at(i)->dump();
198 ////////////////////////////////////////////////////////////////////////
200 ////////////////////////////////////////////////////////////////////////
202 Course::Course(const QXmlAttributes &attrs) {
203 name = attrs.value("name");
206 Course::Course(const QDomElement node) {
207 name = node.attribute("name", "");
210 Course::Course(QString &name,
211 QVector<QString> &par,
212 QVector<QString> &hcp)
216 for (int i = 0; i < par.size(); i++) {
217 Hole *hole = new Hole(i+1, par[i], hcp[i]);
222 QDomElement Course::toElement(QDomDocument doc)
224 QDomElement node = doc.createElement("course");
226 node.setAttribute("name", name);
228 for (int i=0; i < holeList.size(); i++) {
229 Hole *hole = holeList.at(i);
230 node.appendChild(hole->toElement(doc));
235 void Course::addHole(Hole *iHole) {
239 QString Course::getPar(int i) {
240 if (i >= 0 && i < holeList.size())
241 return holeList.at(i)->getPar();
246 QString Course::getHcp(int i) {
247 if (i >= 0 && i < holeList.size())
248 return holeList.at(i)->getHcp();
253 QString& Course::getName()
258 QString Course::getTotal(int what) {
262 for (int i = 0; i < 18; i++)
263 tot += holeList.at(i)->getPar().toInt();
265 if (what == TotalOut)
266 for (int i = 0; i < 9; i++)
267 tot += holeList.at(i)->getPar().toInt();
270 for (int i = 9; i < 18; i++)
271 tot += holeList.at(i)->getPar().toInt();
273 return QString("%1").arg(tot);
277 void Course::dump() {
278 qDebug() << " " << name;
279 for (int i=0; i<holeList.size(); i++)
280 holeList.at(i)->dump();
283 ////////////////////////////////////////////////////////////////////////
285 ////////////////////////////////////////////////////////////////////////
287 Club::Club(const QXmlAttributes &attrs) {
288 name = attrs.value("name");
291 Club::Club(const QDomElement node) {
292 name = node.attribute("name", "");
295 Club::Club(QString &name)
300 void Club::addCourse(Course *iCourse) {
301 courseList << iCourse;
304 QDomElement Club::toElement(QDomDocument doc)
306 QDomElement node = doc.createElement("club");
308 node.setAttribute("name", name);
310 for (int i=0; i < courseList.size(); i++) {
311 Course *course = courseList.at(i);
312 node.appendChild(course->toElement(doc));
319 for (int i=0; i<courseList.size(); i++)
320 courseList.at(i)->dump();
323 QString& Club::getName() { return name; }
325 Course *Club::getCourse(int pos) {
326 return courseList.at(pos);
329 Course *Club::getCourse(const QString &courseName)
331 QListIterator<Course *> i(courseList);
334 while (i.hasNext()) {
336 if (c->getName() == courseName) {