#include "IspindelGUI.h" #include "ui_IspindelGUI.h" #include "Ispindel.h" #include "IspindelData.h" #include "GlobalDefine.h" CIspindelGUI::CIspindelGUI(QWidget *parent) : QDialog(parent), ui(new Ui::CIspindelGUI) { ui->setupUi(this); mIspindelPlot = new QCustomPlot(ui->mIspindelPlot); mIspindelPlot->resize(ui->mIspindelPlot->size()); // create graph and assign data to it: mIspindelPlot->addGraph(); mIspindelPlot->addGraph(mIspindelPlot->xAxis,mIspindelPlot->yAxis2); // give the axes some labels: mIspindelPlot->xAxis->setLabel("Time"); mIspindelPlot->yAxis->setLabel("Gravity"); mIspindelPlot->yAxis2->setLabel("Temprature (C)"); mIspindelPlot->yAxis2->setVisible(true); double now = QDateTime::currentDateTime().toSecsSinceEpoch(); QSharedPointer dateTicker(new QCPAxisTickerDateTime); dateTicker->setDateTimeFormat("hh:mm:ss\ndd MMM"); mIspindelPlot->xAxis->setTicker(dateTicker); mIspindelPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); QList xAxis, yAxis; xAxis.append(mIspindelPlot->xAxis); yAxis.append(mIspindelPlot->yAxis); yAxis.append(mIspindelPlot->yAxis2); mIspindelPlot->axisRect()->setRangeDragAxes(xAxis,yAxis); mIspindelPlot->axisRect()->setRangeZoomAxes(xAxis,yAxis); // mIspindelPlot->yAxis2->axisRect()->setRangeZoomAxes(0,mIspindelPlot->yAxis2); QDateTime Now = QDateTime::currentDateTime().toLocalTime(); QDateTime midnight = Now; midnight.setTime(QTime(0,0,0)); QDateTime eod = Now; eod.setTime(QTime(23,59,0)); //mIspindelPlot->xAxis->setRange(0/*QCPAxisTickerDateTime::dateTimeToKey(midnight)*/,QCPAxisTickerDateTime::dateTimeToKey(eod)); // mIspindelPlot->xAxis->setRange(now, now+(2*3600)); mIspindelPlot->xAxis->setRange(midnight.toSecsSinceEpoch(), eod.toSecsSinceEpoch()); mIspindelPlot->yAxis->setRange(1.000,1.01); mIspindelPlot->yAxis2->setRange(15,25); // mIspindelPlot->graph(0)->addData(now,1.005); // mIspindelPlot->graph(1)->addData(now,20); mIspindelPlot->replot(); } CIspindelGUI::~CIspindelGUI() { delete ui; } void CIspindelGUI::SetLastIspindelFrameData(QString Data) { ui->mLastFrameDataLbl->setText(Data); } int CIspindelGUI::UpdateIspindelPlot(QList *Data) { if(Data->size() == 0) return RET_ERROR; QVector x,y,ty; for(int i = 0; i < Data->size(); i++) { x.append(Data->at(i)->mSampleDateTime.toSecsSinceEpoch()); y.append(Data->at(i)->mGravity); ty.append(Data->at(i)->mTemperature); } if(x.size() == 0 || y.size() == 0) return RET_ERROR; mIspindelPlot->graph(0)->data().clear(); mIspindelPlot->graph(0)->setData(x,y); mIspindelPlot->xAxis->setRange(x.first(),x.last()); mIspindelPlot->yAxis->setRange(y.first(),y.last()); mIspindelPlot->graph(1)->setPen(QColor(Qt::red)); mIspindelPlot->graph(1)->setName("Température"); mIspindelPlot->graph(1)->setData(x,ty); mIspindelPlot->yAxis2->setRange(10,30); mIspindelPlot->replot(); return RET_OK; } int CIspindelGUI::NewIspindelFrameReceived(CIspindelData *Data) { mIspindelPlot->graph(0)->addData(Data->mSampleDateTime.toSecsSinceEpoch(),Data->mGravity); mIspindelPlot->graph(1)->addData(Data->mSampleDateTime.toSecsSinceEpoch(),Data->mTemperature); mIspindelPlot->replot(); }