|
@@ -0,0 +1,162 @@
|
|
|
+#include "mainwindow.h"
|
|
|
+#include "ui_mainwindow.h"
|
|
|
+
|
|
|
+MainWindow::MainWindow(QWidget *parent)
|
|
|
+ : QMainWindow(parent)
|
|
|
+ , ui(new Ui::MainWindow)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+
|
|
|
+ m_chart = new QChart();
|
|
|
+ m_chart->setTheme(QChart::ChartThemeLight);//设置白色主题
|
|
|
+ m_chart->setDropShadowEnabled(true);//背景阴影 m_chart->setAutoFillBackground(true); //设置背景自动填充
|
|
|
+// m_chart->addSeries(&mlineseries);//添加系列到QChart上
|
|
|
+
|
|
|
+
|
|
|
+ m_chart->setTitleBrush(QBrush(QColor(0,0,255)));//设置标题Brush
|
|
|
+ m_chart->setTitleFont(QFont("微软雅黑"));//设置标题字体
|
|
|
+ m_chart->setTitle("曲线图");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ QChartView *chartView = new QChartView(m_chart,ui->centralwidget);
|
|
|
+ chartView->setRenderHint(QPainter::Antialiasing);
|
|
|
+
|
|
|
+
|
|
|
+ chartView->setGeometry(10,10,1300,600);
|
|
|
+ mchartview = chartView;
|
|
|
+
|
|
|
+ mpivchartproc = new ivchartproc();
|
|
|
+ mpivchartproc->start();
|
|
|
+
|
|
|
+ QTimer * timer;
|
|
|
+ timer = new QTimer();
|
|
|
+ connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
|
|
|
+ timer->start(100);
|
|
|
+
|
|
|
+ setWindowTitle("ADC IV Chart View");
|
|
|
+}
|
|
|
+
|
|
|
+MainWindow::~MainWindow()
|
|
|
+{
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::resizeEvent(QResizeEvent *event)
|
|
|
+{
|
|
|
+ qDebug("resize");
|
|
|
+ QSize sizemain = ui->centralwidget->size();
|
|
|
+ qDebug("size x = %d y=%d",sizemain.width(),sizemain.height());
|
|
|
+ mchartview->setGeometry(0,0,sizemain.width(),sizemain.height());
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void MainWindow::on_actionSelect_Data_triggered()
|
|
|
+{
|
|
|
+ std::vector<std::string> xvectorlist = mpivchartproc->GetChartNameList();
|
|
|
+ std::vector<std::string> xvectorused = mvectorused;
|
|
|
+ DialogSelect dialogselect(xvectorlist,xvectorused);
|
|
|
+ int nrtn = dialogselect.exec();
|
|
|
+
|
|
|
+ if(nrtn == QDialog::Accepted)
|
|
|
+ {
|
|
|
+ mvectorused = xvectorused;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ unsigned int i;
|
|
|
+ for(i=0;i<mvectorCUShow.size();i++)
|
|
|
+ {
|
|
|
+ unsigned int j;
|
|
|
+ bool bhave = false;
|
|
|
+ for(j=0;j<mvectorused.size();j++)
|
|
|
+ {
|
|
|
+ if(mvectorCUShow[i].mstrname == mvectorused[j])
|
|
|
+ {
|
|
|
+ bhave = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(bhave == false)
|
|
|
+ {
|
|
|
+ delete mvectorCUShow[i].mlineseries;
|
|
|
+ mvectorCUShow.erase(mvectorCUShow.begin()+i);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ for(i=0;i<mvectorused.size();i++)
|
|
|
+ {
|
|
|
+ bool bhave = false;
|
|
|
+ unsigned int j;
|
|
|
+ for(j=0;j<mvectorCUShow.size();j++)
|
|
|
+ {
|
|
|
+ if(mvectorused[i] == mvectorCUShow[j].mstrname)
|
|
|
+ {
|
|
|
+ bhave = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(bhave == false)
|
|
|
+ {
|
|
|
+ CUShow xcu;
|
|
|
+ xcu.mstrname = mvectorused[i];
|
|
|
+ mvectorCUShow.push_back(xcu);
|
|
|
+
|
|
|
+ mvectorCUShow[mvectorCUShow.size()-1].mlineseries = new QLineSeries();
|
|
|
+ QLineSeries * plineseries = mvectorCUShow[mvectorCUShow.size()-1].mlineseries;
|
|
|
+
|
|
|
+ plineseries->setColor(QColor(255,0,0));
|
|
|
+
|
|
|
+ plineseries->setName(xcu.mstrname.data());
|
|
|
+
|
|
|
+ plineseries->setVisible(true);
|
|
|
+ plineseries->setPointLabelsFormat("(@xPoint,@yPoint)");
|
|
|
+ plineseries->setPointLabelsVisible(false);
|
|
|
+
|
|
|
+
|
|
|
+ m_chart->addSeries(plineseries);//添加系列到QChart上
|
|
|
+
|
|
|
+ //创建X轴和Y轴
|
|
|
+ QValueAxis *axisX = new QValueAxis;
|
|
|
+ axisX->setRange(-3000,0); //默认则坐标为动态计算大小的
|
|
|
+ axisX->setLabelFormat("%dS");
|
|
|
+ QValueAxis *axisY = new QValueAxis;
|
|
|
+ axisY->setRange(-1,1); //默认则坐标为动态计算大小的
|
|
|
+ axisY->setTitleText("value值");
|
|
|
+
|
|
|
+ axisY->setLinePenColor(QColor(0,255,0));
|
|
|
+
|
|
|
+ m_chart->setAxisX(axisX,plineseries);
|
|
|
+ m_chart->setAxisY(axisY,plineseries);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::onTimer()
|
|
|
+{
|
|
|
+ unsigned int i;
|
|
|
+ for(i=0;i<mvectorCUShow.size();i++)
|
|
|
+ {
|
|
|
+ std::vector<iv::ivchart::ivchartunit> xvectorcu = mpivchartproc->GetChartUnit(mvectorCUShow[i].mstrname);
|
|
|
+ unsigned int j;
|
|
|
+ qint64 nnow = QDateTime::currentMSecsSinceEpoch();
|
|
|
+ QList<QPointF> xListPoint;
|
|
|
+ for(j=0;j<xvectorcu.size();j++)
|
|
|
+ {
|
|
|
+
|
|
|
+ xListPoint.push_back(QPointF(xvectorcu[j].timex() - nnow,xvectorcu[j].fvalue()));
|
|
|
+ // qDebug("%f %f ",xListPoint[0].x(),xListPoint[0].y());
|
|
|
+ }
|
|
|
+
|
|
|
+ mvectorCUShow[i].mlineseries->replace(xListPoint);
|
|
|
+ }
|
|
|
+}
|