-
Notifications
You must be signed in to change notification settings - Fork 9
/
mainwindow.cpp
110 lines (86 loc) · 3.05 KB
/
mainwindow.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
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
#include "mainwindow.h"
#include <QHBoxLayout>
#include <QSplitter>
#include <QStatusBar>
#include <QLineEdit>
#include <QInputDialog>
#include <QFileDialog>
#include "ohlc_shrinker.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
view = new View("Top left view");
view->setParent(this);
connect(view, SIGNAL(dataPointHovered(QDateTime, float)), this, SLOT(dataPointHovered(QDateTime, float)));
setCentralWidget(view);
setWindowTitle(tr("TODO titulek"));
createActions();
createMenus();
// loadData();
// doLoadYahooStock("GOOG");
}
void MainWindow::dataPointHovered(QDateTime time, float price) {
QString str = time.toString() + " " + QString::number(price);
statusBar()->showMessage(str);
}
void MainWindow::createActions() {
exitAction = new QAction(tr("Zavrit"), this);
exitAction->setStatusTip(tr("Zavrit program"));
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
loadYahooStockAction = new QAction(tr("Nahrat akcie z Yahoo"), this);
connect(loadYahooStockAction, SIGNAL(triggered()), this, SLOT(loadYahooStock()));
exportImageAction = new QAction(tr("Exportovat obrazek"), this);
connect(exportImageAction, SIGNAL(triggered()), this, SLOT(exportImage()));
}
void MainWindow::createMenus() {
fileMenu = menuBar()->addMenu(tr("Soubor"));
fileMenu->addAction(loadYahooStockAction);
fileMenu->addAction(exportImageAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
}
void MainWindow::exportImage() {
QString filename = QFileDialog::getSaveFileName(this, tr("Exportovat obrázek"), "image.png", tr("Obrázky (*.png *.gif *.bmp)"));
if (filename.isNull()) {
qDebug() << "no file entered";
return;
}
// TODO: scene must exist
QImage image(view->getViewportWidth(), view->getViewportHeight(), QImage::Format_RGB16);
image.fill(Qt::white);
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);
view->getMainScene()->render(&painter);
image.save(filename);
statusBar()->showMessage("Graf byl exportovan.");
}
void MainWindow::doLoadYahooStock(QString symbol) {
source = new OHLCMemoryProvider(QDateTime(QDate(2007, 11, 1)), QDateTime(QDate(2009, 12, 22)), new CI::Day);// Day);
source->setParent(this);
// TODO: fuj!!!
yl = new YahooLoader(symbol, YahooLoader::DAY, source);
yl->setParent(this);
// TODO: handle errors and so on
qDebug() << "Connecting signals";
connect(yl, SIGNAL(dataLoaded()), this, SLOT(drawData()));
qDebug() << "Starting to load data";
yl->load();
qDebug() << "Data started to load";
}
void MainWindow::drawData() {
statusBar()->showMessage("Data byla nahrana.");
// view->changeDataSource(new OHLCShrinker(source, source->getMinimum(), source->getMaximum(), new CI::Month));
view->changeDataSource(source);
}
void MainWindow::loadYahooStock() {
// TODO: hezci dialog?
bool ok;
QString text = QInputDialog::getText(this, tr("Zadej symbol"), tr("Symbol:"), QLineEdit::Normal, "ADSK", &ok);
if (ok) {
if (text.size() > 0) {
doLoadYahooStock(text);
} else {
qDebug() << "nic nezadano...";
}
} else {
qDebug() << "uzivatel nic nezadal...";
}
}