From: Toni Jussila Date: Fri, 5 Mar 2010 09:06:30 +0000 (+0200) Subject: Display top performer in acceleration 0-100 category. Read and parsing results.xml... X-Git-Tag: v0.1~82^2 X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=commitdiff_plain;h=ec2e343485c22d0c34a63e0d0512dbb642a8a4c4;ds=sidebyside Display top performer in acceleration 0-100 category. Read and parsing results.xml-file. --- diff --git a/Client/UI.pro b/Client/UI.pro index 97de2a2..dfacc94 100644 --- a/Client/UI.pro +++ b/Client/UI.pro @@ -11,15 +11,15 @@ SOURCES += main.cpp \ stringlistmodel.cpp \ measuredialog.cpp \ calculate.cpp \ - accelerometer.cpp - + accelerometer.cpp \ + xmlreader.cpp HEADERS += carmainwindow.h \ resultdialog.h \ stringlistmodel.h \ measuredialog.h \ accelerometer.h \ - calculate.h - + calculate.h \ + xmlreader.h FORMS += carmainwindow.ui \ resultdialog.ui \ measuredialog.ui diff --git a/Client/carmainwindow.cpp b/Client/carmainwindow.cpp index b8af9fe..b730a69 100644 --- a/Client/carmainwindow.cpp +++ b/Client/carmainwindow.cpp @@ -1,9 +1,4 @@ #include "carmainwindow.h" -#include "ui_carmainwindow.h" -#include "stringlistmodel.h" -#include -#include -#include /** *Constructor of this class. @@ -14,10 +9,10 @@ CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::Ca ui->setupUi(this); result = new ResultDialog(); measure = new MeasureDialog(); + xmlreader = new XmlReader(); initUnitCompoBox(); initSpeedListView(); - initCategoryCompoBox(); } /** @@ -28,6 +23,7 @@ CarMainWindow::~CarMainWindow() delete ui; delete result; delete measure; + delete xmlreader; } /** @@ -47,8 +43,7 @@ void CarMainWindow::changeEvent(QEvent *e) } /** - *This slot function is called when ever list view is update. - *@param QModelIndex index. + *This slot function is called when ever list view is update. Start-tab view. */ void CarMainWindow::on_listView_clicked(QModelIndex index) { @@ -62,7 +57,7 @@ void CarMainWindow::on_listView_clicked(QModelIndex index) } /** - *This slot function is called when ever auto start button clicked. + *This slot function is called when ever auto start button clicked. Start-tab view. */ void CarMainWindow::on_autoStartButton_clicked() { @@ -80,7 +75,7 @@ void CarMainWindow::on_autoStartButton_clicked() } /** - *This slot function is called when ever list view is update. + *This slot function is called when ever list view is update. Start-tab view. *@param QString unit. */ void CarMainWindow::updateUnitCompoBox(QString unit) @@ -89,16 +84,16 @@ void CarMainWindow::updateUnitCompoBox(QString unit) } /** - *This function is used to init unit combobox. + *This function is used to init unit combobox. Start-tab view. */ void CarMainWindow::initUnitCompoBox() { - units << "km/h" << "km" << "h" << "m" << "min" << "mil" << "in" << "ft" << "yrd"; + units << "km/h" << "km" << "h" << "m" << "min" << "Mile" << "Mph" << "in" << "ft" << "yrd"; ui->unitComboBox->addItems(units); } /** - *This function is used to set items to unit combobox. + *This function is used to set items to unit combobox. Start-tab view. *@param QStringlist numbers */ void CarMainWindow::setUnitCompoBox(QStringList units) @@ -107,18 +102,17 @@ void CarMainWindow::setUnitCompoBox(QStringList units) } /** - *This function is used to init speed listview. + *This function is used to init speed listview. Start-tab view. */ void CarMainWindow::initSpeedListView() { - numbers << "0-100 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"; QAbstractItemModel *model = new StringListModel(numbers); ui->listView->setModel(model); } /** -<<<<<<< HEAD:Client/carmainwindow.cpp - *This function is used to set items to speed listview. + *This function is used to set items to speed listview. Start-tab view. *@param QStringlist numbers */ void CarMainWindow::setSpeedListView(QStringList numbers) @@ -128,36 +122,37 @@ void CarMainWindow::setSpeedListView(QStringList numbers) } /** - *This function is used to init category combobox. - */ -void CarMainWindow::initCategoryCompoBox() -{ - categories << "Top 10 1/4 mile" << "Top 10 0-100 km/h" << "Top 10 car"; - ui->comboBoxTopCategory->addItems(categories); -} - -/** - *This function is used to set items to category combobox. - *@param QStringlist categories + *This function is used to set items to category combobox. Top-tab view. + *@param */ -void CarMainWindow::setCategoryCompoBox(QStringList categories) +void CarMainWindow::setCategoryCompoBox() { - ui->comboBoxTopCategory->addItems(categories); + ui->comboBoxTopCategory->addItems(xmlreader->getTop10List()); } /** - *This slot function is called when ever categories combobox is update. + *This function is used to set items to labelTopList. Top-tab view. *@param QString category */ -void CarMainWindow::on_comboBoxTopCategory_activated(QString category) +void CarMainWindow::setListViewTopList(QString category) { - //TODO: get top list + QString topList; - QStringList topList; - topList << "1. Pertti 7,5s" << "2. Ville 10,2s"; + if (category == "acceleration-0-100") + { + topList.append(xmlreader->getTop10AccelerationList()); + } + + else if (category == "Speed") + { + topList.append(xmlreader->getTop10SpeedList()); + } - QAbstractItemModel *model = new StringListModel(topList); - ui->listViewTopList->setModel(model); + else if (category == "G-force") + { + topList.append(xmlreader->getTop10GforceList()); + } + ui->labelTopList->setText(topList); } /** @@ -168,3 +163,20 @@ void CarMainWindow::openResultView() // Show result dialog. result->show(); } + +/** + *This slot function is called when ever refresh button clicked. Top-tab view. + */ +void CarMainWindow::on_buttonTopRefresh_clicked() +{ + setCategoryCompoBox(); +} + +/** + *This slot function is called when ever category combobox current index changed. Top-tab view. + *@param QString category + */ +void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category) +{ + setListViewTopList(category); +} diff --git a/Client/carmainwindow.h b/Client/carmainwindow.h index 198bb30..8071d08 100644 --- a/Client/carmainwindow.h +++ b/Client/carmainwindow.h @@ -1,17 +1,16 @@ #ifndef CARMAINWINDOW_H #define CARMAINWINDOW_H -/** - *This class - *@author Toni Jussila - *@version 0.0.1 - */ - #include +#include #include #include +#include #include "resultdialog.h" #include "measuredialog.h" +#include "xmlreader.h" +#include "ui_carmainwindow.h" +#include "stringlistmodel.h" namespace Ui { class CarMainWindow; @@ -23,9 +22,10 @@ public: CarMainWindow(QWidget *parent = 0); ~CarMainWindow(); - void setUnitCompoBox(QStringList units); - void setSpeedListView(QStringList numbers); - void setCategoryCompoBox(QStringList categories); + void setUnitCompoBox(QStringList units); //Start-tab + void setSpeedListView(QStringList numbers); //Start-tab + void setListViewTopList(QString category); //Top-tab + void setCategoryCompoBox(); //Top-tab protected: void changeEvent(QEvent *e); @@ -34,22 +34,24 @@ private: Ui::CarMainWindow *ui; ResultDialog *result; MeasureDialog *measure; + XmlReader *xmlreader; - void initUnitCompoBox(); - void initSpeedListView(); - void initCategoryCompoBox(); + void initUnitCompoBox(); //Start-tab + void initSpeedListView(); //Start-tab private: - QStringList numbers; - QStringList units; - QStringList categories; + QStringList numbers; //Start-tab + QStringList units; //Start-tab + QStringList categories; //Top-tab private slots: - void on_comboBoxTopCategory_activated(QString ); - void on_autoStartButton_clicked(); - void on_listView_clicked(QModelIndex index); - void updateUnitCompoBox(QString unit); + 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 diff --git a/Client/carmainwindow.ui b/Client/carmainwindow.ui index af62383..f9ec648 100644 --- a/Client/carmainwindow.ui +++ b/Client/carmainwindow.ui @@ -24,7 +24,7 @@ - 1 + 0 @@ -150,26 +150,7 @@ Refresh list - - - - 360 - 10 - 411 - 311 - - - - - Bitstream Charter - 10 - - - - QListView::LeftToRight - - - + 10 @@ -197,6 +178,27 @@ + + + + 380 + 10 + 371 + 311 + + + + + 9 + + + + TopList + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + diff --git a/Client/readxmlfile.xml b/Client/readxmlfile.xml new file mode 100644 index 0000000..3b30379 --- /dev/null +++ b/Client/readxmlfile.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Client/results.xml b/Client/results.xml new file mode 100755 index 0000000..deb1966 --- /dev/null +++ b/Client/results.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/Client/xmlreader.cpp b/Client/xmlreader.cpp index cf86ef1..3e26629 100644 --- a/Client/xmlreader.cpp +++ b/Client/xmlreader.cpp @@ -1,59 +1,37 @@ -#include -#include -#include -#include #include -#include #include -#include -#include -#include -#include +//#include #include "xmlreader.h" - -/*! @brief Constructor, connects object to GUI - */ -XmlReader::XmlReader(Ui_MainWindow* myMainWindow) +/** + *Constructor of this class. + */ +XmlReader::XmlReader() { - ui = myMainWindow; + xmlShow(); } -/*! @brief Destructor +/** + *Destructor of this class. Should be used to release all allocated resources. */ XmlReader::~XmlReader() { - -} - -QString XmlReader::errorString() const -{ - return QObject::tr("%1\nLine %2, column %3") - .arg(xmlreader.errorString()) - .arg(xmlreader.lineNumber()) - .arg(xmlreader.columnNumber()); + category = ""; + unit = ""; + description = ""; + position = ""; + user = ""; + value = ""; } - -/*! @brief parsing xml file that is sent by server over network. - * Shows received information on screen and parsed information on command line. - * @note Partly commented for git. - * @todo (Development: Seems to omit element tags and some values when reading from QFile. Why? This used - * earlier with QNetworkReply printed all xml contents.) - * @todo Remove command line output and use final GUI widget names. - * @todo Replace using of QFile to QNetworkReply. +/** + *This function is used to parsing xml file. */ void XmlReader::xmlRead(QIODevice *device) -//void XmlReader::xmlRead(QNetworkReply *device) { qDebug() << "_xmlRead"; xmlreader.addData(device->readAll()); - //Or: View webpage contents on textEdit by adding all data to xml stream reader, - //since readAll() empties the buffer - /*QByteArray readAllArr = device->readAll(); - ui->textEditXml->append(readAllArr); - xmlreader.addData(readAllArr);*/ //Go trough the xml document while(!xmlreader.atEnd()) @@ -63,75 +41,112 @@ void XmlReader::xmlRead(QIODevice *device) //Check if this element is starting element if(xmlreader.isStartElement()) { - if(xmlreader.name() == "place") + if(xmlreader.name() == "results") { qDebug() << xmlreader.name(); + attr = xmlreader.attributes(); + + category = attr.value("category").toString(); + unit = attr.value("unit").toString(); + description = attr.value("description").toString(); + + top10List << category; + qDebug() << top10List << unit << description; } - if(xmlreader.name() == "date") - { - qDebug() << xmlreader.name(); - } - if(xmlreader.name() == "time") - { - qDebug() << xmlreader.name(); - } + if(xmlreader.name() == "result") { - //Two consequent start elements - if(xmlreader.readNextStartElement()) + qDebug() << "result"; + attr = xmlreader.attributes(); + + position = attr.value("position").toString(); + user = attr.value("user").toString(); + value = attr.value("value").toString(); + + if (category == "acceleration-0-100") { - if(xmlreader.name() == "speed") - { - QString speed; - QXmlStreamAttributes attr = xmlreader.attributes(); - speed = (attr.value("value").toString() + " " + attr.value("unit").toString()); - //ui->lineEditSpeed->setText(speed); - qDebug() << xmlreader.name() << speed; - } + top10AccelerationList.append(position + "\t" + + user + "\t" + + value + + unit + "\t" + + description + "\n"); } - } - if(xmlreader.name() == "distance") - { - QString distance; - QXmlStreamAttributes attr = xmlreader.attributes(); - distance = (attr.value("value").toString() + " " + attr.value("unit").toString()); - //ui->lineEditDist->setText(distance); - qDebug() << xmlreader.name() << distance; - } - if(xmlreader.name() == "acceleration") - { - QString acceleration; - QXmlStreamAttributes attr = xmlreader.attributes(); - acceleration = (attr.value("value").toString()+ " " + attr.value("unit").toString()); - //ui->lineEditAccel->setText(acceleration); - qDebug() << xmlreader.name() << acceleration; + + if(category == "top10speed") + { + top10SpeedList.append(position + "\t" + + user + "\t" + + value + + unit + "\t" + + description + "\n"); + } + + if(category == "top10gforce") + { + top10GforceList.append(position + "\t" + + user + "\t" + + value + + unit + "\t" + + description + "\n"); + } + qDebug() << position << user << value << unit; } } } } -/*! @brief A function used tmp in development. - * @note Partly harcoded and commented for git. +/** + *This function is used to read example xml file (results.xml). + *@todo Read real xml. */ void XmlReader::xmlShow() { - //QString filename = ui->lineEditFile->text(); - QString filename = "xmlfile.xml"; + QString filename = "results.xml"; QFile file(filename); if (!file.open(QFile::ReadOnly)) { - /*QMessageBox::warning(this->ui->centralWidget, - tr("QXmlStream Bookmarks"), - tr("Cannot write file %1:\n%2.") - .arg(file.fileName()) - .arg(file.errorString()));*/ qDebug() << "_xmlShow fail"; return; } xmlRead(&file); - file.close(); } +/** + *This is return function. + *@todo Read real top 10 category list + *@return QStringList top10List + */ +QStringList XmlReader::getTop10List() +{ + return top10List; +} + +/** + *This is return function. + *@return QString top10AccelerationList + */ +QString XmlReader::getTop10AccelerationList() +{ + return top10AccelerationList; +} + +/** + *This is return function. + *@return QString top10SpeedList + */ +QString XmlReader::getTop10SpeedList() +{ + return top10SpeedList; +} + +/** + *This is return function. + *@return QString top10GforceList + */ +QString XmlReader::getTop10GforceList() +{ + return top10GforceList; +} diff --git a/Client/xmlreader.h b/Client/xmlreader.h index 4b19bfa..fa69133 100644 --- a/Client/xmlreader.h +++ b/Client/xmlreader.h @@ -1,25 +1,37 @@ #ifndef XMLREADER_H #define XMLREADER_H -#include "ui_mainwindow.h" - +#include +#include class XmlReader : public QObject { public: - XmlReader(Ui_MainWindow* myMainWindow); + XmlReader(); ~XmlReader(); - QString errorString() const; + QStringList getTop10List(); + QString getTop10AccelerationList(); + QString getTop10SpeedList(); + QString getTop10GforceList(); private: QXmlStreamReader xmlreader; - Ui_MainWindow* ui; + QStringList top10List; + QString top10AccelerationList; + QString top10SpeedList; + QString top10GforceList; + + QXmlStreamAttributes attr; + QString category; + QString unit; + QString description; + QString position; + QString user; + QString value; public slots: - //void xmlRead(QNetworkReply *device); void xmlRead(QIODevice* device); void xmlShow(); - }; #endif // XMLREADER_H