mainwindow.cc
changeset 28 c55e1f2a4db4
parent 27 dfefb6003498
child 29 830a0d1d9d7f
equal deleted inserted replaced
27:dfefb6003498 28:c55e1f2a4db4
     7 
     7 
     8 using Qt::DefaultLocaleLongDate;
     8 using Qt::DefaultLocaleLongDate;
     9 
     9 
    10 MainWindow::MainWindow(QWidget *parent)
    10 MainWindow::MainWindow(QWidget *parent)
    11     : QMainWindow(parent), ui_(new Ui::MainWindow),
    11     : QMainWindow(parent), ui_(new Ui::MainWindow),
       
    12     igc_(0),
    12     plot_(new QwtPlot(tr("Altitude"), this))
    13     plot_(new QwtPlot(tr("Altitude"), this))
    13 {
    14 {
    14     ui_->setupUi(this);
    15     ui_->setupUi(this);
    15     ui_->tabs->setCurrentIndex(0);	// avoid changes done in the designer!
    16     ui_->tabs->setCurrentIndex(0);	// avoid changes done in the designer!
    16 
    17 
    39 }
    40 }
    40 
    41 
    41 MainWindow::~MainWindow()
    42 MainWindow::~MainWindow()
    42 {
    43 {
    43     delete ui_;
    44     delete ui_;
       
    45     delete igc_;
       
    46     delete plot_;
    44 }
    47 }
    45 
    48 
    46 void MainWindow::open(const QString &s)
    49 void MainWindow::open(const QString &s)
    47 {
    50 {
    48     QString fileName;
    51     QString fileName;
    70 
    73 
    71     input_.setDevice(&currentFile_);
    74     input_.setDevice(&currentFile_);
    72     setWindowTitle(QFileInfo(fileName).baseName());
    75     setWindowTitle(QFileInfo(fileName).baseName());
    73     statusBar()->showMessage(tr("opening %1").arg(fileName), 5000);
    76     statusBar()->showMessage(tr("opening %1").arg(fileName), 5000);
    74 
    77 
    75     igc_.read(input_);
    78     delete igc_;
       
    79     igc_ = new IGC(input_);
    76 
    80 
       
    81     showInfo();
       
    82     showProfile();
    77 
    83 
       
    84 }
       
    85 
       
    86 void MainWindow::showInfo()
       
    87 {
    78     // now let's fill the table
    88     // now let's fill the table
    79     QTableWidget *t = ui_->table;
    89     QTableWidget *t = ui_->table;
    80     int r = 0;
    90     int r = 0;
    81     const int K = 0;
    91     const int K = 0;
    82     const int V = 1;
    92     const int V = 1;
    86     t->setRowCount(0);
    96     t->setRowCount(0);
    87 
    97 
    88     // fill
    98     // fill
    89     t->setRowCount(t->rowCount() + 1);
    99     t->setRowCount(t->rowCount() + 1);
    90     t->setItem(r, K, new QTableWidgetItem(tr("Pilot")));
   100     t->setItem(r, K, new QTableWidgetItem(tr("Pilot")));
    91     t->setItem(r, V, new QTableWidgetItem(igc_.pilot()));
   101     t->setItem(r, V, new QTableWidgetItem(igc_->pilot()));
    92     ++r;
   102     ++r;
    93 
   103 
    94     t->setRowCount(t->rowCount() + 1);
   104     t->setRowCount(t->rowCount() + 1);
    95     t->setItem(r, K, new QTableWidgetItem(tr("Date")));
   105     t->setItem(r, K, new QTableWidgetItem(tr("Date")));
    96     t->setItem(r, V, new QTableWidgetItem(igc_
   106     t->setItem(r, V, new QTableWidgetItem(igc_->date()
    97 	.date()
       
    98 	.toString(DefaultLocaleLongDate)));
   107 	.toString(DefaultLocaleLongDate)));
    99     ++r;
   108     ++r;
   100 
   109 
   101     t->setRowCount(t->rowCount() + 1);
   110     t->setRowCount(t->rowCount() + 1);
   102     t->setItem(r, K, new QTableWidgetItem(tr("Glider")));
   111     t->setItem(r, K, new QTableWidgetItem(tr("Glider")));
   103     t->setItem(r, V, new QTableWidgetItem(igc_.glider()));
   112     t->setItem(r, V, new QTableWidgetItem(igc_->glider()));
   104     ++r;
   113     ++r;
   105 
   114 
   106     t->setRowCount(t->rowCount() + 1);
   115     t->setRowCount(t->rowCount() + 1);
   107     t->setItem(r, K, new QTableWidgetItem(tr("Place")));
   116     t->setItem(r, K, new QTableWidgetItem(tr("Place")));
   108     t->setItem(r, V, new QTableWidgetItem(igc_.start().longitude() + " / " + igc_.start().latitude()));
   117     t->setItem(r, V, new QTableWidgetItem(igc_->start().longitude() + " / " + igc_->start().latitude()));
   109     ++r;
   118     ++r;
   110 
   119 
   111     showProfile();
       
   112 
   120 
   113 }
   121 }
   114 
   122 
   115 void MainWindow::showProfile()
   123 void MainWindow::showProfile()
   116 {
   124 {
   117 	const Fixes f = igc_.fixes();
   125 	QVector<QPointF> pointsGPS = igc_->altitude(Fix::gps);
   118 #ifdef MYPLOT
   126 	QVector<QPointF> pointsBaro = igc_->altitude(Fix::baro);
   119 	QList< QPair<QTime, int> > altitudesBaro;
       
   120 	QList< QPair<QTime, int> > altitudesGPS;
       
   121 #endif
       
   122 	QVector<QPointF> pointsGPS;
       
   123 	QVector<QPointF> pointsBaro;
       
   124 
       
   125 
       
   126 	for (Fixes::const_iterator i = f.begin();
       
   127 	     i != f.end();
       
   128 	     i++) {
       
   129 #ifdef MYPLOT
       
   130 	     altitudesBaro << i->altitudeFix(Fix::baro);
       
   131 	     altitudesGPS << i->altitudeFix(Fix::gps);
       
   132 #endif
       
   133 	     pointsGPS << QPointF(QTime().secsTo(i->time()), i->altitude(Fix::gps));
       
   134 	     pointsBaro << QPointF(QTime().secsTo(i->time()), i->altitude(Fix::baro));
       
   135 	}
       
   136 
       
   137 #ifdef MYPLOT
       
   138 	myPlot_.draw(altitudesBaro.begin(), altitudesBaro.end());
       
   139 	myPlot_.draw(altitudesGPS.begin(), altitudesGPS.end());
       
   140 	ui_->altitude->setScene(&myPlot_);
       
   141 #endif
       
   142 
   127 
   143 	QwtPlotCurve *gps = new QwtPlotCurve(tr("Altitude GPS"));
   128 	QwtPlotCurve *gps = new QwtPlotCurve(tr("Altitude GPS"));
   144 	QwtPlotCurve *baro = new QwtPlotCurve(tr("Altitude barometric"));
   129 	QwtPlotCurve *baro = new QwtPlotCurve(tr("Altitude barometric"));
   145 	QwtPointSeriesData *dataGPS = new QwtPointSeriesData(pointsGPS);
   130 	QwtPointSeriesData *dataGPS = new QwtPointSeriesData(pointsGPS);
   146 	QwtPointSeriesData *dataBaro = new QwtPointSeriesData(pointsBaro);
   131 	QwtPointSeriesData *dataBaro = new QwtPointSeriesData(pointsBaro);