Skip to content

Commit fb8132c

Browse files
committed
add description for pattern client
1 parent 38a36d9 commit fb8132c

File tree

3 files changed

+193
-10
lines changed

3 files changed

+193
-10
lines changed

client/mainwindow.cpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ void MainWindow::fill_personal_area()
419419
{
420420
user_info_t info{this->get_user_info()};
421421

422-
this->pic = QPixmap();
423-
this->pic.load(info.path_to_image);
422+
this->profile_pic = QPixmap();
423+
this->profile_pic.load(info.path_to_image);
424424

425-
this->ui->img_profile->setPixmap(this->pic);
425+
this->ui->img_profile->setPixmap(this->profile_pic);
426426
this->ui->show_login->setText("Логин: " + info.login);
427427
}
428428

@@ -464,7 +464,7 @@ void MainWindow::fill_db_patterns(tinyxml2::XMLElement *body)
464464
QString path_to_image {QDir::currentPath() + "/images/" + name + "." + img_type};
465465
this->save_img_to_file(path_to_image, img_64);
466466

467-
QSqlQuery inser("INSERT INTO Pattern (name, description, code, path_to_image)"
467+
QSqlQuery insert("INSERT INTO Pattern (name, description, code, path_to_image)"
468468
" VALUES ('" + name + "', '" + description + "', '" + code + "', '" + path_to_image + "')");
469469

470470

@@ -548,6 +548,8 @@ void MainWindow::fill_patterns_list_form()
548548
this->pattern_btn_more_list.push_back(new QPushButton(this));
549549
this->pattern_btn_more_list[i]->setText("Подробнее");
550550
this->pattern_laoyut_list[i]->addWidget(this->pattern_btn_more_list[i]);
551+
QString lambda{data[i]};
552+
connect(this->pattern_btn_more_list[i], &QPushButton::clicked, [this, lambda] { this->on_more_btn_clicked(lambda); });
551553

552554
this->pattern_btn_test_list.push_back(new QPushButton(this));
553555
this->pattern_btn_test_list[i]->setText("Тест");
@@ -608,6 +610,32 @@ std::vector<QString> MainWindow::get_patterns_name()
608610
return res;
609611
}
610612

613+
pattern_info_t MainWindow::get_pattern_info(QString name)
614+
{
615+
QSqlQuery query;
616+
if (!query.exec("SELECT name, description, code, path_to_image FROM Pattern WHERE name = '" + name + "'"))
617+
qDebug() << "ERROR";
618+
619+
query.next();
620+
621+
return {query.value(0).toString(), query.value(1).toString(), query.value(2).toString(), query.value(3).toString()};
622+
}
623+
624+
void MainWindow::on_more_btn_clicked(QString name)
625+
{
626+
this->ui->screen_stacked->setCurrentIndex((int)screen::more_pattern);
627+
this->ui->name_more->setText("Название: " + name);
628+
629+
pattern_info_t data{this->get_pattern_info(name)};
630+
this->ui->description_more->setText(data.description);
631+
this->ui->code_more->setText(data.code);
632+
633+
this->pattern_pic = QPixmap();
634+
this->pattern_pic.load(data.path_to_image);
635+
636+
this->ui->img_more->setPixmap(this->pattern_pic);
637+
}
638+
611639
void MainWindow::on_to_register_clicked()
612640
{
613641
this->ui->screen_stacked->setCurrentIndex((int)screen::registration);
@@ -730,3 +758,8 @@ void MainWindow::on_update_patterns_clicked()
730758
connect(socket.get(), SIGNAL(readyRead()), SLOT(slotReadyRead()));
731759
connect(socket.get(), SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError)));
732760
}
761+
762+
void MainWindow::on_to_pattern_list_clicked()
763+
{
764+
this->ui->screen_stacked->setCurrentIndex((int)screen::patterns);
765+
}

client/mainwindow.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ struct result_test_t
4141
QString result;
4242
};
4343

44+
struct pattern_info_t
45+
{
46+
QString name;
47+
QString description;
48+
QString code;
49+
QString path_to_image;
50+
};
51+
4452
class MainWindow : public QMainWindow
4553
{
4654
Q_OBJECT
@@ -49,6 +57,8 @@ class MainWindow : public QMainWindow
4957
MainWindow(QWidget *parent = nullptr);
5058
~MainWindow();
5159

60+
void on_more_btn_clicked(QString name);
61+
5262
private slots:
5363
void on_login_2_clicked();
5464

@@ -80,14 +90,17 @@ private slots:
8090

8191
void on_update_patterns_clicked();
8292

93+
void on_to_pattern_list_clicked();
94+
8395
private:
8496
enum class screen
8597
{
8698
login = 0,
8799
registration = 1,
88100
personal_area = 2,
89101
patterns = 3,
90-
result_test = 4
102+
result_test = 4,
103+
more_pattern = 5
91104
};
92105
enum class type_forward
93106
{
@@ -100,7 +113,8 @@ private slots:
100113

101114
Ui::MainWindow *ui;
102115
Popup *popup;
103-
QPixmap pic;
116+
QPixmap profile_pic;
117+
QPixmap pattern_pic;
104118
QSqlDatabase db;
105119
type_forward forward;
106120
QString base64_file;
@@ -147,5 +161,6 @@ private slots:
147161
user_info_t get_user_info();
148162
std::vector<result_test_t> get_result_test_info();
149163
std::vector<QString> get_patterns_name();
164+
pattern_info_t get_pattern_info(QString name);
150165
};
151166
#endif // MAINWINDOW_H

client/mainwindow.ui

Lines changed: 139 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<item>
2323
<widget class="QStackedWidget" name="screen_stacked">
2424
<property name="currentIndex">
25-
<number>3</number>
25+
<number>5</number>
2626
</property>
2727
<widget class="QWidget" name="login">
2828
<layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -453,8 +453,8 @@
453453
<rect>
454454
<x>0</x>
455455
<y>0</y>
456-
<width>254</width>
457-
<height>288</height>
456+
<width>240</width>
457+
<height>20</height>
458458
</rect>
459459
</property>
460460
<layout class="QVBoxLayout" name="verticalLayout_4">
@@ -568,7 +568,7 @@
568568
<rect>
569569
<x>0</x>
570570
<y>0</y>
571-
<width>98</width>
571+
<width>240</width>
572572
<height>395</height>
573573
</rect>
574574
</property>
@@ -678,6 +678,141 @@
678678
</item>
679679
</layout>
680680
</widget>
681+
<widget class="QWidget" name="more_pattern">
682+
<layout class="QVBoxLayout" name="verticalLayout_2">
683+
<item>
684+
<widget class="QScrollArea" name="scrollArea_2">
685+
<property name="widgetResizable">
686+
<bool>true</bool>
687+
</property>
688+
<widget class="QWidget" name="scrollAreaWidgetContents_2">
689+
<property name="geometry">
690+
<rect>
691+
<x>0</x>
692+
<y>-310</y>
693+
<width>438</width>
694+
<height>599</height>
695+
</rect>
696+
</property>
697+
<layout class="QVBoxLayout" name="verticalLayout_5">
698+
<item>
699+
<widget class="QLabel" name="name_more">
700+
<property name="text">
701+
<string>Название: тест</string>
702+
</property>
703+
</widget>
704+
</item>
705+
<item>
706+
<widget class="Line" name="line">
707+
<property name="orientation">
708+
<enum>Qt::Horizontal</enum>
709+
</property>
710+
</widget>
711+
</item>
712+
<item>
713+
<widget class="QLabel" name="description_more_2">
714+
<property name="text">
715+
<string>Описание:</string>
716+
</property>
717+
</widget>
718+
</item>
719+
<item>
720+
<widget class="QLabel" name="description_more">
721+
<property name="text">
722+
<string>Тест</string>
723+
</property>
724+
<property name="wordWrap">
725+
<bool>true</bool>
726+
</property>
727+
</widget>
728+
</item>
729+
<item>
730+
<widget class="Line" name="line_2">
731+
<property name="orientation">
732+
<enum>Qt::Horizontal</enum>
733+
</property>
734+
</widget>
735+
</item>
736+
<item>
737+
<widget class="QLabel" name="label_8">
738+
<property name="text">
739+
<string>Пример кода:</string>
740+
</property>
741+
</widget>
742+
</item>
743+
<item>
744+
<widget class="QTextEdit" name="code_more">
745+
<property name="readOnly">
746+
<bool>true</bool>
747+
</property>
748+
</widget>
749+
</item>
750+
<item>
751+
<widget class="Line" name="line_3">
752+
<property name="orientation">
753+
<enum>Qt::Horizontal</enum>
754+
</property>
755+
</widget>
756+
</item>
757+
<item>
758+
<widget class="QLabel" name="label_9">
759+
<property name="text">
760+
<string>Иллюстрация к Паттерну:</string>
761+
</property>
762+
</widget>
763+
</item>
764+
<item>
765+
<widget class="QLabel" name="img_more">
766+
<property name="maximumSize">
767+
<size>
768+
<width>512</width>
769+
<height>512</height>
770+
</size>
771+
</property>
772+
<property name="text">
773+
<string/>
774+
</property>
775+
<property name="pixmap">
776+
<pixmap resource="res.qrc">:/default.png</pixmap>
777+
</property>
778+
<property name="scaledContents">
779+
<bool>false</bool>
780+
</property>
781+
<property name="alignment">
782+
<set>Qt::AlignCenter</set>
783+
</property>
784+
</widget>
785+
</item>
786+
</layout>
787+
</widget>
788+
</widget>
789+
</item>
790+
<item>
791+
<layout class="QHBoxLayout" name="horizontalLayout_6">
792+
<item>
793+
<spacer name="horizontalSpacer_14">
794+
<property name="orientation">
795+
<enum>Qt::Horizontal</enum>
796+
</property>
797+
<property name="sizeHint" stdset="0">
798+
<size>
799+
<width>40</width>
800+
<height>20</height>
801+
</size>
802+
</property>
803+
</spacer>
804+
</item>
805+
<item>
806+
<widget class="QPushButton" name="to_pattern_list">
807+
<property name="text">
808+
<string>Назад</string>
809+
</property>
810+
</widget>
811+
</item>
812+
</layout>
813+
</item>
814+
</layout>
815+
</widget>
681816
</widget>
682817
</item>
683818
</layout>

0 commit comments

Comments
 (0)