-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
93 lines (77 loc) · 2.11 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QFile>
#include <QMessageBox>
#include <QTextStream>
#include <QPainter>
#include <QSettings>
#include "filedatasource.h"
#include "drawables.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
_drawer = new QTDrawer();
_drawer->AddDrawable(std::make_shared<Legend>());
_drawer->AddDrawable(std::make_shared<Axes>());
this->setCentralWidget(_drawer);
}
MainWindow::~MainWindow()
{
delete ui;
}
QColor GenColor(int colorIndex)
{
int h=int(100*colorIndex)%360;
return QColor::fromHsv(h, 255, 255);
}
void MainWindow::on_actionAdd_Graph_triggered()
{
const QString DEFAULT_DIR_KEY("Last ssd dir");
QSettings MySettings;
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), MySettings.value(DEFAULT_DIR_KEY).toString(),
tr("Sample files (*.ssd);;"));
if (!fileName.isEmpty()) {
MySettings.setValue(DEFAULT_DIR_KEY, fileName);
try
{
auto fds = std::make_shared<FileDataSource>(fileName.toStdString());
if(!fds->GetErrInfo().empty())
{
QMessageBox mb;
mb.setText(fds->GetErrInfo().c_str());
mb.exec();
}
auto graph = std::make_shared<Graph>(fds);
graph->SetColor(GenColor(++colorIndex));
_drawer->AddDrawable(graph);
_drawer->ResetLimits();
}
catch(std::exception &e)
{
QMessageBox mb;
mb.setText(e.what());
mb.exec();
}
}
}
void MainWindow::on_actionClear_triggered()
{
_drawer->Clear();
}
void MainWindow::on_actionSave_Image_triggered()
{
QImage img =_drawer->GetImage();
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QString(),
tr("Png image files (*.png);;"));
if (!fileName.isEmpty())
{
img.save(fileName);
}
}
void MainWindow::on_actionRemove_last_added_triggered()
{
_drawer->RemoveLastGraph();
}