/
mainwindow.cpp
102 lines (75 loc) · 2.16 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
#include <QToolBar>
#include <QAction>
#include <QHBoxLayout>
#include <QFileDialog>
#include <QMessageBox>
#include <qwt_plot_renderer.h>
#include "mainwindow.h"
#include "graf.h"
#include "panel.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
Settings settings;
settings.s_plot.Xfrom = 0;
settings.s_plot.Xto = 500;
settings.s_plot.Yfrom = 0;
settings.s_plot.Yto = 500;
settings.s_plot.x_name = "X";
settings.s_plot.y_name = "Y";
d_panel = new Panel();
d_panel->setSettings(settings);
QWidget *w = new QWidget( this );
graf = new Graf();
QHBoxLayout *hLayout = new QHBoxLayout( w );
hLayout->addWidget( d_panel );
hLayout->addWidget( graf, 10 );
setCentralWidget( w );
updatePlot();
connect( d_panel, SIGNAL( edited() ), SLOT( updatePlot() ) );
createAction();
createToolBar();
}
MainWindow::~MainWindow()
{
delete graf;
}
void MainWindow::createToolBar()
{
fileToolBar = addToolBar( tr( " &File" ) ) ;
fileToolBar->addAction(exportAction) ;
fileToolBar->addAction(openFile);
}
void MainWindow::createAction()
{
exportAction = new QAction( "&Export", this );
exportAction->setIcon(QIcon(":/images/pdf.png"));
connect(exportAction, SIGNAL(triggered(bool) ), this, SLOT(exportPlot() ) );
openFile = new QAction("&Open File", this );
openFile->setIcon(QIcon(":/images/file2.png"));
connect(openFile, SIGNAL(triggered() ), this, SLOT(open()) );
}
void MainWindow::updatePlot()
{
graf->applySettings( d_panel->settings() );
}
void MainWindow::exportPlot()
{
QwtPlotRenderer renderer;
renderer.exportTo(graf, "Graph.pdf");
}
void MainWindow::open(){
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Graph"));
if (!fileName.isEmpty())
loadFile(fileName);
}
bool MainWindow::loadFile(const QString &fileName){
if (!graf->setGrafData(fileName)) {
QMessageBox::warning(this, tr("Graph"),
tr("Loading canceled"),
QMessageBox::Ok);
return false;
}
return true;
}