-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
198 lines (164 loc) · 5.56 KB
/
Copy pathmainwindow.cpp
File metadata and controls
198 lines (164 loc) · 5.56 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
void MainWindow::__intit()
{
cout << this << "Initializing...";
__mSQL = new SQLInterpreter(ui->SourcePathDisplay->text(), ui->DestinationPathDisplay->text(), ui->Text1, this);
if(__mSQL->isOk) loadOnList();
__setState(true);
}
void MainWindow::__setState(const bool src) noexcept
{
ui->Button1->setEnabled(src);
ui->Button2->setEnabled(src);
ui->Text1->setEnabled(src);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
__setState(false);
// a.show();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_Button4_clicked()
{
//Open Dialog and get path
QString path = QFileDialog::getOpenFileName(this, "Open list", "/home/raidg", "Text Files (*.txt)");
//If path is NULL QString return and set path as not setted
if(path != QString())
{
//We changing path, so let's recreate engine again
if(__mSQL != nullptr)
{
__setState(false);
__mSQL->disconnect();
delete __mSQL;
__mSQL = nullptr;
}
//Testing is everythink good with this file
std::ifstream * tempInput = new std::ifstream(path.toStdString());
//If yes put it on screen
if(tempInput->good()) ui->SourcePathDisplay->setText(path);
else
{
QMessageBox a(QMessageBox::Icon::Critical, "Błąd Pliku", "Brak Możliwości Otworzenia");
a.show();
a.exec();
return;
}
tempInput->close();
//Securing pointer
delete tempInput;
tempInput = nullptr;
//If everythink is set let's init
if(ui->SourcePathDisplay->text() != "" && ui->DestinationPathDisplay->text() != "") __intit();
}else
{
ui->SourcePathDisplay->setText("");
return;
}
}
void MainWindow::loadOnList()
{
cout << this << "loadOnList activated";
ui->List1->clear();
ui->List1->addItem("'::0' -> [val1, val2 ...]");
for(int i = 1; i < __mSQL->howManyColumns()+1 ;i++)
ui->List1->addItem(QString("'::" + QString(i>9 ? "x" : "") + QString::number(i) + "' -> '" + (*__mSQL)["::"+QString(i>9 ? "x" : "")+ QString::number(i)] + "'"));
}
void MainWindow::on_Button5_clicked()
{
//Open Dialog and get path
QString path = QFileDialog::getOpenFileName(this, "Open destination", "/home/raidg", "All Files (*.*)");
//If path is NULL QString return and set path as not setted
if(path != QString())
{
//We changing path, so let's create engine again
if(__mSQL != nullptr)
{
__setState(false);
__mSQL->disconnect();
delete __mSQL;
__mSQL = nullptr;
}
//Testing is everythink good with this file
std::ofstream * tempOutput = new std::ofstream(path.toStdString());
//If yes put it on screen
if(tempOutput->good()) ui->DestinationPathDisplay->setText(path);
else
{
QMessageBox a(QMessageBox::Icon::Critical, "Błąd Pliku", "Brak Możliwości Otworzenia");
a.show();
a.exec();
return;
}
tempOutput->close();
//Securing pointer
delete tempOutput;
tempOutput = nullptr;
//If everythink is set let's init
if(ui->SourcePathDisplay->text() != "" && ui->DestinationPathDisplay->text() != "") __intit();
}else
{
ui->DestinationPathDisplay->setText("");
return;
}
}
void MainWindow::on_Button2_clicked()
{
if(__mSQL == nullptr) return;
QMessageBox msg(QMessageBox::Icon::Information, "Example Query", __mSQL->example(), QMessageBox::Button::Close);
msg.show();
//msg.topLevelWidget();
msg.exec();
}
void MainWindow::on_List1_itemDoubleClicked(QListWidgetItem *item)
{
QString temp = item->text();
temp.resize(4);
temp.remove(0,1);
qDebug() << this << " Resize effect: "<<temp;
ui->Text1->append(temp);
}
void MainWindow::on_Button1_clicked()
{
if(__mSQL == nullptr) return;
__mSQL->save();
a.show();
a.showMessage("Zakończono", "Pomyślnie Zakończono Generowanie Kodu SQL.", QSystemTrayIcon::Information, 3500);
a.hide();
//a.deleteLater();
}
void MainWindow::on_Button3_clicked()
{
QString msg =
QString("0) If you want nice place to generate data go to: generatedata.com and after you decide what data you like, select 'Export as CSV' and reformat file like instruction says further\n") +
QString("\n1) First import *.txt file that is formatted like this:\n\n ")+
QString("\t;colName1;colName2;colName3;\n")+
QString("\ta1;a2;a3;\n")+
QString("\tb1;b2;b3;\n")+
QString("\t...\n")+
QString("\tz1;z2;z3;\n")+
QString("\t!END\n\n")+
QString("2) Select file to insert result. It will be recreated, so current data on that file will be lost\n")+
QString("\n3) Now you can write your SQL querry. Wherever you want to insert data from imnported file, write '::x', where x is column number for example:\n\n")+
QString("\tDELETE FROM 'tableName' WHERE colName='::1'\n\n")+
QString("Gives result like this:\n\n")+
QString("\tDELETE FROM 'tableName' WHERE colName='a1'\n\n")+
QString("If you type '::0' all values will be inserted there in format:\n\n") +
QString("\t\t'a1', 'a2', a3'\n\n")+
QString("So it's perfect for INSERT INTO usage for example:\n\n\t 'INSERT INTO 'tableName' VALUES(::0);' \n") +
QString("\n4) When you press example you will see how it will look like, based on first data line from your file\n") +
QString("\n5) If you are sure that everythink is correct just click 'Generate' button, and when job is done popup will show\n")+
QString("\n6) If you want to correct query, just correct it in text box and press again 'Generate' button. File will be overrided\n") +
QString("\n\nPROTIP: If you doubleclick on item in list box, it will enter propor identifer in the querty");
QMessageBox a(QMessageBox::Icon::Information, "Help", msg, QMessageBox::StandardButton::Close);
a.show();
a.exec();
}