Newer
Older
PhaseMeasure / ChannelCharts.cpp
#include "ChannelCharts.h"
#include "ui_ChannelCharts.h"

#include <iostream>

extern QVector<QVector<double>> 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)
{
/*    QChart * dataChart = new QChart();
    dataChart->setTheme(QChart::ChartThemeDark);
    dataChart->setDropShadowEnabled(true);
    dataChart->legend()->setVisible(false);
    dataChart->setAnimationOptions(QChart::AllAnimations);

    QLineSeries * series = new QLineSeries();
    for (int i = 0; i < phaseVector[index].size(); i++)
    {
        series->append(i, phaseVector[index][i] * 1E12);
    }

    dataChart->addSeries(series);
    dataChart->createDefaultAxes();  */      // 基于已添加到图表的 series 来创建默认的坐标轴
}

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("平均时间(秒)");

    channelAllan[index] << 1.78e-13 << 6.38e-14 << 1.65e-14 << 1.47e-14 << 4.45e-15;

    // prepare y axis:
    ui->allenPlot->yAxis->setRange(channelAllan[index][4] * 0.5, 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);
}