4 * @author Toni Jussila <toni.jussila@fudeco.com>
5 * @author Tiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
6 * @copyright (c) 2010 Speed Freak team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 #include "xmlreader.h"
15 *Constructor of this class.
17 XmlReader::XmlReader()
20 // Remove next line from final code
21 categoryList << "Speed" << "acceleration-0-40" << "acceleration-0-100" << "G-force";
25 *Destructor of this class. Should be used to release all allocated resources.
27 XmlReader::~XmlReader()
38 *This function is used to parsing xml file.
40 void XmlReader::xmlRead(QNetworkReply *device)
42 qDebug() << "_xmlRead";
44 xmlreader.addData(device->readAll());
46 //Go trough the xml document
47 while(!xmlreader.atEnd())
51 //Check if this element is starting element
52 if(xmlreader.isStartElement())
54 if(xmlreader.name() == "results")
56 qDebug() << xmlreader.name();
57 attr = xmlreader.attributes();
59 category = attr.value("category").toString();
60 unit = attr.value("unit").toString();
61 description = attr.value("description").toString();
63 top10List << category;
64 qDebug() << top10List << unit << description;
67 if(xmlreader.name() == "result")
70 attr = xmlreader.attributes();
72 position = attr.value("position").toString();
73 user = attr.value("user").toString();
74 value = attr.value("value").toString();
76 if (category == "acceleration-0-100")
78 top10AccelerationList.append(position + "\t" +
85 if(category == "top10speed")
87 top10SpeedList.append(position + "\t" +
94 if(category == "top10gforce")
96 top10GforceList.append(position + "\t" +
102 qDebug() << position << user << value << unit;
109 *This function is used to read example xml file (results.xml).
110 *@todo Read real xml.
112 void XmlReader::xmlShow()
114 QString filename = "results.xml";
115 QFile file(filename);
117 if (!file.open(QFile::ReadOnly))
119 qDebug() << "_xmlShow fail";
128 *This is return function.
129 *@todo Read real category list
130 *@return QStringList categoryList
132 QStringList XmlReader::getCategoryList()
138 *This is return function.
139 *@todo Read real top 10 category list
140 *@return QStringList top10List
142 QStringList XmlReader::getTop10List()
144 //During development is needed some values for categorylist
146 top10List << "acceleration-0-10" << "acceleration-0-60" << "acceleration-0-100";
151 QString XmlReader::getTopList( QString category, int size)
153 if (category == "acceleration-0-100")
155 //return top10AccelerationList;
156 return "acc-tulos1\nacc-tulos2\nacc-tulos3\nacc-tulos4\nacc-tulos5\nacc-tulos6\nacc-tulos7\nacc-tulos8\nacc-tulos9\nacc-tulos10";
158 else if (category == "acceleration-0-40")
160 //return top10AccelerationList;
161 return "acc-40-tulos1\nacc-40-tulos2\nacc-40-tulos3\nacc-40-tulos4\nacc-40-tulos5\nacc-40-tulos6\nacc-40-tulos7\nacc-40-tulos8\nacc-40-tulos9\nacc-40-tulos10";
163 else if (category == "Speed")
165 //return top10SpeedList;
166 return "speed-tulos1\nspeed-tulos2\nspeed-tulos3\nspeed-tulos4\nspeed-tulos5\nspeed-tulos6\nspeed-tulos7\nspeed-tulos8\nspeed-tulos9\nspeed-tulos10";
168 else if (category == "G-force")
170 //return top10GforceList;
171 return "g-tulos1\ng-tulos2\ng-tulos3\ng-tulos4\ng-tulos5\ng-tulos6\ng-tulos7\ng-tulos8\ng-tulos9\ng-tulos10";