-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot.cpp
More file actions
104 lines (90 loc) · 2.22 KB
/
Plot.cpp
File metadata and controls
104 lines (90 loc) · 2.22 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
#include "wplot/Plot.h"
#include <QPainter>
namespace WPlot {
///////////////////////////////////////////////////////////////////////////////
// PUBLIC SECTION //
///////////////////////////////////////////////////////////////////////////////
Plot::Plot(QWidget *parent) :
QWidget(parent),
m_useAntialiasing(true),
m_background(nullptr)
{}
void Plot::setBackground(const Background::Ptr &background) {
if (background == nullptr) {
return;
}
m_background = background;
}
/**
* Specify if antialiasing must be used in drawing.
*
* @param flag true if antialiasing is desired.
*/
void Plot::setAntialiasingFlag(const bool &flag) {
m_useAntialiasing = flag;
}
/**
* Retrieve the antialiasing flag that specifies if antialiasing must
* be applied.
*
* @return Flag.
*/
bool Plot::getAntialiasingFlag() const {
return m_useAntialiasing;
}
/**
* Set the plot padding.
*
* @param[in] padding Padding.
*/
void Plot::setPadding(const Padding &padding) {
m_padding = padding;
}
/**
* Set the plot padding.
*
* @param[in] padding Padding value.
* @param[in] type Padding type.
*/
void Plot::setPadding(const double &padding, const Padding::Type &type) {
m_padding.setPadding(padding, type);
}
/**
* Retrieve padding values in pixels.
*
* @return Padding values.
*/
Padding::Values Plot::getPixelPadding() const {
return m_padding.getPaddingValues(Padding::PIXELS);
}
/**
* Initialize the painter.
*
* @param[in] painter Painter.
*/
void Plot::initializePainter(QPainter &painter) {
if (true == m_useAntialiasing) {
painter.setRenderHints(QPainter::Antialiasing, true);
}
}
///////////////////////////////////////////////////////////////////////////////
// PROTECTED SECTION //
///////////////////////////////////////////////////////////////////////////////
/**
* Perform drawing. All layers will be drawn starting from the one with the
* lowest index.
*
* @param event Painting event.
*/
void Plot::paintEvent(QPaintEvent * /*event*/) {
drawBackground();
}
/**
* Draw the background if set.
*/
void Plot::drawBackground() {
if (nullptr != m_background) {
m_background->draw(this);
}
}
} // namespace WPlot