This repository was archived by the owner on Sep 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathplotdisplay.cpp
More file actions
134 lines (112 loc) · 3.25 KB
/
plotdisplay.cpp
File metadata and controls
134 lines (112 loc) · 3.25 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "plotdisplay.h"
#include "qwt/qwt_symbol.h"
#include "qwt/qwt_legend.h"
map<QString, QVector<QPointF> > PlotDisplay::dataMap;
map<QString, QwtSymbol> PlotDisplay::symbolMap;
map<QString, QwtPlotCurve::CurveStyle> PlotDisplay::styleMap;
map<QString, QColor> PlotDisplay::colourMap;
PlotDisplay::PlotDisplay(QWidget *parent) :
QwtPlot(parent)
{
// legend
QwtLegend *legend = new QwtLegend;
legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
insertLegend(legend, QwtPlot::RightLegend);
zoomer = new QwtPlotZoomer(canvas());
}
PlotDisplay::~PlotDisplay()
{
for(map<QString, QwtPlotCurve*>::iterator cit = curveMap.begin(); cit != curveMap.end(); cit++)
delete cit->second;
delete zoomer;
}
vector<QString> PlotDisplay::names()
{
vector<QString> names;
for(map<QString, QVector<QPointF> >::const_iterator it = dataMap.begin(); it != dataMap.end(); it++)
names.push_back(it->first);
return names;
}
bool PlotDisplay::nameExists(QString name)
{
map<QString, QVector<QPointF> >::iterator it = dataMap.find(name);
return it != dataMap.end();
}
QwtSymbol PlotDisplay::getSymbol(QString name)
{
return symbolMap[name];
}
QwtPlotCurve::CurveStyle PlotDisplay::getLineStyle(QString name)
{
return styleMap[name];
}
QColor PlotDisplay::getLineColour(QString name)
{
return colourMap[name];
}
void PlotDisplay::setCurveVisibility(QString name, bool visibility)
{
visibleCurves[name] = visibility;
}
bool PlotDisplay::isCurveVisible(QString name)
{
map<QString, bool>::iterator it = visibleCurves.find(name);
if(it != visibleCurves.end())
return it->second;
else
return false;
}
void PlotDisplay::clearMap()
{
dataMap.clear();
}
void PlotDisplay::clearCurves()
{
for(map<QString, QwtPlotCurve*>::iterator cit = curveMap.begin(); cit != curveMap.end(); cit++)
delete cit->second;
curveMap.clear();
}
void PlotDisplay::updateCurveData(QString name, QVector<QPointF> points)
{
bool nameExisted = nameExists(name);
dataMap[name] = points;
map<QString, bool>::iterator it = visibleCurves.find(name);
if(it == visibleCurves.end())
visibleCurves[name] = false;
updateCurve(name);
if(!nameExisted)
emit namesUpdated(names());
}
void PlotDisplay::updateCurveProperties(QString name, QwtSymbol symbol, QwtPlotCurve::CurveStyle lineStyle, QColor lineColour)
{
if(nameExists(name)) {
symbolMap[name] = symbol;
styleMap[name] = lineStyle;
colourMap[name] = lineColour;
updateCurve(name);
}
}
void PlotDisplay::updateCurve(QString name)
{
map<QString, QwtPlotCurve*>::iterator it = curveMap.find(name);
if(it == curveMap.end()) {
curveMap[name] = new QwtPlotCurve(name);
}
QwtPlotCurve* curve = curveMap[name];
curve->setSamples(dataMap[name]);
curve->setStyle(styleMap[name]);
curve->setSymbol(new QwtSymbol(symbolMap[name]));
curve->setPen(QPen(colourMap[name]));
replot();
}
void PlotDisplay::replot()
{
map<QString, QwtPlotCurve*>::iterator cit;
for(cit = curveMap.begin(); cit != curveMap.end(); cit++) {
if(visibleCurves[cit->first])
cit->second->attach(this);
else
cit->second->detach();
}
QwtPlot::replot();
}