From b8104711348ebb86e8c93b23067af8f699870626 Mon Sep 17 00:00:00 2001 From: Tiina Kivilinna-Korhola Date: Fri, 26 Mar 2010 15:02:24 +0200 Subject: [PATCH] Added button for sending route to server. --- Client/carmainwindow.cpp | 17 +++++++--- Client/carmainwindow.h | 1 + Client/carmainwindow.ui | 29 +++++++++++++--- Client/gpsdata.cpp | 7 ---- Client/gpsdata.h | 1 - Client/httpclient.cpp | 17 +++++----- Client/xmlwriter.cpp | 84 +++++++++------------------------------------- Client/xmlwriter.h | 3 +- 8 files changed, 64 insertions(+), 95 deletions(-) diff --git a/Client/carmainwindow.cpp b/Client/carmainwindow.cpp index 9a48d90..5da33b7 100644 --- a/Client/carmainwindow.cpp +++ b/Client/carmainwindow.cpp @@ -156,11 +156,12 @@ void CarMainWindow::on_listViewStartTabAccelerationCategories_clicked(QModelInde { 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"); - 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); @@ -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. @@ -838,3 +844,4 @@ void CarMainWindow::on_calibrateButton_clicked() this->accelerometer->calibrate(); } + diff --git a/Client/carmainwindow.h b/Client/carmainwindow.h index 433ee9d..83cbafa 100644 --- a/Client/carmainwindow.h +++ b/Client/carmainwindow.h @@ -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_sendRoutePushButton_clicked(); void on_pushButtonSendResult_clicked(); void on_pushButtonMeasureTabAbort_clicked(); void on_manualStartButton_clicked(); diff --git a/Client/carmainwindow.ui b/Client/carmainwindow.ui index 6acf29a..8c0e7f0 100644 --- a/Client/carmainwindow.ui +++ b/Client/carmainwindow.ui @@ -24,7 +24,7 @@ - 1 + 4 @@ -489,7 +489,7 @@ 20 - 40 + 20 191 41 @@ -516,7 +516,7 @@ 10 - 130 + 80 201 61 @@ -537,7 +537,7 @@ 10 - 250 + 160 201 61 @@ -622,6 +622,27 @@ + + + + 10 + 240 + 201 + 61 + + + + + Bitstream Charter + 16 + 75 + true + + + + Send route + + diff --git a/Client/gpsdata.cpp b/Client/gpsdata.cpp index 457e609..14a199c 100644 --- a/Client/gpsdata.cpp +++ b/Client/gpsdata.cpp @@ -262,13 +262,6 @@ void GPSData::saveRoute() } } -/** - *@return Pointer to gpsDataArray[][]. - */ -double* GPSData::getGpsDataArray() -{ - return *gpsDataArray; -} /** *@return RoundCounter, the number of gpsDataArray[][] rows. diff --git a/Client/gpsdata.h b/Client/gpsdata.h index 165b937..40e49fd 100644 --- a/Client/gpsdata.h +++ b/Client/gpsdata.h @@ -24,7 +24,6 @@ public: void startRouteRecording(QString time); void stopRouteRecording(QString time); int roundCounter; //testing, move private!!! - double *getGpsDataArray(); int getRoundCounter(); private: diff --git a/Client/httpclient.cpp b/Client/httpclient.cpp index 750aa42..98aa98a 100644 --- a/Client/httpclient.cpp +++ b/Client/httpclient.cpp @@ -92,29 +92,30 @@ void HttpClient::sendResultXml(QString category) */ 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; - 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())); + 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"); - xmlbuffer->close(); + file.close(); } /** diff --git a/Client/xmlwriter.cpp b/Client/xmlwriter.cpp index 26eed66..fd46a6d 100644 --- a/Client/xmlwriter.cpp +++ b/Client/xmlwriter.cpp @@ -16,7 +16,7 @@ */ XmlWriter::XmlWriter() { - tmpvalue = 110; + tmpvalue = 3010; } /** @@ -83,65 +83,37 @@ void XmlWriter::writeResult(QBuffer *netbuf) /** *@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. */ -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; - ptrValue = ptrTable; + //ptrValue = ptrTable; 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++) { - 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.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(); } @@ -182,8 +154,7 @@ bool XmlWriter::writeXmlFile(QIODevice *device) { xmlwriter.setDevice(device); xmlwriter.writeStartDocument(); - //writeItems(); - serverWritesXml(); + writeItems(); xmlwriter.writeEndDocument(); return true; @@ -204,26 +175,3 @@ void XmlWriter::writeItems() 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(); -} diff --git a/Client/xmlwriter.h b/Client/xmlwriter.h index 80ff500..5aba27a 100644 --- a/Client/xmlwriter.h +++ b/Client/xmlwriter.h @@ -38,12 +38,11 @@ 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); + 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(); - void serverWritesXml(); }; #endif // XMLWRITER_H -- 1.7.9.5