mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 16:23:11 +02:00
feat: define connections login.cpp
This commit is contained in:
parent
71e838a1be
commit
69712a3838
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -22,19 +22,17 @@ QT_BEGIN_MOC_NAMESPACE
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
struct qt_meta_stringdata_login_t {
|
||||
const uint offsetsAndSize[6];
|
||||
char stringdata0[30];
|
||||
const uint offsetsAndSize[2];
|
||||
char stringdata0[6];
|
||||
};
|
||||
#define QT_MOC_LITERAL(ofs, len) \
|
||||
uint(offsetof(qt_meta_stringdata_login_t, stringdata0) + ofs), len
|
||||
static const qt_meta_stringdata_login_t qt_meta_stringdata_login = {
|
||||
{
|
||||
QT_MOC_LITERAL(0, 5), // "login"
|
||||
QT_MOC_LITERAL(6, 22), // "on_loginButton_clicked"
|
||||
QT_MOC_LITERAL(29, 0) // ""
|
||||
QT_MOC_LITERAL(0, 5) // "login"
|
||||
|
||||
},
|
||||
"login\0on_loginButton_clicked\0"
|
||||
"login"
|
||||
};
|
||||
#undef QT_MOC_LITERAL
|
||||
|
||||
@ -44,32 +42,21 @@ static const uint qt_meta_data_login[] = {
|
||||
10, // revision
|
||||
0, // classname
|
||||
0, 0, // classinfo
|
||||
1, 14, // methods
|
||||
0, 0, // methods
|
||||
0, 0, // properties
|
||||
0, 0, // enums/sets
|
||||
0, 0, // constructors
|
||||
0, // flags
|
||||
0, // signalCount
|
||||
|
||||
// slots: name, argc, parameters, tag, flags, initial metatype offsets
|
||||
1, 0, 20, 2, 0x08, 1 /* Private */,
|
||||
|
||||
// slots: parameters
|
||||
QMetaType::Void,
|
||||
|
||||
0 // eod
|
||||
};
|
||||
|
||||
void login::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
auto *_t = static_cast<login *>(_o);
|
||||
(void)_t;
|
||||
switch (_id) {
|
||||
case 0: _t->on_loginButton_clicked(); break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
(void)_o;
|
||||
(void)_id;
|
||||
(void)_c;
|
||||
(void)_a;
|
||||
}
|
||||
|
||||
@ -81,7 +68,7 @@ const QMetaObject login::staticMetaObject = { {
|
||||
nullptr,
|
||||
qt_incomplete_metaTypeArray<qt_meta_stringdata_login_t
|
||||
, QtPrivate::TypeAndForceComplete<login, std::true_type>
|
||||
, QtPrivate::TypeAndForceComplete<void, std::false_type>
|
||||
|
||||
|
||||
|
||||
>,
|
||||
@ -105,17 +92,6 @@ void *login::qt_metacast(const char *_clname)
|
||||
int login::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
_id = QMainWindow::qt_metacall(_c, _id, _a);
|
||||
if (_id < 0)
|
||||
return _id;
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
if (_id < 1)
|
||||
qt_static_metacall(this, _c, _id, _a);
|
||||
_id -= 1;
|
||||
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
|
||||
if (_id < 1)
|
||||
*reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();
|
||||
_id -= 1;
|
||||
}
|
||||
return _id;
|
||||
}
|
||||
QT_WARNING_POP
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -33,6 +33,7 @@ public:
|
||||
QLabel *label_3;
|
||||
QLineEdit *inputPassword;
|
||||
QPushButton *loginButton;
|
||||
QPushButton *registerButton;
|
||||
QMenuBar *menubar;
|
||||
QStatusBar *statusbar;
|
||||
|
||||
@ -76,6 +77,11 @@ public:
|
||||
|
||||
formLayout->setWidget(5, QFormLayout::SpanningRole, loginButton);
|
||||
|
||||
registerButton = new QPushButton(centralwidget);
|
||||
registerButton->setObjectName(QString::fromUtf8("registerButton"));
|
||||
|
||||
formLayout->setWidget(6, QFormLayout::SpanningRole, registerButton);
|
||||
|
||||
login->setCentralWidget(centralwidget);
|
||||
menubar = new QMenuBar(login);
|
||||
menubar->setObjectName(QString::fromUtf8("menubar"));
|
||||
@ -97,6 +103,7 @@ public:
|
||||
label_2->setText(QCoreApplication::translate("login", "<html><head/><body><p align=\"center\"><span style=\" font-size:36pt;\">ID</span></p></body></html>", nullptr));
|
||||
label_3->setText(QCoreApplication::translate("login", "<html><head/><body><p align=\"center\"><span style=\" font-size:36pt;\">Password</span></p></body></html>", nullptr));
|
||||
loginButton->setText(QCoreApplication::translate("login", "Login", nullptr));
|
||||
registerButton->setText(QCoreApplication::translate("login", "Register", nullptr));
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
||||
@ -90,7 +90,7 @@ void blogsView::on_actionCreate_new_Blog_entry_triggered()
|
||||
createNewBlogEntry();
|
||||
}
|
||||
|
||||
void blogsView::exit()
|
||||
void blogsView::exit()
|
||||
{
|
||||
QApplication::quit();
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#include "login.h"
|
||||
#include "ui_login.h"
|
||||
#include "blogsview.h"
|
||||
#include "mainwindow.h"
|
||||
#include "universalFunctions.h"
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <iostream>
|
||||
@ -13,6 +15,7 @@ login::login(QWidget *parent) :
|
||||
ui(new Ui::login)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
defineConnections();
|
||||
}
|
||||
|
||||
login::~login()
|
||||
@ -20,6 +23,28 @@ login::~login()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void login::defineConnections() const
|
||||
{
|
||||
connect(ui -> loginButton, &QPushButton::clicked, this, &login::loginUser);
|
||||
connect(ui -> registerButton, &QPushButton::clicked, this, &login::goRegister);
|
||||
connect(ui -> actionExit, &QAction::triggered, this, &login::exit);
|
||||
connect(ui -> actionLogin, &QAction::triggered, this, &login::loginUser);
|
||||
connect(ui -> actionRegister, &QAction::triggered, this, &login::goRegister);
|
||||
}
|
||||
|
||||
void login::exit() const
|
||||
{
|
||||
QApplication::quit();
|
||||
}
|
||||
|
||||
|
||||
void login::goRegister()
|
||||
{
|
||||
MainWindow *r = new MainWindow();
|
||||
r -> show();
|
||||
hide();
|
||||
}
|
||||
|
||||
void login::thisIDDoesNotExist()
|
||||
{
|
||||
QMessageBox idNotExisting;
|
||||
@ -45,8 +70,10 @@ void login::loginSuccessful(const QString &id, const QString &blogId)
|
||||
}
|
||||
|
||||
|
||||
void login::loginUser(QJsonObject &users, QJsonObject &blogs)
|
||||
void login::loginUser()
|
||||
{
|
||||
QJsonObject users = readJsonFile("user.json");
|
||||
QJsonObject blogs = readJsonFile("blogs.json");
|
||||
QString id = ui->inputLoginID_2->text();
|
||||
if(users.find(id) != users.end())
|
||||
{
|
||||
@ -70,21 +97,3 @@ void login::loginUser(QJsonObject &users, QJsonObject &blogs)
|
||||
}else wrongPassword();
|
||||
}else thisIDDoesNotExist();
|
||||
}
|
||||
|
||||
QJsonObject login::readUserJsonFile(const QString &filename)
|
||||
{
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadWrite);
|
||||
QByteArray bytes = file.readAll();
|
||||
file.close();
|
||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
||||
return document.object();
|
||||
}
|
||||
|
||||
void login::on_loginButton_clicked()
|
||||
{
|
||||
QJsonObject users = readUserJsonFile("user.json");
|
||||
QJsonObject blogs = readUserJsonFile("blogs.json");
|
||||
loginUser(users, blogs);
|
||||
}
|
||||
|
||||
|
||||
@ -15,16 +15,17 @@ public:
|
||||
explicit login(QWidget *parent = nullptr);
|
||||
~login();
|
||||
void thisIDDoesNotExist();
|
||||
void loginUser(QJsonObject &users, QJsonObject &blogs);
|
||||
QJsonObject readUserJsonFile(const QString &filename);
|
||||
void loginUser();
|
||||
void wrongPassword();
|
||||
void loginSuccessful(const QString &id, const QString &blogId);
|
||||
|
||||
|
||||
private slots:
|
||||
void on_loginButton_clicked();
|
||||
|
||||
private:
|
||||
void defineConnections() const;
|
||||
void goRegister();
|
||||
void exit() const;
|
||||
Ui::login *ui;
|
||||
};
|
||||
|
||||
|
||||
@ -53,6 +53,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QPushButton" name="registerButton">
|
||||
<property name="text">
|
||||
<string>Register</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
|
||||
@ -43,8 +43,5 @@ private:
|
||||
void saveFiles(QJsonObject &users, QJsonObject &blogs);
|
||||
QJsonObject insertBlogObject(QJsonObject &blogs, const QString &blogId, const QString &ownerId);
|
||||
Ui::MainWindow *ui; // we point to ui class "mainwindow.ui"
|
||||
QString currentFile = ""; // current file we work with
|
||||
|
||||
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
Loading…
Reference in New Issue
Block a user