-
Notifications
You must be signed in to change notification settings - Fork 9
/
candlesticks_overlay.cpp
66 lines (50 loc) · 1.68 KB
/
candlesticks_overlay.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
#include "candlesticks_overlay.h"
#include <QGraphicsScene>
#include "ohlc_provider.h"
#include "candle.h"
#include <assert.h>
void CandlesticksOverlay::numberAxisChanged(NumberAxis numberAxis) {
axisPair.numberAxis = numberAxis;
}
void CandlesticksOverlay::timeAxisChanged(TimeAxis timeAxis) {
axisPair.timeAxis = timeAxis;
}
void CandlesticksOverlay::rebuild() {
qDebug() << "Rebuilding candles...";
connect(controller, SIGNAL(candleEntered(QDateTime)), this, SLOT(slotCandleEntered(QDateTime)));
connect(controller, SIGNAL(candleLeft()), this, SLOT(slotCandleLeft()));
}
void CandlesticksOverlay::projectionChanged(OHLCProvider* projection) {
this->projection = projection;
}
CandlesticksOverlay::CandlesticksOverlay() {
this->controller = new GraphEventController;
this->controller->setParent(this);
}
void CandlesticksOverlay::insertIntoScene(QGraphicsScene* scene) {
// Populate scene
qDebug() << "Rendering candlestick overlay";
int nitems = 0;
rebuild();
for (QDateTime start = projection->getMinimum();
start < projection->getMaximum();
start = projection->getInterval()->firstAfter(start)) {
OHLC tick;
if (projection->tryGetData(start, tick)) {
QDateTime next = projection->getInterval()->firstAfter(start);
Candle *candle = new Candle(start, next, tick, axisPair, controller);
float x = axisPair.getTimeX(start);
qDebug() << "candle for" << start << "at X=" << x;
candle->setPos(QPointF(x, 0));
scene->addItem(candle);
nitems++;
}
}
qDebug() << "Rendered" << nitems << "candlesticks";
}
void CandlesticksOverlay::slotCandleEntered(QDateTime start) {
emit candleEntered(start);
}
void CandlesticksOverlay::slotCandleLeft() {
emit candleLeft();
}