X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Froutedialog.cpp;h=12064bc5f9efb8edaaac1dc3db33ba9787fcb421;hp=da4853e13e355ab7b4cbfebc8d0e7f7099d8ed48;hb=e5d88e68d49f961be9edd1ee1a390c6b0fb88094;hpb=18cc0246bc4dcad660f57b740148e8288993e556 diff --git a/Client/routedialog.cpp b/Client/routedialog.cpp index da4853e..12064bc 100644 --- a/Client/routedialog.cpp +++ b/Client/routedialog.cpp @@ -93,7 +93,8 @@ public: void setEye() { double amarkmag, tempmag; - Vector temp, dist; + Vector temp; + Vector dist; dval = cos(angle/2.0)/sin(angle/2.0); dist = atPoint-fromPoint; @@ -170,23 +171,20 @@ qreal countDistance(Vector *p1, Vector *p2) /** * Constructor of this class. */ -//RouteDialog::RouteDialog(QWidget *parent) : RouteDialog::RouteDialog(RouteSaveDialog *parent) : QDialog(parent), ui(new Ui::RouteDialog) { qDebug() << "__RouteDialog"; ui->setupUi(this); - helpRoutingDialog = NULL; - this->setWindowTitle("Route"); left = 5; top = 5; right = 495; bottom = 295; // Limits in screen coordinates + helpRoutingDialog = NULL; + // Button settings ui->sendPushButton->setAutoFillBackground(true); ui->sendPushButton->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); - ui->newPushButton->setAutoFillBackground(true); - ui->newPushButton->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)"); // Clear labels ui->labelInfoToUser->setText(""); @@ -197,7 +195,9 @@ RouteDialog::RouteDialog(RouteSaveDialog *parent) : checkLogin(); // Set average speed - ui->avgSpeedValueLabel->setText(QString::number(parent->getAverageSpeed()) + " km/h"); + QString average; + ui->avgSpeedValueLabel->setText(average.sprintf("%.1f", parent->getAverageSpeed()) + " km/h"); + ui->distanceValueLabel->setText(parent->getDistanceTraveled() + " km"); } /** @@ -336,13 +336,17 @@ void RouteDialog::paintEvent(QPaintEvent *) checkLogin(); int type = 0; // 0 for 2d, 1 for 3d - int startx, starty; // Starting point of the route - int i, maxi; + int startx = 0; // Starting x point of the route + int starty = 0; // Starting y point of the route + int i = 0; + int maxi = 0; qreal x1, y1, x2, y2; - int x1Screen, y1Screen, x2Screen, y2Screen; + int x1Screen = 0; + int y1Screen = 0; + int x2Screen = 0; + int y2Screen = 0; Vector v1, v2; QPainter painter(this); - int startStop = 0; painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(QPen((Qt::white),2)); @@ -396,8 +400,9 @@ void RouteDialog::paintEvent(QPaintEvent *) } { - qreal maxvx, maxvy; // max speed point coordinates - qreal maxv; // max speed + qreal maxvx = 0; // max speed x point + qreal maxvy = 0; // max speed y point + qreal maxv = 0; // max speed Vector v; maxv = 0.0; @@ -428,35 +433,33 @@ void RouteDialog::paintEvent(QPaintEvent *) /** * + * @param QString route file */ -bool RouteDialog::readRouteFromFile( QString &routeFile) - { - QString rFile = routeFile; //Not used +bool RouteDialog::readRouteFromFile( QString &routeFile ) +{ + QString rFile = routeFile; + fileName = routeFile; Vector temp; QString rivi; QFile file; + int progressbarInt = 5; + int count; - //QString fileName = QFileDialog::getOpenFileName(this, - // tr("Read Route"), "./", tr("Route Files (*.txt)")); - - //file.setFileName( fileName); - file.setFileName( "routetemp.xml"); + file.setFileName( rFile); if (!file.open(QIODevice::ReadOnly)) { - QMessageBox::about(0, "Error", "File not found"); + QMessageBox::about(0, "Error", "Empty file"); return false; } - + emit progressbar(progressbarInt); vertexList.clear(); while(!file.atEnd()) { - int count; bool allRead; QString astr1, astr2, astr3, astr4; QString str1, str2, str3, str4; rivi = file.readLine(); - allRead = false; count = 0; while( !allRead) @@ -472,9 +475,6 @@ bool RouteDialog::readRouteFromFile( QString &routeFile) str2 = astr2.section('"',1,1); str3 = astr3.section('"',1,1); str4 = astr4.section('"',1,1); - //QString str = QString("%1 %2 %3 %4").arg(str1).arg(str2).arg(str3).arg(str4); - //QMessageBox::about(0, "LUKEE", str); - /* */ if (str1.length() > 0) { @@ -482,8 +482,6 @@ bool RouteDialog::readRouteFromFile( QString &routeFile) y = str1.toDouble();// longitude x-value z = str3.toDouble();// altitude z-value v = str4.toDouble();// speed km/h - // QString str = QString("%1 %2 %3 %4").arg(x).arg(y).arg(z).arg(v); - // QMessageBox::about(0, "LUKEE", str); temp.setX( x); // Longitude temp.setY( y); // Latitude temp.setZ( z); // altitude @@ -497,69 +495,59 @@ bool RouteDialog::readRouteFromFile( QString &routeFile) allRead = true; } } + if(progressbarInt < 50) + progressbarInt++; + emit progressbar(progressbarInt); } - // Older version - /* - str1 = rivi.section(" ", 0, 0); - if (str1.compare("Start:") != 0 && str1.compare("Stop:") != 0) - { - str1 = rivi.section(" ", 2, 2); // latitude y-value - str2 = rivi.section(" ", 4, 4); // longitude x-value - str3 = rivi.section(" ", 6, 6); // altitude z-value - str4 = rivi.section(" ", 8, 8); // speed km/h - //QString str = QString("la: %1 lo: %2 al: %3").arg(str1).arg(str2).arg(str3); - //QMessageBox::about(0, "LUKEE", str); - - if (str1.length() > 0) - { - double x, y, z, v; - x = str2.toDouble(); - y = str1.toDouble(); - z = str3.toDouble(); - v = str4.toDouble(); - temp.setX( x); // Longitude - temp.setY( y); // Latitude - temp.setZ( z); // altitude - temp.setV( v); - - vertexList.append(temp); - } - } - */ } - file.close(); - /******** in 3d use only */ - a = 400/2.; - b = 1 - a*(-1); - c = -300/2.; - d = 300 - c*(-1); - //angle = toradians(60); - - view3d.setUp( 1.0, 0.0, 0.0); - view3d.setAngle(toradians(60)); - setAtPoint( &view3d); - xmin = objxmin; xmax = objxmax; ymin = objymin; ymax = objymax; // 2d viewing needs this !!!! - setFromPoint( &view3d); - view3d.setEye(); - /****** end of 3d *****/ - - /* - //Testing distance counting - Vector a1, a2; - qreal dist; - //a1.setX( xmin); a1.setY( ymin); - //a2.setX( xmax); a2.setY( ymax); - a1.setX( 25.483); a1.setY( 65.017); // Oulu - a2.setX( 27.767); a2.setY( 64.283); // Kajaani - dist = countDistance( &a1, &a2); - QString str = QString("Min & Max datan välimatka %1").arg(dist); - QMessageBox::about( 0, "Testi", str); - */ - - return true; - } + if(count == 1) // Check is file empty. + { + progressbarInt = 50; + emit progressbar(progressbarInt); + qDebug() << "count: " + QString::number(count); + /******** in 3d use only */ + a = 400/2.; + b = 1 - a*(-1); + c = -300/2.; + d = 300 - c*(-1); + emit progressbar(60); + //angle = toradians(60); + view3d.setUp( 1.0, 0.0, 0.0); + emit progressbar(70); + view3d.setAngle(toradians(60)); + emit progressbar(80); + setAtPoint( &view3d); // If file is empty software crash here. + emit progressbar(90); + xmin = objxmin; xmax = objxmax; ymin = objymin; ymax = objymax; // 2d viewing needs this !!!! + emit progressbar(95); + setFromPoint( &view3d); + emit progressbar(98); + view3d.setEye(); + emit progressbar(99); + /****** end of 3d *****/ + /* + //Testing distance counting + Vector a1, a2; + qreal dist; + //a1.setX( xmin); a1.setY( ymin); + //a2.setX( xmax); a2.setY( ymax); + a1.setX( 25.483); a1.setY( 65.017); // Oulu + a2.setX( 27.767); a2.setY( 64.283); // Kajaani + dist = countDistance( &a1, &a2); + QString str = QString("Min & Max datan välimatka %1").arg(dist); + QMessageBox::about( 0, "Testi", str); + */ + emit progressbar(100); + return true; + } + else // Probably file is empty. + { + QMessageBox::about(0, "Error", "Empty file"); + return false; + } +} /** * Find out data range for x-, y- and z-coordinates @@ -706,8 +694,13 @@ void WORLDtoSCREEN( qreal xWorld, qreal yWorld, int *xScreen, int *yScreen) */ void clip3d( qreal x1, qreal y1, qreal z1, qreal x2, qreal y2, qreal z2, int *xscreen1, int *yscreen1, int *xscreen2, int *yscreen2) { - int c,c1,c2; - qreal x,y,z,t; + int c = 0; + int c1 = 0; + int c2 = 0; + qreal x = 0; + qreal y = 0; + qreal z = 0; + qreal t = 0; c1 = code(x1,y1,z1); c2 = code(x2,y2,z2); @@ -801,20 +794,41 @@ void transformseg( Viewing *v, Vector *v1, Vector *v2, int *xscreen1, int *yscre } /** - * This slot function is called when ever new push button clicked. - */ -void RouteDialog::on_newPushButton_clicked() -{ - close(); // go back to previous dialog -} - -/** * This slot function is called when ever send push button clicked. */ void RouteDialog::on_sendPushButton_clicked() { ui->sendPushButton->setEnabled(false); - emit sendroute(); + + // Check default file dir. + if(!QDir("/home/user/MyDocs/speedfreak/route").exists()) + { + QDir().mkdir("/home/user/MyDocs/speedfreak/route"); + } + + // If file name is empty set it to default. + if(fileName == "") + fileName = "/home/user/MyDocs/speedfreak/route/"; + + if(fileName == "/home/user/MyDocs/speedfreak/route/routetemp.xml") + fileName = "/home/user/MyDocs/speedfreak/route/route.xml"; + + qDebug() << "__FileName: " + fileName; + QString newFileName = QFileDialog::getSaveFileName(this, tr("Save Route"), fileName); + int server = QMessageBox::question(this, "Save route to server?", "", 4,3); + + if(server == 3) // Yes button + { + qDebug() << "__Save to server: yes"; + emit sendroute(newFileName,1); // Save route to server and phone. + } + else if(server == 4) // No button + { + qDebug() << "__Save to server: no"; + + if(fileName != "") + emit sendroute(newFileName,0); // Save route to phone. + } } /**