Measurement resetting added in carmainwindow.cpp.
[speedfreak] / Client / xmlreader.cpp
index bcf9b15..6067038 100644 (file)
@@ -17,8 +17,6 @@
 XmlReader::XmlReader()
 {
     xmlShow();
-    // Remove next line from final code
-    categoryList << "Speed" << "acceleration-0-40" << "acceleration-0-100" << "G-force";
 }
 
 /**
@@ -37,9 +35,9 @@ XmlReader::~XmlReader()
 /**
   *This function is used to parsing xml file.
   */
-void XmlReader::xmlRead(QNetworkReply *device)
+void XmlReader::xmlReadTop10Results(QNetworkReply *device)
 {
-    qDebug() << "_xmlRead";
+    qDebug() << "_xmlReadTop10Results";
 
     xmlreader.addData(device->readAll());
 
@@ -105,13 +103,49 @@ void XmlReader::xmlRead(QNetworkReply *device)
     }
 }
 
+void XmlReader::xmlReadCategories(QNetworkReply *device)
+//void XmlReader::xmlReadCategories(QIODevice *device)
+{
+    qDebug() << "_xmlReadCategories";
+
+    int i = 0;
+
+    QByteArray array = device->readAll();
+    qDebug() << array;
+    xmlreader.addData(array);
+
+    //Go trough the xml document
+    while(!xmlreader.atEnd())
+    {
+        //Read next node
+        xmlreader.readNext();
+
+        //Check if this element is starting element
+        if(xmlreader.isStartElement())
+        {
+            if(xmlreader.name() == "categories")
+            {
+                qDebug() << xmlreader.name();
+            }
+            if(xmlreader.name() == "category")
+            {
+                qDebug() << xmlreader.name();
+                categoryList.insert(i, xmlreader.readElementText());
+                qDebug() << "i=" << i << categoryList.at(i);
+                i++;
+            }
+        }
+    }
+}
+
 /**
   *This function is used to read example xml file (results.xml).
   *@todo Read real xml.
   */
 void XmlReader::xmlShow()
 {
-    QString filename = "results.xml";
+    //QString filename = "results.xml";
+    QString filename = "xmlcategoryfile.xml";
     QFile file(filename);
 
     if (!file.open(QFile::ReadOnly))
@@ -120,54 +154,8 @@ void XmlReader::xmlShow()
         return;
     }
 
-    //xmlRead(&file);
+    //xmlReadTop10Results(&file);
+    //xmlReadCategories(&file);
     file.close();
 }
 
-/**
-  *This is return function.
-  *@todo Read real category list
-  *@return QStringList categoryList
-  */
-QStringList XmlReader::getCategoryList()
-{
-    return categoryList;
-}
-
-/**
-  *This is return function.
-  *@todo Read real top 10 category list
-  *@return QStringList top10List
-  */
-QStringList XmlReader::getTop10List()
-{
-    //During development is needed some values for categorylist
-    top10List.clear();
-    top10List << "acceleration-0-10" << "acceleration-0-60" << "acceleration-0-100";
-
-    return top10List;
-}
-
-QString XmlReader::getTopList( QString category, int size)
-{
-    if (category == "acceleration-0-100")
-    {
-        //return top10AccelerationList;
-        return "acc-tulos1\nacc-tulos2\nacc-tulos3\nacc-tulos4\nacc-tulos5\nacc-tulos6\nacc-tulos7\nacc-tulos8\nacc-tulos9\nacc-tulos10";
-    }
-    else if (category == "acceleration-0-40")
-    {
-         //return top10AccelerationList;
-         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";
-    }
-    else if (category == "Speed")
-    {
-        //return top10SpeedList;
-        return "speed-tulos1\nspeed-tulos2\nspeed-tulos3\nspeed-tulos4\nspeed-tulos5\nspeed-tulos6\nspeed-tulos7\nspeed-tulos8\nspeed-tulos9\nspeed-tulos10";
-    }
-    else if (category == "G-force")
-    {
-        //return top10GforceList;
-        return "g-tulos1\ng-tulos2\ng-tulos3\ng-tulos4\ng-tulos5\ng-tulos6\ng-tulos7\ng-tulos8\ng-tulos9\ng-tulos10";
-    }
-}