Merge branch 'development/GPSroute'
authorToni Jussila <toni.jussila@fudeco.com>
Thu, 25 Mar 2010 09:58:32 +0000 (11:58 +0200)
committerToni Jussila <toni.jussila@fudeco.com>
Thu, 25 Mar 2010 09:58:32 +0000 (11:58 +0200)
17 files changed:
Client/carmainwindow.cpp
Client/carmainwindow.h
Client/carmainwindow.ui
Client/categorylist.cpp
Client/categorylist.h
Client/gpsdata.cpp
Client/gpsdata.h
Client/httpclient.cpp
Client/httpclient.h
Client/movingaverage.cpp [new file with mode: 0644]
Client/movingaverage.h [new file with mode: 0644]
Client/routedialog.cpp
Client/routedialog.h
Client/xmlreader.cpp
Client/xmlreader.h
Client/xmlwriter.cpp
Client/xmlwriter.h

index 0deeddc..ca0cb8e 100644 (file)
@@ -158,6 +158,7 @@ void CarMainWindow::on_listViewStartTabAccelerationCategories_clicked(QModelInde
 
 /**
   *This slot function is called when ever auto start button clicked. Start-tab view.
+  *@todo Check setDiagramGapStem(100) <- (choiceInt == 2)
   */
 void CarMainWindow::on_autoStartButton_clicked()
 {
@@ -167,19 +168,22 @@ void CarMainWindow::on_autoStartButton_clicked()
     ui->pushButtonShowResultDialog->setEnabled(false);
     choice = ui->listViewStartTabAccelerationCategories->currentIndex();
     choiceInt = choice.row();
-    qDebug() << choiceInt;
+    //qDebug() << "choiceInt" << choiceInt << " " << catList.at(choiceInt);
     if (choiceInt == 0)
     {
         ui->labelMeasureTabHeader->setText("Accelerate to 40 km/h");
         result->setDiagramGapStem(75);
     }
-
     else if (choiceInt == 1)
     {
         ui->labelMeasureTabHeader->setText("Accelerate to 100 km/h");
         result->setDiagramGapStem(30);
+    }   
+    else if (choiceInt == 2)
+    {
+        ui->labelMeasureTabHeader->setText("Accelerate to 10 km/h");
+        result->setDiagramGapStem(100);
     }
-
     else
     {
         ui->labelMeasureTabHeader->setText("Accelerate to 80 km/h");
@@ -223,10 +227,19 @@ void CarMainWindow::setComboBoxStartTabUnits(QStringList units)
 
 /**
   *This function is used to init listViewStartTabAccelerationCategories. Start-tab view.
+  *@todo During development categories index values that are used for measuring are hardcoded
+  *@todo and accelerationCategoriesStartTab and catList are used instead of using
+  *@todo CategoryList::categoryList and CategoryList::cats.
   */
 void CarMainWindow::initListViewStartTabAccelerationCategories()
 {
-    accelerationCategoriesStartTab << "0-40 km/h" << "0-100 km/h"; //<< "0-1/4 Mile" << "0-1/8 Mile" << "0-50 km" << "50-100 Mile" << "0-60 Mph" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
+    //Connect the user`s choice fron GUI to a correct variable name
+    catList.insert(0,"acceleration-0-40");
+    catList.insert(1,"acceleration-0-100");
+    catList.insert(2,"acceleration-0-10");
+
+    accelerationCategoriesStartTab << "0-40 km/h" << "0-100 km/h" << "0-10 km/h";
+    //<< "0-1/4 Mile" << "0-1/8 Mile" << "50-100 Mile" << "0-60 Mph" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
     QAbstractItemModel *model = new StringListModel(accelerationCategoriesStartTab);
     ui->listViewStartTabAccelerationCategories->setModel(model);
 }
@@ -241,6 +254,11 @@ void CarMainWindow::setListViewStartTabAccelerationCategories(QStringList accele
     ui->listViewStartTabAccelerationCategories->setModel(model);
 }
 
+void CarMainWindow::setLabelInfoToUser(QString infoText)
+{
+    ui->labelInfoToUser->setText(infoText);
+}
+
 /**
   *This function is used to set items to category combobox. Top-tab view.
   *@param
@@ -397,7 +415,8 @@ void CarMainWindow::on_pushButtonMeasureTabAbort_clicked()
   */
 void CarMainWindow::on_pushButtonSendResult_clicked()
 {
-    myHttpClient->sendResultXml("acceleration-0-100");
+    //Pick up relevant category name and pass it to the server
+    myHttpClient->sendResultXml(catList.at(choiceInt));
     ui->pushButtonSendResult->setEnabled(false);
 }
 
@@ -428,7 +447,11 @@ void CarMainWindow::regUserToServer()
 
 void CarMainWindow::on_drawRoutePushButton_clicked()
 {
-    myRoute->show();
+    QString routeFile = QString("route.txt");
+    if (myRoute->readRouteFromFile( routeFile) == true)
+    {
+        myRoute->show();
+    }
 }
 
 /**
@@ -532,7 +555,6 @@ void CarMainWindow::handleCheckPoint(double totalTime, double currentSpeed)
         this->speed = 0;
         counterForSaveResults = 0;
     }
-
     else if (choiceInt == 1 && measures->getTime100kmh() != 0)
     {
         setTimeAxisGapAndShowResult(measures->getTime100kmh());
@@ -541,9 +563,16 @@ void CarMainWindow::handleCheckPoint(double totalTime, double currentSpeed)
         this->time = 0;
         this->speed = 0;
         counterForSaveResults = 0;
-
     }
-
+    else if (choiceInt == 2 && measures->getTime10kmh() != 0)
+    {
+        setTimeAxisGapAndShowResult(measures->getTime10kmh());
+        this->timer->stop();
+        this->accelerometerTimer->stop();
+        this->time = 0;
+        this->speed = 0;
+        counterForSaveResults = 0;
+    }
     else if (choiceInt != 1 && choiceInt != 0 && measures->getTime80kmh() != 0)
     {
         setTimeAxisGapAndShowResult(measures->getTime80kmh());
@@ -553,10 +582,9 @@ void CarMainWindow::handleCheckPoint(double totalTime, double currentSpeed)
         this->speed = 0;
         counterForSaveResults = 0;
     }
-
     else
     {
-
+        qDebug() << "something wrong in handleCheckPoint()";
     }
 }
 
index d35218a..b85b062 100644 (file)
@@ -57,9 +57,11 @@ public:
     ~CarMainWindow();
     Registration *myRegistration;       //Check if this should be public or private
     LoginWindow *myLogin;
+    GPSData *gpsData;
 
     void setComboBoxStartTabUnits(QStringList units);       //Start-tab view
     void setListViewStartTabAccelerationCategories(QStringList numbers); //Start-tab view
+    void setLabelInfoToUser(QString infoText);
 
 protected:
     void changeEvent(QEvent *e);
@@ -72,7 +74,6 @@ private:
     CategoryList *myCategorylist;
     HttpClient *myHttpClient;
     RouteDialog *myRoute;
-    GPSData *gpsData;
     Maemo5Location *location;
     //void initCategoryCompoBox();
     void initComboBoxStartTabUnits();                   //Start-tab view
@@ -96,6 +97,7 @@ private:
 
     QModelIndex choice;
     int choiceInt;
+    QStringList catList;
 
     Calculate *calculate;
 
index a7eca51..e348b26 100644 (file)
@@ -24,7 +24,7 @@
      </rect>
     </property>
     <property name="currentIndex">
-     <number>4</number>
+     <number>1</number>
     </property>
     <widget class="QWidget" name="tabTop">
      <attribute name="title">
      <widget class="QListView" name="listViewStartTabAccelerationCategories">
       <property name="geometry">
        <rect>
-        <x>0</x>
+        <x>20</x>
         <y>10</y>
-        <width>151</width>
+        <width>251</width>
         <height>301</height>
        </rect>
       </property>
      <widget class="QWidget" name="layoutWidget">
       <property name="geometry">
        <rect>
-        <x>160</x>
+        <x>320</x>
         <y>10</y>
-        <width>311</width>
+        <width>161</width>
         <height>301</height>
        </rect>
       </property>
      <widget class="QLabel" name="labelMeasureTabHeader">
       <property name="geometry">
        <rect>
-        <x>40</x>
+        <x>20</x>
         <y>10</y>
         <width>261</width>
         <height>41</height>
      <widget class="QLabel" name="labelMeasureTabTimeHeader">
       <property name="geometry">
        <rect>
-        <x>25</x>
+        <x>20</x>
         <y>70</y>
         <width>60</width>
         <height>41</height>
      <widget class="QLabel" name="labelMeasureTabSpeedHeader">
       <property name="geometry">
        <rect>
-        <x>25</x>
+        <x>20</x>
         <y>160</y>
         <width>81</width>
         <height>41</height>
      <string>Registrate</string>
     </property>
    </widget>
+   <widget class="QLabel" name="labelInfoToUser">
+    <property name="geometry">
+     <rect>
+      <x>20</x>
+      <y>370</y>
+      <width>461</width>
+      <height>41</height>
+     </rect>
+    </property>
+    <property name="text">
+     <string/>
+    </property>
+   </widget>
   </widget>
   <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
index 3d3f451..243c5d3 100644 (file)
@@ -36,6 +36,7 @@ QStringList CategoryList::getCategoryList()
 
 /**
   *Append an item in the end of the categorylist.
+  *@param Item.
   */
 void CategoryList::appendCategoryList(QString item)
 {
@@ -44,6 +45,8 @@ void CategoryList::appendCategoryList(QString item)
 
 /**
   *Input an item into the categorylist.
+  *@param Index.
+  *@param Item to be appended.
   */
 void CategoryList::fillCategoryList(int index, QString item)
 {
@@ -52,6 +55,7 @@ void CategoryList::fillCategoryList(int index, QString item)
 
 /**
   *Show an item of the categorylist.
+  *@param Index.
   */
 QString CategoryList::itemOfCategoryList(int index)
 {
@@ -64,7 +68,6 @@ QString CategoryList::itemOfCategoryList(int index)
 void CategoryList::clearCategoryList()
 {
     categoryList.clear();
-    qDebug() << "_clearCategoryList" ;
 }
 
 /**
@@ -76,7 +79,42 @@ int CategoryList::sizeOfCategoryList()
 }
 
 /**
-  *This function is used to get items to top list of current category.
+  *Append an item in the end of the categoryelementable.
+  *@param Index.
+  *@param Description of category.
+  *@param Unit.
+  *@param Category.
+  */
+void CategoryList::appendCats(int ind, QString des, QString uni, QString cat)
+{
+    cats[ind].description = des;
+    cats[ind].unit = uni;
+    cats[ind].category = cat;
+}
+
+/**
+  *Clear categs.
+  */
+QString CategoryList::desOfCats(int ind)
+{
+    return cats[ind].description;
+}
+
+/**
+  *Clear cats.
+  */
+void CategoryList::clearCats()
+{
+    for(int i = 0; i < 10; i++)
+    {
+        cats[i].description.clear();
+        cats[i].unit.clear();
+        cats[i].category.clear();
+    }
+}
+
+/**
+  *This function is used to get items to top list of the category that is chosen from combobox.
   *@param QString category
   *@param int size
   */
index c7cdc9f..a03586e 100644 (file)
@@ -2,6 +2,7 @@
  * Categorylist
  *
  * @author     Olavi Pulkkinen <olavi.pulkkinena@fudeco.com>
+ * @author     Tiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
  * @copyright  (c) 2010 Speed Freak team
  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  */
@@ -25,9 +26,18 @@ public:
     QString getTopList( QString category, int size);
     void clearCategoryList();
     int sizeOfCategoryList();
+    void appendCats(int ind, QString des, QString uni, QString cat);
+    void clearCats();
+    QString desOfCats(int i);
 
 private:
-    QStringList categoryList;
+    QStringList categoryList;   //Stores categories. categoryList is routed to UI.
+    typedef struct {
+        QString category;       //name of category variable
+        QString description;    //verbal description of category
+        QString unit;           //km/h, miles/h
+    } categoryElements;
+    categoryElements cats[10];
 
 };
 
index fe7c0d3..457e609 100644 (file)
@@ -261,3 +261,19 @@ void GPSData::saveRoute()
         file.close();
     }
 }
+
+/**
+  *@return Pointer to gpsDataArray[][].
+  */
+double* GPSData::getGpsDataArray()
+{
+    return *gpsDataArray;
+}
+
+/**
+  *@return RoundCounter, the number of gpsDataArray[][] rows.
+  */
+int GPSData::getRoundCounter()
+{
+    return roundCounter;
+}
index f24e6eb..165b937 100644 (file)
@@ -24,6 +24,8 @@ public:
     void startRouteRecording(QString time);
     void stopRouteRecording(QString time);
     int roundCounter; //testing, move private!!!
+    double *getGpsDataArray();
+    int getRoundCounter();
 
 private:
     Maemo5Location *location;
index 53ad791..750aa42 100644 (file)
@@ -27,7 +27,6 @@ HttpClient::~HttpClient()
 /**
   *@brief Sends registration information to the server in xml format.
   *Reads user name, password and emaol address from resuldialogs internal variables.
-  *@todo Replace msg box with better reaction to server`s responce.
   */
 void HttpClient::requestRegistration()
 {
@@ -50,6 +49,7 @@ void HttpClient::requestRegistration()
     currentDownload = netManager->post(request, ("xml=" + regbuffer->data()));
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRegistration()));
     //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    myMainw->setLabelInfoToUser("Reguesting registration from server");
 
     regbuffer->close();
 }
@@ -57,7 +57,6 @@ void HttpClient::requestRegistration()
 /**
   *@brief Sends result(s) to the server in xml format.
   *Send authentication information in the header.
-  *@todo Read category elsewhere.
   */
 void HttpClient::sendResultXml(QString category)
 {
@@ -81,6 +80,39 @@ void HttpClient::sendResultXml(QString category)
     currentDownload = netManager->post(request, ("xml=" + xmlbuffer->data()));
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfResult()));
     //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    myMainw->setLabelInfoToUser("Sending result to server");
+
+    xmlbuffer->close();
+}
+
+/**
+  *@brief Sends route to the server in xml format.
+  *Send authentication information in the header.
+  *@todo Check destination URL.
+  */
+void HttpClient::sendRouteXml()
+{
+    qDebug() << "_sendResultXml";
+
+    QBuffer *xmlbuffer = new QBuffer();
+
+    QUrl qurl("http://api.speedfreak-app.com/api/update/route");
+    qDebug() << qurl.toString();
+    QNetworkRequest request(qurl);
+    QNetworkReply *currentDownload;
+
+    xmlbuffer->open(QBuffer::ReadWrite);
+    myXmlwriter->writeGpsTrack(xmlbuffer, myMainw->gpsData->getGpsDataArray(), myMainw->gpsData->getRoundCounter());
+    qDebug() << "carmainwindow: xmlbuffer->data(): " << xmlbuffer->data();
+
+    QString credentials = myMainw->myLogin->getUserName() + ":" + myMainw->myLogin->getPassword();
+    credentials = "Basic " + credentials.toAscii().toBase64();
+    request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
+
+    currentDownload = netManager->post(request, ("xml=" + xmlbuffer->data()));
+    connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRoute()));
+    //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    myMainw->setLabelInfoToUser("Sending route to server");
 
     xmlbuffer->close();
 }
@@ -108,6 +140,7 @@ void HttpClient::requestTopList(QString category, QString limit)
     currentDownload = netManager->post(request, ("data=" ));
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfToplist()));
     //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    myMainw->setLabelInfoToUser("Reguesting top10 list from server");
 }
 
 
@@ -131,6 +164,7 @@ void HttpClient::requestCategories()
     currentDownload = netManager->post(request, ("data=" ));
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfCategories()));
     //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    myMainw->setLabelInfoToUser("Reguesting categories from server");
 }
 
 
@@ -154,17 +188,19 @@ void HttpClient::checkLogin()
     currentDownload = netManager->post(request, ("data=" ));
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfLogin()));
     //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
+    myMainw->setLabelInfoToUser("Checking login validity from server");
 }
 
 
 /**
   *@brief React to servers responce after result has been sent.
-  *@todo Implement consequencies of reply.
   */
 void HttpClient::ackOfResult()
 {
     qDebug() << "_ackOfResult";
 
+    myMainw->setLabelInfoToUser("");
+
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
 
     QNetworkReply::NetworkError errorcode;
@@ -177,9 +213,30 @@ void HttpClient::ackOfResult()
         qDebug() << "errorcode:" << errorcode << reply->errorString();
         QMessageBox::about(myMainw, "Server reply to result sending", "Result received " + reply->readAll());
     }
-
 }
 
+/**
+  *@brief React to servers responce after route has been sent.
+  */
+void HttpClient::ackOfRoute()
+{
+    qDebug() << "_ackOfRoute";
+
+    myMainw->setLabelInfoToUser("");
+
+    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
+
+    QNetworkReply::NetworkError errorcode;
+    errorcode = reply->error();
+    if(errorcode != 0) {
+        qDebug() <<  "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(myMainw, "Server reply to route sending ",reply->errorString());
+    }
+    else {
+        qDebug() << "errorcode:" << errorcode << reply->errorString();
+        QMessageBox::about(myMainw, "Server reply to route sending", "Route received " + reply->readAll());
+    }
+}
 
 /**
   *@brief React to servers responce after registration has been sent.
@@ -189,6 +246,8 @@ void HttpClient::ackOfRegistration()
 {
     qDebug() << "_ackOfRegistration";
 
+    myMainw->setLabelInfoToUser("");
+
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
 
     QNetworkReply::NetworkError errorcode;
@@ -201,7 +260,6 @@ void HttpClient::ackOfRegistration()
         qDebug() << "errorcode=0" << errorcode << reply->errorString();
         QMessageBox::about(myMainw, "Server reply to registration", "User registration " + reply->readAll());
     }
-
 }
 
 
@@ -212,6 +270,8 @@ void HttpClient::ackOfCategories()
 {
     qDebug() << "_ackOfCategories";
 
+    myMainw->setLabelInfoToUser("");
+
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
     myXmlreader->xmlReadCategories(reply);
 
@@ -225,18 +285,18 @@ void HttpClient::ackOfCategories()
         qDebug() <<  "errorcode:" << errorcode << reply->errorString();
         QMessageBox::about(myMainw, "Server reply to requesting categories ", "OK");
     }
-
 }
 
 
 /**
   *@brief React to servers responce after request of TopList in certain category has been sent.
-  *@todo Implement routing reply`s contents to UI.
   */
 void HttpClient::ackOfLogin()
 {
     qDebug() << "_ackOffLogin";
 
+    myMainw->setLabelInfoToUser("");
+
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
 
     QNetworkReply::NetworkError errorcode;
@@ -259,29 +319,31 @@ void HttpClient::errorFromServer(QNetworkReply::NetworkError errorcode)
 {
     qDebug() << "_errorFromServer";
 
+    myMainw->setLabelInfoToUser("");
+
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
 
     if(errorcode != 0) {
         qDebug() <<  "errorcode:" << errorcode;
-        //Note that errors are already reported on other ach-functions for server communication
+        //Note that errors are already reported on other each functions for server communication
         //QMessageBox::about(myMainw, "Server reported an error", reply->errorString());
     }
     else {
         qDebug() <<  "errorcode:" << errorcode << reply->errorString();
         qDebug() << reply->readAll();
     }
-
 }
 
 
 /**
   *@brief React to servers responce after request of TopList in certain category has been sent.
-  *@todo Implement routing reply`s contents to UI.
   */
 void HttpClient::ackOfToplist()
 {
     qDebug() << "_ackOfToplist";
 
+    myMainw->setLabelInfoToUser("");
+
     QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
     myXmlreader->xmlReadTop10Results(reply);
 
@@ -295,6 +357,5 @@ void HttpClient::ackOfToplist()
         qDebug() <<  "errorcode:" << errorcode << reply->errorString();
         QMessageBox::about(myMainw, "Server reply to requesting top 10 list", "OK " + reply->readAll());
     }
-
 }
 
index ff50ffa..bdacf0e 100644 (file)
@@ -34,9 +34,11 @@ public slots:
     void requestRegistration();
     void checkLogin();
     void sendResultXml(QString category);
+    void sendRouteXml();
     void requestTopList(QString category, QString limit);
     void requestCategories();
     void ackOfResult();
+    void ackOfRoute();
     void ackOfRegistration();
     void ackOfCategories();
     void ackOfToplist();
diff --git a/Client/movingaverage.cpp b/Client/movingaverage.cpp
new file mode 100644 (file)
index 0000000..645f34a
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *  Class for moving average of acceleration data.
+ *
+ * @author      Kai Rasilainen
+ * @copyright   (c) 2010 Speed Freak team
+ * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
+ */
+
+#include "movingaverage.h"
+#include <QList>
+
+MovingAverage::MovingAverage(int sizeLimit)
+{
+    SizeLimit = sizeLimit;
+}
+
+double MovingAverage::Average()
+{
+    double sum = 0;
+
+    if (queue.count() == 0)
+        return 0;
+
+    QList<double> temp = queue;
+    foreach (double value, temp)
+    {
+        sum += value;
+    }
+
+    return sum / queue.count();
+}
+
+void MovingAverage::Resize(int sizeLimit)
+{
+    SizeLimit = sizeLimit;
+    while (queue.count() > SizeLimit)
+    {
+        queue.dequeue();
+    }
+}
+
+void MovingAverage::Enqueue(double item)
+{
+    queue.enqueue(item);
+    if (queue.count() > SizeLimit)
+        queue.dequeue();
+}
+
+
diff --git a/Client/movingaverage.h b/Client/movingaverage.h
new file mode 100644 (file)
index 0000000..53962fb
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  Class for moving average of acceleration data.
+ *
+ * @author      Kai Rasilainen
+ * @copyright   (c) 2010 Speed Freak team
+ * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
+ */
+
+#ifndef MOVINGAVERAGE_H
+#define MOVINGAVERAGE_H
+
+#include <QQueue>
+
+class MovingAverage
+{
+
+public:
+    MovingAverage(int sizeLimit);
+
+    double Average();
+    void Resize(int sizeLimit);
+    void Enqueue(double item);
+
+private:
+    int SizeLimit;
+    QQueue<double> queue;
+};
+
+#endif // MOVINGAVERAGE_H
index bc4f8c7..a410944 100644 (file)
@@ -11,7 +11,9 @@
 #include <cmath>
 #include <QPainter>
 #include <QList>
-//#include <QMessageBox>
+#include <QMessageBox>
+#include <QFile>
+#include <QFileDialog>
 
 /*
   * Vector class
@@ -53,81 +55,98 @@ public:
     };
 };
 
-int left, top, right, bottom;       // Limits in screen coordinates
+
+class Viewing
+{
+    Vector atPoint, fromPoint, up, a1, a2, a3;
+    qreal offsx, offsy, offsz;
+    qreal dval;
+    qreal angle;
+public:
+    qreal getOffsx() { return offsx; };
+    qreal getOffsy() { return offsx; };
+    qreal getOffsz() { return offsz; };
+    qreal getDval() { return dval; };
+    void setAngle( qreal newA) { angle = newA; };
+    void setUp( qreal newUpX, qreal newUpY, qreal newUpZ)
+    {
+        up.setX(newUpX); up.setY(newUpY); up.setZ(newUpZ);
+    };
+    void setAtPoint( qreal newX, qreal newY, qreal newZ)
+    {
+        atPoint.setX(newX); atPoint.setY(newY); atPoint.setZ(newZ);
+    };
+    void setFromPoint(qreal newX, qreal newY, qreal newZ)
+    {
+        fromPoint.setX(newX); fromPoint.setY(newY); fromPoint.setZ(newZ);
+    }
+    void setEye()
+    {
+        double amarkmag, tempmag;
+        Vector temp, dist;
+
+        dval = cos(angle/2.0)/sin(angle/2.0);
+        dist = atPoint-fromPoint;
+        amarkmag = dist.length();
+        a3 = dist/amarkmag;
+
+        temp.crossProduct( dist, up);
+        tempmag = temp.length();
+        a1 = temp/tempmag;
+
+        temp.crossProduct( a1, a3);
+        tempmag = temp.length();
+        a2 = temp/tempmag;
+
+        offsx = -a1.getX()*fromPoint.getX() - a1.getY()*fromPoint.getY() - a1.getZ()*fromPoint.getZ();
+        offsy = -a2.getX()*fromPoint.getX() - a2.getY()*fromPoint.getY() - a2.getZ()*fromPoint.getZ();
+        offsz = -a3.getX()*fromPoint.getX() - a3.getY()*fromPoint.getY() - a3.getZ()*fromPoint.getZ();
+        QString jono2 = QString("offsx %1 offsy %2 offsz %3").arg(offsx).arg(offsy).arg(offsz);
+        QMessageBox::about(0,"offs x y z", jono2);
+    } ;
+    Vector getAtPoint() { return atPoint; };
+    Vector getFromPoint() { return fromPoint; };
+    Vector getA1() { return a1; };
+    Vector getA2() { return a2; };
+    Vector getA3() { return a3; };
+    Viewing () {};
+};
+
 qreal xmax, xmin, ymin, ymax;       // Limits in world coordinates
 
 QList<Vector> vertexList;           // Vertecies of route
 
-Vector atPoint, fromPoint, up, a1, a2, a3;
-qreal offsx, offsy, offsz;
+//Vector atPoint, fromPoint, up, a1, a2, a3;
+//qreal offsx, offsy, offsz;
 
 qreal objxmin, objxmax, objymin, objymax, objzmin, objzmax;
-qreal angle;
-qreal a, b,c,d, dval;
+//qreal angle;
+qreal a, b,c,d; //, dval;
 
 #define maxof(val1,val2)  ((val1>val2)?val1:val2)
 #define toradians( degrees) (degrees*0.017453293)
 
 #define WIDTH 1.8
 
-int length = 24;
-int connection[30];
+int length = 34; // 24;
+int connection[50];
+
+void setAtPoint( Viewing *v);
+void setFromPoint( Viewing *v);
+//void setEye();
+
+Viewing view3d;
+
+void dataMinMax( void);
+
 
-void setAtPoint();
-void setFromPoint();
-void setEye();
 
 RouteDialog::RouteDialog(QWidget *parent) :
     QDialog(parent),
     ui(new Ui::RouteDialog)
 {
     ui->setupUi(this);
-    //left = 50; top = 50; right = 350; bottom = 200;
-    left = 5; top = 5; right = 395; bottom = 295;
-    xmin =0.0; xmax=100.0; ymin = 0.0; ymax = 20.0;
-    // Ruudun koko 400 x 300
-
-    /*vertexList.append(QVector3D(40.02, 10.02, 10.02));
-   vertexList.append(QVector3D(50.01,  5.01, 10));
-   vertexList.append(QVector3D(69.98,  4.98, 10));
-   vertexList.append(QVector3D(80.02,  9.98, 10));
-   vertexList.append(QVector3D(70.01, 15.01, 10));
-   vertexList.append(QVector3D(49.99, 14.97, 10));
-   vertexList.append(QVector3D(40.01, 10.01, 10.02));
-*/
-       vertexList.append(Vector(0.0, 0.0, 0.0));
-       vertexList.append(Vector(1.0, 1.0, 1.0));
-       vertexList.append(Vector(1.0, 1.0, 0.0));
-
-       vertexList.append(Vector(1.0, 0.0, 0.0));
-       vertexList.append(Vector(1.0, 0.0, 1.0));
-       vertexList.append(Vector(0.0, 1.0, 1.0));
-
-       vertexList.append(Vector(0.0, 1.0, 0.0));
-       vertexList.append(Vector(0.0, 0.0, 0.0));
-       vertexList.append(Vector(0.0, 0.0, 1.0));
-
-   connection[0] = 0;
-   connection[1] = 1; connection[2] = 5; connection[3] = 8; connection[4] = -4;
-   connection[5] =  5; connection[6] = 6; connection[7] = 7; connection[8] = -8;
-   connection[9] =  6; connection[10] = 2; connection[11] = 3; connection[12] = -7;
-   connection[13] = 1; connection[14] = 4; connection[15] = 3; connection[16] = -2;
-   connection[17] = 8; connection[18] = 7; connection[19] = 3; connection[20] = -4;
-   connection[21] = 6;  connection[22] = 5; connection[23] = 1;  connection[24] = -2;
-
-   fromPoint.setX( 1.0); fromPoint.setY( 0.0); fromPoint.setZ( 0.0);
-   atPoint.setX( 0.0); atPoint.setY( 0.0); atPoint.setZ( 0.0);
-   up.setX( 0.0); up.setY( 0.0); up.setZ(1.0);
-
-   a = 400/2.;
-   b = 1 - a*(-1);
-   c = -300/2.;
-   d = 300 - c*(-1);
-   angle = toradians(60);
-
-   setAtPoint();
-   setFromPoint();
-   setEye();
+    left = 5; top = 5; right = 395; bottom = 195; // Limits in screen coordinates
 }
 
 RouteDialog::~RouteDialog()
@@ -151,50 +170,170 @@ void RouteDialog::changeEvent(QEvent *e)
 /**
   * Draws route to the route dialog
   * @param QPaintEvent
- *
+ */
+/* */
 void RouteDialog::paintEvent(QPaintEvent *)
 {
     // 2d draw
+    int startx, starty; // Starting point of the route
     int i, maxi;
     qreal x1, y1, x2, y2;
     int scx1, scy1, scx2, scy2;
+    Vector v1, v2;
+    QPainter painter(this);
 
-        QPainter painter(this);
-
-        painter.setRenderHint(QPainter::Antialiasing, true);
-        painter.setPen(QPen((Qt::black),2));
-        painter.setBrush(QBrush((Qt::yellow), Qt::SolidPattern));
+    painter.setRenderHint(QPainter::Antialiasing, true);
+    painter.setPen(QPen((Qt::white),2));
+    painter.setBrush(QBrush((Qt::yellow), Qt::SolidPattern));
 
-        // Draw route window frsme
-        painter.drawLine(left,top,right,top);
-        painter.drawLine(right,top,right,bottom);
-        painter.drawLine(left,top,left,bottom);
-        painter.drawLine(left,bottom,right,bottom);
+    // Draw route window frame
+    /*painter.drawLine(left,top,right,top);
+    painter.drawLine(right,top,right,bottom);
+    painter.drawLine(left,top,left,bottom);
+    painter.drawLine(left,bottom,right,bottom);
+    */
 
-        //maxi = vertexList.size();
-        for (i=0; i<maxi-1; i++)
+    maxi = vertexList.size()-1; // -1 to remove wrong last point !!!
+    for (i=0; i<maxi-1; i++)
+    {
+        v1 = vertexList.at(i);
+        v2 = vertexList.at(i+1);
+        x1 = v1.getX(); y1 = v1.getY();
+        x2 = v2.getX(); y2 = v2.getY();
+        //QString jono = QString("x: %1 y: %2").arg(x1).arg(y1);
+        //QMessageBox::about(0,"Tark",jono);
+
+        scx1 = left + (x1-xmin)/(xmax-xmin)*(right-left);
+        scy1 = top + (ymax-y1)/(ymax-ymin)*(bottom-top);
+        scx2 = left + (x2-xmin)/(xmax-xmin)*(right-left);
+        scy2 = top + (ymax-y2)/(ymax-ymin)*(bottom-top);
+
+        // Show with circle if starting point
+        if (i==0)
         {
-            x1 = vertexList.at(i).x();
-            y1 = vertexList.at(i).y();
-            x2 = vertexList.at(i+1).x();
-            y2 = vertexList.at(i+1).y();
-
-            scx1 = left + (x1-xmin)/(xmax-xmin)*(right-left);
-            scy1 = top + (ymax-y1)/(ymax-ymin)*(bottom-top);
-            scx2 = left + (x2-xmin)/(xmax-xmin)*(right-left);
-            scy2 = top + (ymax-y2)/(ymax-ymin)*(bottom-top);
-
-            painter.drawLine( scx1, scy1, scx2, scy2);
+            // Starting point
+            startx = scx1; starty = scy1;
+            painter.drawEllipse( scx1-5, scy1-5, 10, 10);
         }
+        painter.drawLine( scx1, scy1, scx2, scy2);
+    }
+    // Show the endig point if different than the starting point
+    if (scx2 != startx || scy2 != starty)
+    {
+        painter.drawEllipse( scx2-5, scy2-5, 10, 10);
+    }
 }
-*/
+/* */
 
 void RouteDialog::on_closePushButton_clicked()
 {
     close();
 }
 
-// Next functions below for 3D
+bool RouteDialog::readRouteFromFile( QString &filename)
+{
+/* 2d */
+    Vector temp;
+    int i;
+    QString rivi;
+    QFile file;
+    //file.setFileName("route.txt");
+    QString fileName = QFileDialog::getOpenFileName(this,
+    tr("Read Route"), "./", tr("Route Files (*.txt)"));
+
+    file.setFileName( fileName);
+    if (!file.open(QIODevice::ReadOnly))
+    {
+        QMessageBox::about(0, "Error", "File not found");
+        return false;
+    }
+
+    vertexList.clear();
+    i = 0;
+    //while( file.canReadLine())
+    while(!file.atEnd())
+    {
+        QString str1, str2, str3;
+        rivi = file.readLine();
+
+        str1 = rivi.section(" ", 0, 0);
+        if (str1.compare("Start:") == 0 || str1.compare("Stop:") == 0)
+        {
+
+        }
+        else
+        {
+            //QMessageBox::about(0, "LUKEE", file.readLine());
+            str1 = rivi.section(" ",  2, 2); // latitude y-value
+            str2 = rivi.section(" ",  4, 4); // longitude x-value
+            str3 = rivi.section(" ",  6, 6); // altitude z-value
+            QString str = QString("la: %1 lo: %2 al: %3").arg(str1).arg(str2).arg(str3);
+            //QMessageBox::about(0, "LUKEE", str);
+
+            double x, y, z;
+            x = str2.toDouble();
+            y = str1.toDouble();
+            z = str3.toDouble();
+            temp.setX( x); // Longitude
+            temp.setY( y);// Latitude
+            temp.setZ( z);// altitude
+
+           vertexList.append(temp);
+        }
+        i++;
+    }
+
+   // la: lo: al:
+    file.close();
+
+   /* */
+     /* for 3D test */
+     /*vertexList.append(Vector(0.0, 0.0, 0.0));
+     vertexList.append(Vector(1.0, 1.0, 1.0));
+     vertexList.append(Vector(1.0, 1.0, 0.0));
+
+     vertexList.append(Vector(1.0, 0.0, 0.0));
+     vertexList.append(Vector(1.0, 0.0, 1.0));
+     vertexList.append(Vector(0.0, 1.0, 1.0));
+
+     vertexList.append(Vector(0.0, 1.0, 0.0));
+     vertexList.append(Vector(0.0, 0.0, 0.0));
+     vertexList.append(Vector(0.0, 0.0, 1.0));
+*/
+     /* For 3d */
+     //int i;
+     for(i= 0; i<35; i++)
+     {
+         connection[i] = i;
+     }
+ /* connection[0] = 0;
+ connection[1] = 1; connection[2] = 5; connection[3] = 8; connection[4] = -4;
+ connection[5] =  5; connection[6] = 6; connection[7] = 7; connection[8] = -8;
+ connection[9] =  6; connection[10] = 2; connection[11] = 3; connection[12] = -7;
+ connection[13] = 1; connection[14] = 4; connection[15] = 3; connection[16] = -2;
+ connection[17] = 8; connection[18] = 7; connection[19] = 3; connection[20] = -4;
+ connection[21] = 6;  connection[22] = 5; connection[23] = 1;  connection[24] = -2;*/
+
+     /********  in 3d use only */
+     a = 400/2.;
+     b = 1 - a*(-1);
+     c = -300/2.;
+     d = 300 - c*(-1);
+     //angle = toradians(60);
+
+     view3d.setUp( 0.0, 0.0, 1.0);
+     view3d.setAngle(toradians(60));
+     setAtPoint( &view3d);
+     xmin = objxmin; xmax = objxmax; ymin = objymin; ymax = objymax;
+     setFromPoint( &view3d);
+     view3d.setEye();
+     /****** end of 3d *****/
+     return true;
+}
+
+/*
+  * Find out data range for x-, y- and z-coordinates
+  */
 void dataMinMax( void)
 {
     int i, maxi;
@@ -206,7 +345,7 @@ void dataMinMax( void)
     objymax = objymin = temp.getY();
     objzmax = objzmin = temp.getZ();
 
-    maxi = vertexList.size();
+    maxi = vertexList.size()-1; // Wrong last data
     //maxi = 9;
     for (i=1; i<maxi; i++)
     {
@@ -248,29 +387,54 @@ void dataMinMax( void)
     //QMessageBox::about(0,"Tark", jono);
 }
 
-void setAtPoint()
+
+void setAtPoint( Viewing *v)
 {
+    qreal x, y, z;
     dataMinMax();
-    atPoint.setX((objxmax+objxmin)/2.0);
-    atPoint.setY((objymax+objymin)/2.0);
-    atPoint.setZ((objzmax+objzmin)/2.0);
+    Vector test;
+    //atPoint.setX((
+            x = (objxmax+objxmin)/2.0;
+    //atPoint.setY(
+            y= (objymax+objymin)/2.0;
+    //atPoint.setZ(
+            z= (objzmax+objzmin)/2.0;
+            v->setAtPoint( x, y, z);
     //QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(atPoint.x()).arg(atPoint.y()).arg(atPoint.z());
     //QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(atPoint.x).arg(atPoint.y).arg(atPoint.z);
-    //QMessageBox::about(0,"At point", jono);
+
+    /* *
+    test = v->getAtPoint();
+    QString jono = QString("AtX %1 Aty %2 AtZ %3").arg(test.getX()).arg(test.getY()).arg(test.getZ());
+    QMessageBox::about(0,"At point", jono);
+    * */
 }
 
-void setFromPoint()
+void setFromPoint( Viewing *v)
 {
+    qreal x, y, z;
+    Vector point;
+    point = v->getAtPoint();
+    Vector test;
     //fromPoint.setX( atPoint.getX() + (objxmax-objxmin)/2.0 + WIDTH*maxof((objzmax-objzmin)/2.0,(objymax-objymin)/2.0));
-    fromPoint.setX(3.0);
-    fromPoint.setY( atPoint.getY());
-    fromPoint.setZ( atPoint.getZ());
+    //fromPoint.setX(
+            //x = 3.0;
+            x = point.getX() + 300; //25;
+    //fromPoint.setY(
+            y = point.getY();
+    //fromPoint.setZ(
+            z = point.getZ(); // + 150;
+            v->setFromPoint(x,y,z);
     //QString jono = QString("FromX %1 FromY %2 FromZ %3").arg(fromPoint.x()).arg(fromPoint.y()).arg(fromPoint.z());
     //QString jono = QString("FromX %1 FromY %2 FromZ %3").arg(fromPoint.x).arg(fromPoint.y).arg(fromPoint.z);
-    //QMessageBox::about(0,"From point", jono); // (1.9, 0.5, 0.5)
+    /* *
+    test = v->getFromPoint();
+    QString jono = QString("FromX %1 FromY %2 FromZ %3").arg(test.getX()).arg(test.getY()).arg(test.getZ());
+    QMessageBox::about(0,"From point", jono); // (1.9, 0.5, 0.5)
+    * */
 }
 
-void setEye()
+/*void setEye()
 {
     double amarkmag, tempmag;
     Vector temp, dist;
@@ -293,7 +457,7 @@ void setEye()
     offsz = -a3.getX()*fromPoint.getX() - a3.getY()*fromPoint.getY() - a3.getZ()*fromPoint.getZ();
     //QString jono2 = QString("offsx %1 offsy %2 offsz %3").arg(offsx).arg(offsy).arg(offsz);
     //QMessageBox::about(0,"offs x y z", jono2);
-}
+}*/
 
 #define NOEDGE     0x00
 #define LEFTEDGE   0x01
@@ -404,10 +568,20 @@ void clip3d( qreal x1, qreal y1, qreal z1, qreal x2, qreal y2, qreal z2, int *xs
   * Transform the segment connecting the two vectors into the viewing plane.
   * clip3d() clips the line if needed.
   */
-void transformseg( Vector *v1, Vector *v2, int *xscreen1, int *yscreen1, int *xscreen2, int *yscreen2 )
+void transformseg( Viewing *v, Vector *v1, Vector *v2, int *xscreen1, int *yscreen1, int *xscreen2, int *yscreen2 )
 
 {
     qreal x1, y1, z1, x2, y2, z2;
+    qreal offsx, offsy, offsz;
+    qreal dval;
+    Vector a1, a2, a3;
+    a1 = v->getA1();
+    a2 = v->getA2();
+    a3 = v->getA3();
+    offsx = v->getOffsx();
+    offsy = v->getOffsy();
+    offsz = v->getOffsz();
+    dval = v->getDval();
 
     x1 = (a1.getX()*v1->getX() + a1.getY()*v1->getY() + a1.getZ()*v1->getZ() + offsx)*dval;
     y1 = (a2.getX()*v1->getX() + a2.getY()*v1->getY() + a2.getZ()*v1->getZ() + offsy)*dval;
@@ -420,12 +594,14 @@ void transformseg( Vector *v1, Vector *v2, int *xscreen1, int *yscreen1, int *xs
     clip3d(x1,y1,z1,x2,y2,z2, xscreen1, yscreen1, xscreen2, yscreen2 );
 }
 
+/*
+  *
+  * 3D route viewing
+*
 void RouteDialog::paintEvent(QPaintEvent *)
 {
     int i, startofside;
-    qreal x1, y1, x2, y2;
-    int scx1, scy1, scx2, scy2;
-    int xpc1, ypc1, xpc2, ypc2;
+    int xscreen1, yscreen1, xscreen2, yscreen2;
     Vector temp1, temp2;
 
     QPainter painter(this);
@@ -440,6 +616,21 @@ void RouteDialog::paintEvent(QPaintEvent *)
     //painter.drawLine(left,top,left,bottom);
     //painter.drawLine(left,bottom,right,bottom);
 
+    i = 1;
+    while (i<length)
+    {
+        temp1 = vertexList.at(connection[i-1]);
+        temp2 = vertexList.at(connection[i]);
+        transformseg( &view3d, &temp1,&temp2, &xscreen1, &yscreen1, &xscreen2, &yscreen2);
+
+        painter.drawLine(xscreen1, yscreen1, xscreen2, yscreen2);
+        if (i==1)
+        {
+            painter.drawEllipse( xscreen1-5, yscreen1-5, 10, 10);
+        }
+        i++;
+    }
+    /*
     i=1;
     while(i<length)
     {
@@ -450,23 +641,29 @@ void RouteDialog::paintEvent(QPaintEvent *)
             //transformseg( &pa[connection[i-1]],&pa[connection[i]], &xpc1, &ypc1, &xpc2, &ypc2);
             temp1 = vertexList.at(connection[i-1]);
             temp2 = vertexList.at(connection[i]);
-            transformseg( &temp1,&temp2, &xpc1, &ypc1, &xpc2, &ypc2);
+            transformseg( &view3d, &temp1,&temp2, &xscreen1, &yscreen1, &xscreen2, &yscreen2);
 
-            painter.drawLine(xpc1, ypc1, xpc2, ypc2);
+            painter.drawLine(xscreen1, yscreen1, xscreen2, yscreen2);
+            if (i==2)
+            {
+                painter.drawEllipse( xscreen1-5, yscreen1-5, 10, 10);
+            }
             i++;
         }
         // to last segment
         //transformseg( &pa[connection[i-1]],&pa[-connection[i]],&xpc1, &ypc1, &xpc2, &ypc2);
         temp1 = vertexList.at(connection[i-1]);
         temp2 = vertexList.at(-connection[i]);
-        transformseg( &temp1,&temp2, &xpc1, &ypc1, &xpc2, &ypc2);
-        painter.drawLine(xpc1, ypc1, xpc2, ypc2);
+        transformseg( &view3d, &temp1,&temp2, &xscreen1, &yscreen1, &xscreen2, &yscreen2);
+        painter.drawLine(xscreen1, yscreen1, xscreen2, yscreen2);
         // from last segemt to start
         //transformseg( &pa[-connection[i]],&pa[connection[startofside]],&xpc1, &ypc1, &xpc2, &ypc2);
         temp1 = vertexList.at(-connection[i]);
         temp2 = vertexList.at(connection[startofside]);
-        transformseg( &temp1,&temp2, &xpc1, &ypc1, &xpc2, &ypc2);
-        painter.drawLine(xpc1, ypc1, xpc2, ypc2);
+        transformseg( &view3d, &temp1,&temp2, &xscreen1, &yscreen1, &xscreen2, &yscreen2);
+        painter.drawLine(xscreen1, yscreen1, xscreen2, yscreen2);
         i++;
     }
+    *
 }
+** */
index 11794f1..ce4a6a5 100644 (file)
@@ -12,6 +12,7 @@ class RouteDialog : public QDialog {
 public:
     RouteDialog(QWidget *parent = 0);
     ~RouteDialog();
+    bool readRouteFromFile( QString &routeFile);
 
 protected:
     void changeEvent(QEvent *e);
@@ -19,6 +20,7 @@ protected:
 
 private:
     Ui::RouteDialog *ui;
+    int left, top, right, bottom;       // Limits in screen coordinates in route dialog
 
 private slots:
     void on_closePushButton_clicked();
index b997989..2bcc168 100644 (file)
@@ -112,7 +112,7 @@ void XmlReader::xmlReadCategories(QNetworkReply *device)
     if(myCategoryList->sizeOfCategoryList() != 0) {
         myCategoryList->clearCategoryList();
     }
-    //qDebug() << "sizeOfCategoryList(): " << myCategoryList->sizeOfCategoryList();
+    myCategoryList->clearCats();
 
     //Go trough the xml document
     while(!xmlreader.atEnd())
@@ -130,8 +130,14 @@ void XmlReader::xmlReadCategories(QNetworkReply *device)
             if(xmlreader.name() == "category")
             {
                 qDebug() << xmlreader.name();
-                myCategoryList->appendCategoryList(xmlreader.readElementText());
-                qDebug() << "i=" << i << myCategoryList->itemOfCategoryList(i);
+                attr = xmlreader.attributes();
+                description = attr.value("description").toString();
+                unit = attr.value("unit").toString();
+                category = xmlreader.readElementText();
+                myCategoryList->appendCategoryList(category);
+                myCategoryList->appendCats(i, description, unit, category);
+                //qDebug() << "i=" << i << myCategoryList->itemOfCategoryList(i);
+                //qDebug() << "description: " << description << "unit: " << unit << "category: " << category;
                 i++;
                 receivedFlag = 1;
             }
index 9704ec3..4a751a3 100644 (file)
@@ -32,6 +32,7 @@ private:
     QString position;
     QString user;
     QString value;
+    QString description;
 
 signals:
     void receivedCategoryList();
index 51eeb46..26eed66 100644 (file)
@@ -17,7 +17,6 @@
 XmlWriter::XmlWriter()
 {
     tmpvalue = 110;
-    trackInd = 0;
 }
 
 /**
@@ -84,17 +83,21 @@ void XmlWriter::writeResult(QBuffer *netbuf)
 
 /**
   *@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.
+  *@param ptrTable points to GPSData::gpsDataArray[100][4].
+  *@param counter is GPSData::roundCounter.
+  *@todo Decide suitable attributes.
   */
-void XmlWriter::writeGpsTrack(int startInd, int stopInd)
+void XmlWriter::writeGpsTrack(QBuffer *netbuf, double *ptrTable, int counter)
 {
     qDebug() << "_writeGpsTrack";
-    analyzeGpsData();
 
-    int i = 0;
+    double *ptrValue;
+    ptrValue = ptrTable;
+    double tmp = 0;
+
+    xmlwriter.setDevice(netbuf);
+
+    xmlwriter.writeStartDocument();
 
     xmlwriter.writeStartElement("gpx");
     xmlwriter.writeAttribute("someattribute", "abc");
@@ -115,27 +118,31 @@ void XmlWriter::writeGpsTrack(int startInd, int stopInd)
     xmlwriter.writeCharacters("Example Track");
     xmlwriter.writeEndElement();
     xmlwriter.writeStartElement("trkseg");
-    for(i = startInd; i < (stopInd - startInd); i++) {
+    for(int i = 0; i < counter; i++)
+    {
         xmlwriter.writeStartElement("trkpt");
-        xmlwriter.writeAttribute("lat", QString::number(trackTable[i].latitude));
-        xmlwriter.writeAttribute("lon", QString::number(trackTable[i].longitude));
+        tmp = *ptrValue;
+        ptrValue++;
+        xmlwriter.writeAttribute("lat", QString::number(tmp));    //gpspoints[i][0]
+        tmp = *ptrValue;
+        ptrValue++;
+        xmlwriter.writeAttribute("lon", QString::number(tmp));    //gpspoints[i][1]
         xmlwriter.writeStartElement("ele");
-        xmlwriter.writeCharacters(QString::number(trackTable[i].altitude));
-        xmlwriter.writeEndElement();
-        xmlwriter.writeStartElement("time");
-        xmlwriter.writeCharacters(QString::number(trackTable[i].time));
+        tmp = *ptrValue;
+        ptrValue++;
+        xmlwriter.writeCharacters(QString::number(tmp));          //gpspoints[i][2]
         xmlwriter.writeEndElement();
         xmlwriter.writeStartElement("speed");
-        xmlwriter.writeCharacters(QString::number(trackTable[i].speed));
-        xmlwriter.writeEndElement();
-        xmlwriter.writeStartElement("track");
-        xmlwriter.writeCharacters(QString::number(trackTable[i].track));
+        tmp = *ptrValue;
+        ptrValue++;
+        xmlwriter.writeCharacters(QString::number(tmp));          //gpspoints[i][3]
         xmlwriter.writeEndElement();
         xmlwriter.writeEndElement();    //trkpt
     }
-    xmlwriter.writeEndElement();    //trkseg
-    xmlwriter.writeEndElement();    //trk
-    xmlwriter.writeEndElement();    //gpx
+    xmlwriter.writeEndElement();        //trkseg
+    xmlwriter.writeEndElement();        //trk
+    xmlwriter.writeEndElement();        //gpx
+    xmlwriter.writeEndDocument();
 }
 
 
@@ -176,8 +183,7 @@ bool XmlWriter::writeXmlFile(QIODevice *device)
     xmlwriter.setDevice(device);
     xmlwriter.writeStartDocument();
     //writeItems();
-    //serverWritesXml();
-    writeGpsTrack(0, 16);
+    serverWritesXml();
     xmlwriter.writeEndDocument();
 
     return true;
@@ -204,26 +210,6 @@ void XmlWriter::writeItems()
   */
 void XmlWriter::serverWritesXml()
 {
-    /* Server sends to client */
-    /*
-    int i = 0;
-    int n = 5;
-
-    //Write top 10 Results
-    xmlwriter.writeStartElement("results");
-    xmlwriter.writeAttribute("category", "acceleration-0-40");
-    xmlwriter.writeAttribute("unit", "seconds");
-    xmlwriter.writeAttribute("description", "Acceleration from 0 to 100 km/h");
-
-    for (i = 0; i < n; i++) {
-        xmlwriter.writeStartElement("result");
-        xmlwriter.writeAttribute("position", QString::number(i));
-        xmlwriter.writeAttribute("user", "test123");
-        xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
-        xmlwriter.writeAttribute("value", QString::number(i+i+1));
-        xmlwriter.writeEndElement();
-    }
-    */
     //Write categories
     xmlwriter.writeStartElement("categories");
 
@@ -241,87 +227,3 @@ 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 34bf284..80ff500 100644 (file)
@@ -30,16 +30,6 @@ 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:
@@ -48,14 +38,12 @@ private:
 public slots:
     void writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email);
     void writeResult(QBuffer *netbuf);
+    void writeGpsTrack(QBuffer *netbuf, double *ptrTable, int counter);
     bool writeXmlFile(QIODevice *device);
     //void writeXml(QString usr, QString psswd, QString email);
     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