-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcurve.cpp
More file actions
90 lines (74 loc) · 1.76 KB
/
curve.cpp
File metadata and controls
90 lines (74 loc) · 1.76 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
#include "curve.hpp"
#include "curvenode.hpp"
#include "scalemap.hpp"
#include <cmath>
namespace
{
QPainterPath buildCurve(int pointCount)
{
QPainterPath path;
double sinStep = 4 * (2 * 3.1415) / pointCount;
for (int i = 0; i < pointCount; ++i)
{
path.lineTo(i * (10000. / pointCount), i * (10000. / pointCount));
//path.lineTo(i, sin(i * sinStep));
}
return path;
}
} // anonymous namespace
Curve::Curve(QQuickItem *parent)
: QQuickItem(parent)
, m_xScaleMap(0)
, m_yScaleMap(0)
{
setFlag(ItemHasContents);
setClip(true); // enable clipping by default
}
ScaleMap* Curve::xScaleMap() const
{
return m_xScaleMap;
}
void Curve::setXScaleMap(ScaleMap* scaleMap)
{
if (m_xScaleMap != scaleMap)
{
m_xScaleMap = scaleMap;
emit xScaleMapChanged(scaleMap);
}
}
ScaleMap* Curve::yScaleMap() const
{
return m_yScaleMap;
}
void Curve::setYScaleMap(ScaleMap* scaleMap)
{
if (m_yScaleMap != scaleMap)
{
m_yScaleMap = scaleMap;
emit yScaleMapChanged(scaleMap);
}
}
void Curve::geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry)
{
Q_UNUSED(oldGeometry);
if (m_xScaleMap)
m_xScaleMap->setPixelLength(newGeometry.width());
if (m_yScaleMap)
m_yScaleMap->setPixelLength(newGeometry.height());
}
QSGNode* Curve::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
{
Q_UNUSED(data);
if (width() <= 0 || height() <= 0)
{
delete oldNode;
return 0;
}
CurveNode* curveNode = static_cast<CurveNode*>(oldNode);
if (!curveNode)
curveNode = new CurveNode;
m_curve = buildCurve(4000);
curveNode->updateFromCurve(this, m_curve);
return curveNode;
}