#include "ChannelCharts.h" #include "ui_ChannelCharts.h" #include "IconHelper.h" #include "common/utils/SettingConfig.h" extern QVector<QVector<QStringList>> phaseVector; extern QVector<QVector<double>> channelAllan; ChannelCharts::ChannelCharts(QWidget *parent) : QWidget(parent), ui(new Ui::ChannelCharts) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); // 窗口关闭后释放本对象 this->setWindowFlags(Qt::FramelessWindowHint); QRect screenRect = QApplication::desktop()->availableGeometry(); qint16 screenWidth = screenRect.width(); qint16 screenHeight = screenRect.height(); resize(screenWidth, screenHeight); IconHelper::Instance()->setIcon(ui->closeButt, QChar(0xf00d)); ui->closeButt->setStyleSheet("border-style:none; border-radius:0px; padding:5px; color:#DCDCDC;"); } ChannelCharts::~ChannelCharts() { delete ui; } void ChannelCharts::setTitleText(QString titleText) { ui->label->setText(titleText); } void ChannelCharts::initDataChart(int index) { QCPGraph * graph = ui->dataPlot->addGraph(); graph->setName("时差(ns)"); graph->setAdaptiveSampling(true); // 默认启用自适应采样(绘图) QPen pen; pen.setColor(QColor("#2ed573")); pen.setWidth(2);//线宽 graph->setPen(pen); // 时间坐标轴 seconds since Epoch (January 1, 1970, 00:00 UTC). QSharedPointer<QCPAxisTickerDateTime> timeTicker(new QCPAxisTickerDateTime); timeTicker->setDateTimeFormat("MM-dd hh:mm:ss"); // 刻度单位:分钟 ui->dataPlot->xAxis->setTicker(timeTicker); ui->dataPlot->yAxis->setNumberFormat("gbc"); // Y 轴:g灵活的格式,b漂亮的指数形式,c乘号改成× ui->dataPlot->yAxis->setNumberPrecision(4); // Y 轴:精度,有效数字的位数 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->dataPlot->setBackground(QBrush(gradient)); ui->dataPlot->xAxis->setBasePen(QPen(Qt::white)); ui->dataPlot->xAxis->setTickPen(QPen(Qt::white)); ui->dataPlot->xAxis->setPadding(5); ui->dataPlot->xAxis->grid()->setVisible(true); ui->dataPlot->xAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); ui->dataPlot->xAxis->setTickLabelColor(Qt::white); ui->dataPlot->xAxis->setLabelColor(Qt::white); ui->dataPlot->xAxis->setLabel("时间"); ui->dataPlot->yAxis->setPadding(5); // a bit more space to the left border ui->dataPlot->yAxis->setLabel("时差测量值"); ui->dataPlot->yAxis->setBasePen(QPen(Qt::white)); ui->dataPlot->yAxis->setTickPen(QPen(Qt::white)); ui->dataPlot->yAxis->setSubTickPen(QPen(Qt::white)); ui->dataPlot->yAxis->grid()->setSubGridVisible(true); ui->dataPlot->yAxis->setTickLabelColor(Qt::white); ui->dataPlot->yAxis->setLabelColor(Qt::white); ui->dataPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine)); ui->dataPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); if (phaseVector[index].isEmpty() == false) { double minTm = phaseVector[index].first().at(0).toLongLong() / 1000; double maxTm = phaseVector[index].last().at(0).toLongLong() / 1000; double minValue = phaseVector[index].first().at(1).toDouble(); double maxValue = phaseVector[index].first().at(1).toDouble(); QVector<QCPGraphData> vecPoints; for (int i = 0; i < phaseVector[index].size(); i++) { // 新的数据点 QCPGraphData onePoint; QDateTime dtime = QDateTime::fromSecsSinceEpoch(phaseVector[index].at(i).at(0).toLongLong() / 1000); // 日期时间 onePoint.key = QCPAxisTickerDateTime::dateTimeToKey(dtime); onePoint.value = phaseVector[index].at(i).at(1).toDouble(); vecPoints.append(onePoint); if (phaseVector[index].at(i).at(1).toDouble() < minValue) { minValue = phaseVector[index][i].at(1).toDouble(); } if (phaseVector[index].at(i).at(1).toDouble() > maxValue) { maxValue = phaseVector[index][i].at(1).toDouble(); } } graph->data()->clear(); graph->data()->set(vecPoints, true); ui->dataPlot->xAxis->setRange(minTm, maxTm); ui->dataPlot->yAxis->setRange(minValue, maxValue); } ui->dataPlot->legend->setVisible(false); // ui->dataPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } void ChannelCharts::initAllenChart(int index) { QCPGraph * graph = ui->allenPlot->addGraph(); graph->setName("阿伦方差"); graph->setAdaptiveSampling(true); // 默认启用自适应采样(绘图) QPen pen; pen.setColor(QColor("#2ed573")); pen.setWidth(2);//线宽 graph->setPen(pen); 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)); ui->allenPlot->xAxis->setBasePen(QPen(Qt::white)); ui->allenPlot->xAxis->setTickPen(QPen(Qt::white)); ui->allenPlot->xAxis->setPadding(5); 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("平均时间(秒)"); 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)); // 对数坐标轴 横轴也缩放到对数 QSharedPointer<QCPAxisTickerLog> logTicker(new QCPAxisTickerLog); ui->allenPlot->xAxis->setTicker(logTicker); ui->allenPlot->yAxis->setNumberFormat("gbc"); // Y 轴:g灵活的格式,b漂亮的指数形式,c乘号改成× ui->allenPlot->yAxis->setNumberPrecision(4); // Y 轴:精度,有效数字的位数 ui->allenPlot->xAxis->setScaleType(QCPAxis::stLogarithmic); if (channelAllan[index].isEmpty() == false) { double minValue = channelAllan[index].first(); double maxValue = channelAllan[index].first(); QVector<QCPGraphData> vecPoints; for (int i = 0; i < channelAllan[index].size(); i++) { // 新的数据点 QCPGraphData onePoint; onePoint.key = pow(10, i); onePoint.value = channelAllan[index].at(i); vecPoints.append(onePoint); if (channelAllan[index].at(i) < minValue) { minValue = channelAllan[index].at(i); } if (channelAllan[index].at(i) > maxValue) { maxValue = channelAllan[index].at(i); } } graph->data()->clear(); graph->data()->set(vecPoints, true); ui->allenPlot->xAxis->setRange(1, 11000); ui->allenPlot->yAxis->setRange(minValue, maxValue); } ui->allenPlot->legend->setVisible(false); // ui->allenPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); } void ChannelCharts::on_closeButt_clicked() { this->close(); }