Repository navigation
Expand file tree
/
Copy pathCartesianPlot2D.cpp
More file actions
152 lines (136 loc) · 3.58 KB
/
Copy pathCartesianPlot2D.cpp
File metadata and controls
152 lines (136 loc) · 3.58 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "wplot/CartesianPlot2D.h"
namespace WPlot {
//////////////////////////////////////////////////////////////////////////////
// PUBLIC SECTION //
//////////////////////////////////////////////////////////////////////////////
CartesianPlot2D::CartesianPlot2D(QWidget *parent) :
Plot2D(parent)
{}
/**
* Add a grid to the plot.
*
* @param[in] grid Grid that must be added.
*/
void CartesianPlot2D::addGrid(const CartesianGrid2D::Ptr &grid) {
if (grid == nullptr) {
return;
}
m_gridList.append(grid);
}
/**
* Add a grid to the plot at specified index.
*
* @param[in] index Index.
* @param[in] grid Grid that must be added.
*/
void CartesianPlot2D::addGrid(const int &index, const CartesianGrid2D::Ptr &grid) {
if (grid == nullptr) {
return;
}
if (index > m_gridList.size()) {
m_gridList.append(grid);
} else if (index < 0) {
m_gridList.prepend(grid);
} else {
m_gridList.insert(index, grid);
}
}
/**
* Add a graph to plot. The graph will be set with highest available index, so
* it will be the last to be drawn.
*
* @param[in] graph Graph to be added.
*/
void CartesianPlot2D::addGraph(const CartesianGraph2D::Ptr &graph) {
if (graph == nullptr) {
return;
}
m_graphList.append(graph);
}
/**
* Insert a graph in specified position. If a graph exists in that position, it
* will be moved before it. If an out-of-range index is given, the graph will be
* put in first or last position.
*
* @param[in] index Position index.
* @param[in] graph Graph to be added.
*/
void CartesianPlot2D::addGraph(const int &index, const CartesianGraph2D::Ptr &graph) {
if (graph == nullptr) {
return;
}
if (index > m_graphList.size()) {
m_graphList.append(graph);
} else if (index < 0) {
m_graphList.prepend(graph);
} else {
m_graphList.insert(index, graph);
}
}
/**
* Set the limits of the plot area.
*
* @param[in] upperLeftCorner Coordinetes of upper left corner.
* @param[in] lowerRightCorner Coordinates of lower right corner.
*/
void CartesianPlot2D::setPlotLimits(const QPointF &upperLeftCorner, const QPointF &lowerRightCorner) {
m_upperLeftCorner = upperLeftCorner;
m_lowerRightCorner = lowerRightCorner;
}
/**
* Set the limits of the plot area.
*
* @param[in] xMin Minimum X value.
* @param[in] xMax Maximum X value.
* @param[in] yMin Minimym Y value.
* @param[in] yMax Maximym Y value.
*/
void CartesianPlot2D::setPlotLimits(const double &xMin, const double &xMax, const double &yMin, const double &yMax) {
m_upperLeftCorner.setX(xMin);
m_upperLeftCorner.setY(yMax);
m_lowerRightCorner.setX(xMax);
m_lowerRightCorner.setY(yMin);
}
///////////////////////////////////////////////////////////////////////////////
// PROTECTED SECTION //
///////////////////////////////////////////////////////////////////////////////
/**
* Perform drawing. All layers will be drawn starting from the one with the
* lowest index.
*
* @param event Painting event.
*/
void CartesianPlot2D::paintEvent(QPaintEvent * /*event*/) {
initPainterCoordinates();
drawBackground();
drawGrids();
drawGraphs();
drawAxes();
drawItems();
drawBoundaries();
}
/**
* Draw all grids that are added.
*/
void CartesianPlot2D::drawGrids() {
for (auto& it : m_gridList) {
it->drawLines(this);
}
}
/**
* Draw grid boundaries.
*/
void CartesianPlot2D::drawBoundaries() {
for (auto& it : m_gridList) {
it->drawBoundary(this);
}
}
/**
* Draw all graphs that are added.
*/
void CartesianPlot2D::drawGraphs() {
for (auto& it : m_graphList) {
it->draw(this);
}
}
} // namespace WPlot