#include "ChannelCharts.h" #include "ui_ChannelCharts.h" #include <iostream> extern QVector<QVector<QStringList>> phaseVector; extern QVector<QVector<double>> channelAllan; ChannelCharts::ChannelCharts(QWidget *parent) : QWidget(parent), ui(new Ui::ChannelCharts) { ui->setupUi(this); } ChannelCharts::~ChannelCharts() { std::cout << "in destructor" << std::endl; delete ui; } void ChannelCharts::initDataChart(int index) { ui->dataPlot->addGraph(); // blue line ui->dataPlot->graph(0)->setPen(QPen(QColor(40, 110, 255))); // ui->dataPlot->addGraph(); // red line // ui->dataPlot->graph(1)->setPen(QPen(QColor(255, 110, 40))); QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime); timeTicker->setTimeFormat("%h:%m:%s"); ui->dataPlot->xAxis->setTicker(timeTicker); ui->dataPlot->axisRect()->setupFullAxesBox(); ui->dataPlot->yAxis->setRange(1e-9, 1e-8); qint64 base = phaseVector[index].at(0).at(0).toLongLong(); QColor color(20+200,105, 150, 150); ui->dataPlot->graph()->setLineStyle(QCPGraph::lsLine); ui->dataPlot->graph()->setPen(QPen(color.lighter(200))); ui->dataPlot->graph()->setBrush(QBrush(color)); // generate random walk data: // QVector<QCPGraphData> timeData(phaseVector[index].size()); for (int i=0; i<phaseVector[index].size(); ++i) { ui->dataPlot->graph(0)->addData((phaseVector[index].at(i).at(0).toLongLong() - base) / 1000.0, phaseVector[index].at(i).at(1).toDouble()); } // ui->dataPlot->graph()->data()->set(timeData); // configure bottom axis to show date instead of number: // configure left axis text labels: // set a more compact font size for bottom and left axis tick labels: ui->dataPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8)); ui->dataPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8)); // set axis labels: ui->dataPlot->xAxis->setLabel("Date"); ui->dataPlot->yAxis->setLabel("Random wobbly lines value"); // make top and right axes visible but without ticks and labels: ui->dataPlot->xAxis2->setVisible(true); ui->dataPlot->yAxis2->setVisible(true); ui->dataPlot->xAxis2->setTicks(false); ui->dataPlot->yAxis2->setTicks(false); ui->dataPlot->xAxis2->setTickLabels(false); ui->dataPlot->yAxis2->setTickLabels(false); // set axis ranges to show all data: ui->dataPlot->xAxis->setRange((phaseVector[index].at(0).at(0).toULongLong() - base) / 1000.0, (phaseVector[index].last().at(0).toULongLong() - base) / 1000.0); // show legend with slightly transparent background brush: ui->dataPlot->legend->setVisible(false); ui->dataPlot->legend->setBrush(QColor(255, 255, 255, 150)); ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } void ChannelCharts::initAllenChart(int index) { QLinearGradient gradient(0, 0, 0, 400); gradient.setColorAt(0, QColor(90, 90, 90)); gradient.setColorAt(0.38, QColor(105, 105, 105)); gradient.setColorAt(1, QColor(70, 70, 70)); ui->allenPlot->setBackground(QBrush(gradient)); // create empty bar chart objects: QCPBars * allen = new QCPBars(ui->allenPlot->xAxis, ui->allenPlot->yAxis); allen->setAntialiased(false); // gives more crisp, pixel aligned bar borders allen->setStackingGap(1); // set names and colors: allen->setName("allen"); allen->setPen(QPen(QColor(0, 168, 140).lighter(130))); allen->setBrush(QColor(0, 168, 140)); // stack bars on top of each other: // prepare x axis with country labels: QVector<double> ticks; QVector<QString> labels; ticks << 1 << 2 << 3 << 4 << 5; labels << "1" << "10" << "100" << "1000" << "10000"; QSharedPointer<QCPAxisTickerText> textTicker(new QCPAxisTickerText); textTicker->addTicks(ticks, labels); ui->allenPlot->xAxis->setTicker(textTicker); ui->allenPlot->xAxis->setSubTicks(false); ui->allenPlot->xAxis->setTickLength(0, 4); ui->allenPlot->xAxis->setRange(0, 6); ui->allenPlot->xAxis->setBasePen(QPen(Qt::white)); ui->allenPlot->xAxis->setTickPen(QPen(Qt::white)); ui->allenPlot->xAxis->grid()->setVisible(true); ui->allenPlot->xAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); ui->allenPlot->xAxis->setTickLabelColor(Qt::white); ui->allenPlot->xAxis->setLabelColor(Qt::white); ui->allenPlot->xAxis->setLabel("平均时间(秒)"); // prepare y axis: ui->allenPlot->yAxis->setRange(-1e-15, channelAllan[index].isEmpty() ? 0.1 : channelAllan[index][0]); ui->allenPlot->yAxis->setPadding(5); // a bit more space to the left border ui->allenPlot->yAxis->setLabel("阿伦方差"); ui->allenPlot->yAxis->setBasePen(QPen(Qt::white)); ui->allenPlot->yAxis->setTickPen(QPen(Qt::white)); ui->allenPlot->yAxis->setSubTickPen(QPen(Qt::white)); ui->allenPlot->yAxis->grid()->setSubGridVisible(true); ui->allenPlot->yAxis->setTickLabelColor(Qt::white); ui->allenPlot->yAxis->setLabelColor(Qt::white); ui->allenPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->allenPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); // Add data: QVector<double> allenData; if (channelAllan[index].isEmpty() == true) { allenData << 0.0 << 0.0 << 0.0 << 0.0 << 0.0; } else { allenData << channelAllan[index][0] << channelAllan[index][1] << channelAllan[index][2] << channelAllan[index][3] << channelAllan[index][4]; } allen->setData(ticks, allenData); // setup legend: ui->allenPlot->legend->setVisible(false); // ui->allenPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter); // ui->allenPlot->legend->setBrush(QColor(255, 255, 255, 100)); // ui->allenPlot->legend->setBorderPen(Qt::NoPen); // QFont legendFont = font(); // legendFont.setPointSize(10); // ui->allenPlot->legend->setFont(legendFont); ui->allenPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); }