-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
175 lines (142 loc) · 4.56 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
storage = new Storage();
this->updateWindowTitle();
ui->textEdit->setReadOnly(1);
scene = new MyScene(storage);
ui->graphicsView->setScene(scene);
ui->masterKeyLabel->setText("Введите связи между атрибутами для отображения ключа универсального отношения.");
this->show();
NewDialog *wd = new NewDialog(this, this, storage);
wd->show();
connect(storage, SIGNAL(loopedMatrix()), this, SLOT(loopedMatrix()));
}
MainWindow::~MainWindow()
{
delete ui;
delete storage;
}
void MainWindow::showOutput()
{
QString outText;
ui->textEdit->setHtml(storage->getOutputText(outText));
scene->fillScene();
}
void MainWindow::saveFile()
{
QFile file(filePath);
file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << version << *(storage->getAttrTable())
<< *(storage->getVMatrix()) << *(storage->getUniTable()) << storage->getdbName();
}
void MainWindow::reset()
{
scene->clear();
storage->clear();
ui->textEdit->clear();
ui->masterKeyLabel->setText("Введите связи между атрибутами для отображения ключа универсального отношения.");
}
void MainWindow::updateSuperKeyLabel()
{
ui->masterKeyLabel->setText(storage->getSuperKeyString());
}
void MainWindow::on_addAttrButton_clicked()
{
Attribute *wa = new Attribute(this, storage);
wa->show();
}
void MainWindow::on_addConButton_clicked()
{
Connection *wc = new Connection(this, storage);
wc->show();
}
void MainWindow::on_normButton_clicked()
{
loopedMatirxFlag = false;
storage->startNormalization();
if (loopedMatirxFlag) return;
else
this->showOutput();
}
void MainWindow::on_pushButton_clicked()
{
exit(EXIT_SUCCESS);
}
void MainWindow::on_actionSave_File_triggered()
{
saveFile();
qDebug() << filePath << "saved.";
}
void MainWindow::on_actionOpen_File_triggered()
{
filePath = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("Files (*.dbp)"));
QFile file(filePath);
file.open(QIODevice::ReadOnly);
QDataStream in(&file);
QString outVersion;
QVector<QVector<QString> > outAttrTable;
QVector<QVector<int> > outVMatrix;
QVector<QVector<QString> > outUniTable;
QString outdbName;
in >> outVersion >> outAttrTable >> outVMatrix >> outUniTable >> outdbName;
if (outVersion != version && outVersion != "0.85") {
qDebug() << "Разные версии";
//QMessageBox::information(this, tr("Ошибка"), tr("Выбран некорректный файл."));
return;
}
storage->setAttrTable(outAttrTable);
storage->setVMatrix(outVMatrix);
storage->setUniTable(outUniTable);
storage->setdbName(outdbName);
qDebug() << filePath << "opened.";
if (storage->getAttrTable()->isEmpty() || storage->getVMatrix()->isEmpty()) return;
on_normButton_clicked();
updateSuperKeyLabel();
updateWindowTitle();
}
void MainWindow::on_actionSave_ass_triggered()
{
filePath = QFileDialog::getSaveFileName(this, tr("Save file"), "untitled.dbp", tr("DB prom files (*.dbp)"));
saveFile();
qDebug() << filePath << "saved ass...";
}
void MainWindow::updateWindowTitle()
{
QString title = storage->getdbName() + tr(" [DB prom]") + " v" + version + " " + filePath;
this->setWindowTitle(title);
}
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::about(this, tr("О программе..."), tr("Программа нормализации реляционных баз данных. 2014. Масленников Роман. E-mail: m3angreen@gmail.com"));
}
void MainWindow::on_actionExit_triggered()
{
exit(EXIT_SUCCESS);
}
void MainWindow::on_uniRelButton_clicked()
{
UniversalRelationTable *wu = new UniversalRelationTable(this, storage);
wu->show();
}
void MainWindow::on_action_triggered()
{
DBnameDialog *wdb = new DBnameDialog(this, storage);
wdb->show();
}
void MainWindow::on_actionNew_data_base_scheme_triggered()
{
auto result = QMessageBox::question(this, "Внимание", tr("Все не сохраненные данные будут потеряны. Продолжить?"));
if ( result == QMessageBox::No) return;
NewDialog *wd = new NewDialog(this, this, storage);
wd->show();
}
void MainWindow::loopedMatrix()
{
loopedMatirxFlag = true;
}