measuredialog.cpp \
calculate.cpp \
accelerometer.cpp \
+ loginwindow.cpp \
+ registration.cpp \
+ measures.cpp \
+ xmlwriter.cpp \
xmlreader.cpp
+
HEADERS += carmainwindow.h \
resultdialog.h \
stringlistmodel.h \
measuredialog.h \
accelerometer.h \
calculate.h \
+ loginwindow.h \
+ registration.h \
+ measures.h \
+ xmlwriter.h \
xmlreader.h
+
FORMS += carmainwindow.ui \
resultdialog.ui \
- measuredialog.ui
+ measuredialog.ui \
+ loginwindow.ui \
+ registration.ui
#define kFilteringFactor 0.1
#define kGravity 9.81
+#define kFileName "/sys/class/i2c-adapter/i2c-3/3-001d/coord"
static int sampleIndex=0;
+/**
+ * Default constructor for Accelerometer class
+ *
+ */
Accelerometer::Accelerometer()
{
- QTimer *timer = new QTimer(this);
+ calculate = new Calculate();
+
+ timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(processData()));
- sampleRate = 100;
- timer->start(sampleRate);
- now.restart();
+ sampleRate = 40;
+ initValues();
+}
+
+/**
+ * Constructor for Accelerometer class that takes accelerometer sample rate as parameter
+ *
+ * @param p_SampleRate the desired sample rate of accelerometer in milliseconds
+ */
+Accelerometer::Accelerometer(int p_SampleRate)
+{
+ calculate = new Calculate();
+ timer = new QTimer(this);
+ connect(timer, SIGNAL(timeout()), this, SLOT(processData()));
+ sampleRate = p_SampleRate;
initValues();
}
-Accelerometer::~Accelerometer() {
+/**
+ * Default destructor for Accelerometer class
+ *
+ */
+Accelerometer::~Accelerometer()
+{
}
-void Accelerometer::start() {
+/**
+ * Start measuring
+ *
+ */
+void Accelerometer::start()
+{
+ initValues();
+ calibrate();
timer->start(sampleRate);
now.restart();
}
-void Accelerometer::initValues() {
+/**
+ * Init class members
+ *
+ */
+void Accelerometer::initValues()
+{
accelerationX=0;
accelerationY=0;
accelerationZ=0;
lastDistanceTraveled=0;
averageSpeed=0;
sampleRate=0;
+ reverseAcceleration = false;
}
-void Accelerometer::stop() {
+/**
+ * Calibrate. Purpose of this function is to calibrate
+ * accelerometer when stationary.
+ *
+ */
+void Accelerometer::calibrate(void)
+{
+ QFile file(kFileName);
+ if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
+
+ unsigned int iteration = 0;
+
+ QByteArray line;
+ QRegExp rx("([0-9-]+) ([0-9-]+) ([0-9-]+)");
+
+ do {
+ // Read data, parse with regular expressions and process it
+ line = file.readLine();
+ rx.indexIn(line);
+
+ int sampleX = rx.cap(1).toInt();
+ int sampleY = rx.cap(2).toInt();
+ int sampleZ = rx.cap(3).toInt();
+
+ calibrationX += sampleX; // Accumulate Samples
+ calibrationY += sampleY; // for all axes.
+ calibrationZ += sampleZ;
+
+ iteration++;
+ } while(iteration!=1024); // 1024 times
+
+ calibrationX = calibrationX>>10; // division by 1024
+ calibrationY = calibrationY>>10;
+ calibrationZ = calibrationZ>>10;
+
+ file.close();
+}
+
+/**
+ * Stop measuring
+ *
+ */
+void Accelerometer::stop()
+{
timer->stop();
}
-void Accelerometer::setSampleRate(int pSampleRate) {
+/**
+ * Set the sample rate of accelerometer
+ *
+ * @param pSampleRate desired sample rate
+ */
+void Accelerometer::setSampleRate(int pSampleRate)
+{
sampleRate = pSampleRate;
}
-int Accelerometer::getSampleRate() {
+/**
+ * Get the sample rate of accelerometer
+ *
+ * @return sampleRate the sample rate of the accelerometer in milliseconds
+ */
+int Accelerometer::getSampleRate()
+{
return sampleRate;
}
-qreal Accelerometer::getCurrentAcceleration() {
+qreal Accelerometer::getCurrentAcceleration()
+{
return currentAcceleration;
}
-qreal Accelerometer::getPreviousTotalAcceleration() {
+qreal Accelerometer::getPreviousTotalAcceleration()
+{
return previousAcceleration;
}
-qreal Accelerometer::getTotalAcceleration() {
+qreal Accelerometer::getTotalAcceleration()
+{
return totalAcceleration;
}
-qreal Accelerometer::getDistanceTraveled() {
+qreal Accelerometer::getDistanceTraveled()
+{
return distanceTraveled;
}
-qreal Accelerometer::getLastDistanceTraveled() {
+qreal Accelerometer::getLastDistanceTraveled()
+{
return lastDistanceTraveled;
}
-qreal Accelerometer::getAverageSpeed() {
+qreal Accelerometer::getAverageSpeed()
+{
return averageSpeed;
}
-qreal Accelerometer::getTrueAccelerationX() {
+qreal Accelerometer::getTrueAccelerationX()
+{
return trueAccelerationX;
}
-qreal Accelerometer::getTrueAccelerationY() {
+qreal Accelerometer::getTrueAccelerationY()
+{
return trueAccelerationY;
}
-qreal Accelerometer::getTrueAccelerationZ() {
+qreal Accelerometer::getTrueAccelerationZ()
+{
return trueAccelerationZ;
}
-qreal Accelerometer::getPreviousSpeed() {
+qreal Accelerometer::getPreviousSpeed()
+{
return previousSpeed;
}
-qreal Accelerometer::getCurrentSpeed() {
+qreal Accelerometer::getCurrentSpeed()
+{
return currentSpeed;
}
-qreal Accelerometer::getintervalTime() {
+qreal Accelerometer::getIntervalTime()
+{
return intervalTime;
}
+qreal Accelerometer::getTotalTime()
+{
+ return totalTime;
+}
+
/**
* Processes Accelerometer data
*
+ * Opens the accelerometer value file for reading and reads and parses accelerometer values.
+ * Forwards data to Calculate class for processing
+ *
*/
void Accelerometer::processData()
{
- QFile file("/sys/class/i2c-adapter/i2c-3/3-001d/coord");
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
- return;
+ QFile file(kFileName);
+ if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
// Read data, parse with regular expressions and process it
QByteArray line = file.readLine();
smoothData(rx.cap(1).toInt(), rx.cap(2).toInt(), rx.cap(3).toInt());
- trueAccelerationX = (accelerationX - previousAccelerationX)/1000*kGravity;
- trueAccelerationY = (accelerationY - previousAccelerationY)/1000*kGravity;
- trueAccelerationZ = (accelerationZ - previousAccelerationZ)/1000*kGravity;
+ // Apply calibration
+ trueAccelerationX = accelerationX - calibrationX;
+ trueAccelerationY = accelerationY - calibrationY;
+ trueAccelerationZ = accelerationZ - calibrationZ;
+
+ // Discrimination window for acceleration values
+ if (trueAccelerationX <= 30 && trueAccelerationX >= -30) { trueAccelerationX = 0; }
+ if (trueAccelerationY <= 30 && trueAccelerationY >= -30) { trueAccelerationY = 0; }
+ if (trueAccelerationZ <= 30 && trueAccelerationZ >= -30) { trueAccelerationZ = 0; }
+
+ trueAccelerationX = (accelerationX - previousAccelerationX) /*/ 1000 * kGravity*/;
+ trueAccelerationY = (accelerationY - previousAccelerationY) /*/ 1000 * kGravity*/;
+ trueAccelerationZ = (accelerationZ - previousAccelerationZ) /*/ 1000 * kGravity*/;
previousAccelerationX = accelerationX;
previousAccelerationY = accelerationY;
previousAccelerationZ = accelerationZ;
currentAcceleration = sqrt(trueAccelerationX * trueAccelerationX +
- trueAccelerationY * trueAccelerationY +
- trueAccelerationZ * trueAccelerationZ );
+ trueAccelerationY * trueAccelerationY +
+ trueAccelerationZ * trueAccelerationZ );
totalAcceleration = currentAcceleration - previousAcceleration;
-
- totalAcceleration = fabs(totalAcceleration);
-
previousAcceleration = currentAcceleration;
- // v = v0 + at
- // x = x0 + v0t + (at^2)/2
- // v = (v + v0)/2
-
- intervalTime = now.restart();
- intervalTime = intervalTime/1000; // millisecs to secs
+ // Measure time interval
+ intervalTime = now.restart(); // millisecs to secs
+ intervalTime = intervalTime/1000;
totalTime = totalTime + intervalTime;
- // filter noise
- // TODO: do this in smoothdata: implement a better filter.
- if (totalAcceleration > 0.02) {
- currentSpeed = ( previousSpeed + ( totalAcceleration * intervalTime ) / 2 );
- } else {
- currentSpeed = 0;
- }
-
- // filter noise
- if (currentSpeed > 0.02) {
- distanceTraveled = ( lastDistanceTraveled + ( ( currentSpeed + previousSpeed ) * intervalTime) / 2 );
- } else {
- //distanceTraveled = 0;
+ // Filter out acceleration caused by noise.
+ if (fabs(currentAcceleration) < 0.09) {
+ return;
}
- averageSpeed = distanceTraveled / totalTime;
+ // Using calculate class to calculate velocity and distance etc.
+ calculate->calculateParameters(currentAcceleration,intervalTime );
- previousSpeed = currentSpeed;
- lastDistanceTraveled = distanceTraveled;
+ currentSpeed = calculate->getCurrentSpeed();
+ distanceTraveled = calculate->getDistanceTraveled();
file.close();
}
/**
* Smooths Accelerometer data
*
- * @param x Accelerometers x-axis raw input
- * @param y Accelerometers y-axis raw input
- * @param z Accelerometers z-axis raw input
+ * @param x accelerometer's x-axis input
+ * @param y accelerometer's y-axis input
+ * @param z accelerometer's z-axis input
*/
-void Accelerometer::smoothData(qreal x, qreal y, qreal z) {
+void Accelerometer::smoothData(qreal x, qreal y, qreal z)
+{
accelerationX = x;
accelerationY = y;
accelerationZ = z;
#include <QObject>
#include <QTime>
#include <QTimer>
+#include <QFile>
+
+#include "calculate.h"
class Accelerometer : public QObject
{
Q_OBJECT
public:
Accelerometer();
+ Accelerometer(int p_SampleRate);
~Accelerometer();
+ void calibrate();
+
void start();
void stop();
qreal getTotalAcceleration();
qreal getPreviousTotalAcceleration();
- qreal getintervalTime();
+ int calibrationX;
+ int calibrationY;
+ int calibrationZ;
+
+ qreal getIntervalTime();
+ qreal getTotalTime();
private slots:
void processData();
void smoothData(qreal x, qreal y, qreal z);
private:
+ Calculate *calculate;
+
qreal accelerationX, accelerationY, accelerationZ;
qreal trueAccelerationX,trueAccelerationY,trueAccelerationZ;
qreal previousAccelerationX,previousAccelerationY,previousAccelerationZ;
qreal previousSpeed, currentSpeed;
qreal currentAcceleration, previousAcceleration, totalAcceleration;
+
QTime now;
QTimer *timer;
+
double intervalTime;
double totalTime;
- double distanceTraveled,lastDistanceTraveled,averageSpeed;
+ double distanceTraveled;
+ double lastDistanceTraveled;
+ double averageSpeed;
double sampleRate;
+
+ bool reverseAcceleration;
};
#endif // ACCELEROMETER_H
const double G_ACCELERATION = 9.80665;
const double SECONDS_IN_HOUR = 3600;
-Calculate::Calculate() {
-
+Calculate::Calculate()
+{
this->reset();
-
}
-Calculate::~Calculate() {
-}
+Calculate::~Calculate()
+{
-void Calculate::reset() {
+}
+void Calculate::reset()
+{
averageSpeed = 0;
currentSpeed = 0;
distanceTraveled = 0;
lastSpeed = 0;
numOfIterations = 0;
totalTime = 0;
+ count = 0;
}
-/* Getters and setters
- */
+// Getters and setters
-double Calculate::AverageSpeed()
+double Calculate::getAverageSpeed()
{
return averageSpeed;
}
-void Calculate::AverageSpeed(double value)
+
+void Calculate::setAverageSpeed(double value)
{
averageSpeed = value;
}
-double Calculate::CurrentSpeed()
+
+double Calculate::getCurrentSpeed()
{
return currentSpeed;
}
-void Calculate::CurrentSpeed(double value)
+
+void Calculate::setCurrentSpeed(double value)
{
currentSpeed = value;
}
-double Calculate::DistanceTraveled()
+
+double Calculate::getDistanceTraveled()
{
return distanceTraveled;
}
-void Calculate::DistanceTraveled(double value)
+
+void Calculate::setDistanceTraveled(double value)
{
distanceTraveled = value;
}
-double Calculate::LastAcceleration()
+
+double Calculate::getLastAcceleration()
{
return lastAcceleration;
}
-void Calculate::LastAcceleration(double value)
+
+void Calculate::setLastAcceleration(double value)
{
lastAcceleration = value;
}
-double Calculate::LastDistance()
+
+double Calculate::getLastDistance()
{
return lastDistance;
}
-void Calculate::LastDistance(double value)
+
+void Calculate::setLastDistance(double value)
{
lastDistance = value;
}
-double Calculate::LastSpeed()
+
+double Calculate::getLastSpeed()
{
return lastSpeed;
}
-void Calculate::LastSpeed(double value)
+
+void Calculate::setLastSpeed(double value)
{
lastSpeed = value;
}
-long Calculate::NumOfIterations()
+
+long Calculate::getNumOfIterations()
{
return numOfIterations;
}
-void Calculate::NumOfIterations(long value)
+
+void Calculate::setNumOfIterations(long value)
{
numOfIterations = value;
}
-double Calculate::TotalTime()
+
+double Calculate::getTotalTime()
{
return totalTime;
}
-void Calculate::TotalTime(double value)
+
+void Calculate::setTotalTime(double value)
{
totalTime = value;
}
-/*
- This is a main function for calculating various parameters. Accelerometer
- provides currentAcceleration and calling function measures time (seconds).
- This function should be called 20-30 times/second to minimize
- calculation error.
+/**
+ * This is a main function for calculating various parameters. Accelerometer
+ * provides currentAcceleration and calling function measures time (seconds).
+ * This function should be called 20-30 times/second to minimize
+ * calculation error.
- To be added: params like horsepower.
+ * To be added: params like horsepower.
*/
-void Calculate::CalculateParameters(double currentAcceleration, double seconds)
+void Calculate::calculateParameters(double currentAcceleration, double seconds)
{
numOfIterations++;
totalTime = (totalTime + seconds);
// v=v0 + a*t
// v(n) = v(n-1)+(a(n) + a(n-1))*(seconds)/2
- /* First integration of acceleration provides speed
- */
+ // First integration of acceleration provides speed
currentSpeed = (lastSpeed + (((currentAcceleration + lastAcceleration) * seconds) / 2));
- /* Second integration: distance.
- */
+ // Second integration: distance.
distanceTraveled = (lastDistance + (((currentSpeed + lastSpeed) * seconds) / 2));
- /* Average speed
- */
+ // Average speed
averageSpeed = (distanceTraveled / totalTime);
+ // Check for movement
+ accelStoppedCheck(currentAcceleration);
+
lastSpeed = currentSpeed;
lastAcceleration = currentAcceleration;
lastDistance = distanceTraveled;
}
+/**
+ * This function checks if acceleration has stopped for
+ * a short period of time. Velocity is set to zero to avoid
+ * distance errors.
+ */
+void Calculate::accelStoppedCheck(double currentAcceleration)
+{
+ // counting number of acceleration samples that equals zero
+ if (currentAcceleration==0) {
+ count++;
+ } else {
+ count = 0;
+ }
-
+ // if count exceeds 25, we assume that velocity is zero
+ if (count >= 25)
+ {
+ currentSpeed=0;
+ }
+}
~Calculate();
void reset();
- void CalculateParameters(double currentAcceleration, double seconds);
+ void calculateParameters(double currentAcceleration, double seconds);
+ void accelStoppedCheck(double currentAcceleration);
- double AverageSpeed();
- void AverageSpeed(double value);
+ double getAverageSpeed();
+ void setAverageSpeed(double value);
- double CurrentSpeed();
- void CurrentSpeed(double value);
+ double getCurrentSpeed();
+ void setCurrentSpeed(double value);
- double DistanceTraveled();
- void DistanceTraveled(double value);
+ double getDistanceTraveled();
+ void setDistanceTraveled(double value);
- double LastAcceleration();
- void LastAcceleration(double value);
+ double getLastAcceleration();
+ void setLastAcceleration(double value);
- double LastCheckpoint();
- void LastCheckpoint(double value);
+ double getLastCheckpoint();
+ void setLastCheckpoint(double value);
- double LastDistance();
- void LastDistance(double value);
+ double getLastDistance();
+ void setLastDistance(double value);
- double LastSpeed();
- void LastSpeed(double value);
+ double getLastSpeed();
+ void setLastSpeed(double value);
- long NumOfIterations();
- void NumOfIterations(long value);
+ long getNumOfIterations();
+ void setNumOfIterations(long value);
- double TotalTime();
- void TotalTime(double value);
+ double getTotalTime();
+ void setTotalTime(double value);
private:
double averageSpeed;
double lastSpeed;
long numOfIterations;
double totalTime;
-
+ int count;
};
initUnitCompoBox();
initSpeedListView();
+<<<<<<< HEAD:Client/carmainwindow.cpp
+ initCategoryCompoBox();
+
+ myLogin = new LoginWindow(this);
+ myRegistration = new Registration(this);
+ manager = new QNetworkAccessManager(this);
+ connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(networkResponse(QNetworkReply*)));
+
+=======
+>>>>>>> feature/XMLreader:Client/carmainwindow.cpp
}
/**
*/
void CarMainWindow::on_autoStartButton_clicked()
{
- if(measure)
- {
- delete measure;
- measure = NULL;
- measure = new MeasureDialog();
- }
- connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
+ delete measure;
+ measure = NULL;
+ measure = new MeasureDialog();
+ connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
// Show measure dialog.
measure->show();
}
*/
void CarMainWindow::initSpeedListView()
{
+<<<<<<< HEAD:Client/carmainwindow.cpp
+ numbers << "0-40 km/h" << "0-1/4 mil" << "0-50 km" << "50-100 mil" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
+=======
numbers << "0-40 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";
+>>>>>>> feature/XMLreader:Client/carmainwindow.cpp
QAbstractItemModel *model = new StringListModel(numbers);
ui->listView->setModel(model);
}
*/
void CarMainWindow::openResultView()
{
+ result->saveMeasuresToArray(measure->measures);
// Show result dialog.
result->show();
}
/**
+<<<<<<< HEAD:Client/carmainwindow.cpp
+ *This slot function is called when the server has finished guery.
+ */
+void CarMainWindow::networkResponse(QNetworkReply *reply)
+{
+}
+
+/**
+ *This slot function is called when the user will to send data to server.
+ */
+void CarMainWindow::on_pushButton_clicked()
+{
+ QNetworkRequest postData;
+ postData.setUrl(QString("http://weather.yahooapis.com/forecastrss?p=FIXX0013&u=c"));
+ manager->get(postData);
+
+}
+
+/**
+ *This slot function is called when login/logout button is clicked.
+ */
+void CarMainWindow::on_loginLogoutButton_clicked()
+{
+ //LoginWindow myLogin;
+
+ myLogin->show();
+ //ui->loginLogoutButton->setText("logout");
+}
+
+/**
+ *This slot function is called when registrate button is clicked.
+ */
+void CarMainWindow::on_registratePushButton_clicked()
+{
+ myRegistration->show();
+=======
*This slot function is called when ever refresh button clicked. Top-tab view.
*/
void CarMainWindow::on_buttonTopRefresh_clicked()
void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category)
{
setListViewTopList(category);
+>>>>>>> feature/XMLreader:Client/carmainwindow.cpp
}
#include <QModelIndex>
#include <QStringList>
#include <QString>
+#include <QNetworkAccessManager>
+#include <QStandardItemModel>
+#include <QNetworkRequest>
#include "resultdialog.h"
#include "measuredialog.h"
+#include "loginwindow.h"
+#include "registration.h"
#include "xmlreader.h"
#include "ui_carmainwindow.h"
#include "stringlistmodel.h"
ResultDialog *result;
MeasureDialog *measure;
XmlReader *xmlreader;
-
+ QNetworkAccessManager* manager;
+ LoginWindow *myLogin;
+ Registration *myRegistration;
+ void initCategoryCompoBox();
void initUnitCompoBox(); //Start-tab
void initSpeedListView(); //Start-tab
QStringList categories; //Top-tab
private slots:
+ void on_registratePushButton_clicked();
+ void on_loginLogoutButton_clicked();
+ void on_comboBoxTopCategory_activated(QString );
+ void on_pushButton_clicked();
+ void networkResponse(QNetworkReply*);
void on_comboBoxTopCategory_currentIndexChanged(QString category); //Top-tab
void on_listView_clicked(QModelIndex index); //Start-tab
void updateUnitCompoBox(QString unit); //Start-tab
void openResultView();
void on_buttonTopRefresh_clicked(); //Top-tab: button
void on_autoStartButton_clicked(); //Start-tab: button
-
};
#endif // CARMAINWINDOW_H
<string>Refresh list</string>
</property>
</widget>
+ <widget class="QListView" name="listViewTopList">
+ <property name="geometry">
+ <rect>
+ <x>360</x>
+ <y>10</y>
+ <width>411</width>
+ <height>311</height>
+ </rect>
+ </property>
+ <property name="font">
+ <font>
+ <family>Bitstream Charter</family>
+ <pointsize>10</pointsize>
+ </font>
+ </property>
+ <property name="flow">
+ <enum>QListView::LeftToRight</enum>
+ </property>
+ </widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
</item>
</layout>
</widget>
+ <widget class="QPushButton" name="loginLogoutButton">
+ <property name="geometry">
+ <rect>
+ <x>690</x>
+ <y>0</y>
+ <width>93</width>
+ <height>27</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Login</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="registratePushButton">
+ <property name="geometry">
+ <rect>
+ <x>580</x>
+ <y>0</y>
+ <width>93</width>
+ <height>27</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Registrate</string>
+ </property>
+ </widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
--- /dev/null
+#include "loginwindow.h"
+#include "ui_loginwindow.h"
+#include <QMessageBox>
+
+LoginWindow::LoginWindow(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::LoginWindow)
+{
+ ui->setupUi(this);
+ this->setWindowTitle("Login to Speed Freak server");
+}
+
+LoginWindow::~LoginWindow()
+{
+ delete ui;
+}
+
+void LoginWindow::changeEvent(QEvent *e)
+{
+ QDialog::changeEvent(e);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
+
+void LoginWindow::on_cancelPushButton_clicked()
+{
+ close();
+}
+
+void LoginWindow::on_loginPushButton_clicked()
+{
+ // To do
+ //loginToServer(ui->userNameLineEdit->text(),
+ // ui->passwordLineEdit->text());
+ //close();
+ QMessageBox::about(this,"Login",ui->userNameLineEdit->text()+ui->passwordLineEdit->text());
+}
+
+
+
--- /dev/null
+#ifndef LOGINWINDOW_H
+#define LOGINWINDOW_H
+
+#include <QDialog>
+
+namespace Ui {
+ class LoginWindow;
+}
+
+class LoginWindow : public QDialog {
+ Q_OBJECT
+public:
+ LoginWindow(QWidget *parent = 0);
+ ~LoginWindow();
+
+protected:
+ void changeEvent(QEvent *e);
+
+private:
+ Ui::LoginWindow *ui;
+
+private slots:
+ void on_loginPushButton_clicked();
+ void on_cancelPushButton_clicked();
+};
+
+#endif // LOGINWINDOW_H
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LoginWindow</class>
+ <widget class="QDialog" name="LoginWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>400</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>LoginWindow</string>
+ </property>
+ <widget class="QPushButton" name="loginPushButton">
+ <property name="geometry">
+ <rect>
+ <x>60</x>
+ <y>130</y>
+ <width>75</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Login</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="cancelPushButton">
+ <property name="geometry">
+ <rect>
+ <x>150</x>
+ <y>130</y>
+ <width>75</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ </widget>
+ <widget class="QWidget" name="layoutWidget">
+ <property name="geometry">
+ <rect>
+ <x>51</x>
+ <y>62</y>
+ <width>193</width>
+ <height>48</height>
+ </rect>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="userNameLabel">
+ <property name="text">
+ <string>Username:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="userNameLineEdit">
+ <property name="maxLength">
+ <number>12</number>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="passwordLabel">
+ <property name="text">
+ <string>Password:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="passwordLineEdit">
+ <property name="maxLength">
+ <number>255</number>
+ </property>
+ <property name="echoMode">
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
+
timer = new QTimer();
accelerometer = new Accelerometer();
- //accelerometer->start();
+ accelerometer->setSampleRate(100);
+ accelerometer->start();
- timer->setInterval(1000);
+ measures = new Measures();
+ this->initializeMeasures();
+
+ timer->setInterval(100);
timer->start();
connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout()));
}
void MeasureDialog::after_timeout()
{
QString timeString, speedString;
- time++;
+ //time++;
+ time = accelerometer->getTotalTime();
speed = accelerometer->getCurrentSpeed();
+ //speed = speed +10;
+
+ if(speed > 9.7 && speed < 10.3)
+ {
+ measures->setTime10kmh(time);
+ }
+
+ else if (speed > 19.7 && speed < 20.3)
+ {
+ measures->setTime20kmh(time);
+ }
+
+ else if (speed > 29.7 && speed < 30.3)
+ {
+ measures->setTime30kmh(time);
+ }
+
+ else if (speed > 39.7 && speed < 40.3)
+ {
+ measures->setTime40kmh(time);
+ }
+
+ else if (speed > 49.7 && speed < 50.3)
+ {
+ measures->setTime50kmh(time);
+ }
+
+ else if (speed > 59.7 && speed < 60.3)
+ {
+ measures->setTime60kmh(time);
+ }
+
+ else if (speed > 69.7 && speed < 70.3)
+ {
+ measures->setTime70kmh(time);
+ }
+
+ else if (speed > 79.7 && speed < 80.3)
+ {
+ measures->setTime80kmh(time);
+ }
+
+ else if (speed > 89.7 && speed < 90.3)
+ {
+ measures->setTime90kmh(time);
+ }
+
+ else if (speed > 99.7 && speed < 100.3)
+ {
+ measures->setTime100kmh(time);
+ }
+
+ else
+ {
+
+ }
// If speed is over 100 km/h emits speedAchieved() signal and close this dialog.
- if(speed>=100.0)
+ if (speed >= 40.0)
{
timer->stop();
- //accelerometer->stop();
+ accelerometer->stop();
time = 0;
speed = 0;
emit this->speedAchieved();
ui->labelTime->setText(timeString);
timer->start();
}
+
}
/**
*/
void MeasureDialog::on_pushButtonAbort_clicked()
{
+ measures->setTime10kmh(0);
+ measures->setTime20kmh(0);
+ measures->setTime30kmh(0);
+ measures->setTime40kmh(0);
+ measures->setTime50kmh(0);
+ measures->setTime60kmh(0);
+ measures->setTime70kmh(0);
+ measures->setTime80kmh(0);
+ measures->setTime90kmh(0);
+ measures->setTime100kmh(0);
timer->stop();
- //accelerometer->stop();
+ accelerometer->stop();
time = 0;
speed = 0;
this->close();
}
+
+void MeasureDialog::initializeMeasures()
+{
+ measures->setTime10kmh(0);
+ measures->setTime20kmh(0);
+ measures->setTime30kmh(0);
+ measures->setTime40kmh(0);
+ measures->setTime50kmh(0);
+ measures->setTime60kmh(0);
+ measures->setTime70kmh(0);
+ measures->setTime80kmh(0);
+ measures->setTime90kmh(0);
+ measures->setTime100kmh(0);
+}
#define MEASUREDIALOG_H
#include "accelerometer.h"
+#include "measures.h"
#include <QDialog>
#include <QTimer>
public:
MeasureDialog(QWidget *parent = 0);
~MeasureDialog();
-
+ Measures *measures;
+ void initializeMeasures();
protected:
void changeEvent(QEvent *e);
QTimer *timer;
Accelerometer *accelerometer;
-
- int time;
- qreal speed;
+ double time;
+ double speed;
signals:
void speedAchieved();
--- /dev/null
+#include "measures.h"
+
+Measures::Measures()
+{
+}
+
+qreal Measures::getTime10kmh()
+{
+ return time10kmh;
+}
+
+qreal Measures::getTime20kmh()
+{
+ return time20kmh;
+}
+
+qreal Measures::getTime30kmh()
+{
+ return time30kmh;
+}
+
+qreal Measures::getTime40kmh()
+{
+ return time40kmh;
+}
+
+qreal Measures::getTime50kmh()
+{
+ return time50kmh;
+}
+
+qreal Measures::getTime60kmh()
+{
+ return time60kmh;
+}
+
+qreal Measures::getTime70kmh()
+{
+ return time70kmh;
+}
+
+qreal Measures::getTime80kmh()
+{
+ return time80kmh;
+}
+
+qreal Measures::getTime90kmh()
+{
+ return time90kmh;
+}
+
+qreal Measures::getTime100kmh()
+{
+ return time100kmh;
+}
+
+void Measures::setTime10kmh(qreal pTime)
+{
+ time10kmh = pTime;
+}
+
+void Measures::setTime20kmh(qreal pTime)
+{
+ time20kmh = pTime;
+}
+
+void Measures::setTime30kmh(qreal pTime)
+{
+ time30kmh = pTime;
+}
+
+void Measures::setTime40kmh(qreal pTime)
+{
+ time40kmh = pTime;
+}
+
+void Measures::setTime50kmh(qreal pTime)
+{
+ time50kmh = pTime;
+}
+
+void Measures::setTime60kmh(qreal pTime)
+{
+ time60kmh = pTime;
+}
+
+void Measures::setTime70kmh(qreal pTime)
+{
+ time70kmh = pTime;
+}
+
+void Measures::setTime80kmh(qreal pTime)
+{
+ time80kmh = pTime;
+}
+
+void Measures::setTime90kmh(qreal pTime)
+{
+ time90kmh = pTime;
+}
+
+void Measures::setTime100kmh(qreal pTime)
+{
+ time100kmh = pTime;
+}
--- /dev/null
+#ifndef MEASURES_H
+#define MEASURES_H
+
+#include <QObject>
+
+class Measures
+{
+public:
+ Measures();
+ qreal getTime10kmh();
+ qreal getTime20kmh();
+ qreal getTime30kmh();
+ qreal getTime40kmh();
+ qreal getTime50kmh();
+ qreal getTime60kmh();
+ qreal getTime70kmh();
+ qreal getTime80kmh();
+ qreal getTime90kmh();
+ qreal getTime100kmh();
+
+ void setTime10kmh(qreal pTime);
+ void setTime20kmh(qreal pTime);
+ void setTime30kmh(qreal pTime);
+ void setTime40kmh(qreal pTime);
+ void setTime50kmh(qreal pTime);
+ void setTime60kmh(qreal pTime);
+ void setTime70kmh(qreal pTime);
+ void setTime80kmh(qreal pTime);
+ void setTime90kmh(qreal pTime);
+ void setTime100kmh(qreal pTime);
+
+
+private:
+ qreal time10kmh;
+ qreal time20kmh;
+ qreal time30kmh;
+ qreal time40kmh;
+ qreal time50kmh;
+ qreal time60kmh;
+ qreal time70kmh;
+ qreal time80kmh;
+ qreal time90kmh;
+ qreal time100kmh;
+};
+
+#endif // MEASURES_H
--- /dev/null
+#include "registration.h"
+#include "ui_registration.h"
+#include <QMessageBox>
+
+Registration::Registration(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::Registration)
+{
+ ui->setupUi(this);
+ this->setWindowTitle("Registration for Speed Freak server");
+}
+
+Registration::~Registration()
+{
+ delete ui;
+}
+
+void Registration::changeEvent(QEvent *e)
+{
+ QDialog::changeEvent(e);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
+
+void Registration::on_registratePushButton_clicked()
+{
+ // Send username, password and email to SpeedFreak server
+ //close(); // Needs some new signal/slot to go forward or ???
+ //registrateToServer(ui->newUsernameLineEdit->text(),
+ // ui->newPasswordLineEdit->text(),
+ // ui->eMailLineEdit->text());
+ QMessageBox::about(this,"Registrate",ui->newUsernameLineEdit->text()+ui->newPasswordLineEdit->text()+ui->eMailLineEdit->text());
+}
+
+void Registration::on_cancelPushButton_clicked()
+{
+ close();
+}
+
--- /dev/null
+#ifndef REGISTRATION_H
+#define REGISTRATION_H
+
+#include <QDialog>
+
+namespace Ui {
+ class Registration;
+}
+
+class Registration : public QDialog {
+ Q_OBJECT
+public:
+ Registration(QWidget *parent = 0);
+ ~Registration();
+
+protected:
+ void changeEvent(QEvent *e);
+
+private:
+ Ui::Registration *ui;
+
+private slots:
+ void on_cancelPushButton_clicked();
+ void on_registratePushButton_clicked();
+};
+
+#endif // REGISTRATION_H
+
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Registration</class>
+ <widget class="QDialog" name="Registration">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>400</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Registration</string>
+ </property>
+ <widget class="QLabel" name="infoLabel">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>20</y>
+ <width>381</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Give your new username (max. 12 characters) and password for registration.</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="infoLabel_2">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>40</y>
+ <width>181</width>
+ <height>16</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Give also your valid email address.</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="registratePushButton">
+ <property name="geometry">
+ <rect>
+ <x>60</x>
+ <y>180</y>
+ <width>75</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Registrate</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="cancelPushButton">
+ <property name="geometry">
+ <rect>
+ <x>160</x>
+ <y>180</y>
+ <width>75</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ </widget>
+ <widget class="QWidget" name="">
+ <property name="geometry">
+ <rect>
+ <x>40</x>
+ <y>80</y>
+ <width>239</width>
+ <height>74</height>
+ </rect>
+ </property>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="newUserNameLabel">
+ <property name="text">
+ <string>Your new username:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="newUsernameLineEdit">
+ <property name="maxLength">
+ <number>12</number>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="newPasswordLabel">
+ <property name="text">
+ <string>Your new password:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="newPasswordLineEdit">
+ <property name="maxLength">
+ <number>255</number>
+ </property>
+ <property name="echoMode">
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="eMailLabel">
+ <property name="text">
+ <string>Your Emai:l</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="eMailLineEdit">
+ <property name="maxLength">
+ <number>255</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
+
const int diagramGap = 30;
-
// Test arrays for changing speeds and times to the points in diagram
-static const int speedArray[10] = {12, 34, 56, 78, 90, 100, 104, 100, 90, 80};
-static const int timeArray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 12};
-
-
+static const int speedArray[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
+//static const int timeArray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 12};
// Test point array for the diagram.
QPoint points[10];
{
ui->setupUi(this);
- QString time, timeInteger;
- timeInteger.setNum(timeArray[9]);
- time = "0 - 100 km/h: ";
- time.append(timeInteger);
- ui->labelResult->setText(time);
-
- timeInteger.setNum(timeArray[8]);
- time = "0 - 90 km/h: ";
- time.append(timeInteger);
- ui->labelResult_2->setText(time);
-
- timeInteger.setNum(timeArray[7]);
- time = "0 - 80 km/h: ";
- time.append(timeInteger);
- ui->labelResult_3->setText(time);
-
- timeInteger.setNum(timeArray[6]);
- time = "0 - 70 km/h: ";
- time.append(timeInteger);
- ui->labelResult_4->setText(time);
-
- timeInteger.setNum(timeArray[5]);
- time = "0 - 60 km/h: ";
- time.append(timeInteger);
- ui->labelResult_5->setText(time);
-
- timeInteger.setNum(timeArray[4]);
- time = "0 - 50 km/h: ";
- time.append(timeInteger);
- ui->labelResult_6->setText(time);
- timeInteger.setNum(timeArray[3]);
- time = "0 - 40 km/h: ";
- time.append(timeInteger);
- ui->labelResult_7->setText(time);
- for(int i = 0; i < 10; i++)
- {
- points[i] = changeMeasuresToDiagramPoint(speedArray[i], timeArray[i]);
- }
// ui->labelXLine->setText(ui->labelXLine->text().append(": time/ s"));
// ui->labelYLine->setText(ui->labelYLine->text().append(": speed/ km/h"));
}
painter.drawLine(currentX, currentY, currentX+10, currentY);
}
- painter.drawPolyline(points, 10);
+ painter.drawPolyline(points, 4);
}
*@param aSpeed is speed which need to change, aTime is time in seconds which need to change.
*@return point is calculated from aSpeed and aTime.
**/
-QPoint ResultDialog::changeMeasuresToDiagramPoint(int aSpeed, int aTime)
+QPoint ResultDialog::changeMeasuresToDiagramPoint(int aSpeed, qreal aTime)
{
QPoint point;
return point;
}
+
+/**
+ *Saves the given measures to array.
+ *@param pMeasures has information about acceleration.
+ **/
+void ResultDialog::saveMeasuresToArray(Measures *pMeasures)
+{
+ timeArray[0] = pMeasures->getTime10kmh();
+ timeArray[1] = pMeasures->getTime20kmh();
+ timeArray[2] = pMeasures->getTime30kmh();
+ timeArray[3] = pMeasures->getTime40kmh();
+ timeArray[4] = pMeasures->getTime50kmh();
+ timeArray[5] = pMeasures->getTime60kmh();
+ timeArray[6] = pMeasures->getTime70kmh();
+ timeArray[7] = pMeasures->getTime80kmh();
+ timeArray[8] = pMeasures->getTime90kmh();
+ timeArray[9] = pMeasures->getTime100kmh();
+
+ for(int i = 0; i < 4; i++)
+ {
+ points[i] = changeMeasuresToDiagramPoint(speedArray[i], timeArray[i]);
+ }
+
+ QString time, timeInteger;
+ timeInteger.setNum(timeArray[3]);
+ time = "0 - 40 km/h: ";
+ time.append(timeInteger);
+ ui->labelResult40kmh->setText(time);
+
+ timeInteger.setNum(timeArray[2]);
+ time = "0 - 30 km/h: ";
+ time.append(timeInteger);
+ ui->labelResult30kmh->setText(time);
+
+ timeInteger.setNum(timeArray[1]);
+ time = "0 - 20 km/h: ";
+ time.append(timeInteger);
+ ui->labelResult20kmh->setText(time);
+
+ timeInteger.setNum(timeArray[0]);
+ time = "0 - 10 km/h: ";
+ time.append(timeInteger);
+ ui->labelResult10kmh->setText(time);
+
+ /* timeInteger.setNum(timeArray[5]);
+ time = "0 - 60 km/h: ";
+ time.append(timeInteger);
+ ui->labelResult_5->setText(time);
+
+ timeInteger.setNum(timeArray[4]);
+ time = "0 - 50 km/h: ";
+ time.append(timeInteger);
+ ui->labelResult_6->setText(time);
+
+ timeInteger.setNum(timeArray[3]);
+ time = "0 - 40 km/h: ";
+ time.append(timeInteger);
+ ui->labelResult_7->setText(time);*/
+
+ this->repaint();
+
+ for(int i = 0; i < 10; i++)
+ {
+ timeArray[i] = 0;
+ }
+}
#define RESULTDIALOG_H
#include <QDialog>
+#include "measures.h"
namespace Ui {
class ResultDialog;
public:
ResultDialog(QWidget *parent = 0);
~ResultDialog();
+ void saveMeasuresToArray(Measures *pMeasures);
protected:
void changeEvent(QEvent *e);
void paintEvent(QPaintEvent *);
private:
- QPoint changeMeasuresToDiagramPoint(int aSpeed, int aTime);
+ QPoint changeMeasuresToDiagramPoint(int aSpeed, qreal aTime);
+ qreal timeArray[10];
private:
Ui::ResultDialog *ui;
<property name="windowTitle">
<string>Dialog</string>
</property>
- <widget class="QLabel" name="labelResult_4">
+ <widget class="QLabel" name="labelResult10kmh">
<property name="geometry">
<rect>
- <x>520</x>
- <y>120</y>
+ <x>410</x>
+ <y>230</y>
<width>191</width>
<height>31</height>
</rect>
</property>
<property name="text">
- <string>0 - 50 km/h: 5,6 s</string>
+ <string>0 - 10 km/h: 5,6 s</string>
</property>
</widget>
- <widget class="QLabel" name="labelResult_7">
+ <widget class="QLabel" name="labelResult40kmh">
<property name="geometry">
<rect>
- <x>520</x>
- <y>240</y>
+ <x>410</x>
+ <y>90</y>
<width>191</width>
<height>31</height>
</rect>
</property>
<property name="text">
- <string>0 - 20 km/h: 1,1 s</string>
+ <string>0 - 40 km/h: 9,8 s</string>
</property>
</widget>
- <widget class="QLabel" name="labelResult">
+ <widget class="QLabel" name="labelResult20kmh">
<property name="geometry">
<rect>
- <x>520</x>
- <y>10</y>
- <width>191</width>
- <height>31</height>
- </rect>
- </property>
- <property name="text">
- <string>0 - 100 km/h: 9,8 s</string>
- </property>
- </widget>
- <widget class="QLabel" name="labelResult_6">
- <property name="geometry">
- <rect>
- <x>520</x>
- <y>200</y>
- <width>191</width>
- <height>31</height>
- </rect>
- </property>
- <property name="text">
- <string>0 - 30 km/h: 3,2 s</string>
- </property>
- </widget>
- <widget class="QLabel" name="labelResult_5">
- <property name="geometry">
- <rect>
- <x>520</x>
- <y>160</y>
+ <x>410</x>
+ <y>180</y>
<width>191</width>
<height>31</height>
</rect>
</property>
<property name="text">
- <string>0 - 40 km/h:4,5 s</string>
+ <string>0 - 20 km/h: 6,9 s</string>
</property>
</widget>
- <widget class="QLabel" name="labelResult_3">
+ <widget class="QLabel" name="labelResult30kmh">
<property name="geometry">
<rect>
- <x>520</x>
- <y>80</y>
- <width>191</width>
- <height>31</height>
- </rect>
- </property>
- <property name="text">
- <string>0 - 60 km/h: 6,9 s</string>
- </property>
- </widget>
- <widget class="QLabel" name="labelResult_2">
- <property name="geometry">
- <rect>
- <x>520</x>
- <y>40</y>
+ <x>410</x>
+ <y>140</y>
<width>191</width>
<height>31</height>
</rect>
</property>
<property name="text">
- <string>0 - 80 km/h: 8,6 s</string>
+ <string>0 - 30 km/h: 8,6 s</string>
</property>
</widget>
<widget class="QLabel" name="labelY2">
/********************************************************************************
** Form generated from reading ui file 'resultdialog.ui'
**
-** Created: Wed Feb 24 13:07:28 2010
+** Created: Fri Mar 5 08:43:19 2010
** by: Qt User Interface Compiler version 4.5.3
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
class Ui_ResultDialog
{
public:
- QLabel *labelResult_4;
- QLabel *labelResult_7;
- QLabel *labelResult;
- QLabel *labelResult_6;
- QLabel *labelResult_5;
- QLabel *labelResult_3;
- QLabel *labelResult_2;
+ QLabel *labelResult10kmh;
+ QLabel *labelResult40kmh;
+ QLabel *labelResult20kmh;
+ QLabel *labelResult30kmh;
QLabel *labelY2;
QLabel *labelY6;
QLabel *labelY1;
if (ResultDialog->objectName().isEmpty())
ResultDialog->setObjectName(QString::fromUtf8("ResultDialog"));
ResultDialog->resize(800, 480);
- labelResult_4 = new QLabel(ResultDialog);
- labelResult_4->setObjectName(QString::fromUtf8("labelResult_4"));
- labelResult_4->setGeometry(QRect(520, 120, 191, 31));
- labelResult_7 = new QLabel(ResultDialog);
- labelResult_7->setObjectName(QString::fromUtf8("labelResult_7"));
- labelResult_7->setGeometry(QRect(520, 240, 191, 31));
- labelResult = new QLabel(ResultDialog);
- labelResult->setObjectName(QString::fromUtf8("labelResult"));
- labelResult->setGeometry(QRect(520, 10, 191, 31));
- labelResult_6 = new QLabel(ResultDialog);
- labelResult_6->setObjectName(QString::fromUtf8("labelResult_6"));
- labelResult_6->setGeometry(QRect(520, 200, 191, 31));
- labelResult_5 = new QLabel(ResultDialog);
- labelResult_5->setObjectName(QString::fromUtf8("labelResult_5"));
- labelResult_5->setGeometry(QRect(520, 160, 191, 31));
- labelResult_3 = new QLabel(ResultDialog);
- labelResult_3->setObjectName(QString::fromUtf8("labelResult_3"));
- labelResult_3->setGeometry(QRect(520, 80, 191, 31));
- labelResult_2 = new QLabel(ResultDialog);
- labelResult_2->setObjectName(QString::fromUtf8("labelResult_2"));
- labelResult_2->setGeometry(QRect(520, 40, 191, 31));
+ labelResult10kmh = new QLabel(ResultDialog);
+ labelResult10kmh->setObjectName(QString::fromUtf8("labelResult10kmh"));
+ labelResult10kmh->setGeometry(QRect(410, 230, 191, 31));
+ labelResult40kmh = new QLabel(ResultDialog);
+ labelResult40kmh->setObjectName(QString::fromUtf8("labelResult40kmh"));
+ labelResult40kmh->setGeometry(QRect(410, 90, 191, 31));
+ labelResult20kmh = new QLabel(ResultDialog);
+ labelResult20kmh->setObjectName(QString::fromUtf8("labelResult20kmh"));
+ labelResult20kmh->setGeometry(QRect(410, 180, 191, 31));
+ labelResult30kmh = new QLabel(ResultDialog);
+ labelResult30kmh->setObjectName(QString::fromUtf8("labelResult30kmh"));
+ labelResult30kmh->setGeometry(QRect(410, 140, 191, 31));
labelY2 = new QLabel(ResultDialog);
labelY2->setObjectName(QString::fromUtf8("labelY2"));
labelY2->setGeometry(QRect(20, 280, 31, 17));
void retranslateUi(QDialog *ResultDialog)
{
ResultDialog->setWindowTitle(QApplication::translate("ResultDialog", "Dialog", 0, QApplication::UnicodeUTF8));
- labelResult_4->setText(QApplication::translate("ResultDialog", "0 - 50 km/h: 5,6 s", 0, QApplication::UnicodeUTF8));
- labelResult_7->setText(QApplication::translate("ResultDialog", "0 - 20 km/h: 1,1 s", 0, QApplication::UnicodeUTF8));
- labelResult->setText(QApplication::translate("ResultDialog", "0 - 100 km/h: 9,8 s", 0, QApplication::UnicodeUTF8));
- labelResult_6->setText(QApplication::translate("ResultDialog", "0 - 30 km/h: 3,2 s", 0, QApplication::UnicodeUTF8));
- labelResult_5->setText(QApplication::translate("ResultDialog", "0 - 40 km/h:4,5 s", 0, QApplication::UnicodeUTF8));
- labelResult_3->setText(QApplication::translate("ResultDialog", "0 - 60 km/h: 6,9 s", 0, QApplication::UnicodeUTF8));
- labelResult_2->setText(QApplication::translate("ResultDialog", "0 - 80 km/h: 8,6 s", 0, QApplication::UnicodeUTF8));
+ labelResult10kmh->setText(QApplication::translate("ResultDialog", "0 - 10 km/h: 5,6 s", 0, QApplication::UnicodeUTF8));
+ labelResult40kmh->setText(QApplication::translate("ResultDialog", "0 - 40 km/h: 9,8 s", 0, QApplication::UnicodeUTF8));
+ labelResult20kmh->setText(QApplication::translate("ResultDialog", "0 - 20 km/h: 6,9 s", 0, QApplication::UnicodeUTF8));
+ labelResult30kmh->setText(QApplication::translate("ResultDialog", "0 - 30 km/h: 8,6 s", 0, QApplication::UnicodeUTF8));
labelY2->setText(QApplication::translate("ResultDialog", "20", 0, QApplication::UnicodeUTF8));
labelY6->setText(QApplication::translate("ResultDialog", "60", 0, QApplication::UnicodeUTF8));
labelY1->setText(QApplication::translate("ResultDialog", "10", 0, QApplication::UnicodeUTF8));
#include "xmlwriter.h"
-/*! @brief Constructor, connects object to GUI
- */
-XmlWriter::XmlWriter(Ui_MainWindow* myMainWindow)
+/**
+ *@brief Constructor, connects object to GUI
+ *@param Pointer to carmainwindow, which is temporarily used during development
+ */
+XmlWriter::XmlWriter(Ui_CarMainWindow* myMainWindow)
{
ui = myMainWindow;
}
-/*! @brief Destructor
+/**
+ *@brief Destructor
*/
XmlWriter::~XmlWriter()
{
}
-/*! @brief Opens and closes a file, when xml information is written into a file,
- * and passes file to writeXmlFile()
- * @note Partly harcoded and commented for git.
- * @todo Replace hardcoced filename and GUI elements to finally used widgets.
+/**
+ *@brief Opens and closes a file, when xml information is written into a file,
+ *and passes file to writeXmlFile()
+ *@note Partly harcoded and commented for git.
+ *@todo Replace hardcoced filename and GUI elements to finally used widgets.
*/
-void XmlWriter::xmlWrite()
+void XmlWriter::writeXml()
{
- //QString filename = ui->lineEditFile->text();
QString filename = "xmlfile.xml";
QFile file(filename);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
- /*QMessageBox::warning(this->ui->centralWidget, tr("QXmlStream Bookmarks"),
- tr("Cannot write file %1:\n%2.")
- .arg(filename)
- .arg(file.errorString()));
- */
qDebug() << "_xmlWrite fail";
return;
}
file.close();
}
-/*! @brief Writes general xml information.
- * @todo Check API connection to QBuffer, when Speed Freek network client has been written.
+/**
+ *@brief Writes general xml information.
+ *Calls other functions to insert login and result information.
+ *@todo Check API connection to QBuffer, when Speed Freek network client has been written.
*/
bool XmlWriter::writeXmlFile(QIODevice *device)
//bool XmlWriter::writeXmlFile(QBuffer *device)
{
xmlwriter.setDevice(device);
xmlwriter.writeStartDocument();
- xmlwriter.writeDTD("<!DOCTYPE xml>");
xmlwriter.writeStartElement("xml");
xmlwriter.writeAttribute("version", "1.0");
+ writeRegister();
writeItems();
xmlwriter.writeEndDocument();
return true;
}
-/*! @brief Writes Speed Freek application specific items as tags and contents.
- * @brief Results of speed/ direction/ acceleration into QMap are calculated elsewhere
- * @todo Consider looping of writing QMap values.
- * @todo Replace hardcoced names to finally used GUI elements.
+/**
+ *@brief Writes Speed Freek application specific items as tags and contents.
+ *@brief Results of speed/ direction/ acceleration into QMap are calculated elsewhere
+ *@todo Replace hardcoced user, password and email to finally used GUI elements.
*/
-void XmlWriter::writeItems()
+void XmlWriter::writeRegister()
{
- //xmlwriter.writeCharacters(ui->lineEditPlace->text());
- //Temporarily:
- xmlwriter.writeStartElement("place");
- xmlwriter.writeCharacters("rallirata");
- xmlwriter.writeEndElement();
+ xmlwriter.writeStartElement("user");
- xmlwriter.writeStartElement("date");
- xmlwriter.writeCharacters(QDate::currentDate().toString());
+ xmlwriter.writeStartElement("login");
+ xmlwriter.writeCharacters("test123");
xmlwriter.writeEndElement();
- xmlwriter.writeStartElement("time");
- xmlwriter.writeCharacters(QTime::currentTime().toString());
+ xmlwriter.writeStartElement("password");
+ xmlwriter.writeCharacters("thisisaveryinsecurepassword");
xmlwriter.writeEndElement();
- /* Or combined:
- xmlwriter.writeStartElement("datetime");
- xmlwriter.writeCharacters(QDateTime::currentDateTime().toString());
- xmlwriter.writeEndElement(); */
-
- xmlwriter.writeStartElement("result");
- xmlwriter.writeStartElement("speed");
- xmlwriter.writeAttribute("value", QString::number(resultmap.value("speed")));
- xmlwriter.writeAttribute("unit", "m/s");
- xmlwriter.writeEndElement();
- xmlwriter.writeStartElement("distance");
- xmlwriter.writeAttribute("value", QString::number(resultmap.value("distance")));
- xmlwriter.writeAttribute("unit", "m");
+ //Is this neacessary when sending results
+ xmlwriter.writeStartElement("email");
+ xmlwriter.writeCharacters("test@example.com");
xmlwriter.writeEndElement();
- xmlwriter.writeStartElement("acceleration");
- xmlwriter.writeAttribute("value", QString::number(resultmap.value("acceleration")));
- xmlwriter.writeAttribute("unit", "m/s2");
+
xmlwriter.writeEndElement();
- xmlwriter.writeEndElement(); //result
- //or:
- //xmlwriter.writeTextElement("speed", QString::number(resultmap.value("speed")) + " m/s");
- //xmlwriter.writeTextElement("distance", QString::number(resultmap.value("distance")) + " m");
- //xmlwriter.writeTextElement("acceleration", QString::number(resultmap.value("acceleration")) + " m/s2");
}
-/*! @brief Initializes QMap by zeroing values for a new measurement.
+/**
+ *@brief Writes Speed Freek results items as tags and contents.
+ *@brief Results of speed/ direction/ acceleration into QMap are calculated elsewhere
+ *@todo Consider looping of writing QMap values.
+ *@todo Replace hardcoced names to finally used values.
*/
-void XmlWriter::initResultmap()
+void XmlWriter::writeItems()
{
- resultmap["acceleration"] = 0;
- resultmap["speed"] = 0;
- resultmap["distance"] = 0;
+ //During development
+ this->fillResultmap();
+
+ xmlwriter.writeStartElement("result");
+ xmlwriter.writeAttribute("value", QString::number(resultmap.value("speed")));
+ xmlwriter.writeAttribute("unit", "seconds");
+ xmlwriter.writeAttribute("date", QDateTime::currentDateTime().toString());
+ xmlwriter.writeEndElement();
}
-/*! @brief A temp function during development, used until real QMap available.
+
+/**
+ *@brief A temp function during development, used until real QMap available.
*/
void XmlWriter::fillResultmap()
{
resultmap["speed"] = 48;
resultmap["distance"] = 600;
}
+
+/**
+ *@brief A temp function during development, used to create a "serverfile".
+ */
+void XmlWriter::serverWritesTop()
+{
+ int i = 0;
+ int n = 5;
+
+ /* Server sends to client */
+ xmlwriter.writeStartElement("results");
+ xmlwriter.writeAttribute("category", "acceleration-0-100");
+ 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();
+ }
+}
#ifndef XMLWRITER_H
#define XMLWRITER_H
-#include "ui_mainwindow.h"
+#include "ui_carmainwindow.h"
class XmlWriter : public QObject
{
public:
- XmlWriter(Ui_MainWindow* myMainWindow);
+ XmlWriter(Ui_CarMainWindow* myMainWindow);
~XmlWriter();
private:
QXmlStreamWriter xmlwriter;
QMap<QString, int> resultmap;
- Ui_MainWindow* ui;
+ Ui_CarMainWindow* ui;
public slots:
bool writeXmlFile(QIODevice* device);
void writeItems();
- void initResultmap();
void fillResultmap();
- void xmlWrite();
+ void writeXml();
+ void writeRegister();
+ void serverWritesTop();
};