diff -r 4d79c3f357ad -r dfefb6003498 mainwindow.cc --- a/mainwindow.cc Sat Jan 28 13:03:19 2012 +0100 +++ b/mainwindow.cc Sun Jan 29 00:38:40 2012 +0100 @@ -1,22 +1,38 @@ #include "mainwindow.h" +#include + #include "ui_mainwindow.h" #include "plot.h" + using Qt::DefaultLocaleLongDate; MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent), ui(new Ui::MainWindow) + : QMainWindow(parent), ui_(new Ui::MainWindow), + plot_(new QwtPlot(tr("Altitude"), this)) { - ui->setupUi(this); - connect(ui->actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); - connect(ui->actionExit, SIGNAL(triggered()), qApp, SLOT(quit())); - connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open())); + ui_->setupUi(this); + ui_->tabs->setCurrentIndex(0); // avoid changes done in the designer! + + // prepare the Qwt tab + plot_->setAxisTitle(plot_->yLeft, tr("Altitude")); + plot_->setAxisTitle(plot_->xBottom, tr("Time")); + ui_->qwt->setLayout(new QGridLayout); + ui_->qwt->layout()->addWidget(plot_); + +#ifndef MYPLOT + ui_->tabs->removeTab(1); // altitude +#endif + + connect(ui_->actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); + connect(ui_->actionExit, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(ui_->actionOpen, SIGNAL(triggered()), this, SLOT(open())); /* QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, "localhost", 3128)); - ui->view->load(QUrl("http://maps.google.com/")); + ui_->view->load(QUrl("http://maps.google.com/")); */ @@ -24,7 +40,7 @@ MainWindow::~MainWindow() { - delete ui; + delete ui_; } void MainWindow::open(const QString &s) @@ -60,7 +76,7 @@ // now let's fill the table - QTableWidget *t = ui->table; + QTableWidget *t = ui_->table; int r = 0; const int K = 0; const int V = 1; @@ -92,42 +108,47 @@ t->setItem(r, V, new QTableWidgetItem(igc_.start().longitude() + " / " + igc_.start().latitude())); ++r; - showProfile(); } void MainWindow::showProfile() { - Plot *plot = new Plot(this); + const Fixes f = igc_.fixes(); +#ifdef MYPLOT + QList< QPair > altitudesBaro; + QList< QPair > altitudesGPS; +#endif + QVector pointsGPS; + QVector pointsBaro; - /* - for (IGC::Iterator i = igc_.begin() - i != igc_.end(); - ++i) { - qDebug() << *i; - } - */ - - // get all the altitudes - const Fixes f = igc_.fixes(); - QList< QPair > altitudesBaro; - QList< QPair > altitudesGPS; - for (Fixes::const_iterator i = f.begin(); - i != f.end(); - i++) { - altitudesBaro << i->altitudeFix(Fix::baro); - altitudesGPS << i->altitudeFix(Fix::gps); - } + for (Fixes::const_iterator i = f.begin(); + i != f.end(); + i++) { +#ifdef MYPLOT + altitudesBaro << i->altitudeFix(Fix::baro); + altitudesGPS << i->altitudeFix(Fix::gps); +#endif + pointsGPS << QPointF(QTime().secsTo(i->time()), i->altitude(Fix::gps)); + pointsBaro << QPointF(QTime().secsTo(i->time()), i->altitude(Fix::baro)); + } - /* - plot->setXAxis(0, 100, 10); - plot->setYAxis(0, 200, 10); - */ - plot->draw(altitudesBaro.begin(), altitudesBaro.end()); - plot->draw(altitudesGPS.begin(), altitudesGPS.end()); - ui->altitude->setScene(plot); +#ifdef MYPLOT + myPlot_.draw(altitudesBaro.begin(), altitudesBaro.end()); + myPlot_.draw(altitudesGPS.begin(), altitudesGPS.end()); + ui_->altitude->setScene(&myPlot_); +#endif - // ui->altitude->show(); + QwtPlotCurve *gps = new QwtPlotCurve(tr("Altitude GPS")); + QwtPlotCurve *baro = new QwtPlotCurve(tr("Altitude barometric")); + QwtPointSeriesData *dataGPS = new QwtPointSeriesData(pointsGPS); + QwtPointSeriesData *dataBaro = new QwtPointSeriesData(pointsBaro); + + gps->setData(dataGPS); + baro->setData(dataBaro); + gps->attach(plot_); + baro->attach(plot_); + + // ui_->altitude->show(); }