Added button for sending route to server. v0.1
authorTiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
Fri, 26 Mar 2010 13:02:24 +0000 (15:02 +0200)
committerTiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
Fri, 26 Mar 2010 13:02:24 +0000 (15:02 +0200)
Client/carmainwindow.cpp
Client/carmainwindow.h
Client/carmainwindow.ui
Client/gpsdata.cpp
Client/gpsdata.h
Client/httpclient.cpp
Client/xmlwriter.cpp
Client/xmlwriter.h

index 9a48d90..5da33b7 100644 (file)
@@ -156,11 +156,12 @@ void CarMainWindow::on_listViewStartTabAccelerationCategories_clicked(QModelInde
 {
     QString str = index.data().toString();
     QStringList list = str.split("-");
 {
     QString str = index.data().toString();
     QStringList list = str.split("-");
-    QStringList list2 = list[1].split(" ");
+    QStringList list3 = list[1].split(" ");
+    QStringList list2 = list[0].split(" ");
 
 
-    ui->lineEditStartTabMin->setText(list[0]);
-    ui->lineEditStartTabMax->setText(list2[0]);
-    updateComboBoxStartTabUnits(list2[1]);
+    ui->lineEditStartTabMin->setText(list2[1]);
+    ui->lineEditStartTabMax->setText(list3[0]);
+    updateComboBoxStartTabUnits(list3[1]);
 }
 
 /**
 }
 
 /**
@@ -245,7 +246,7 @@ void CarMainWindow::initListViewStartTabAccelerationCategories()
     catList.insert(1,"acceleration-0-100");
     catList.insert(2,"acceleration-0-10");
 
     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";
+    accelerationCategoriesStartTab << "Acceleration 0-40 km/h" << "Acceleration 0-100 km/h" << "Acceleration 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);
     //<< "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);
@@ -445,6 +446,11 @@ void CarMainWindow::on_drawRoutePushButton_clicked()
     }
 }
 
     }
 }
 
+void CarMainWindow::on_sendRoutePushButton_clicked()
+{
+    myHttpClient->sendRouteXml();
+}
+
 /**
   * Opens result dialog when show result button is clicked.
   * Sends measures as parameter to the resultdialogs saveMeasuresToArray-function.
 /**
   * Opens result dialog when show result button is clicked.
   * Sends measures as parameter to the resultdialogs saveMeasuresToArray-function.
@@ -838,3 +844,4 @@ void CarMainWindow::on_calibrateButton_clicked()
 
     this->accelerometer->calibrate();
 }
 
     this->accelerometer->calibrate();
 }
+
index 433ee9d..83cbafa 100644 (file)
@@ -146,6 +146,7 @@ private slots:
     void on_gpsOnCheckBox_stateChanged(int GPSState);   //Route-tab view
     void gpsStatus();                                   //Route-tab view
     void on_drawRoutePushButton_clicked();
     void on_gpsOnCheckBox_stateChanged(int GPSState);   //Route-tab view
     void gpsStatus();                                   //Route-tab view
     void on_drawRoutePushButton_clicked();
+    void on_sendRoutePushButton_clicked();
     void on_pushButtonSendResult_clicked();
     void on_pushButtonMeasureTabAbort_clicked();
     void on_manualStartButton_clicked();
     void on_pushButtonSendResult_clicked();
     void on_pushButtonMeasureTabAbort_clicked();
     void on_manualStartButton_clicked();
index 6acf29a..8c0e7f0 100644 (file)
@@ -24,7 +24,7 @@
      </rect>
     </property>
     <property name="currentIndex">
      </rect>
     </property>
     <property name="currentIndex">
-     <number>1</number>
+     <number>4</number>
     </property>
     <widget class="QWidget" name="tabTop">
      <attribute name="title">
     </property>
     <widget class="QWidget" name="tabTop">
      <attribute name="title">
       <property name="geometry">
        <rect>
         <x>20</x>
       <property name="geometry">
        <rect>
         <x>20</x>
-        <y>40</y>
+        <y>20</y>
         <width>191</width>
         <height>41</height>
        </rect>
         <width>191</width>
         <height>41</height>
        </rect>
       <property name="geometry">
        <rect>
         <x>10</x>
       <property name="geometry">
        <rect>
         <x>10</x>
-        <y>130</y>
+        <y>80</y>
         <width>201</width>
         <height>61</height>
        </rect>
         <width>201</width>
         <height>61</height>
        </rect>
       <property name="geometry">
        <rect>
         <x>10</x>
       <property name="geometry">
        <rect>
         <x>10</x>
-        <y>250</y>
+        <y>160</y>
         <width>201</width>
         <height>61</height>
        </rect>
         <width>201</width>
         <height>61</height>
        </rect>
        </item>
       </layout>
      </widget>
        </item>
       </layout>
      </widget>
+     <widget class="QPushButton" name="sendRoutePushButton">
+      <property name="geometry">
+       <rect>
+        <x>10</x>
+        <y>240</y>
+        <width>201</width>
+        <height>61</height>
+       </rect>
+      </property>
+      <property name="font">
+       <font>
+        <family>Bitstream Charter</family>
+        <pointsize>16</pointsize>
+        <weight>75</weight>
+        <bold>true</bold>
+       </font>
+      </property>
+      <property name="text">
+       <string>Send route</string>
+      </property>
+     </widget>
     </widget>
    </widget>
    <widget class="QPushButton" name="registratePushButton">
     </widget>
    </widget>
    <widget class="QPushButton" name="registratePushButton">
index 457e609..14a199c 100644 (file)
@@ -262,13 +262,6 @@ void GPSData::saveRoute()
     }
 }
 
     }
 }
 
-/**
-  *@return Pointer to gpsDataArray[][].
-  */
-double* GPSData::getGpsDataArray()
-{
-    return *gpsDataArray;
-}
 
 /**
   *@return RoundCounter, the number of gpsDataArray[][] rows.
 
 /**
   *@return RoundCounter, the number of gpsDataArray[][] rows.
index 165b937..40e49fd 100644 (file)
@@ -24,7 +24,6 @@ public:
     void startRouteRecording(QString time);
     void stopRouteRecording(QString time);
     int roundCounter; //testing, move private!!!
     void startRouteRecording(QString time);
     void stopRouteRecording(QString time);
     int roundCounter; //testing, move private!!!
-    double *getGpsDataArray();
     int getRoundCounter();
 
 private:
     int getRoundCounter();
 
 private:
index 750aa42..98aa98a 100644 (file)
@@ -92,29 +92,30 @@ void HttpClient::sendResultXml(QString category)
   */
 void HttpClient::sendRouteXml()
 {
   */
 void HttpClient::sendRouteXml()
 {
-    qDebug() << "_sendResultXml";
+    qDebug() << "_sendRouteXml";
 
 
-    QBuffer *xmlbuffer = new QBuffer();
+    QString filename = "route.xml";
+    QFile file(filename);
+    if (!file.open(QFile::ReadOnly)) {
+        qDebug() << "_sendRouteXml file.open() fail";
+        return;
+    }
 
     QUrl qurl("http://api.speedfreak-app.com/api/update/route");
     qDebug() << qurl.toString();
     QNetworkRequest request(qurl);
     QNetworkReply *currentDownload;
 
 
     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());
 
     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()));
+    currentDownload = netManager->post(request, ("xml=" + file.readAll()));
     connect(currentDownload,SIGNAL(finished()),this,SLOT(ackOfRoute()));
     //connect(currentDownload,SIGNAL(error(QNetworkReply::NetworkError)),myMainw,SLOT(errorFromServer(QNetworkReply::NetworkError)));
     myMainw->setLabelInfoToUser("Sending route to server");
 
     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();
+    file.close();
 }
 
 /**
 }
 
 /**
index 26eed66..fd46a6d 100644 (file)
@@ -16,7 +16,7 @@
   */
 XmlWriter::XmlWriter()
 {
   */
 XmlWriter::XmlWriter()
 {
-    tmpvalue = 110;
+    tmpvalue = 3010;
 }
 
 /**
 }
 
 /**
@@ -83,65 +83,37 @@ void XmlWriter::writeResult(QBuffer *netbuf)
 
 /**
   *@brief Write track to server.
 
 /**
   *@brief Write track to server.
-  *@param ptrTable points to GPSData::gpsDataArray[100][4].
+  *@param netbuf where to write.
   *@param counter is GPSData::roundCounter.
   *@todo Decide suitable attributes.
   */
   *@param counter is GPSData::roundCounter.
   *@todo Decide suitable attributes.
   */
-void XmlWriter::writeGpsTrack(QBuffer *netbuf, double *ptrTable, int counter)
+void XmlWriter::writeGpsTrack(QBuffer *netbuf, int counter, int start, int stop, int lat, int lon, int alt, int speed, int time)
 {
     qDebug() << "_writeGpsTrack";
 
     double *ptrValue;
 {
     qDebug() << "_writeGpsTrack";
 
     double *ptrValue;
-    ptrValue = ptrTable;
+    //ptrValue = ptrTable;
     double tmp = 0;
 
     xmlwriter.setDevice(netbuf);
 
     xmlwriter.writeStartDocument();
 
     double tmp = 0;
 
     xmlwriter.setDevice(netbuf);
 
     xmlwriter.writeStartDocument();
 
-    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");
+    xmlwriter.writeStartElement("Route");
+    xmlwriter.writeAttribute("starttime", QDateTime::currentDateTime().toString());
+    xmlwriter.writeAttribute("endtime", QDateTime::currentDateTime().toString());
+    xmlwriter.writeAttribute("points", QDateTime::currentDateTime().toString());
     for(int i = 0; i < counter; i++)
     {
     for(int i = 0; i < counter; i++)
     {
-        xmlwriter.writeStartElement("trkpt");
-        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");
-        tmp = *ptrValue;
-        ptrValue++;
-        xmlwriter.writeCharacters(QString::number(tmp));          //gpspoints[i][2]
+        xmlwriter.writeStartElement("point");
+        xmlwriter.writeAttribute("lat", QString::number(lat));
+        xmlwriter.writeAttribute("lon", QString::number(lon));
+        xmlwriter.writeAttribute("alt", QString::number(alt));
+        xmlwriter.writeAttribute("speed", QString::number(speed));
+        xmlwriter.writeAttribute("time", QString::number(time));
         xmlwriter.writeEndElement();
         xmlwriter.writeEndElement();
-        xmlwriter.writeStartElement("speed");
-        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();
     xmlwriter.writeEndDocument();
 }
 
     xmlwriter.writeEndDocument();
 }
 
@@ -182,8 +154,7 @@ bool XmlWriter::writeXmlFile(QIODevice *device)
 {
     xmlwriter.setDevice(device);
     xmlwriter.writeStartDocument();
 {
     xmlwriter.setDevice(device);
     xmlwriter.writeStartDocument();
-    //writeItems();
-    serverWritesXml();
+    writeItems();
     xmlwriter.writeEndDocument();
 
     return true;
     xmlwriter.writeEndDocument();
 
     return true;
@@ -204,26 +175,3 @@ void XmlWriter::writeItems()
     xmlwriter.writeEndElement();
 }
 
     xmlwriter.writeEndElement();
 }
 
-
-/**
-  *@brief A temp function during development, used to create a "serverfile".
-  */
-void XmlWriter::serverWritesXml()
-{
-    //Write categories
-    xmlwriter.writeStartElement("categories");
-
-    xmlwriter.writeStartElement("category");
-    xmlwriter.writeCharacters("acceleration-0-10");
-    xmlwriter.writeEndElement();
-
-    xmlwriter.writeStartElement("category");
-    xmlwriter.writeCharacters("acceleration-0-40");
-    xmlwriter.writeEndElement();
-
-    xmlwriter.writeStartElement("category");
-    xmlwriter.writeCharacters("acceleration-0-100");
-    xmlwriter.writeEndElement();
-
-    xmlwriter.writeEndElement();
-}
index 80ff500..5aba27a 100644 (file)
@@ -38,12 +38,11 @@ private:
 public slots:
     void writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email);
     void writeResult(QBuffer *netbuf);
 public slots:
     void writeRegistering(QBuffer *netbuf, QString usr, QString psswd, QString email);
     void writeResult(QBuffer *netbuf);
-    void writeGpsTrack(QBuffer *netbuf, double *ptrTable, int counter);
+    void writeGpsTrack(QBuffer *netbuf, int counter, int start, int stop, int lat, int lon, int alt, int speed, int time);
     bool writeXmlFile(QIODevice *device);
     //void writeXml(QString usr, QString psswd, QString email);
     void writeXml();
     void writeItems();
     bool writeXmlFile(QIODevice *device);
     //void writeXml(QString usr, QString psswd, QString email);
     void writeXml();
     void writeItems();
-    void serverWritesXml();
 };
 
 #endif // XMLWRITER_H
 };
 
 #endif // XMLWRITER_H