@@ -36,6 +36,8 @@ MainWindow::MainWindow(QWidget *parent)
3636 {
3737 qDebug () << this ->db .lastError ().text ();
3838 }
39+
40+ this ->fill_personal_area ();
3941 this ->ui ->screen_stacked ->setCurrentIndex ((int )screen::personal_area);
4042 }
4143}
@@ -98,6 +100,7 @@ void MainWindow::slotReadyRead()
98100 this ->ui ->screen_stacked ->setCurrentIndex ((int )screen::personal_area);
99101 this ->create_db ();
100102 this ->fill_db_login (doc.FirstChildElement (" body" ));
103+ this ->fill_personal_area ();
101104 }
102105 else
103106 {
@@ -112,6 +115,11 @@ void MainWindow::slotReadyRead()
112115 {
113116 this ->ui ->screen_stacked ->setCurrentIndex ((int )screen::personal_area);
114117 this ->create_db ();
118+ this ->fill_db_register ();
119+ this ->fill_personal_area ();
120+
121+ this ->base64_file = " " ;
122+ this ->file_type = " " ;
115123 }
116124 else
117125 {
@@ -200,7 +208,7 @@ void MainWindow::create_db()
200208 " name VARCHAR(45) NOT NULL UNIQUE, "
201209 " description TEXT NOT NULL, "
202210 " code TEXT NOT NULL, "
203- " path_to_image VARCHAR(45 ) NOT NULL); " );
211+ " path_to_image VARCHAR(256 ) NOT NULL); " );
204212 query.exec (" CREATE TABLE Pattern_test ( "
205213 " id_pattern INTEGER NOT NULL, "
206214 " question TEXT NOT NULL, "
@@ -213,10 +221,10 @@ void MainWindow::create_db()
213221 query.exec (" CREATE TABLE User ( "
214222 " login VARCHAR(45) NOT NULL UNIQUE, "
215223 " password VARCHAR(45) NOT NULL UNIQUE, "
216- " path_to_image VARCHAR(45 ) NOT NULL UNIQUE); " );
224+ " path_to_image VARCHAR(256 ) NOT NULL UNIQUE);" );
217225 query.exec (" CREATE TABLE User_test ( "
218226 " pattern VARCHAR(45) NOT NULL UNIQUE, "
219- " count_corrent INTEGER NOT NULL); " );
227+ " count_corrent INTEGER NOT NULL); " );
220228}
221229
222230void MainWindow::fill_db_login (tinyxml2::XMLElement *body)
@@ -247,11 +255,23 @@ void MainWindow::fill_db_login(tinyxml2::XMLElement *body)
247255 }
248256}
249257
258+ void MainWindow::fill_db_register ()
259+ {
260+ QString login {this ->ui ->reg_login ->text ()};
261+ QString password {this ->ui ->reg_pas ->text ()};
262+ // qDebug() << "in reg: " + this->file_type;
263+ QString path_to_image {QDir::currentPath () + " /images/user." + this ->file_type };
264+
265+ this ->save_img_to_file (path_to_image, this ->base64_file );
266+
267+ QSqlQuery insert;
268+ insert.exec (" INSERT INTO User (login, password, path_to_image) VALUES ('" + login + " ', '" + password + " ', '" + path_to_image + " ')" );
269+ }
270+
250271void MainWindow::save_img_to_file (const QString &path, const QString &img)
251272{
252273 std::ofstream tmp_file (path.toUtf8 ());
253274 tmp_file.close ();
254- qDebug () << path;
255275
256276 std::ofstream file (path.toUtf8 (), std::ios::out | std::ios::binary);
257277 auto data{ base64_decode (img.toStdString ()) };
@@ -262,6 +282,50 @@ void MainWindow::save_img_to_file(const QString &path, const QString &img)
262282 file.close ();
263283}
264284
285+ void MainWindow::fill_personal_area ()
286+ {
287+ user_info_t info{this ->get_user_info ()};
288+
289+ this ->pic = QPixmap ();
290+ this ->pic .load (info.path_to_image );
291+
292+ // this->pic = this->pic.scaled(QSize(256,256), Qt::AspectRatioMode(), Qt::SmoothTransformation);
293+ this ->ui ->img_profile ->setPixmap (this ->pic );
294+ this ->ui ->show_login ->setText (" Логин: " + info.login );
295+ }
296+
297+ user_info_t MainWindow::get_user_info ()
298+ {
299+ QSqlQuery query;
300+ query.exec (" SELECT login, password, path_to_image FROM User" );
301+ QString login;
302+ QString path_to_file;
303+ QString password;
304+ while (query.next ())
305+ {
306+ login = query.value (0 ).toString ();
307+ password = query.value (1 ).toString ();
308+ path_to_file = query.value (2 ).toString ();
309+ }
310+
311+ return {login, password, path_to_file};
312+ }
313+
314+ std::vector<result_test_t > MainWindow::get_result_test_info ()
315+ {
316+ std::vector<result_test_t > res;
317+ QSqlQuery query;
318+ query.exec (" SELECT pattern, count_corrent FROM User_test" );
319+ while (query.next ())
320+ {
321+ result_test_t tmp;
322+ tmp.name = query.value (0 ).toString ();
323+ tmp.result = query.value (1 ).toString ();
324+ res.push_back (std::move (tmp));
325+ }
326+ return res;
327+ }
328+
265329void MainWindow::on_to_register_clicked ()
266330{
267331 this ->ui ->screen_stacked ->setCurrentIndex ((int )screen::registration);
@@ -309,12 +373,7 @@ void MainWindow::on_register_2_clicked()
309373 tinyxml2::XMLPrinter printer;
310374 doc.Print (&printer);
311375
312- // qDebug() << printer.CStr();
313-
314376 this ->send (printer.CStr ());
315-
316- this ->base64_file = " " ;
317- this ->file_type = " " ;
318377}
319378
320379void MainWindow::on_reg_img_clicked ()
@@ -330,3 +389,34 @@ void MainWindow::on_reg_img_clicked()
330389 this ->base64_file = base64_encode (data).c_str ();
331390 this ->file_type = fileName.split (" ." ).back ();
332391}
392+
393+ void MainWindow::on_quit_clicked ()
394+ {
395+ this ->socket .reset (new QTcpSocket ());
396+ socket->connectToHost (this ->host , this ->port );
397+ connect (socket.get (), SIGNAL (connected ()), SLOT (slotConnected ()));
398+ connect (socket.get (), SIGNAL (readyRead ()), SLOT (slotReadyRead ()));
399+ connect (socket.get (), SIGNAL (errorOccurred (QAbstractSocket::SocketError)), this , SLOT (slotError (QAbstractSocket::SocketError)));
400+
401+ this ->ui ->screen_stacked ->setCurrentIndex ((int )screen::login);
402+ this ->forward = type_forward::login;
403+
404+ this ->db .close ();
405+ QFile::remove (QDir::currentPath () + " /main.db" );
406+ QDir image_dir (QDir::currentPath () + " /images" );
407+ image_dir.removeRecursively ();
408+ QDir dir (QDir::currentPath ());
409+ dir.mkdir (" images" );
410+ this ->ui ->login_2 ->setEnabled (false );
411+ this ->ui ->register_2 ->setEnabled (false );
412+ }
413+
414+ void MainWindow::on_to_result_test_clicked ()
415+ {
416+ this ->ui ->screen_stacked ->setCurrentIndex ((int )screen::result_test);
417+ }
418+
419+ void MainWindow::on_to_personal_area_clicked ()
420+ {
421+ this ->ui ->screen_stacked ->setCurrentIndex ((int )screen::personal_area);
422+ }
0 commit comments