diff --git a/include/cyrobot_monitor/main_window.hpp b/include/cyrobot_monitor/main_window.hpp index 8a92197..370b3ea 100644 --- a/include/cyrobot_monitor/main_window.hpp +++ b/include/cyrobot_monitor/main_window.hpp @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include #include #include #include "./include/cyrobot_monitor/animationstackedwidget.h" @@ -56,6 +59,7 @@ public: void initUis(); void initVideos(); void initTopicList(); + void initCharts(); public slots: /****************************************** ** Auto-connections (connectSlotsByName()) @@ -102,6 +106,7 @@ public slots: void slot_closeWindows(); void slot_minWindows(); void slot_maxWindows(); + void slot_chartTimerTimeout(); // void on_horizontalSlider_raw_valueChanged(int value); private slots: @@ -140,6 +145,18 @@ private: QGraphicsScene *m_qgraphicsScene=NULL; roboMap *m_roboMap=NULL; QVariantList m_sendVelList,m_recvVelList,m_timeList; + //曲线 + QSplineSeries* line; + //曲线点的最大数量 + int line_max = 10; + //绘图变量和坐标 + QChart* chart; + QValueAxis *axisX; + QValueAxis *axisY; + QQueue data1; + QQueue data2; + QTimer *m_timerChart; + QChartView *chartView; }; }// namespace cyrobot_monitor diff --git a/src/main_window.cpp b/src/main_window.cpp index 5da26b5..2c8914c 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -131,6 +131,7 @@ void MainWindow::initUis() ui.close_btn->setIcon(QIcon("://images/close.png")); rock_widget =new JoyStick(ui.JoyStick_widget); rock_widget->show(); + initCharts(); } void MainWindow::connections() @@ -213,6 +214,69 @@ void MainWindow::slot_hide_table_widget(){ ui.table_hide_btn->setStyleSheet("QPushButton{background-image: url(://images/show.png);border:none;}"); } } +void MainWindow::initCharts(){ + line = new QSplineSeries(this); + chart = new QChart(); + chart->addSeries(line); + axisX = new QValueAxis(this); + axisY = new QValueAxis(this); + + chartView = new QChartView(ui.widget_chart); + chartView->setFixedWidth(ui.widget_chart->width()); + chartView->setFixedHeight(ui.widget_chart->height()); + chartView->setRenderHint(QPainter::Antialiasing); + m_timerChart=new QTimer; + m_timerChart->setInterval(100); + connect(m_timerChart,SIGNAL(timeout()),this,SLOT(slot_chartTimerTimeout())); + m_timerChart->start(); +} +void MainWindow::slot_chartTimerTimeout(){ + QVector list; + QVector newlist; + list = line->pointsVector();//获取现在图中列表 + if (list.size() < line_max) + { + //保持原来 + newlist = list; + } + else + { + //错位移动 + for(int i =1 ; i< list.size();i++) + { + newlist.append(QPointF(i-1,list.at(i).y())); + } + } + newlist.append(QPointF(newlist.size(),rand()));//最后补上新的数据 + line->replace(newlist);//替换更新 + + + line->setName("send");//设置曲线名称 + line->setPen(QColor(255, 0, 0));//设置曲线颜色 + line->setUseOpenGL(true);//openGl 加速 + + chart->setTitle("Pressure Data");//设置图标标题 + chart->removeSeries(line); + chart->addSeries(line); + chart->createDefaultAxes();//设置坐标轴 + + // axisX->setRange(0,line_max);//范围 + // axisX->setTitleText("times(secs)");//标题 + axisX->setTickCount(10);//分隔个数 + axisX->setLineVisible(true);//可视化 + axisX->setLinePenColor(Qt::blue);//颜色 + + // axisY->setRange(-200,1200); + // axisY->setTitleText("value"); + // axisY->setTickCount(6); + // axisY->setLineVisible(true); + // axisY->setLinePenColor(Qt::blue); + + // chart->setAxisX(axisX,line); + // chart->setAxisY(axisY,line); + + chartView->setChart(chart); +} //设置界面 void MainWindow::slot_setting_frame() { diff --git a/ui/main_window.ui b/ui/main_window.ui index cd9eec5..cf5083a 100644 --- a/ui/main_window.ui +++ b/ui/main_window.ui @@ -31,12 +31,30 @@ padding:0 + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + 10 + @@ -287,12 +305,26 @@ padding:0 QWidget{ background-color:rgb(67, 154, 246); -padding:0; } + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + @@ -319,6 +351,8 @@ background-color:green QPushButton{ background-color:rgb(67, 154, 246); border:none; +padding:0px 0px 0px 0px; +margin:0px 0px 0px 0px; } @@ -361,6 +395,8 @@ background-color:green QPushButton{ background-color:rgb(67, 154, 246); border:none; +padding:0px 0px 0px 0px; +margin:0px 0px 0px 0px; } @@ -605,6 +641,19 @@ border:none; + + + + + 400 + 200 + + + + border:1px solid rgb(0, 0, 0) + + +