Merge branch 'development/GPS'
authorToni Jussila <toni.jussila@fudeco.com>
Mon, 22 Mar 2010 12:28:52 +0000 (14:28 +0200)
committerToni Jussila <toni.jussila@fudeco.com>
Mon, 22 Mar 2010 12:28:52 +0000 (14:28 +0200)
1  2 
Client/carmainwindow.cpp
Client/carmainwindow.h

diff --combined Client/carmainwindow.cpp
@@@ -35,13 -35,11 +35,13 @@@ CarMainWindow::CarMainWindow(QWidget *p
      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
@@@ -50,9 -48,8 +50,9 @@@
      connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus()));
      gpsTime = new QDateTime();
  
 -    time = 0;
 -    speed = 0;
 +    this->time = 0;
 +    this->speed = 0;
 +    counterForSaveResults = 0;
      timer = new QTimer();
  
      // Accelerometer
      stopTime = 0;
      accelerationStartThreshold = 0.02;
  
 -    QTimer *accelerometerTimer = new QTimer(this);
 +    accelerometerTimer = new QTimer(this);
      connect(accelerometerTimer, SIGNAL(timeout()), this, SLOT(readAccelerometerData()));
 -    accelerometerTimer->start(kAccelerometerSampleRate);
 +    //accelerometerTimer->start(kAccelerometerSampleRate);
  
      // Calculate
      calculate = new Calculate();
 -    //connect(calculate, SIGNAL(checkPointReached()), this, SLOT(handleCheckPoint()));
 +    connect(calculate, SIGNAL(checkPointReached()), this, SLOT(handleCheckPoint()));
  
      resetAccelerometerMeasurements();
  
      measures = new Measures();
      this->initializeMeasures();
  
 -    timer->setInterval(300);
 +    this->timer->setInterval(300);
  
      connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout()));
      connect(myLogin, SIGNAL( userNameChanged()), this, SLOT(updateUserName()));
  
      ui->labelMeasureTabResult->hide();
 +    ui->pushButtonShowResultDialog->setEnabled(false);
  
      this->setWindowTitle("Speed Freak");
  
@@@ -99,8 -95,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;
@@@ -146,10 -142,6 +146,10 @@@ void CarMainWindow::on_listViewStartTab
    */
  void CarMainWindow::on_autoStartButton_clicked()
  {
 +    initializeMeasures();
 +    resetAccelerometerMeasurements();
 +    ui->pushButtonSendResult->setEnabled(false);
 +    ui->pushButtonShowResultDialog->setEnabled(false);
      choice = ui->listViewStartTabAccelerationCategories->currentIndex();
      choiceInt = choice.row();
      qDebug() << choiceInt;
          result->setDiagramGapStem(37.5);
      }
      ui->labelMeasureTabResult->setText("");
 -    //delete measure;
 -    //measure = NULL;
 -    //measure = new MeasureDialog();
 -   // connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
 -    timer->start();
 -    // Show measure dialog.
 -    //measure->show();
 -
 -    // TODO: Move next if else to the function which is called when target speed
 -    // has reached.
 -    if (choiceInt == 0)
 -    {
 -        if (floor(this->measures->getTime40kmh()) <= 5)
 -        {
 -            result->setDiagramGapHorizontal(80);
 -        }
 -
 -        else if (floor(this->measures->getTime40kmh()) <= 10)
 -        {
 -            result->setDiagramGapHorizontal(40);
 -        }
 -
 -        else
 -        {
 -            result->setDiagramGapHorizontal(20);
 -        }
 -    }
 -
 -    else
 -    {
 -        if (floor(this->measures->getTime40kmh()) <= 5)
 -        {
 -            result->setDiagramGapHorizontal(80);
 -        }
 -
 -        else if (floor(this->measures->getTime40kmh()) <= 10)
 -        {
 -            result->setDiagramGapHorizontal(40);
 -        }
 -
 -        else
 -        {
 -            result->setDiagramGapHorizontal(20);
 -        }
 -    }
  
 +    this->accelerometerTimer->start(kAccelerometerSampleRate);
 +    this->timer->start();
 +    this->time = 0;
 +    this->speed = 0;
      ui->tabWidget->setCurrentWidget(this->ui->tabMeasureResult);
  }
  
@@@ -232,30 -265,17 +232,30 @@@ void CarMainWindow::setListViewStartTab
    */
  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);
  }
  
    */
  void CarMainWindow::openResultView()
  {
 -    //result->saveMeasuresToArray(measure->measures);
 -    // Show result dialog.
 -    //result->show();
 -    ui->pushButtonSendResult->setEnabled(true);
 -    QString timeInteger;
 -    if (choiceInt == 0)
 -    {
 -        if (floor(this->measures->getTime40kmh()) <= 5)
 -        {
 -            result->setDiagramGapHorizontal(80);
 -        }
 -
 -        else if (floor(this->measures->getTime40kmh()) <= 10)
 -        {
 -            result->setDiagramGapHorizontal(40);
 -        }
  
 -        else
 -        {
 -            result->setDiagramGapHorizontal(20);
 -        }
 -    }
 -
 -    else
 -    {
 -        if (floor(this->measures->getTime40kmh()) <= 5)
 -        {
 -            result->setDiagramGapHorizontal(80);
 -        }
 -
 -        else if (floor(this->measures->getTime40kmh()) <= 10)
 -        {
 -            result->setDiagramGapHorizontal(40);
 -        }
 -
 -        else
 -        {
 -            result->setDiagramGapHorizontal(20);
 -        }
 -    }
 -    timeInteger.setNum(this->measures->getTime40kmh());
 -    //time = "0 - 40 km/h: ";
 -    //time.append(timeInteger);
 -    //ui->labelResult40kmh->setText(time);
 -    ui->labelMeasureTabResult->show();
 -    ui->labelMeasureTabResult->setText(timeInteger);
 -    //ui->tabWidget->setCurrentWidget(this->ui->tabMeasureResult);
  }
  
  /**
@@@ -281,20 -347,30 +281,20 @@@ void CarMainWindow::on_registratePushBu
  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);
  }
  
  /**
@@@ -322,14 -398,87 +322,14 @@@ void CarMainWindow::on_manualStartButto
  void CarMainWindow::after_timeout()
  {
      QString timeString, speedString;
 -    time++;
 -    speed = speed +10;
 -
 -    if (floor(speed) == 10)
 -    {
 -        measures->setTime10kmh(time);
 -    }
 -
 -    else if (floor(speed) == 20)
 -    {
 -        measures->setTime20kmh(time);
 -    }
 -
 -    else if (floor(speed) == 30)
 -    {
 -        measures->setTime30kmh(time);
 -    }
 -
 -    else if (floor(speed) == 40)
 -    {
 -        measures->setTime40kmh(time);
 -    }
 -
 -    else if (floor(speed) == 50)
 -    {
 -        measures->setTime50kmh(time);
 -    }
 -
 -    else if (floor(speed) == 60)
 -    {
 -        measures->setTime60kmh(time);
 -    }
 -
 -    else if (floor(speed) == 70)
 -    {
 -        measures->setTime70kmh(time);
 -    }
 -
 -    else if (floor(speed) == 80)
 -    {
 -        measures->setTime80kmh(time);
 -    }
 -
 -    else if (floor(speed) == 90)
 -    {
 -        measures->setTime90kmh(time);
 -    }
 -
 -    else if (floor(speed) == 100)
 -    {
 -        measures->setTime100kmh(time);
 -    }
 -
 -    else
 -    {
 -
 -    }
 -
 -    // If speed is over 40 km/h emits speedAchieved() signal and close this dialog.
 -    if (speed >= 40.0)
 -    {
 -        timer->stop();
 -        time = 0;
 -        speed = 0;
 -        //emit this->speedAchieved();
 -        this->openResultView();
 -        //this->close();
 -
 -    }
 -
 -    // Updates speed and time.
 -    else
 -    {
 -        timeString.setNum(time);
 -        speedString.setNum(speed);
 -        ui->labelMeasureTabTime->setText(timeString);
 -        ui->labelMeasureTabSpeed->setText(speedString);
 -
 -        timer->start();
 -    }
 +    //time++;
 +    //speed = speed +10;
 +    timeString.setNum(time);
 +    speedString.setNum(speed);
 +    ui->labelMeasureTabTime->setText(timeString);
 +    ui->labelMeasureTabSpeed->setText(speedString);
  
 +    //handleCheckPoint(time, speed);
  }
  
  /**
@@@ -354,11 -503,6 +354,11 @@@ void CarMainWindow::initializeMeasures(
    */
  void CarMainWindow::on_pushButtonMeasureTabAbort_clicked()
  {
 +    ui->pushButtonSendResult->setEnabled(false);
 +    ui->pushButtonShowResultDialog->setEnabled(false);
 +    ui->labelMeasureTabResult->hide();
 +    ui->labelMeasureTabTime->setText("");
 +    ui->labelMeasureTabSpeed->setText("");
      measures->setTime10kmh(0);
      measures->setTime20kmh(0);
      measures->setTime30kmh(0);
      measures->setTime80kmh(0);
      measures->setTime90kmh(0);
      measures->setTime100kmh(0);
 -    timer->stop();
 -    time = 0;
 -    speed = 0;
 +    this->accelerometerTimer->stop();
 +    this->timer->stop();
 +    this->time = 0;
 +    this->speed = 0;
      ui->tabWidget->setCurrentWidget(this->ui->StartTab);
      //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);
  }
  
@@@ -397,12 -536,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");
      }
  }
  
@@@ -423,7 -562,19 +423,7 @@@ void CarMainWindow::on_drawRoutePushBut
    */
  void CarMainWindow::on_pushButtonShowResultDialog_clicked()
  {
 -    Measures meas;
 -    meas.setTime10kmh(1.3);
 -    meas.setTime20kmh(2.5);
 -    meas.setTime30kmh(3.6);
 -    meas.setTime40kmh(6.7);
 -    meas.setTime50kmh(7.3);
 -    meas.setTime60kmh(7.5);
 -    meas.setTime70kmh(8.6);
 -    meas.setTime80kmh(8.7);
 -    meas.setTime90kmh(9.6);
 -    meas.setTime100kmh(9.9);
 -    result->setDiagramGapHorizontal(40);
 -    result->saveMeasuresToArray(&meas);
 +    result->saveMeasuresToArray(measures);
      this->result->show();
  }
  
@@@ -462,88 -613,10 +462,88 @@@ void CarMainWindow::resetAccelerometerM
    */
  void CarMainWindow::handleCheckPoint(double totalTime, double currentSpeed)
  {
 -    // TODO
 -    //totalTime;
 -    //currentSpeed;
 -    return;
 +    switch (counterForSaveResults)
 +    {
 +    case 0:
 +        measures->setTime10kmh(totalTime);
 +        break;
 +
 +    case 1:
 +        measures->setTime20kmh(totalTime);
 +        break;
 +
 +    case 2:
 +        measures->setTime30kmh(totalTime);
 +        break;
 +
 +    case 3:
 +        measures->setTime40kmh(totalTime);
 +        break;
 +
 +    case 4:
 +        measures->setTime50kmh(totalTime);
 +        break;
 +
 +    case 5:
 +        measures->setTime60kmh(totalTime);
 +        break;
 +
 +    case 6:
 +        measures->setTime70kmh(totalTime);
 +        break;
 +
 +    case 7:
 +        measures->setTime80kmh(totalTime);
 +        break;
 +
 +    case 8:
 +        measures->setTime90kmh(totalTime);
 +        break;
 +
 +    case 9:
 +        measures->setTime100kmh(totalTime);
 +        break;
 +
 +    default:
 +        break;
 +    }
 +    counterForSaveResults++;
 +
 +    if (choiceInt == 0 && measures->getTime40kmh() != 0)
 +    {
 +        setTimeAxisGapAndShowResult(measures->getTime40kmh());
 +        this->timer->stop();
 +        this->accelerometerTimer->stop();
 +        this->time = 0;
 +        this->speed = 0;
 +        counterForSaveResults = 0;
 +    }
 +
 +    else if (choiceInt == 1 && measures->getTime100kmh() != 0)
 +    {
 +        setTimeAxisGapAndShowResult(measures->getTime100kmh());
 +        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());
 +        this->timer->stop();
 +        this->accelerometerTimer->stop();
 +        this->time = 0;
 +        this->speed = 0;
 +        counterForSaveResults = 0;
 +    }
 +
 +    else
 +    {
 +
 +    }
  }
  
  /**
@@@ -580,7 -653,7 +580,7 @@@ void CarMainWindow::readAccelerometerDa
      currentAcceleration = sqrt(x*x + y*y + z*z);
      changeInAcceleration = (currentAcceleration - firstAcceleration); // firstAcceleration only gets set once
  
 -    if (((abs(changeInAcceleration) <= accelerationStartThreshold)
 +    if (((fabs(changeInAcceleration) <= accelerationStartThreshold)
                  && !vehicleStartedMoving))
      {
          return;
          if ((changeInAcceleration <= 0))
          {
              // actually increasing here...
 -            changeInAcceleration = abs(changeInAcceleration);
 +            changeInAcceleration = fabs(changeInAcceleration);
          }
          else
          {
          {
              // we started to move backwards first time through
              reverseAccelerationFlag = true;
 -            changeInAcceleration = abs(changeInAcceleration);
 +            changeInAcceleration = fabs(changeInAcceleration);
          }
          vehicleStartedMoving = true;
  
@@@ -689,7 -762,8 +689,8 @@@ void CarMainWindow::gpsStatus(
          if (location->getSatellitesInUse() >= 4)
          {
              //Set status
-             ui->labelRouteTabGPSStatus->setText("GPS ready");
+             //ui->labelRouteTabGPSStatus->setText("GPS ready");
+             ui->labelRouteTabGPSStatus->setText(QString::number(gpsData->roundCounter));
  
              //Set time
              gpsTime->setTime_t(location->getTime());
              ui->labelRouteTabGPSStatus->setText("Waiting for GPS");
          }
      }
+     ui->labelRouteTabSpeed->setText(QString::number(location->getSpeed()));
+ }
+ void CarMainWindow::on_startRecPushButton_clicked()
+ {
+     ui->labelRouteTabRecStatus->setText("Recording started");
+     gpsData->startRouteRecording(ui->labelRouteTabGPSTime->text());
+ }
+ void CarMainWindow::on_stopRecPushButton_clicked()
+ {
+     ui->labelRouteTabRecStatus->setText("Recording stopped");
+     gpsData->stopRouteRecording(ui->labelRouteTabGPSTime->text());
  }
 +
 +/**
 +  *Sets time axis right way in result dialog and shows target speed result.
 +  *@param double pTime is the target speed result time which is shown to the user.
 +  */
 +void CarMainWindow::setTimeAxisGapAndShowResult(double pTime)
 +{
 +    ui->pushButtonShowResultDialog->setEnabled(true);
 +    ui->pushButtonSendResult->setEnabled(true);
 +    QString timeInteger;
 +    timeInteger.setNum(pTime);
 +    ui->labelMeasureTabResult->show();
 +    ui->labelMeasureTabResult->setText(timeInteger);
 +
 +    if (floor(pTime) <= 5)
 +    {
 +        result->setDiagramGapHorizontal(80);
 +    }
 +
 +    else if (floor(pTime) <= 10)
 +    {
 +        result->setDiagramGapHorizontal(40);
 +    }
 +
 +    else
 +    {
 +        result->setDiagramGapHorizontal(20);
 +    }
 +}
diff --combined Client/carmainwindow.h
@@@ -56,10 -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);
@@@ -69,8 -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;
      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);
  
  private:
      QStringList accelerationCategoriesStartTab;         //Start-tab view
      QStringList units;                                  //Start-tab view
 -    QStringList categories;                             //Top-tab view
 +    QString recentCategory;
  
      QTimer *timer;
      Accelerometer *accelerometer;
  
      QDateTime *gpsTime;
  
 +    int counterForSaveResults;
 +
  signals:
      void speedAchieved();
      void userNameChanged();
  
  private slots:
+     void on_stopRecPushButton_clicked();
+     void on_startRecPushButton_clicked();
      void on_pushButtonShowResultDialog_clicked();
      void on_gpsOnCheckBox_stateChanged(int GPSState);   //Route-tab view
      void gpsStatus();                                   //Route-tab view
      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
      void userLogin();
      void readAccelerometerData();
      void handleCheckPoint(double totalTime, double currentSpeed);
 +    void setCategoryCompoBox();                         //Top-tab
 +    void showTop10();
 +
  };
  
  #endif // CARMAINWINDOW_H