-
Notifications
You must be signed in to change notification settings - Fork 0
/
qcustomplotgraph.cpp
77 lines (64 loc) · 1.86 KB
/
qcustomplotgraph.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "qcustomplotgraph.h"
QCustomPlotGraph::QCustomPlotGraph(QObject *parent) :
QObject(parent)
{
this->visible = true;
this->plotIsConnected = false;
this->graphNumIsSet = false;
QPen *pen = new QPen;
pen->setWidth(1);
pen->setColor(QColor(0,0,0));
setPen(*pen);
delete pen;
}
void QCustomPlotGraph::setPen(QPen pen) {
this->pen = pen;
if (plotIsConnected && graphNumIsSet){
this->connectedPlot->graph(this->graphNum)->setPen(this->pen);
this->connectedPlot->replot();
}
}
void QCustomPlotGraph::show(){
this->visible = true;
if (plotIsConnected){
this->sendDataToPlot();
}
}
void QCustomPlotGraph::hide(){
this->visible = false;
if (plotIsConnected){
this->sendDataToPlot();
}
}
void QCustomPlotGraph::connectWithPlot(QCustomPlot *pPlot){
this->connectedPlot = pPlot;
this->plotIsConnected = true;
}
void QCustomPlotGraph::setGraphNum(int num){
this->graphNum = num;
this->graphNumIsSet = true;
}
bool QCustomPlotGraph::readyForPlot(){
return (this->plotIsConnected && this->graphNumIsSet && !this->xAxis.empty() && !this->yAxis.empty());
}
void QCustomPlotGraph::sendDataToPlot(){
if (this->readyForPlot()){
this->connectedPlot->graph(this->graphNum)->setData(this->xAxis,this->yAxis);
this->connectedPlot->graph(this->graphNum)->setVisible(this->visible);
this->connectedPlot->replot();
}
}
void QCustomPlotGraph::setXAxis(QVector <double> x){
this->xAxis = x;
}
void QCustomPlotGraph::setYAxis(QVector <double> y){
this->yAxis = y;
}
void QCustomPlotGraph::clearData() {
this->connectedPlot->graph(graphNum)->clearData();
this->connectedPlot->replot();
}
void QCustomPlotGraph::setSignal(DataSignal *inputSignal){
this->setXAxis(inputSignal->getTimeScale());
this->setYAxis(inputSignal->getData());
}