Files
gcs-nf/App/ComponentUI/Scope/Chart.h
T

123 lines
2.6 KiB
C++

#ifndef CHART_H
#define CHART_H
#include <QObject>
#include "QWidget"
#include "QDebug"
#include "QChart"
#include <QChartView>
#include <QLineSeries>
#include <QValueAxis>
#include <QDateTimeAxis>
#include <QSplineSeries>
#include <QMouseEvent>
#include <QGraphicsSimpleTextItem>
#include "QTimer"
using namespace QtCharts;
namespace ColorMap{
static QColor Color[16] = {
QColor(165, 42, 42), //Channel1Color
QColor (255, 127, 80), //Channel2Color
QColor (30, 144, 255), //Channel3Color
QColor (218, 165, 32), //Channel4Color
QColor (255, 0, 255), //Channel5Color
QColor (147, 112, 219), //Channel6Color
QColor (0, 255, 255), //Channel7Color
QColor (0, 0, 128), //Channel8Color
QColor (128, 0, 128), //Channel9Color
QColor (46, 139, 87), //Channel10Color
QColor (152, 251, 152), //Channel11Color
QColor (0, 255, 127), //Channel12Color
QColor (0, 0, 255), //Channel13Color
QColor (135, 206, 250), //Channel14Color
QColor (255, 192, 203), //Channel15Color
QColor (127, 255, 0) //Channel16Color
};
}
class Chart : public QChartView
{
Q_OBJECT
public:
explicit Chart( QWidget *parent = nullptr);
explicit Chart(QChart *chart, QWidget *parent = nullptr);
~Chart();
static int ChannelIndex;
void setScroll(const bool &value)
{
isscroll = value;
}
bool isScroll(void)
{
return isscroll;
}
protected:
void hideEvent(QHideEvent *e);
void showEvent(QShowEvent *e);
void leaveEvent(QEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
void mouseDoubleClickEvent(QMouseEvent *e);
void wheelEvent(QWheelEvent *e);
void resizeEvent(QResizeEvent *e);
signals:
public slots:
void timeout(void);
void chartUpdate(void);
void setUseOpenGL(const bool &value);
bool addSeries(QString name);
bool addSeries(QString name,int index);
bool addSeries(QString name, QColor color);
void removeSerie(QString name);
void removeAllSerie(void);
void setSerieData(QString name,QVariant data);
private:
QGraphicsSimpleTextItem *m_coordItem;
QVariant m_xMin;
QVariant m_xMax;
QVariant m_yMin;
QVariant m_yMax;
QPoint lastPoint;
bool isPress = false;
QLineSeries *series;
QTimer *updateTimer = nullptr;
qreal timeseries = 0;//时间基准,注意时间长度,可能会出现时间反转的情况
bool isOpenGL = false;
bool isscroll = true;
};
#endif // CHART_H