-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.cpp
132 lines (114 loc) · 4.59 KB
/
controller.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "controller.h"
Controller::Controller(QObject *parent) : QObject{parent} {}
void Controller::setModel(Model *_model) { model = _model; }
void Controller::setMainWindow(MainWindow *_mainwindow) { mainwindow = _mainwindow; }
void Controller::open() const
{
QString path = QFileDialog::getOpenFileName(mainwindow,
tr("Open json graph file"), "",
tr("Json file (*.json);;All Files (*)"));
model->readJson(path.toStdString());
mainwindow->setTableView();
if(mainwindow->getChart()){ mainwindow->drawChart(mainwindow->getChart()); }
}
Model *Controller::getModel() const { return model; }
void Controller::newChart() const
{
QString rowLabel = QInputDialog::getText(mainwindow, "Insert", "Row label:", QLineEdit::Normal);
QString columnLabel = QInputDialog::getText(mainwindow, "Insert", "Column label:", QLineEdit::Normal);
model->newModel(rowLabel.toStdString(), columnLabel.toStdString());
mainwindow->setTableView();
if(mainwindow->getChart()){ mainwindow->drawChart(mainwindow->getChart()); }
};
void Controller::saveAsPdf() const
{
auto chart = mainwindow->getChartView();
QPrinter printer(QPrinter::HighResolution);
QString path = QFileDialog::getSaveFileName(mainwindow,
tr("Pdf file"), "",
tr("Pdf file (*.pdf)"));
printer.setOutputFileName(path);
printer.setPageMargins(QMarginsF(0, 0, 0, 0));
QPainter painter;
painter.begin(&printer);
double xscale = printer.pageLayout().fullRectPixels(printer.resolution()).width() / double(chart->width());
double yscale = printer.pageLayout().fullRectPixels(printer.resolution()).height() / double(chart->height());
double scale = qMin(xscale, yscale);
painter.scale(scale, scale);
chart->render(&painter);
}
void Controller::saveAsImage() const
{
QWidget *widget = mainwindow->getChartView();
QPixmap pic = widget->grab(QRect(QPoint(10, 10), QSize(widget->width(), widget->height())));
widget->render(&pic);
QString path = QFileDialog::getSaveFileName(mainwindow,
tr("Png image"), "",
tr("Png image (*.png)"));
pic.save(path);
}
void Controller::save() const
{
QString path = QFileDialog::getSaveFileName(mainwindow,
tr("Json graph file"), "",
tr("Json file (*.json);;All Files (*)"));
model->writeJson(path.toStdString());
};
void Controller::addColumnB()
{
QString label = QInputDialog::getText(mainwindow, "Insert", "Column label:", QLineEdit::Normal);
if (!label.isEmpty())
{
model->insertColumn(mainwindow->getSelectedColumn(), label.toStdString());
mainwindow->setTableView();
if(mainwindow->getChart()){ mainwindow->drawChart(mainwindow->getChart()); }
}
};
void Controller::addColumnA()
{
QString label = QInputDialog::getText(mainwindow, "Insert", "Column label:", QLineEdit::Normal);
if (!label.isEmpty())
{
model->insertColumn(mainwindow->getSelectedColumn() + 1, label.toStdString());
mainwindow->setTableView();
if(mainwindow->getChart()){ mainwindow->drawChart(mainwindow->getChart()); }
}
};
void Controller::addRowB()
{
QString label = QInputDialog::getText(mainwindow, "Insert", "Row label:", QLineEdit::Normal);
if (!label.isEmpty())
{
model->insertRow(mainwindow->getSelectedRow(), label.toStdString());
mainwindow->setTableView();
if(mainwindow->getChart()){ mainwindow->drawChart(mainwindow->getChart()); }
}
}
void Controller::addRowA()
{
QString label = QInputDialog::getText(mainwindow, "Insert", "Row label:", QLineEdit::Normal);
if (!label.isEmpty())
{
model->insertRow(mainwindow->getSelectedRow() + 1, label.toStdString());
mainwindow->setTableView();
if(mainwindow->getChart()){ mainwindow->drawChart(mainwindow->getChart()); }
}
}
void Controller::removeColumn()
{
model->removeColumn(mainwindow->getSelectedColumn());
mainwindow->setTableView();
if(mainwindow->getChart()){ mainwindow->drawChart(mainwindow->getChart()); }
}
void Controller::removeRow()
{
model->removeRow(mainwindow->getSelectedRow());
mainwindow->setTableView();
if(mainwindow->getChart()){ mainwindow->drawChart(mainwindow->getChart()); }
}
void Controller::init()
{
mainwindow->setTableView();
mainwindow->show();
new InitWindow(this);
}