And some more colors. Seems to be hard to change HeaderView background
[scorecard] / src / xml-parser.cpp
1 /*
2  * Copyright (C) 2009 Sakari Poussa
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 2.
7  */
8
9 #include <QtGui>
10
11 #include <QDebug>
12
13 #include "xml-parser.h"
14 #include "data.h"
15
16 //
17 // Score
18 //
19 ScoreHandler::ScoreHandler(QList<Score *> &scoreList) : scoreList(scoreList)
20 {
21   score = 0;
22   hole = 0;
23 }
24
25 bool ScoreHandler::startDocument()
26 {
27   inScore = false;
28   return true;
29 }
30
31 bool ScoreHandler::endDocument()
32 {
33   return true;
34 }
35
36 bool ScoreHandler::startElement(const QString & /* namespaceURI */,
37                                 const QString & /* localName */,
38                                 const QString &name,
39                                 const QXmlAttributes &attrs)
40 {
41   if (inScore && name == "hole") {
42     hole = new Hole(attrs);
43   }
44   else if (name == "score") {
45     score = new Score(attrs);
46     inScore = true;
47   }
48   return true;
49 }
50
51 bool ScoreHandler::endElement(const QString & /* namespaceURI */,
52                               const QString & /* localName */,
53                               const QString &name)
54 {
55   if (name == "score") {
56     inScore = false;
57     scoreList << score;
58   } else if (name == "hole")
59     score->addHole(hole);
60
61   return true;
62 }
63
64 bool ScoreHandler::fatalError(const QXmlParseException &exception)
65 {
66   qWarning() << "Fatal error on line" << exception.lineNumber()
67              << ", column" << exception.columnNumber() << ":"
68              << exception.message();
69
70   return false;
71 }
72
73 QString ScoreHandler::errorString() const
74 {
75   return errorStr;
76 }
77
78 //
79 // Club
80 //
81 ClubHandler::ClubHandler(QList<Club *> &clubList) : clubList(clubList)
82 {
83   club = 0;
84   hole = 0;
85 }
86
87 bool ClubHandler::startDocument()
88 {
89   inClub = false;
90   inCourse = false;
91   return true;
92 }
93
94 bool ClubHandler::endDocument()
95 {
96   return true;
97 }
98
99 bool ClubHandler::startElement(const QString & /* namespaceURI */,
100                                const QString & /* localName */,
101                                const QString &name,
102                                const QXmlAttributes &attrs)
103 {
104   if (inCourse && name == "hole") {
105     hole = new Hole(attrs);
106   }
107   else if (name == "course") {
108     course = new Course(attrs);
109     inCourse = true;
110   }  
111   else if (name == "club") {
112     club = new Club(attrs);
113     inClub = true;
114   }
115   return true;
116 }
117
118 bool ClubHandler::endElement(const QString & /* namespaceURI */,
119                              const QString & /* localName */,
120                              const QString &name)
121 {
122   if (name == "club") {
123     inClub = false;
124     clubList << club;
125   } 
126   else if (name == "course") {
127     inCourse = false;
128     club->addCourse(course);
129   }
130   else if (name == "hole")
131     course->addHole(hole);
132
133   return true;
134 }
135
136 bool ClubHandler::fatalError(const QXmlParseException &exception)
137 {
138   qWarning() << "Fatal error on line" << exception.lineNumber()
139              << ", column" << exception.columnNumber() << ":"
140              << exception.message();
141
142   return false;
143 }
144
145 QString ClubHandler::errorString() const
146 {
147   return errorStr;
148 }