Routing of server results on GUI.
authorTiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
Mon, 22 Mar 2010 12:19:18 +0000 (14:19 +0200)
committerTiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
Mon, 22 Mar 2010 12:19:18 +0000 (14:19 +0200)
Client/carmainwindow.cpp
Client/carmainwindow.h
Client/categorylist.cpp
Client/categorylist.h
Client/httpclient.cpp
Client/httpclient.h
Client/xmlreader.cpp
Client/xmlreader.h
Client/xmlwriter.cpp
Client/xmlwriter.h

index e854ab1..55faff9 100644 (file)
@@ -35,11 +35,13 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca
     initListViewStartTabAccelerationCategories();
 
     myLogin = new LoginWindow(this);
-    categorylist = new CategoryList();
+    myCategorylist = new CategoryList();
     myHttpClient = new HttpClient(this);
     myRegistration = new Registration(this);
     connect(myRegistration,SIGNAL(sendregistration()),this,SLOT(regUserToServer()));
     connect(myLogin,SIGNAL(userNameChanged()),this,SLOT(userLogin()));
+    connect(myHttpClient->myXmlreader, SIGNAL(receivedCategoryList()), this, SLOT(setCategoryCompoBox()));
+    connect(myHttpClient->myXmlreader, SIGNAL(receivedTop10List()), this, SLOT(showTop10()));
     myRoute = new RouteDialog( this);
 
     //GPS
@@ -97,8 +99,8 @@ CarMainWindow::~CarMainWindow()
     ui = NULL;
     //delete result;
     //delete measure;
-    delete categorylist;
-    categorylist = NULL;
+    delete myCategorylist;
+    myCategorylist = NULL;
     delete welcomeDialog;
     welcomeDialog = NULL;
     delete myRoute;
@@ -230,17 +232,30 @@ void CarMainWindow::setListViewStartTabAccelerationCategories(QStringList accele
   */
 void CarMainWindow::setCategoryCompoBox()
 {
-    ui->comboBoxTopCategory->addItems(categorylist->getCategoryList());
+    qDebug() << "_setCategoryCompoBox";
+    ui->comboBoxTopCategory->addItems(myHttpClient->myXmlreader->myCategoryList->getCategoryList());
+}
+
+/**
+  *This function prcesses UI updating after a new top10List has been received.
+  *@todo Check where limitNr is taken, fixed or user input, see on_comboBoxTopCategory_currentIndexChanged.
+  */
+void CarMainWindow::showTop10()
+{
+    int limitNr = 5;
+    setListViewTopList(recentCategory, limitNr);
 }
 
 /**
   *This function is used to set items to labelTopList. Top-tab view.
-  *@param QString category
+  *@param Category
+  *@param Size, number of results.
   */
 void CarMainWindow::setListViewTopList(QString category, int size)
 {
+    qDebug() << "_setListViewTopList";
     QString topList;
-    topList.append( categorylist->getTopList(category, size));
+    topList.append(myHttpClient->myXmlreader->myCategoryList->getTopList(category, size));
     ui->labelTopList->setText(topList);
 }
 
@@ -266,30 +281,20 @@ void CarMainWindow::on_registratePushButton_clicked()
 void CarMainWindow::on_buttonTopRefresh_clicked()
 {
     myHttpClient->requestCategories();
-    setCategoryCompoBox();
 }
 
 /**
   *This slot function is called when ever category combobox current index changed. Top-tab view.
-  *@param QString category
-  *@todo Check where limitNr is taken.
+  *@param QString category.
+  *@todo Check where limitNr is taken, fixed or user input, see showTop10.
   */
 void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category)
 {
-    int limitNr = 5;                    //replace with real value?
+    qDebug() << "_on_comboBoxTopCategory_currentIndexChanged: " << category;
+    recentCategory = category;      //for showTop10()
+    int limitNr = 5;
     QString limit = QString::number(limitNr);
-    category = "acceleration-0-100";    //replace with real value from category list/top window
     myHttpClient->requestTopList(category, limit);
-    setListViewTopList(category,10);
-}
-
-/**
-  *This slot function is called when ever category combobox activated. Top-tab view.
-  *@param QString category
-  */
-void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
-{
-    setListViewTopList(category,10);
 }
 
 /**
@@ -372,9 +377,13 @@ void CarMainWindow::on_pushButtonMeasureTabAbort_clicked()
     //this->close();
 }
 
+/**
+  *This slot function is called when pushButtonSendResult is clicked.
+  *@todo Use real category value.
+  */
 void CarMainWindow::on_pushButtonSendResult_clicked()
 {
-    myHttpClient->sendResultXml();
+    myHttpClient->sendResultXml("acceleration-0-100");
     ui->pushButtonSendResult->setEnabled(false);
 }
 
@@ -388,12 +397,12 @@ void CarMainWindow::updateUserName()
     if (newUserName.length())
     {
        ui->setUserPushButton->setText( "Change User");
-       this->setWindowTitle("Speed freak - " + newUserName);
+       this->setWindowTitle("Speed Freak - " + newUserName);
     }
     else
     {
         ui->setUserPushButton->setText( "Set User");
-        this->setWindowTitle("Speed freak");
+        this->setWindowTitle("Speed Freak");
     }
 }
 
index 934a48c..c91bcf0 100644 (file)
@@ -56,12 +56,10 @@ public:
     CarMainWindow(QWidget *parent = 0);
     ~CarMainWindow();
     Registration *myRegistration;       //Check if this should be public or private
-
+    LoginWindow *myLogin;
 
     void setComboBoxStartTabUnits(QStringList units);       //Start-tab view
     void setListViewStartTabAccelerationCategories(QStringList numbers); //Start-tab view
-    void setListViewTopList(QString category, int size);    //Top-tab view
-    void setCategoryCompoBox();                             //Top-tab
 
 protected:
     void changeEvent(QEvent *e);
@@ -71,9 +69,8 @@ private:
     ResultDialog *result;
     //MeasureDialog *measure;
     WelcomeDialog *welcomeDialog;
-    CategoryList *categorylist;
+    CategoryList *myCategorylist;
     HttpClient *myHttpClient;
-    LoginWindow *myLogin;
     RouteDialog *myRoute;
     GPSData *gpsData;
     Maemo5Location *location;
@@ -81,6 +78,7 @@ private:
     void initComboBoxStartTabUnits();                   //Start-tab view
     void initListViewStartTabAccelerationCategories();  //Start-tab view
     void initializeMeasures();
+    void setListViewTopList(QString category, int size);    //Top-tab view
     void resetAccelerometerMeasurements();
     void calibrateAccelerometer();
     void setTimeAxisGapAndShowResult(double pTime);
@@ -88,7 +86,7 @@ private:
 private:
     QStringList accelerationCategoriesStartTab;         //Start-tab view
     QStringList units;                                  //Start-tab view
-    QStringList categories;                             //Top-tab view
+    QString recentCategory;
 
     QTimer *timer;
     Accelerometer *accelerometer;
@@ -140,8 +138,6 @@ private slots:
     void on_manualStartButton_clicked();
     void on_setUserPushButton_clicked();
     void on_registratePushButton_clicked();
-    void on_comboBoxTopCategory_activated(QString );
-    //void on_pushButton_clicked();
     void on_comboBoxTopCategory_currentIndexChanged(QString category);          //Top-tab view
     void on_listViewStartTabAccelerationCategories_clicked(QModelIndex index);  //Start-tab view
     void updateComboBoxStartTabUnits(QString unit);     //Start-tab view
@@ -154,6 +150,9 @@ private slots:
     void userLogin();
     void readAccelerometerData();
     void handleCheckPoint(double totalTime, double currentSpeed);
+    void setCategoryCompoBox();                         //Top-tab
+    void showTop10();
+
 };
 
 #endif // CARMAINWINDOW_H
index 3226bbf..3d3f451 100644 (file)
@@ -6,6 +6,7 @@
  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  */
 
+#include <QDebug>
 #include "categorylist.h"
 
 /**
@@ -13,8 +14,7 @@
   */
 CategoryList::CategoryList()
 {
-    categoryList << "Speed" << "acceleration-0-40" << "acceleration-0-100" << "G-force"; // OLPU
-    //top10AccelerationList << "acc-tulos1\nacc-tulos2\nacc-tulos3\nacc-tulos4\nacc-tulos5\nacc-tulos6\nacc-tulos7\nacc-tulos8\nacc-tulos9\nacc-tulos10";
+
 }
 
 /**
@@ -26,47 +26,73 @@ CategoryList::~CategoryList()
 
 /**
   *This is return function.
-  *@todo Read real top 10 category list
   *@return QStringList categoryList
   */
 QStringList CategoryList::getCategoryList()
 {
+    qDebug() << "_getCategoryList" ;
     return categoryList;
 }
 
 /**
+  *Append an item in the end of the categorylist.
+  */
+void CategoryList::appendCategoryList(QString item)
+{
+    categoryList.append(item);
+}
+
+/**
+  *Input an item into the categorylist.
+  */
+void CategoryList::fillCategoryList(int index, QString item)
+{
+    categoryList.insert(index, item);
+}
+
+/**
+  *Show an item of the categorylist.
+  */
+QString CategoryList::itemOfCategoryList(int index)
+{
+    return categoryList.at(index);
+}
+
+/**
+  *Clear categorylist.
+  */
+void CategoryList::clearCategoryList()
+{
+    categoryList.clear();
+    qDebug() << "_clearCategoryList" ;
+}
+
+/**
+  *Read size of categorylist.
+  */
+int CategoryList::sizeOfCategoryList()
+{
+    return categoryList.size();
+}
+
+/**
   *This function is used to get items to top list of current category.
   *@param QString category
   *@param int size
   */
 QString CategoryList::getTopList( QString category, int size)
 {
-    if (category == "acceleration-0-100")
-    {
-        //topList.append(xmlreader->getTop10AccelerationList());
-        //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")
-    {
-                //topList.append(xmlreader->getTop10AccelerationList());
-                //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";
+    qDebug() << "_getTopList";
 
-    }
-    else if (category == "Speed")
+    if(!(top10List.isEmpty()))
     {
-        //topList.append(xmlreader->getTop10SpeedList());
-        //return top10SpeedList;
-        return "speed-tulos1\nspeed-tulos2\nspeed-tulos3\nspeed-tulos4\nspeed-tulos5\nspeed-tulos6\nspeed-tulos7\nspeed-tulos8\nspeed-tulos9\nspeed-tulos10";
+        return top10List;
     }
-    else if (category == "G-force")
+    else
     {
-        //topList.append(xmlreader->getTop10GforceList());
-        //return top10GforceList;
-        return "g-tulos1\ng-tulos2\ng-tulos3\ng-tulos4\ng-tulos5\ng-tulos6\ng-tulos7\ng-tulos8\ng-tulos9\ng-tulos10";
-
+        QString emptyStr("");
+        qDebug() << "_getTopList: Category not found";
+        return emptyStr;
     }
 }
 
index c96faea..c7cdc9f 100644 (file)
@@ -16,14 +16,19 @@ class CategoryList : public QObject
 public:
     CategoryList();
     ~CategoryList();
+    QString top10List;
+
     QStringList getCategoryList();
+    void fillCategoryList(int index, QString item);
+    void appendCategoryList(QString item);
+    QString itemOfCategoryList(int index);
     QString getTopList( QString category, int size);
+    void clearCategoryList();
+    int sizeOfCategoryList();
 
 private:
     QStringList categoryList;
-    QString top10AccelerationList;
-    QString top10SpeedList;
-    QString top10GforceList;
+
 };
 
 #endif // CATEGORYLIST_H
index 5a25562..53ad791 100644 (file)
@@ -3,6 +3,7 @@
 #include "httpclient.h"
 #include "carmainwindow.h"
 
+
 /**
   *@brief Constructor, connects object to GUI
   *@param Pointer to carmainwindow, which is temporarily used during development
@@ -58,14 +59,13 @@ void HttpClient::requestRegistration()
   *Send authentication information in the header.
   *@todo Read category elsewhere.
   */
-void HttpClient::sendResultXml()
+void HttpClient::sendResultXml(QString category)
 {
     qDebug() << "_sendResultXml";
 
     QBuffer *xmlbuffer = new QBuffer();
-    QString category_name = "acceleration-0-100";    //replace with real value from category list
 
-    QUrl qurl("http://api.speedfreak-app.com/api/update/" + category_name);
+    QUrl qurl("http://api.speedfreak-app.com/api/update/" + category);
     qDebug() << qurl.toString();
     QNetworkRequest request(qurl);
     QNetworkReply *currentDownload;
@@ -74,7 +74,7 @@ void HttpClient::sendResultXml()
     myXmlwriter->writeResult(xmlbuffer);
     qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data();
 
-    QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword();
+    QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword();
     credentials = "Basic " + credentials.toAscii().toBase64();
     request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
 
@@ -101,7 +101,7 @@ void HttpClient::requestTopList(QString category, QString limit)
     QNetworkRequest request(qurl);
     QNetworkReply *currentDownload;
 
-    QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword();
+    QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword();
     credentials = "Basic " + credentials.toAscii().toBase64();
     request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
 
@@ -124,7 +124,7 @@ void HttpClient::requestCategories()
     QNetworkRequest request(qurl);
     QNetworkReply *currentDownload;
 
-    QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword();
+    QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword();
     credentials = "Basic " + credentials.toAscii().toBase64();
     request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
 
@@ -147,7 +147,7 @@ void HttpClient::checkLogin()
     QNetworkRequest request(qurl);
     QNetworkReply *currentDownload;
 
-    QString credentials = myMainw->myRegistration->getUserName() + ":" + myMainw->myRegistration->getPassword();
+    QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword();
     credentials = "Basic " + credentials.toAscii().toBase64();
     request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
 
@@ -175,7 +175,7 @@ void HttpClient::ackOfResult()
     }
     else {
         qDebug() << "errorcode:" << errorcode << reply->errorString();
-        qDebug() << reply->readAll();
+        QMessageBox::about(myMainw, "Server reply to result sending", "Result received " + reply->readAll());
     }
 
 }
@@ -223,7 +223,7 @@ void HttpClient::ackOfCategories()
     }
     else {
         qDebug() <<  "errorcode:" << errorcode << reply->errorString();
-        qDebug() << reply->readAll();
+        QMessageBox::about(myMainw, "Server reply to requesting categories ", "OK");
     }
 
 }
@@ -238,7 +238,6 @@ void HttpClient::ackOfLogin()
     qDebug() << "_ackOffLogin";
 
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
-    myXmlreader->xmlReadTop10Results(reply);
 
     QNetworkReply::NetworkError errorcode;
     errorcode = reply->error();
@@ -294,7 +293,7 @@ void HttpClient::ackOfToplist()
     }
     else {
         qDebug() <<  "errorcode:" << errorcode << reply->errorString();
-        qDebug() << reply->readAll();
+        QMessageBox::about(myMainw, "Server reply to requesting top 10 list", "OK " + reply->readAll());
     }
 
 }
index decff1b..ff50ffa 100644 (file)
@@ -18,8 +18,7 @@ class CarMainWindow;
 
 
 
-class HttpClient : public QObject
-{
+class HttpClient : public QObject {
     Q_OBJECT
 public:
     HttpClient(CarMainWindow *myCarw);
@@ -30,13 +29,11 @@ public:
 private:
     CarMainWindow *myMainw;
     QNetworkAccessManager *netManager;
-    //XmlWriter *myXmlwriter;
-    //XmlReader *myXmlreader;
 
 public slots:
     void requestRegistration();
     void checkLogin();
-    void sendResultXml();
+    void sendResultXml(QString category);
     void requestTopList(QString category, QString limit);
     void requestCategories();
     void ackOfResult();
index 6067038..b997989 100644 (file)
@@ -16,7 +16,7 @@
   */
 XmlReader::XmlReader()
 {
-    xmlShow();
+    myCategoryList = new CategoryList();
 }
 
 /**
@@ -26,20 +26,31 @@ XmlReader::~XmlReader()
 {
     category = "";
     unit = "";
-    description = "";
     position = "";
     user = "";
     value = "";
+    delete myCategoryList;
 }
 
 /**
-  *This function is used to parsing xml file.
+  *This function is used to parse top 10 results of a certain category.
   */
 void XmlReader::xmlReadTop10Results(QNetworkReply *device)
 {
     qDebug() << "_xmlReadTop10Results";
 
-    xmlreader.addData(device->readAll());
+    int i = 0;
+    int receivedFlag = 0;
+
+    xmlreader.clear();
+    QByteArray array = device->readAll();
+    qDebug() << "array: " << array;
+    xmlreader.addData(array);
+    //xmlreader.addData(device->readAll());
+
+    if(!(myCategoryList->top10List.isEmpty())) {
+        myCategoryList->top10List.clear();
+    }
 
     //Go trough the xml document
     while(!xmlreader.atEnd())
@@ -52,55 +63,36 @@ void XmlReader::xmlReadTop10Results(QNetworkReply *device)
             if(xmlreader.name() == "results")
             {
                 qDebug() << xmlreader.name();
-                attr = xmlreader.attributes();
-
-                category = attr.value("category").toString();
-                unit = attr.value("unit").toString();
-                description = attr.value("description").toString();
-
-                top10List << category;
-                qDebug() << top10List << unit << description;
             }
-
             if(xmlreader.name() == "result")
             {
                 qDebug() << "result";
                 attr = xmlreader.attributes();
 
+                user = attr.value("username").toString();
                 position = attr.value("position").toString();
-                user = attr.value("user").toString();
+                date = attr.value("date").toString();
+                unit = attr.value("unit").toString();
                 value = attr.value("value").toString();
 
-                if (category == "acceleration-0-100")
-                {
-                    top10AccelerationList.append(position + "\t" +
+                myCategoryList->top10List.append(position + "\t" +
                                                 user + "\t" +
-                                                value +
+                                                value + " " +
                                                 unit + "\t" +
-                                                description + "\n");
-                }
-
-                if(category == "top10speed")
-                {
-                    top10SpeedList.append(position + "\t" +
-                                          user + "\t" +
-                                          value +
-                                          unit + "\t" +
-                                          description + "\n");
-                }
-
-                if(category == "top10gforce")
-                {
-                    top10GforceList.append(position + "\t" +
-                                           user + "\t" +
-                                           value +
-                                           unit + "\t" +
-                                           description + "\n");
-                }
-                qDebug() << position << user << value << unit;
+                                                date + "\n");
+
+                qDebug() << position << user << value << unit << date;
+                i++;
+                receivedFlag = 1;
             }
         }
     }
+    //Only change labelTopList if a new top10List has been received
+    if(receivedFlag)
+    {
+        qDebug() << "receivedTop10List() emitted";
+        emit receivedTop10List();
+    }
 }
 
 void XmlReader::xmlReadCategories(QNetworkReply *device)
@@ -109,10 +101,18 @@ void XmlReader::xmlReadCategories(QNetworkReply *device)
     qDebug() << "_xmlReadCategories";
 
     int i = 0;
+    int receivedFlag = 0;
 
+    xmlreader.clear();
     QByteArray array = device->readAll();
-    qDebug() << array;
+    qDebug() << "array: " << array;
     xmlreader.addData(array);
+    //xmlreader.addData(device->readAll());
+
+    if(myCategoryList->sizeOfCategoryList() != 0) {
+        myCategoryList->clearCategoryList();
+    }
+    //qDebug() << "sizeOfCategoryList(): " << myCategoryList->sizeOfCategoryList();
 
     //Go trough the xml document
     while(!xmlreader.atEnd())
@@ -130,12 +130,19 @@ void XmlReader::xmlReadCategories(QNetworkReply *device)
             if(xmlreader.name() == "category")
             {
                 qDebug() << xmlreader.name();
-                categoryList.insert(i, xmlreader.readElementText());
-                qDebug() << "i=" << i << categoryList.at(i);
+                myCategoryList->appendCategoryList(xmlreader.readElementText());
+                qDebug() << "i=" << i << myCategoryList->itemOfCategoryList(i);
                 i++;
+                receivedFlag = 1;
             }
         }
     }
+    //Only change comboBoxTopCategory if a new list has been received
+    if(receivedFlag)
+    {
+        qDebug() << "receivedCategoryList() emitted";
+        emit receivedCategoryList();
+    }
 }
 
 /**
index 43615a7..9704ec3 100644 (file)
 #include <QXmlStreamReader>
 #include <QStringList>
 #include <QNetworkReply>
+#include "categorylist.h"
 
-class XmlReader : public QObject
-{
+class XmlReader : public QObject {
+    Q_OBJECT
 public:
     XmlReader();
     ~XmlReader();
+    CategoryList *myCategoryList;
 
 private:
     QXmlStreamReader xmlreader;
-    QStringList top10List;              // Next 4 to be removed. Categorylist now in own class.
-    QStringList categoryList;
-    QString top10AccelerationList;
-    QString top10SpeedList;
-    QString top10GforceList;
 
     QXmlStreamAttributes attr;
     QString category;
     QString unit;
-    QString description;
+    QString date;
     QString position;
     QString user;
     QString value;
 
+signals:
+    void receivedCategoryList();
+    void receivedTop10List();
+
 public slots:
     void xmlReadTop10Results(QNetworkReply *device);
     void xmlReadCategories(QNetworkReply *device);
index dac4d62..51eeb46 100644 (file)
@@ -16,7 +16,8 @@
   */
 XmlWriter::XmlWriter()
 {
-    tmpvalue = 10;
+    tmpvalue = 110;
+    trackInd = 0;
 }
 
 /**
@@ -76,14 +77,69 @@ void XmlWriter::writeResult(QBuffer *netbuf)
     tmpvalue++;
     qDebug() << tmpvalue;
     xmlwriter.writeAttribute("value", QString::number(tmpvalue));
-    xmlwriter.writeAttribute("unit", "seconds");
-    xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
     xmlwriter.writeEndElement();
     xmlwriter.writeEndDocument();
 }
 
 
 /**
+  *@brief Write track to server.
+  *@param Starting index of gps results table.
+  *@param Ending index of gps results table.
+  *@todo Connect to real values.
+  *@todo Decide suitable parameters.
+  */
+void XmlWriter::writeGpsTrack(int startInd, int stopInd)
+{
+    qDebug() << "_writeGpsTrack";
+    analyzeGpsData();
+
+    int i = 0;
+
+    xmlwriter.writeStartElement("gpx");
+    xmlwriter.writeAttribute("someattribute", "abc");
+    xmlwriter.writeAttribute("otherattribute", "cde");
+
+    xmlwriter.writeStartElement("metadata");
+    xmlwriter.writeStartElement("link");
+    xmlwriter.writeAttribute("href", "http://api.speedfreak-app.com/api/track");
+    xmlwriter.writeCharacters("Speed Freak");
+    xmlwriter.writeEndElement();
+    xmlwriter.writeStartElement("time");
+    xmlwriter.writeCharacters(QDateTime::currentDateTime().toString());
+    xmlwriter.writeEndElement();
+    xmlwriter.writeEndElement();    //metadata
+
+    xmlwriter.writeStartElement("trk");
+    xmlwriter.writeStartElement("name");
+    xmlwriter.writeCharacters("Example Track");
+    xmlwriter.writeEndElement();
+    xmlwriter.writeStartElement("trkseg");
+    for(i = startInd; i < (stopInd - startInd); i++) {
+        xmlwriter.writeStartElement("trkpt");
+        xmlwriter.writeAttribute("lat", QString::number(trackTable[i].latitude));
+        xmlwriter.writeAttribute("lon", QString::number(trackTable[i].longitude));
+        xmlwriter.writeStartElement("ele");
+        xmlwriter.writeCharacters(QString::number(trackTable[i].altitude));
+        xmlwriter.writeEndElement();
+        xmlwriter.writeStartElement("time");
+        xmlwriter.writeCharacters(QString::number(trackTable[i].time));
+        xmlwriter.writeEndElement();
+        xmlwriter.writeStartElement("speed");
+        xmlwriter.writeCharacters(QString::number(trackTable[i].speed));
+        xmlwriter.writeEndElement();
+        xmlwriter.writeStartElement("track");
+        xmlwriter.writeCharacters(QString::number(trackTable[i].track));
+        xmlwriter.writeEndElement();
+        xmlwriter.writeEndElement();    //trkpt
+    }
+    xmlwriter.writeEndElement();    //trkseg
+    xmlwriter.writeEndElement();    //trk
+    xmlwriter.writeEndElement();    //gpx
+}
+
+
+/**
   *@brief Opens and closes a file, when xml information is written into a file,
   *and passes file to writeXmlFile()
   *@param usr for user name.
@@ -119,8 +175,9 @@ bool XmlWriter::writeXmlFile(QIODevice *device)
 {
     xmlwriter.setDevice(device);
     xmlwriter.writeStartDocument();
-    writeItems();
+    //writeItems();
     //serverWritesXml();
+    writeGpsTrack(0, 16);
     xmlwriter.writeEndDocument();
 
     return true;
@@ -175,7 +232,7 @@ void XmlWriter::serverWritesXml()
     xmlwriter.writeEndElement();
 
     xmlwriter.writeStartElement("category");
-    xmlwriter.writeCharacters("acceleration-0-60");
+    xmlwriter.writeCharacters("acceleration-0-40");
     xmlwriter.writeEndElement();
 
     xmlwriter.writeStartElement("category");
@@ -184,3 +241,87 @@ void XmlWriter::serverWritesXml()
 
     xmlwriter.writeEndElement();
 }
+
+
+/**
+  *@brief A temp function during development, used to create data for drawing route and for server.
+  */
+void XmlWriter::analyzeGpsData()
+{
+    qDebug() << "_analyzeGpsData";
+
+    double startTime;
+    int tableSize = 0;
+
+    qDebug() << "sizeof(analyzeTable)" << sizeof(analyzeTable);
+    tableSize = 16;
+
+    for(int i = 1; i < tableSize; i++)
+    {
+        //example of one feature whose consequent values are compared and saved if they differentiate too much
+        if(analyzeTable[i].speed < (analyzeTable[i-1].speed - 1) ||
+           analyzeTable[i].speed > (analyzeTable[i-1].speed + 1) )
+        {
+           trackTable[trackInd] = analyzeTable[i];
+           trackInd++;
+           qDebug() << "trackTable[trackInd].speed" << trackTable[trackInd].speed;
+        }
+    }
+}
+
+void XmlWriter::initPointTable(gpsPoint *table, int count, double add1, int add2, int add3)
+{
+    qDebug() << "_initPointTable";
+
+    int i = 1;
+    int j = 0;
+
+    table[0].latitude = 67.00;
+    table[0].longitude = 27.50;
+    table[0].altitude = 7.00;
+    table[0].speed = 0;
+    table[0].time = 0;
+
+    for(j = 0; j < count; j++)
+    {
+        table[i].latitude = table[i-1].latitude + add1;
+        //table[i].longitude = table[i-1].longitude + add1;
+        table[i].altitude = table[i-1].altitude + add1;
+        table[i].speed = table[i-1].speed + add2;
+        table[i].track = table[i-1].track + 1;
+        table[i].time = table[i-1].time + add3;
+        i++;
+    }
+    for(j = 0; j < count; j++)
+    {
+        //table[i].latitude = table[i-1].latitude + add1;
+        table[i].longitude = table[i-1].longitude + add1;
+        table[i].altitude = table[i-1].altitude -add1;
+        table[i].speed = table[i-1].speed + add2;
+        table[i].track = table[i-1].track + 1;
+        table[i].time = table[i-1].time + add3;
+        i++;
+    }
+    for(j = 0; j < count; j++)
+    {
+        table[i].latitude = table[i-1].latitude - add1;
+        //table[i].longitude = table[i-1].longitude + add1;
+        table[i].altitude = table[i-1].altitude + add1;
+        table[i].speed = table[i-1].speed - add2;
+        table[i].track = table[i-1].track - 1;
+        table[i].time = table[i-1].time + add3;
+        i++;
+    }
+    for(j = 0; j < count; j++)
+    {
+        //table[i].latitude = table[i-1].latitude + add1;
+        table[i].longitude = table[i-1].longitude - add1;
+        table[i].altitude = table[i-1].altitude - add1;
+        table[i].speed = table[i-1].speed - add2;
+        table[i].track = table[i-1].track - 1;
+        table[i].time = table[i-1].time + add3;
+        i++;
+    }
+}
+
+
index 89a6ad0..34bf284 100644 (file)
 #include <QApplication>
 
 
-class XmlWriter : public QObject
-{
+class XmlWriter : public QObject {
+    Q_OBJECT
 public:
     XmlWriter();
     ~XmlWriter();
     int tmpvalue;
+    typedef struct {
+            double time;
+            double latitude;
+            double longitude;
+            double altitude;
+            double speed;
+            double track;
+        } gpsPoint;
+    gpsPoint trackTable[100];
+    gpsPoint analyzeTable[100];
+    int trackInd;
 
 private:
     QXmlStreamWriter xmlwriter;
@@ -42,7 +53,10 @@ public slots:
     void writeXml();
     void writeItems();
     void serverWritesXml();
-
+    void writeGpsTrack(int startInd, int stopInd);
+    void initPointTable(gpsPoint *table, int count, double add1, int add2, int add3);
+    void analyzeGpsData();
 };
 
 #endif // XMLWRITER_H
+