Răsfoiți Sursa

add ivchart for use QtCharts show variable, but not complete.

yuchuli 4 ani în urmă
părinte
comite
65ea407cb8

+ 73 - 0
src/common/ivchart/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 28 - 0
src/common/ivchart/ivchart.cpp

@@ -0,0 +1,28 @@
+#include "ivchart.h"
+
+
+#include "ivchart_impl.h"
+
+namespace iv {
+
+Ivchart::Ivchart()
+{
+    ivchart_impl * p = new ivchart_impl();
+    p->start();
+    mpimpl = (void *)p;
+}
+
+Ivchart::~Ivchart()
+{
+    ivchart_impl * p = (ivchart_impl *)mpimpl;
+    delete p;
+}
+
+
+void Ivchart::chartvalue(std::string varname, const double fvalue,const double fvalue_RangeMin ,const double fvalue_RangeMax)
+{
+    ivchart_impl * p = (ivchart_impl *)mpimpl;
+    p->chartvalue(varname,fvalue,fvalue_RangeMin,fvalue_RangeMax);
+}
+
+}

+ 30 - 0
src/common/ivchart/ivchart.h

@@ -0,0 +1,30 @@
+#ifndef IVCHART_H
+#define IVCHART_H
+
+#include <QtCore/qglobal.h>
+
+#include <string>
+
+#if defined(IVCHART_LIBRARY)
+#  define IVCHART_EXPORT Q_DECL_EXPORT
+#else
+#  define IVCHART_EXPORT Q_DECL_IMPORT
+#endif
+
+namespace iv {
+
+
+class IVCHART_EXPORT Ivchart
+{
+public:
+    Ivchart();
+    ~Ivchart();
+public:
+    void chartvalue(std::string varname,const double fvalue,const double fvalue_RangeMin = 0.0,const double fvalue_RangeMax = 1.0);
+private:
+    void * mpimpl;
+};
+
+}
+
+#endif // IVCHART_H

+ 42 - 0
src/common/ivchart/ivchart.pro

@@ -0,0 +1,42 @@
+QT -= gui
+
+QT += dbus
+
+TEMPLATE = lib
+DEFINES += IVCHART_LIBRARY
+
+CONFIG += c++11
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+    ../../include/msgtype/ivchart.pb.cc \
+    ivchart.cpp \
+    ivchart_impl.cpp
+
+HEADERS += \
+    ../../include/msgtype/ivchart.pb.h \
+    ivchart.h \
+    ivchart_impl.h
+
+# Default rules for deployment.
+unix {
+    target.path = /usr/lib
+}
+!isEmpty(target.path): INSTALLS += target
+
+INCLUDEPATH += $$PWD/../../include/msgtype
+
+unix: LIBS += -lprotobuf
+
+win32: LIBS += $$PWD\..\..\..\thirdpartylib\protobuf\lib\libprotobuf.a
+win32: INCLUDEPATH+= $$PWD\..\..\..\thirdpartylib\protobuf\src

+ 88 - 0
src/common/ivchart/ivchart_impl.cpp

@@ -0,0 +1,88 @@
+#include "ivchart_impl.h"
+
+namespace  iv {
+
+
+ivchart_impl::ivchart_impl()
+{
+
+    mmsg = QDBusMessage::createSignal("/catarc/adc",  "adciv.interface", "ivchart");
+    mmsg<<1;
+}
+
+ivchart_impl::~ivchart_impl()
+{
+    requestInterruption();
+    int i;
+    for(i=0;i<100;i++)
+    {
+        if(isFinished())
+            break;
+        msleep(1);
+    }
+}
+
+void ivchart_impl::chartvalue(std::string varname, const double fvalue, const double fvalue_RangeMin, const double fvalue_RangeMax)
+{
+    iv::ivchart::ivchartunit xivchartunit;
+    xivchartunit.set_strvarname(varname);
+    xivchartunit.set_timex(QDateTime::currentMSecsSinceEpoch());
+    xivchartunit.set_fvalue(fvalue);
+    xivchartunit.set_fvalue_rangemin(fvalue_RangeMin);
+    xivchartunit.set_fvalue_rangemax(fvalue_RangeMax);
+
+    if(mvectorchart.xivchartunit_size() > 10000)
+    {
+        qDebug("ivchart_impl::chartvalue ivchartunit is big value is %d ",mvectorchart.xivchartunit_size());
+        return;
+    }
+
+    mMutexVector.lock();
+    iv::ivchart::ivchartunit * p = mvectorchart.add_xivchartunit();
+    p->CopyFrom(xivchartunit);
+    mMutexVector.unlock();
+}
+
+int ivchart_impl::writechart(iv::ivchart::ivchartarray *pxvectorchart)
+{
+    char * str;
+    int ndatasize = pxvectorchart->ByteSize();
+    str = new char[ndatasize];
+    std::shared_ptr<char> pstr;
+    pstr.reset(str);
+    if(!pxvectorchart->SerializeToArray(str,ndatasize))
+    {
+        qDebug("ivchart_impl::writechart SerializeToArray error.");
+        return -1;
+    }
+    QByteArray ba;
+    ba.append(str,ndatasize);
+
+    QList<QVariant> x;
+    x<<ba;
+    mmsg.setArguments(x);
+    QDBusConnection::sessionBus().send(mmsg);
+    return 0;
+}
+
+void ivchart_impl::run()
+{
+    iv::ivchart::ivchartarray xvectorchart;
+    while(!QThread::isInterruptionRequested())
+    {
+        mWaitMutex.lock();
+        mwc.wait(&mWaitMutex,50);
+        mWaitMutex.unlock();
+        mMutexVector.lock();
+        xvectorchart.Clear();
+        xvectorchart.CopyFrom(mvectorchart);
+        mvectorchart.Clear();
+        mMutexVector.unlock();
+        if(xvectorchart.xivchartunit_size()>0)
+        {
+            writechart(&xvectorchart);
+        }
+    }
+}
+
+}

+ 45 - 0
src/common/ivchart/ivchart_impl.h

@@ -0,0 +1,45 @@
+#ifndef IVCHART_IMPL_H
+#define IVCHART_IMPL_H
+
+#include <QDateTime>
+#include <QtDBus/qdbusmessage.h>
+#include <QtDBus/QDBusConnection>
+
+#include <QThread>
+#include <QWaitCondition>
+#include <QMutex>
+#include <vector>
+#include <memory>
+#include <iostream>
+
+#include <unistd.h>
+
+#include "ivchart.pb.h"
+
+
+namespace  iv {
+
+
+
+class ivchart_impl : public QThread
+{
+public:
+    ivchart_impl();
+    ~ivchart_impl();
+
+public:
+    void chartvalue(std::string varname,const double fvalue,const double fvalue_RangeMin = 0.0,const double fvalue_RangeMax = 1.0);
+
+private:
+    QDBusMessage mmsg;
+    void run();
+    QWaitCondition mwc;
+    QMutex mWaitMutex;
+    iv::ivchart::ivchartarray mvectorchart;
+    QMutex mMutexVector;
+    int writechart(iv::ivchart::ivchartarray * pxvectorchart);
+};
+
+}
+
+#endif // IVCHART_IMPL_H

+ 17 - 0
src/include/proto/ivchart.proto

@@ -0,0 +1,17 @@
+syntax = "proto2";
+
+package iv.ivchart;
+
+message ivchartunit
+{
+  required string strvarname = 1;
+  required int64 timex = 2;
+  required double fvalue = 3;
+  required double fvalue_RangeMin = 4;
+  required double fvalue_RangeMax = 5;
+};
+
+message ivchartarray
+{
+	repeated ivchartunit xivchartunit = 1;
+};

+ 73 - 0
src/test/testivchart/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 30 - 0
src/test/testivchart/main.cpp

@@ -0,0 +1,30 @@
+#include <QCoreApplication>
+
+#include <thread>
+
+#include "ivchart.h"
+
+#include <math.h>
+
+iv::Ivchart * givchart;
+bool gbrun = true;
+
+void testthread(std::string varname,int ninter,double fratio,double foff)
+{
+    int index = 0;
+    while(gbrun)
+    {
+        givchart->chartvalue(varname,foff + fratio*sin(index*2.0*M_PI/100),-1,1);
+        index = index + 10;
+        std::this_thread::sleep_for(std::chrono::milliseconds(ninter));
+    }
+}
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    givchart = new iv::Ivchart();
+    std::thread * pthread = new std::thread(testthread,"test",10,1.0,0.0);
+    return a.exec();
+}

+ 28 - 0
src/test/testivchart/testivchart.pro

@@ -0,0 +1,28 @@
+QT -= gui
+
+QT += dbus
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+        main.cpp
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+INCLUDEPATH +=$$PWD/../../common/ivchart
+
+LIBS += -L$$PWD/../../common/build-ivchart-Debug -livchart

+ 73 - 0
src/tool/view_ivchart/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 81 - 0
src/tool/view_ivchart/dialogselect.cpp

@@ -0,0 +1,81 @@
+#include "dialogselect.h"
+#include "ui_dialogselect.h"
+
+#include <QGroupBox>
+#include <QScrollArea>
+
+DialogSelect::DialogSelect(std::vector<std::string> xvectorlist, std::vector<std::string> &xvectorused,QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogSelect)
+{
+    ui->setupUi(this);
+
+    mpvectorused = &xvectorused;
+
+    QGroupBox * pGroup = new QGroupBox();
+    pGroup->setGeometry(50,100,560,3000);
+
+    QScrollArea * pScroll = new QScrollArea(this);
+    pScroll->setWidget(pGroup);
+
+    pScroll->setGeometry(30,100,600,300);
+
+    int ntotalwidth = 560;
+    int ncheckwidth = 80;
+    int ncheckheight = 23;
+    int nhospace = 100;
+    int nvespace = 30;
+
+    unsigned int i;
+    int ipos = 0;
+    int jpos = 0;
+    for(i=0;i<xvectorlist.size();i++)
+    {
+        QCheckBox * pcheck = new QCheckBox(pGroup);
+        pcheck->setGeometry(30+ipos*nhospace,30+jpos*nvespace,ncheckwidth,ncheckheight);
+        pcheck->setText(xvectorlist[i].data());
+
+        mvectorcheck.push_back(pcheck);
+        unsigned int j;
+        bool bused = false;
+        for(j=0;j<xvectorused.size();j++)
+        {
+            if(xvectorused[j] == xvectorlist[i])
+            {
+                bused = true;
+                break;
+            }
+        }
+        pcheck->setChecked(bused);
+        ipos++;
+        if(ipos>=((ntotalwidth -30)/nhospace))
+        {
+            ipos = 0;
+            jpos++;
+        }
+    }
+
+    setWindowTitle("Select Chart Item");
+
+
+}
+
+DialogSelect::~DialogSelect()
+{
+    delete ui;
+}
+
+void DialogSelect::on_pushButton_Select_clicked()
+{
+    mpvectorused->clear();
+    unsigned int i;
+    for(i=0;i<mvectorcheck.size();i++)
+    {
+        if(mvectorcheck[i]->isChecked())
+        {
+            mpvectorused->push_back(mvectorcheck[i]->text().toStdString());
+        }
+    }
+
+    this->accept();
+}

+ 32 - 0
src/tool/view_ivchart/dialogselect.h

@@ -0,0 +1,32 @@
+#ifndef DIALOGSELECT_H
+#define DIALOGSELECT_H
+
+#include <QDialog>
+
+#include <string>
+#include <vector>
+#include <QCheckBox>
+
+namespace Ui {
+class DialogSelect;
+}
+
+class DialogSelect : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogSelect(std::vector<std::string> xvectorlist, std::vector<std::string> &xvectorused,QWidget *parent = nullptr);
+    ~DialogSelect();
+
+private slots:
+    void on_pushButton_Select_clicked();
+
+private:
+    Ui::DialogSelect *ui;
+
+    std::vector<QCheckBox *> mvectorcheck;
+    std::vector<std::string> * mpvectorused;
+};
+
+#endif // DIALOGSELECT_H

+ 32 - 0
src/tool/view_ivchart/dialogselect.ui

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogSelect</class>
+ <widget class="QDialog" name="DialogSelect">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>660</width>
+    <height>430</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QPushButton" name="pushButton_Select">
+   <property name="geometry">
+    <rect>
+     <x>40</x>
+     <y>20</y>
+     <width>89</width>
+     <height>25</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Select</string>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 126 - 0
src/tool/view_ivchart/ivchartproc.cpp

@@ -0,0 +1,126 @@
+#include "ivchartproc.h"
+
+ivchartproc::ivchartproc()
+{
+    bool bconnect = QDBusConnection::sessionBus().connect(QString(),"/catarc/adc",  "adciv.interface", "ivchart",this,SLOT(onChartMsg(QByteArray)));
+//    qDebug("connect is %d",bconnect);
+}
+
+void ivchartproc::run()
+{
+    const int nkeep = 300000;
+    while(mbrun&&(!QThread::isInterruptionRequested()))
+    {
+        std::vector<iv::ivchart::ivchartarray> xvectorivarray;
+        mMutexArray.lock();
+        xvectorivarray = mvectorarray;
+        mvectorarray.clear();
+        mMutexArray.unlock();
+
+        int i;
+        int nsize = xvectorivarray.size();
+        for(i=0;i<nsize;i++)
+        {
+            unsigned int k;
+            for(k=0;k<xvectorivarray[i].xivchartunit_size();k++)
+            {
+                bool bhave = false;
+                int j;
+                mMutex.lock();
+                int ncucount = mvectorCU.size();
+                for(j=0;j<ncucount;j++)
+                {
+                    if(xvectorivarray[i].xivchartunit(k).strvarname() == mvectorCU[j].strname)
+                    {
+                        mvectorCU[j].mvectorchartunit.push_back(xvectorivarray[i].xivchartunit(k));
+                        bhave = true;
+                        break;
+                    }
+                }
+                if(bhave == false)
+                {
+                    ChartUnit xcu;
+                    xcu.strname = xvectorivarray[i].xivchartunit(k).strvarname();
+                    xcu.mvectorchartunit.push_back(xvectorivarray[i].xivchartunit(k));
+                    mvectorCU.push_back(xcu);
+                }
+
+                mMutex.unlock();
+            }
+        }
+
+        qint64 nnow = QDateTime::currentMSecsSinceEpoch();
+
+        int ncusize = mvectorCU.size();
+
+        mMutex.lock();
+        for(i=0;i<ncusize;i++)
+        {
+            int j;
+            int nsizechart = mvectorCU[i].mvectorchartunit.size();
+            for(j=0;j<nsizechart;j++)
+            {
+                if(mvectorCU[i].mvectorchartunit[j].timex()>(nnow - nkeep))
+                {
+                    break;
+                }
+            }
+        }
+        mMutex.unlock();
+
+        if(xvectorivarray.size()  == 0)
+        {
+            msleep(1);
+        }
+
+    }
+}
+
+
+void ivchartproc::onChartMsg(QByteArray value)
+{
+
+    qDebug("chart msg size is %d",value.size());
+    iv::ivchart::ivchartarray xivarray;
+    if(xivarray.ParseFromArray(value.data(),value.size()))
+    {
+        mMutexArray.lock();
+        if(mvectorarray.size()<10000)
+            mvectorarray.push_back(xivarray);
+        mMutexArray.unlock();
+    }
+    else
+    {
+        qDebug("ivchartproc::onChartMsg parse error.");
+    }
+}
+
+std::vector<std::string> ivchartproc::GetChartNameList()
+{
+    std::vector<std::string> xvectorname;
+    mMutex.lock();
+    unsigned int i;
+    for(i=0;i<mvectorCU.size();i++)
+    {
+        xvectorname.push_back(mvectorCU[i].strname);
+    }
+    mMutex.unlock();
+    return xvectorname;
+}
+
+std::vector<iv::ivchart::ivchartunit> ivchartproc::GetChartUnit(std::string strname)
+{
+    std::vector<iv::ivchart::ivchartunit> xvectorcu;
+    mMutex.lock();
+    unsigned int i;
+    for(i=0;i<mvectorCU.size();i++)
+    {
+        if(strname == mvectorCU[i].strname)
+        {
+            xvectorcu= mvectorCU[i].mvectorchartunit;
+            break;
+        }
+    }
+    mMutex.unlock();
+    return xvectorcu;
+}

+ 42 - 0
src/tool/view_ivchart/ivchartproc.h

@@ -0,0 +1,42 @@
+#ifndef IVCHARTPROC_H
+#define IVCHARTPROC_H
+
+#include <QThread>
+
+#include <QMutex>
+
+#include <QDateTime>
+#include <QtDBus/qdbusmessage.h>
+#include <QtDBus/QDBusConnection>
+
+#include "ivchart.pb.h"
+
+class ChartUnit
+{
+public:
+    std::string strname;
+    std::vector<iv::ivchart::ivchartunit> mvectorchartunit;
+};
+
+class ivchartproc : public QThread
+{
+    Q_OBJECT
+public:
+    ivchartproc();
+
+private slots:
+    void onChartMsg(QByteArray value);
+private:
+    void run();
+    std::vector<ChartUnit> mvectorCU;
+    QMutex mMutex;
+    std::vector<iv::ivchart::ivchartarray> mvectorarray;
+    QMutex mMutexArray;
+    bool mbrun = true;
+
+public:
+    std::vector<std::string > GetChartNameList();
+    std::vector<iv::ivchart::ivchartunit> GetChartUnit(std::string strname);
+};
+
+#endif // IVCHARTPROC_H

+ 11 - 0
src/tool/view_ivchart/main.cpp

@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+    MainWindow w;
+    w.show();
+    return a.exec();
+}

+ 162 - 0
src/tool/view_ivchart/mainwindow.cpp

@@ -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);
+    }
+}

+ 51 - 0
src/tool/view_ivchart/mainwindow.h

@@ -0,0 +1,51 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include <QtCharts>
+#include <QLineSeries>
+
+#include "ivchartproc.h"
+#include "dialogselect.h"
+
+QT_BEGIN_NAMESPACE
+namespace Ui { class MainWindow; }
+QT_END_NAMESPACE
+
+struct CUShow
+{
+public:
+    std::string mstrname;
+    QLineSeries * mlineseries;
+};
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    MainWindow(QWidget *parent = nullptr);
+    ~MainWindow();
+
+private slots:
+    void onTimer();
+
+private:
+    Ui::MainWindow *ui;
+
+    QChart * m_chart;
+    QChartView * mchartview;
+
+    ivchartproc * mpivchartproc;
+
+    std::vector<std::string> mvectorused;
+
+    std::vector<CUShow> mvectorCUShow;
+public:
+     void resizeEvent(QResizeEvent *event);
+
+private slots:
+     void on_actionSelect_Data_triggered();
+};
+#endif // MAINWINDOW_H

+ 43 - 0
src/tool/view_ivchart/mainwindow.ui

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>800</width>
+    <height>600</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralwidget"/>
+  <widget class="QMenuBar" name="menubar">
+   <property name="geometry">
+    <rect>
+     <x>0</x>
+     <y>0</y>
+     <width>800</width>
+     <height>28</height>
+    </rect>
+   </property>
+   <widget class="QMenu" name="menuFunc">
+    <property name="title">
+     <string>Func</string>
+    </property>
+    <addaction name="actionSelect_Data"/>
+   </widget>
+   <addaction name="menuFunc"/>
+  </widget>
+  <widget class="QStatusBar" name="statusbar"/>
+  <action name="actionSelect_Data">
+   <property name="text">
+    <string>Select Data</string>
+   </property>
+  </action>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 45 - 0
src/tool/view_ivchart/view_ivchart.pro

@@ -0,0 +1,45 @@
+QT       += core gui charts dbus
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+CONFIG += c++11
+
+# The following define makes your compiler emit warnings if you use
+# any Qt feature that has been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+    ../../include/msgtype/ivchart.pb.cc \
+    dialogselect.cpp \
+    ivchartproc.cpp \
+    main.cpp \
+    mainwindow.cpp
+
+HEADERS += \
+    ../../include/msgtype/ivchart.pb.h \
+    dialogselect.h \
+    ivchartproc.h \
+    mainwindow.h
+
+FORMS += \
+    dialogselect.ui \
+    mainwindow.ui
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+INCLUDEPATH += $$PWD/../../include/msgtype
+
+unix: LIBS += -lprotobuf
+
+win32: LIBS += $$PWD\..\..\..\thirdpartylib\protobuf\lib\libprotobuf.a
+win32: INCLUDEPATH+= $$PWD\..\..\..\thirdpartylib\protobuf\src