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()
23 *Destructor of this class. Should be used to release all allocated resources.
25 XmlReader::~XmlReader()
36 *This function is used to parsing xml file.
38 void XmlReader::xmlReadTop10Results(QNetworkReply *device)
40 qDebug() << "_xmlReadTop10Results";
42 xmlreader.addData(device->readAll());
44 //Go trough the xml document
45 while(!xmlreader.atEnd())
49 //Check if this element is starting element
50 if(xmlreader.isStartElement())
52 if(xmlreader.name() == "results")
54 qDebug() << xmlreader.name();
55 attr = xmlreader.attributes();
57 category = attr.value("category").toString();
58 unit = attr.value("unit").toString();
59 description = attr.value("description").toString();
61 top10List << category;
62 qDebug() << top10List << unit << description;
65 if(xmlreader.name() == "result")
68 attr = xmlreader.attributes();
70 position = attr.value("position").toString();
71 user = attr.value("user").toString();
72 value = attr.value("value").toString();
74 if (category == "acceleration-0-100")
76 top10AccelerationList.append(position + "\t" +
83 if(category == "top10speed")
85 top10SpeedList.append(position + "\t" +
92 if(category == "top10gforce")
94 top10GforceList.append(position + "\t" +
100 qDebug() << position << user << value << unit;
106 void XmlReader::xmlReadCategories(QNetworkReply *device)
107 //void XmlReader::xmlReadCategories(QIODevice *device)
109 qDebug() << "_xmlReadCategories";
113 QByteArray array = device->readAll();
115 xmlreader.addData(array);
117 //Go trough the xml document
118 while(!xmlreader.atEnd())
121 xmlreader.readNext();
123 //Check if this element is starting element
124 if(xmlreader.isStartElement())
126 if(xmlreader.name() == "categories")
128 qDebug() << xmlreader.name();
130 if(xmlreader.name() == "category")
132 qDebug() << xmlreader.name();
133 categoryList.insert(i, xmlreader.readElementText());
134 qDebug() << "i=" << i << categoryList.at(i);
142 *This function is used to read example xml file (results.xml).
143 *@todo Read real xml.
145 void XmlReader::xmlShow()
147 //QString filename = "results.xml";
148 QString filename = "xmlcategoryfile.xml";
149 QFile file(filename);
151 if (!file.open(QFile::ReadOnly))
153 qDebug() << "_xmlShow fail";
157 //xmlReadTop10Results(&file);
158 //xmlReadCategories(&file);