mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-20 21:12:25 +01:00
Fix: blogsviewe now displays entries
This commit is contained in:
parent
69712a3838
commit
c32650ed8c
Binary file not shown.
@ -8,6 +8,11 @@
|
|||||||
"content": "fassfda",
|
"content": "fassfda",
|
||||||
"datetime": "16:29:27 Wed Apr 6 2022",
|
"datetime": "16:29:27 Wed Apr 6 2022",
|
||||||
"title": "saa"
|
"title": "saa"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "aszcdasd",
|
||||||
|
"datetime": "19:31:04 Wed Apr 6 2022",
|
||||||
|
"title": "Title"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"ownerId": "2",
|
"ownerId": "2",
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -22,35 +22,17 @@ QT_BEGIN_MOC_NAMESPACE
|
|||||||
QT_WARNING_PUSH
|
QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_DEPRECATED
|
QT_WARNING_DISABLE_DEPRECATED
|
||||||
struct qt_meta_stringdata_blogEntry_t {
|
struct qt_meta_stringdata_blogEntry_t {
|
||||||
const uint offsetsAndSize[30];
|
const uint offsetsAndSize[2];
|
||||||
char stringdata0[185];
|
char stringdata0[10];
|
||||||
};
|
};
|
||||||
#define QT_MOC_LITERAL(ofs, len) \
|
#define QT_MOC_LITERAL(ofs, len) \
|
||||||
uint(offsetof(qt_meta_stringdata_blogEntry_t, stringdata0) + ofs), len
|
uint(offsetof(qt_meta_stringdata_blogEntry_t, stringdata0) + ofs), len
|
||||||
static const qt_meta_stringdata_blogEntry_t qt_meta_stringdata_blogEntry = {
|
static const qt_meta_stringdata_blogEntry_t qt_meta_stringdata_blogEntry = {
|
||||||
{
|
{
|
||||||
QT_MOC_LITERAL(0, 9), // "blogEntry"
|
QT_MOC_LITERAL(0, 9) // "blogEntry"
|
||||||
QT_MOC_LITERAL(10, 20), // "on_saveEntry_clicked"
|
|
||||||
QT_MOC_LITERAL(31, 0), // ""
|
|
||||||
QT_MOC_LITERAL(32, 9), // "saveEntry"
|
|
||||||
QT_MOC_LITERAL(42, 12), // "readJsonFile"
|
|
||||||
QT_MOC_LITERAL(55, 5), // "title"
|
|
||||||
QT_MOC_LITERAL(61, 12), // "saveJsonFile"
|
|
||||||
QT_MOC_LITERAL(74, 12), // "QJsonObject&"
|
|
||||||
QT_MOC_LITERAL(87, 5), // "users"
|
|
||||||
QT_MOC_LITERAL(93, 4), // "name"
|
|
||||||
QT_MOC_LITERAL(98, 11), // "removeEntry"
|
|
||||||
QT_MOC_LITERAL(110, 21), // "on_pushButton_clicked"
|
|
||||||
QT_MOC_LITERAL(132, 26), // "on_editEntryButton_clicked"
|
|
||||||
QT_MOC_LITERAL(159, 9), // "editEntry"
|
|
||||||
QT_MOC_LITERAL(169, 15) // "saveEditedEntry"
|
|
||||||
|
|
||||||
},
|
},
|
||||||
"blogEntry\0on_saveEntry_clicked\0\0"
|
"blogEntry"
|
||||||
"saveEntry\0readJsonFile\0title\0saveJsonFile\0"
|
|
||||||
"QJsonObject&\0users\0name\0removeEntry\0"
|
|
||||||
"on_pushButton_clicked\0on_editEntryButton_clicked\0"
|
|
||||||
"editEntry\0saveEditedEntry"
|
|
||||||
};
|
};
|
||||||
#undef QT_MOC_LITERAL
|
#undef QT_MOC_LITERAL
|
||||||
|
|
||||||
@ -60,57 +42,22 @@ static const uint qt_meta_data_blogEntry[] = {
|
|||||||
10, // revision
|
10, // revision
|
||||||
0, // classname
|
0, // classname
|
||||||
0, 0, // classinfo
|
0, 0, // classinfo
|
||||||
9, 14, // methods
|
0, 0, // methods
|
||||||
0, 0, // properties
|
0, 0, // properties
|
||||||
0, 0, // enums/sets
|
0, 0, // enums/sets
|
||||||
0, 0, // constructors
|
0, 0, // constructors
|
||||||
0, // flags
|
0, // flags
|
||||||
0, // signalCount
|
0, // signalCount
|
||||||
|
|
||||||
// slots: name, argc, parameters, tag, flags, initial metatype offsets
|
|
||||||
1, 0, 68, 2, 0x08, 1 /* Private */,
|
|
||||||
3, 0, 69, 2, 0x08, 2 /* Private */,
|
|
||||||
4, 1, 70, 2, 0x08, 3 /* Private */,
|
|
||||||
6, 2, 73, 2, 0x108, 5 /* Private | MethodIsConst */,
|
|
||||||
10, 0, 78, 2, 0x08, 8 /* Private */,
|
|
||||||
11, 0, 79, 2, 0x08, 9 /* Private */,
|
|
||||||
12, 0, 80, 2, 0x08, 10 /* Private */,
|
|
||||||
13, 0, 81, 2, 0x08, 11 /* Private */,
|
|
||||||
14, 0, 82, 2, 0x08, 12 /* Private */,
|
|
||||||
|
|
||||||
// slots: parameters
|
|
||||||
QMetaType::Void,
|
|
||||||
QMetaType::Void,
|
|
||||||
QMetaType::QJsonObject, QMetaType::QString, 5,
|
|
||||||
QMetaType::Void, 0x80000000 | 7, QMetaType::QString, 8, 9,
|
|
||||||
QMetaType::Void,
|
|
||||||
QMetaType::Void,
|
|
||||||
QMetaType::Void,
|
|
||||||
QMetaType::Void,
|
|
||||||
QMetaType::Void,
|
|
||||||
|
|
||||||
0 // eod
|
0 // eod
|
||||||
};
|
};
|
||||||
|
|
||||||
void blogEntry::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
void blogEntry::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
||||||
{
|
{
|
||||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
(void)_o;
|
||||||
auto *_t = static_cast<blogEntry *>(_o);
|
(void)_id;
|
||||||
(void)_t;
|
(void)_c;
|
||||||
switch (_id) {
|
(void)_a;
|
||||||
case 0: _t->on_saveEntry_clicked(); break;
|
|
||||||
case 1: _t->saveEntry(); break;
|
|
||||||
case 2: { QJsonObject _r = _t->readJsonFile((*reinterpret_cast< std::add_pointer_t<QString>>(_a[1])));
|
|
||||||
if (_a[0]) *reinterpret_cast< QJsonObject*>(_a[0]) = std::move(_r); } break;
|
|
||||||
case 3: _t->saveJsonFile((*reinterpret_cast< std::add_pointer_t<QJsonObject&>>(_a[1])),(*reinterpret_cast< std::add_pointer_t<QString>>(_a[2]))); break;
|
|
||||||
case 4: _t->removeEntry(); break;
|
|
||||||
case 5: _t->on_pushButton_clicked(); break;
|
|
||||||
case 6: _t->on_editEntryButton_clicked(); break;
|
|
||||||
case 7: _t->editEntry(); break;
|
|
||||||
case 8: _t->saveEditedEntry(); break;
|
|
||||||
default: ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QMetaObject blogEntry::staticMetaObject = { {
|
const QMetaObject blogEntry::staticMetaObject = { {
|
||||||
@ -121,7 +68,7 @@ const QMetaObject blogEntry::staticMetaObject = { {
|
|||||||
nullptr,
|
nullptr,
|
||||||
qt_incomplete_metaTypeArray<qt_meta_stringdata_blogEntry_t
|
qt_incomplete_metaTypeArray<qt_meta_stringdata_blogEntry_t
|
||||||
, QtPrivate::TypeAndForceComplete<blogEntry, std::true_type>
|
, QtPrivate::TypeAndForceComplete<blogEntry, std::true_type>
|
||||||
, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<QJsonObject, std::false_type>, QtPrivate::TypeAndForceComplete<const QString, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<QJsonObject &, std::false_type>, QtPrivate::TypeAndForceComplete<const QString, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>
|
|
||||||
|
|
||||||
|
|
||||||
>,
|
>,
|
||||||
@ -145,17 +92,6 @@ void *blogEntry::qt_metacast(const char *_clname)
|
|||||||
int blogEntry::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
int blogEntry::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||||
{
|
{
|
||||||
_id = QWidget::qt_metacall(_c, _id, _a);
|
_id = QWidget::qt_metacall(_c, _id, _a);
|
||||||
if (_id < 0)
|
|
||||||
return _id;
|
|
||||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
|
||||||
if (_id < 9)
|
|
||||||
qt_static_metacall(this, _c, _id, _a);
|
|
||||||
_id -= 9;
|
|
||||||
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
|
|
||||||
if (_id < 9)
|
|
||||||
*reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();
|
|
||||||
_id -= 9;
|
|
||||||
}
|
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
QT_WARNING_POP
|
QT_WARNING_POP
|
||||||
|
|||||||
Binary file not shown.
@ -22,24 +22,20 @@ QT_BEGIN_MOC_NAMESPACE
|
|||||||
QT_WARNING_PUSH
|
QT_WARNING_PUSH
|
||||||
QT_WARNING_DISABLE_DEPRECATED
|
QT_WARNING_DISABLE_DEPRECATED
|
||||||
struct qt_meta_stringdata_blogsView_t {
|
struct qt_meta_stringdata_blogsView_t {
|
||||||
const uint offsetsAndSize[12];
|
const uint offsetsAndSize[8];
|
||||||
char stringdata0[100];
|
char stringdata0[35];
|
||||||
};
|
};
|
||||||
#define QT_MOC_LITERAL(ofs, len) \
|
#define QT_MOC_LITERAL(ofs, len) \
|
||||||
uint(offsetof(qt_meta_stringdata_blogsView_t, stringdata0) + ofs), len
|
uint(offsetof(qt_meta_stringdata_blogsView_t, stringdata0) + ofs), len
|
||||||
static const qt_meta_stringdata_blogsView_t qt_meta_stringdata_blogsView = {
|
static const qt_meta_stringdata_blogsView_t qt_meta_stringdata_blogsView = {
|
||||||
{
|
{
|
||||||
QT_MOC_LITERAL(0, 9), // "blogsView"
|
QT_MOC_LITERAL(0, 9), // "blogsView"
|
||||||
QT_MOC_LITERAL(10, 40), // "on_actionCreate_new_Blog_entr..."
|
QT_MOC_LITERAL(10, 18), // "displayBlogEntries"
|
||||||
QT_MOC_LITERAL(51, 0), // ""
|
QT_MOC_LITERAL(29, 0), // ""
|
||||||
QT_MOC_LITERAL(52, 18), // "displayBlogEntries"
|
QT_MOC_LITERAL(30, 4) // "exit"
|
||||||
QT_MOC_LITERAL(71, 23), // "on_actionExit_triggered"
|
|
||||||
QT_MOC_LITERAL(95, 4) // "exit"
|
|
||||||
|
|
||||||
},
|
},
|
||||||
"blogsView\0on_actionCreate_new_Blog_entry_triggered\0"
|
"blogsView\0displayBlogEntries\0\0exit"
|
||||||
"\0displayBlogEntries\0on_actionExit_triggered\0"
|
|
||||||
"exit"
|
|
||||||
};
|
};
|
||||||
#undef QT_MOC_LITERAL
|
#undef QT_MOC_LITERAL
|
||||||
|
|
||||||
@ -49,7 +45,7 @@ static const uint qt_meta_data_blogsView[] = {
|
|||||||
10, // revision
|
10, // revision
|
||||||
0, // classname
|
0, // classname
|
||||||
0, 0, // classinfo
|
0, 0, // classinfo
|
||||||
4, 14, // methods
|
2, 14, // methods
|
||||||
0, 0, // properties
|
0, 0, // properties
|
||||||
0, 0, // enums/sets
|
0, 0, // enums/sets
|
||||||
0, 0, // constructors
|
0, 0, // constructors
|
||||||
@ -57,14 +53,10 @@ static const uint qt_meta_data_blogsView[] = {
|
|||||||
0, // signalCount
|
0, // signalCount
|
||||||
|
|
||||||
// slots: name, argc, parameters, tag, flags, initial metatype offsets
|
// slots: name, argc, parameters, tag, flags, initial metatype offsets
|
||||||
1, 0, 38, 2, 0x08, 1 /* Private */,
|
1, 0, 26, 2, 0x08, 1 /* Private */,
|
||||||
3, 0, 39, 2, 0x08, 2 /* Private */,
|
3, 0, 27, 2, 0x08, 2 /* Private */,
|
||||||
4, 0, 40, 2, 0x08, 3 /* Private */,
|
|
||||||
5, 0, 41, 2, 0x08, 4 /* Private */,
|
|
||||||
|
|
||||||
// slots: parameters
|
// slots: parameters
|
||||||
QMetaType::Void,
|
|
||||||
QMetaType::Void,
|
|
||||||
QMetaType::Void,
|
QMetaType::Void,
|
||||||
QMetaType::Void,
|
QMetaType::Void,
|
||||||
|
|
||||||
@ -77,10 +69,8 @@ void blogsView::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, v
|
|||||||
auto *_t = static_cast<blogsView *>(_o);
|
auto *_t = static_cast<blogsView *>(_o);
|
||||||
(void)_t;
|
(void)_t;
|
||||||
switch (_id) {
|
switch (_id) {
|
||||||
case 0: _t->on_actionCreate_new_Blog_entry_triggered(); break;
|
case 0: _t->displayBlogEntries(); break;
|
||||||
case 1: _t->displayBlogEntries(); break;
|
case 1: _t->exit(); break;
|
||||||
case 2: _t->on_actionExit_triggered(); break;
|
|
||||||
case 3: _t->exit(); break;
|
|
||||||
default: ;
|
default: ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +85,7 @@ const QMetaObject blogsView::staticMetaObject = { {
|
|||||||
nullptr,
|
nullptr,
|
||||||
qt_incomplete_metaTypeArray<qt_meta_stringdata_blogsView_t
|
qt_incomplete_metaTypeArray<qt_meta_stringdata_blogsView_t
|
||||||
, QtPrivate::TypeAndForceComplete<blogsView, std::true_type>
|
, QtPrivate::TypeAndForceComplete<blogsView, std::true_type>
|
||||||
, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>
|
, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>
|
||||||
|
|
||||||
|
|
||||||
>,
|
>,
|
||||||
@ -122,13 +112,13 @@ int blogsView::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
|||||||
if (_id < 0)
|
if (_id < 0)
|
||||||
return _id;
|
return _id;
|
||||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||||
if (_id < 4)
|
if (_id < 2)
|
||||||
qt_static_metacall(this, _c, _id, _a);
|
qt_static_metacall(this, _c, _id, _a);
|
||||||
_id -= 4;
|
_id -= 2;
|
||||||
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
|
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
|
||||||
if (_id < 4)
|
if (_id < 2)
|
||||||
*reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();
|
*reinterpret_cast<QMetaType *>(_a[0]) = QMetaType();
|
||||||
_id -= 4;
|
_id -= 2;
|
||||||
}
|
}
|
||||||
return _id;
|
return _id;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@ -10,11 +10,13 @@
|
|||||||
#define UI_LOGIN_H
|
#define UI_LOGIN_H
|
||||||
|
|
||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
|
#include <QtGui/QAction>
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
#include <QtWidgets/QFormLayout>
|
#include <QtWidgets/QFormLayout>
|
||||||
#include <QtWidgets/QLabel>
|
#include <QtWidgets/QLabel>
|
||||||
#include <QtWidgets/QLineEdit>
|
#include <QtWidgets/QLineEdit>
|
||||||
#include <QtWidgets/QMainWindow>
|
#include <QtWidgets/QMainWindow>
|
||||||
|
#include <QtWidgets/QMenu>
|
||||||
#include <QtWidgets/QMenuBar>
|
#include <QtWidgets/QMenuBar>
|
||||||
#include <QtWidgets/QPushButton>
|
#include <QtWidgets/QPushButton>
|
||||||
#include <QtWidgets/QStatusBar>
|
#include <QtWidgets/QStatusBar>
|
||||||
@ -25,6 +27,9 @@ QT_BEGIN_NAMESPACE
|
|||||||
class Ui_login
|
class Ui_login
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
QAction *actionExit;
|
||||||
|
QAction *actionLogin;
|
||||||
|
QAction *actionRegister;
|
||||||
QWidget *centralwidget;
|
QWidget *centralwidget;
|
||||||
QFormLayout *formLayout;
|
QFormLayout *formLayout;
|
||||||
QLabel *label;
|
QLabel *label;
|
||||||
@ -35,6 +40,7 @@ public:
|
|||||||
QPushButton *loginButton;
|
QPushButton *loginButton;
|
||||||
QPushButton *registerButton;
|
QPushButton *registerButton;
|
||||||
QMenuBar *menubar;
|
QMenuBar *menubar;
|
||||||
|
QMenu *menuApp;
|
||||||
QStatusBar *statusbar;
|
QStatusBar *statusbar;
|
||||||
|
|
||||||
void setupUi(QMainWindow *login)
|
void setupUi(QMainWindow *login)
|
||||||
@ -42,6 +48,12 @@ public:
|
|||||||
if (login->objectName().isEmpty())
|
if (login->objectName().isEmpty())
|
||||||
login->setObjectName(QString::fromUtf8("login"));
|
login->setObjectName(QString::fromUtf8("login"));
|
||||||
login->resize(800, 600);
|
login->resize(800, 600);
|
||||||
|
actionExit = new QAction(login);
|
||||||
|
actionExit->setObjectName(QString::fromUtf8("actionExit"));
|
||||||
|
actionLogin = new QAction(login);
|
||||||
|
actionLogin->setObjectName(QString::fromUtf8("actionLogin"));
|
||||||
|
actionRegister = new QAction(login);
|
||||||
|
actionRegister->setObjectName(QString::fromUtf8("actionRegister"));
|
||||||
centralwidget = new QWidget(login);
|
centralwidget = new QWidget(login);
|
||||||
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
|
centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
|
||||||
formLayout = new QFormLayout(centralwidget);
|
formLayout = new QFormLayout(centralwidget);
|
||||||
@ -86,11 +98,18 @@ public:
|
|||||||
menubar = new QMenuBar(login);
|
menubar = new QMenuBar(login);
|
||||||
menubar->setObjectName(QString::fromUtf8("menubar"));
|
menubar->setObjectName(QString::fromUtf8("menubar"));
|
||||||
menubar->setGeometry(QRect(0, 0, 800, 19));
|
menubar->setGeometry(QRect(0, 0, 800, 19));
|
||||||
|
menuApp = new QMenu(menubar);
|
||||||
|
menuApp->setObjectName(QString::fromUtf8("menuApp"));
|
||||||
login->setMenuBar(menubar);
|
login->setMenuBar(menubar);
|
||||||
statusbar = new QStatusBar(login);
|
statusbar = new QStatusBar(login);
|
||||||
statusbar->setObjectName(QString::fromUtf8("statusbar"));
|
statusbar->setObjectName(QString::fromUtf8("statusbar"));
|
||||||
login->setStatusBar(statusbar);
|
login->setStatusBar(statusbar);
|
||||||
|
|
||||||
|
menubar->addAction(menuApp->menuAction());
|
||||||
|
menuApp->addAction(actionExit);
|
||||||
|
menuApp->addAction(actionLogin);
|
||||||
|
menuApp->addAction(actionRegister);
|
||||||
|
|
||||||
retranslateUi(login);
|
retranslateUi(login);
|
||||||
|
|
||||||
QMetaObject::connectSlotsByName(login);
|
QMetaObject::connectSlotsByName(login);
|
||||||
@ -99,11 +118,15 @@ public:
|
|||||||
void retranslateUi(QMainWindow *login)
|
void retranslateUi(QMainWindow *login)
|
||||||
{
|
{
|
||||||
login->setWindowTitle(QCoreApplication::translate("login", "MainWindow", nullptr));
|
login->setWindowTitle(QCoreApplication::translate("login", "MainWindow", nullptr));
|
||||||
|
actionExit->setText(QCoreApplication::translate("login", "Exit", nullptr));
|
||||||
|
actionLogin->setText(QCoreApplication::translate("login", "Login", nullptr));
|
||||||
|
actionRegister->setText(QCoreApplication::translate("login", "Register", nullptr));
|
||||||
label->setText(QCoreApplication::translate("login", "<html><head/><body><p align=\"center\"><span style=\" font-size:72pt;\">Login</span></p></body></html>", nullptr));
|
label->setText(QCoreApplication::translate("login", "<html><head/><body><p align=\"center\"><span style=\" font-size:72pt;\">Login</span></p></body></html>", nullptr));
|
||||||
label_2->setText(QCoreApplication::translate("login", "<html><head/><body><p align=\"center\"><span style=\" font-size:36pt;\">ID</span></p></body></html>", nullptr));
|
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));
|
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));
|
loginButton->setText(QCoreApplication::translate("login", "Login", nullptr));
|
||||||
registerButton->setText(QCoreApplication::translate("login", "Register", nullptr));
|
registerButton->setText(QCoreApplication::translate("login", "Register", nullptr));
|
||||||
|
menuApp->setTitle(QCoreApplication::translate("login", "App", nullptr));
|
||||||
} // retranslateUi
|
} // retranslateUi
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Binary file not shown.
@ -1,5 +1,6 @@
|
|||||||
#include "blogentry.h"
|
#include "blogentry.h"
|
||||||
#include "ui_blogentry.h"
|
#include "ui_blogentry.h"
|
||||||
|
#include "universalFunctions.h"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -13,21 +14,44 @@ blogEntry::blogEntry(QWidget *parent) :
|
|||||||
editMode = false;
|
editMode = false;
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui -> editEntryButton -> setDisabled(true);
|
ui -> editEntryButton -> setDisabled(true);
|
||||||
|
defineConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
void blogEntry::setUpBlogEntryFromJson(const QJsonObject entry)
|
|
||||||
|
void blogEntry::disableEdition()
|
||||||
{
|
{
|
||||||
dateTime = entry["datetime"].toString();
|
ui -> textEdit -> setReadOnly(true);
|
||||||
ui -> lineEdit-> setText(entry["title"].toString());
|
ui -> lineEdit -> setReadOnly(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void blogEntry::enableEdition()
|
||||||
|
{
|
||||||
|
ui -> textEdit -> setReadOnly(false);
|
||||||
|
ui -> lineEdit -> setReadOnly(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void blogEntry::defineConnections() const
|
||||||
|
{
|
||||||
|
connect(ui -> pushButton, &QPushButton::clicked, this, &blogEntry::removeEntry);
|
||||||
|
connect(ui -> editEntryButton, &QPushButton::clicked, this, &blogEntry::editEntryClicked);
|
||||||
|
connect(ui -> saveEntry, &QPushButton::clicked, this, &blogEntry::saveEntryMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
void blogEntry::fillEntry(const QJsonObject &entry)
|
||||||
|
{
|
||||||
|
ui -> lineEdit -> setText(entry["title"].toString());
|
||||||
ui -> textEdit -> setText(entry["content"].toString());
|
ui -> textEdit -> setText(entry["content"].toString());
|
||||||
ui -> dateTime -> setText(entry["datetime"].toString());
|
ui -> dateTime -> setText(entry["datetime"].toString());
|
||||||
ui -> ownerID -> setText("Owner ID: " + userId);
|
ui -> ownerID -> setText("Owner ID: " + userId);
|
||||||
ui -> textEdit -> setReadOnly(true);
|
}
|
||||||
ui -> lineEdit -> setReadOnly(true);
|
|
||||||
ui -> saveEntry -> setDisabled(true);
|
|
||||||
ui -> editEntryButton -> setDisabled(false);
|
|
||||||
|
|
||||||
|
void blogEntry::setUpBlogEntryFromJson(const QJsonObject &entry)
|
||||||
|
{
|
||||||
|
dateTime = entry["datetime"].toString();
|
||||||
|
fillEntry(entry);
|
||||||
|
disableEdition();
|
||||||
|
enableEditing();
|
||||||
}
|
}
|
||||||
|
|
||||||
blogEntry::~blogEntry()
|
blogEntry::~blogEntry()
|
||||||
@ -47,113 +71,98 @@ void blogEntry::setBlogId(const QString &blogId)
|
|||||||
this->blogId = blogId;
|
this->blogId = blogId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonObject blogEntry::setDateTime(QJsonObject &entry)
|
||||||
QJsonObject blogEntry::readJsonFile(const QString title)
|
|
||||||
{
|
{
|
||||||
QFile file(title);
|
|
||||||
file.open( QIODevice::ReadWrite);
|
|
||||||
QByteArray bytes = file.readAll();
|
|
||||||
file.close();
|
|
||||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
|
||||||
return document.object();
|
|
||||||
}
|
|
||||||
|
|
||||||
void blogEntry::saveJsonFile(QJsonObject &users, const QString name) const
|
|
||||||
{
|
|
||||||
QFile jsonFile(name);
|
|
||||||
QJsonDocument document;
|
|
||||||
document.setObject( users );
|
|
||||||
QByteArray bytes = document.toJson( QJsonDocument::Indented );
|
|
||||||
jsonFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate );
|
|
||||||
QTextStream iStream( &jsonFile );
|
|
||||||
// iStream.setCodec( "utf-8" );
|
|
||||||
iStream << bytes;
|
|
||||||
jsonFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void blogEntry::saveEntry()
|
|
||||||
{
|
|
||||||
|
|
||||||
ui -> textEdit -> setReadOnly(true);
|
|
||||||
ui -> lineEdit -> setReadOnly(true);
|
|
||||||
QJsonObject blogsFile = readJsonFile("blogs.json");
|
|
||||||
QJsonObject blogEntryJson = blogsFile[blogId].toObject();
|
|
||||||
QJsonObject entry;
|
|
||||||
entry["title"] = ui -> lineEdit -> text();
|
|
||||||
QString Time = QTime::currentTime().toString();
|
QString Time = QTime::currentTime().toString();
|
||||||
QString Date = QDate::currentDate().toString();
|
QString Date = QDate::currentDate().toString();
|
||||||
entry["datetime"] = Time + " " + Date;
|
entry["datetime"] = Time + " " + Date;
|
||||||
dateTime = Time + " " + Date;
|
dateTime = Time + " " + Date;
|
||||||
ui -> dateTime -> setText( Time + " " + Date);
|
ui -> dateTime -> setText( Time + " " + Date);
|
||||||
entry["content"] = ui -> textEdit -> toPlainText();
|
return entry;
|
||||||
QJsonArray items = blogEntryJson["items"].toArray();
|
}
|
||||||
items.append(entry);
|
|
||||||
blogEntryJson.insert("items", items);
|
void blogEntry::enableEditing()
|
||||||
blogsFile.insert(blogId, blogEntryJson);
|
{
|
||||||
saveJsonFile(blogsFile, "blogs.json");
|
|
||||||
ui -> saveEntry -> setDisabled(true);
|
ui -> saveEntry -> setDisabled(true);
|
||||||
ui -> editEntryButton -> setDisabled(false);
|
ui -> editEntryButton -> setDisabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject blogEntry::setEntry()
|
||||||
|
{
|
||||||
|
QJsonObject entry;
|
||||||
|
entry["title"] = ui -> lineEdit -> text();
|
||||||
|
|
||||||
|
entry = setDateTime(entry);
|
||||||
|
|
||||||
|
entry["content"] = ui -> textEdit -> toPlainText();
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
void blogEntry::saveEntryMethod()
|
||||||
|
{
|
||||||
|
disableEdition();
|
||||||
|
|
||||||
|
QJsonObject blogsFile = readJsonFile("blogs.json");
|
||||||
|
QJsonObject blogEntryJson = blogsFile[blogId].toObject();
|
||||||
|
QJsonObject entry = setEntry();
|
||||||
|
|
||||||
|
QJsonArray items = blogEntryJson["items"].toArray();
|
||||||
|
items.append(entry);
|
||||||
|
saveItemToBlogEntryToBlogsFile(items, blogEntryJson, blogsFile);
|
||||||
|
enableEditing();
|
||||||
|
}
|
||||||
|
|
||||||
|
int blogEntry::findEntry(const QJsonArray &items)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for(i = 0; i < items.size(); i++)
|
||||||
|
{
|
||||||
|
QJsonObject currentItem = items[i].toObject();
|
||||||
|
if(currentItem["datetime"].toString() == dateTime)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonArray blogEntry::removeEntryFromArray(const QJsonObject &blogEntryJson)
|
||||||
|
{
|
||||||
|
|
||||||
|
QJsonArray items = blogEntryJson["items"].toArray();
|
||||||
|
int entryI = findEntry(items);
|
||||||
|
if(entryI == -1)
|
||||||
|
{
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
items.removeAt(entryI);
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
void blogEntry::removeEntry()
|
void blogEntry::removeEntry()
|
||||||
{
|
{
|
||||||
QJsonObject blogsFile = readJsonFile("blogs.json");
|
QJsonObject blogsFile = readJsonFile("blogs.json");
|
||||||
QJsonObject blogEntryJson = blogsFile[blogId].toObject();
|
QJsonObject blogEntryJson = blogsFile[blogId].toObject();
|
||||||
QJsonArray items = blogEntryJson["items"].toArray();
|
QJsonArray items = removeEntryFromArray(blogEntryJson);
|
||||||
for(int i = 0; i < items.size(); i++)
|
saveItemToBlogEntryToBlogsFile(items, blogEntryJson, blogsFile);
|
||||||
{
|
|
||||||
QJsonObject currentItem = items[i].toObject();
|
|
||||||
qDebug() << currentItem["datetime"].toString();
|
|
||||||
qDebug() << ui -> dateTime -> text();
|
|
||||||
if(currentItem["datetime"].toString() == dateTime)
|
|
||||||
{
|
|
||||||
items.removeAt(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
blogEntryJson.insert("items", items);
|
|
||||||
blogsFile.insert(blogId, blogEntryJson);
|
|
||||||
saveJsonFile(blogsFile, "blogs.json");
|
|
||||||
this -> ~blogEntry();
|
this -> ~blogEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
void blogEntry::editEntry()
|
void blogEntry::editEntry()
|
||||||
{
|
{
|
||||||
editMode = true;
|
editMode = true;
|
||||||
ui -> textEdit -> setReadOnly(false);
|
enableEdition();
|
||||||
ui -> lineEdit -> setReadOnly(false);
|
|
||||||
ui -> saveEntry -> setDisabled(true);
|
ui -> saveEntry -> setDisabled(true);
|
||||||
ui -> editEntryButton -> setText("Save edit");
|
ui -> editEntryButton -> setText("Save edit");
|
||||||
}
|
}
|
||||||
|
|
||||||
void blogEntry::on_saveEntry_clicked()
|
QJsonArray blogEntry::addEdit(const QJsonObject &blogEntryJson)
|
||||||
{
|
{
|
||||||
saveEntry();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void blogEntry::on_pushButton_clicked()
|
|
||||||
{
|
|
||||||
removeEntry();
|
|
||||||
}
|
|
||||||
|
|
||||||
void blogEntry::saveEditedEntry()
|
|
||||||
{
|
|
||||||
ui -> textEdit -> setReadOnly(true);
|
|
||||||
ui -> lineEdit -> setReadOnly(true);
|
|
||||||
editMode = false;
|
|
||||||
ui -> editEntryButton -> setText("Edit Entry");
|
|
||||||
QJsonObject blogsFile = readJsonFile("blogs.json");
|
|
||||||
QJsonObject blogEntryJson = blogsFile[blogId].toObject();
|
|
||||||
QJsonArray items = blogEntryJson["items"].toArray();
|
QJsonArray items = blogEntryJson["items"].toArray();
|
||||||
|
|
||||||
for(int i = 0; i < items.size(); i++)
|
for(int i = 0; i < items.size(); i++)
|
||||||
{
|
{
|
||||||
QJsonObject currentItem = items[i].toObject();
|
QJsonObject currentItem = items[i].toObject();
|
||||||
qDebug() << currentItem["datetime"].toString();
|
|
||||||
qDebug() << ui -> dateTime -> text();
|
|
||||||
if(currentItem["datetime"].toString() == dateTime)
|
if(currentItem["datetime"].toString() == dateTime)
|
||||||
{
|
{
|
||||||
currentItem["title"] = ui -> lineEdit -> text();
|
currentItem["title"] = ui -> lineEdit -> text();
|
||||||
@ -163,13 +172,34 @@ void blogEntry::saveEditedEntry()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
void blogEntry::saveItemToBlogEntryToBlogsFile(QJsonArray &items, QJsonObject &blogEntryJson, QJsonObject &blogsFile)
|
||||||
|
{
|
||||||
blogEntryJson.insert("items", items);
|
blogEntryJson.insert("items", items);
|
||||||
blogsFile.insert(blogId, blogEntryJson);
|
blogsFile.insert(blogId, blogEntryJson);
|
||||||
saveJsonFile(blogsFile, "blogs.json");
|
saveJsonFile(blogsFile, "blogs.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
void blogEntry::on_editEntryButton_clicked()
|
void blogEntry::saveEntry(QJsonObject &blogEntryJson, QJsonObject &blogsFile)
|
||||||
|
{
|
||||||
|
QJsonArray items = addEdit(blogEntryJson);
|
||||||
|
saveItemToBlogEntryToBlogsFile(items, blogEntryJson, blogsFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void blogEntry::saveEditedEntry()
|
||||||
|
{
|
||||||
|
disableEdition();
|
||||||
|
editMode = false;
|
||||||
|
ui -> editEntryButton -> setText("Edit Entry");
|
||||||
|
QJsonObject blogsFile = readJsonFile("blogs.json");
|
||||||
|
QJsonObject blogEntryJson = blogsFile[blogId].toObject();
|
||||||
|
saveEntry(blogEntryJson, blogsFile);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void blogEntry::editEntryClicked()
|
||||||
{
|
{
|
||||||
if(!editMode) editEntry();
|
if(!editMode) editEntry();
|
||||||
else saveEditedEntry();
|
else saveEditedEntry();
|
||||||
|
|||||||
@ -19,22 +19,34 @@ public:
|
|||||||
~blogEntry();
|
~blogEntry();
|
||||||
void setUserId(const QString &userId);
|
void setUserId(const QString &userId);
|
||||||
void setBlogId(const QString &blogId);
|
void setBlogId(const QString &blogId);
|
||||||
void setUpBlogEntryFromJson(const QJsonObject entry);
|
void setUpBlogEntryFromJson(const QJsonObject &entry);
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_saveEntry_clicked();
|
|
||||||
void saveEntry();
|
|
||||||
QJsonObject readJsonFile(const QString title);
|
|
||||||
void saveJsonFile(QJsonObject &users, const QString name) const;
|
|
||||||
void removeEntry();
|
|
||||||
void on_pushButton_clicked();
|
|
||||||
|
|
||||||
void on_editEntryButton_clicked();
|
|
||||||
void editEntry();
|
|
||||||
void saveEditedEntry();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void removeEntry();
|
||||||
|
void enableEdition();
|
||||||
|
void disableEdition();
|
||||||
|
void saveEntryMethod();
|
||||||
|
void enableEditing();
|
||||||
|
void editEntry();
|
||||||
|
void saveEditedEntry();
|
||||||
|
void defineConnections() const;
|
||||||
|
void editEntryClicked();
|
||||||
|
void saveEntry(QJsonObject &blogEntryJson, QJsonObject &blogsFile);
|
||||||
|
void saveItemToBlogEntryToBlogsFile(QJsonArray &items, QJsonObject &blogEntryJson, QJsonObject &blogsFile);
|
||||||
|
void fillEntry(const QJsonObject &entry);
|
||||||
|
|
||||||
|
int findEntry(const QJsonArray &items);
|
||||||
|
|
||||||
|
QJsonArray removeEntryFromArray(const QJsonObject &blogEntryJson);
|
||||||
|
QJsonArray addEdit(const QJsonObject &blogEntryJson);
|
||||||
|
QJsonArray getItemsList();
|
||||||
|
|
||||||
|
QJsonObject setDateTime(QJsonObject &entry);
|
||||||
|
QJsonObject setEntry();
|
||||||
|
|
||||||
Ui::blogEntry *ui;
|
Ui::blogEntry *ui;
|
||||||
QString userId;
|
QString userId;
|
||||||
QString blogId;
|
QString blogId;
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
|
#include "universalFunctions.h"
|
||||||
#include "blogsview.h"
|
#include "blogsview.h"
|
||||||
#include "ui_blogsview.h"
|
#include "ui_blogsview.h"
|
||||||
#include "blogentry.h"
|
#include "blogentry.h"
|
||||||
#include "ui_blogentry.h"
|
#include "ui_blogentry.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -13,7 +15,13 @@ blogsView::blogsView(QWidget *parent) :
|
|||||||
ui(new Ui::blogsView)
|
ui(new Ui::blogsView)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
displayBlogEntries();
|
defineConnections();
|
||||||
|
}
|
||||||
|
|
||||||
|
void blogsView::defineConnections() const
|
||||||
|
{
|
||||||
|
connect(ui -> actionCreate_new_Blog_entry, &QAction::triggered, this, &blogsView::createNewBlogEntry);
|
||||||
|
connect(ui -> actionExit, &QAction::triggered, this, &blogsView::exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
blogsView::~blogsView()
|
blogsView::~blogsView()
|
||||||
@ -28,51 +36,41 @@ void blogsView::setUserId(const QString &userId)
|
|||||||
|
|
||||||
void blogsView::setBlogId(const QString &blogId)
|
void blogsView::setBlogId(const QString &blogId)
|
||||||
{
|
{
|
||||||
|
qDebug() << "blog id before set: " << blogId;
|
||||||
this->blogId = blogId;
|
this->blogId = blogId;
|
||||||
|
qDebug() << "blog id after set: " << this->blogId;
|
||||||
|
displayBlogEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject blogsView::readJsonFile(const QString title)
|
|
||||||
{
|
|
||||||
QFile file(title);
|
|
||||||
file.open(QIODevice::ReadWrite);
|
|
||||||
QByteArray bytes = file.readAll();
|
|
||||||
file.close();
|
|
||||||
QJsonDocument document = QJsonDocument::fromJson( bytes );
|
|
||||||
return document.object();
|
|
||||||
}
|
|
||||||
|
|
||||||
void blogsView::saveJsonFile(QJsonObject &users, const QString name) const
|
|
||||||
{
|
|
||||||
QFile jsonFile(name);
|
|
||||||
QJsonDocument document;
|
|
||||||
document.setObject( users );
|
|
||||||
QByteArray bytes = document.toJson( QJsonDocument::Indented );
|
|
||||||
jsonFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate );
|
|
||||||
QTextStream iStream( &jsonFile );
|
|
||||||
// iStream.setCodec( "utf-8" );
|
|
||||||
iStream << bytes;
|
|
||||||
jsonFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void blogsView::createNewBlogEntry()
|
void blogsView::createNewBlogEntry()
|
||||||
{
|
{
|
||||||
QJsonObject blogsFile = readJsonFile("blogs.json");
|
|
||||||
QJsonObject blogEntryJson;
|
|
||||||
blogEntryJson["title"];
|
|
||||||
blogEntryJson["datetime"];
|
|
||||||
blogEntryJson["content"];
|
|
||||||
qDebug() << "blogsView id: " << userId;
|
|
||||||
blogEntry *e = new blogEntry();
|
blogEntry *e = new blogEntry();
|
||||||
e -> setUserId(userId);
|
e -> setUserId(userId);
|
||||||
e -> setBlogId(blogId);
|
e -> setBlogId(blogId);
|
||||||
ui -> blogsLayout -> addWidget(e);
|
ui -> blogsLayout -> addWidget(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void blogsView::displayBlogEntriesLoop(const QJsonArray &blogEntries)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < blogEntries.size(); i++)
|
||||||
|
{
|
||||||
|
QJsonObject entry = (blogEntries.at(i)).toObject();
|
||||||
|
blogEntry *e = new blogEntry();
|
||||||
|
e -> setUserId(userId);
|
||||||
|
e -> setUpBlogEntryFromJson(entry);
|
||||||
|
ui -> blogsLayout -> addWidget(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void blogsView::displayBlogEntries()
|
void blogsView::displayBlogEntries()
|
||||||
{
|
{
|
||||||
QJsonObject blogsFile = readJsonFile("blogs.json");
|
QJsonObject blogsFile = readJsonFile("blogs.json");
|
||||||
QJsonObject userBlog = blogsFile[blogId].toObject();
|
QJsonObject userBlog = blogsFile[blogId].toObject();
|
||||||
|
qDebug() << blogId;
|
||||||
|
qDebug() << userBlog["blogId"].toString();
|
||||||
QJsonArray blogEntries = userBlog["items"].toArray();
|
QJsonArray blogEntries = userBlog["items"].toArray();
|
||||||
|
qDebug() << blogEntries.size();
|
||||||
for(int i = 0; i < blogEntries.size(); i++)
|
for(int i = 0; i < blogEntries.size(); i++)
|
||||||
{
|
{
|
||||||
QJsonObject entry = (blogEntries.at(i)).toObject();
|
QJsonObject entry = (blogEntries.at(i)).toObject();
|
||||||
@ -82,12 +80,6 @@ void blogsView::displayBlogEntries()
|
|||||||
ui -> blogsLayout -> addWidget(e);
|
ui -> blogsLayout -> addWidget(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void blogsView::on_actionCreate_new_Blog_entry_triggered()
|
|
||||||
{
|
|
||||||
createNewBlogEntry();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void blogsView::exit()
|
void blogsView::exit()
|
||||||
@ -95,8 +87,4 @@ void blogsView::on_actionCreate_new_Blog_entry_triggered()
|
|||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void blogsView::on_actionExit_triggered()
|
|
||||||
{
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class blogsView;
|
class blogsView;
|
||||||
}
|
}
|
||||||
@ -14,21 +15,17 @@ class blogsView : public QMainWindow
|
|||||||
public:
|
public:
|
||||||
explicit blogsView(QWidget *parent = nullptr);
|
explicit blogsView(QWidget *parent = nullptr);
|
||||||
~blogsView();
|
~blogsView();
|
||||||
void createNewBlogEntry();
|
|
||||||
void setUserId(const QString &userId);
|
void setUserId(const QString &userId);
|
||||||
QJsonObject readJsonFile(const QString title);
|
|
||||||
void saveJsonFile(QJsonObject &users, const QString name) const;
|
|
||||||
void setBlogId(const QString &blogId);
|
void setBlogId(const QString &blogId);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_actionCreate_new_Blog_entry_triggered();
|
|
||||||
void displayBlogEntries();
|
void displayBlogEntries();
|
||||||
|
void exit();
|
||||||
|
|
||||||
void on_actionExit_triggered();
|
|
||||||
void exit();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void defineConnections() const;
|
||||||
|
void displayBlogEntriesLoop(const QJsonArray &blogEntries);
|
||||||
|
void createNewBlogEntry();
|
||||||
Ui::blogsView *ui;
|
Ui::blogsView *ui;
|
||||||
QString userId;
|
QString userId;
|
||||||
QString blogId;
|
QString blogId;
|
||||||
|
|||||||
@ -45,23 +45,9 @@ void login::goRegister()
|
|||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void login::thisIDDoesNotExist()
|
|
||||||
{
|
|
||||||
QMessageBox idNotExisting;
|
|
||||||
idNotExisting.setText("THIS ID DOES NOT EXIST!");
|
|
||||||
idNotExisting.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
void login::wrongPassword()
|
|
||||||
{
|
|
||||||
QMessageBox wrongPassword;
|
|
||||||
wrongPassword.setText("WRONG PASSWORD!");
|
|
||||||
wrongPassword.exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
void login::loginSuccessful(const QString &id, const QString &blogId)
|
void login::loginSuccessful(const QString &id, const QString &blogId)
|
||||||
{
|
{
|
||||||
qDebug() << "login id: " << id;
|
qDebug() << "blog id: " << blogId;
|
||||||
blogsView *b = new blogsView();
|
blogsView *b = new blogsView();
|
||||||
b -> setUserId(id);
|
b -> setUserId(id);
|
||||||
b -> setBlogId(blogId);
|
b -> setBlogId(blogId);
|
||||||
@ -69,31 +55,37 @@ void login::loginSuccessful(const QString &id, const QString &blogId)
|
|||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString login::findCurrentBlogId(const QJsonObject &blogs, const QString &id)
|
||||||
|
{
|
||||||
|
QString currentBlogId = "";
|
||||||
|
QStringList keys = blogs.keys();
|
||||||
|
for(int i = 0; i < keys.size(); i++)
|
||||||
|
{
|
||||||
|
QJsonObject currentBlog = blogs[keys.at(i)].toObject();
|
||||||
|
if(currentBlog["ownerId"] == id)
|
||||||
|
{
|
||||||
|
currentBlogId = (currentBlog.take("blogId")).toString();
|
||||||
|
return currentBlogId;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void login::loginUser()
|
void login::loginUser()
|
||||||
{
|
{
|
||||||
QJsonObject users = readJsonFile("user.json");
|
QJsonObject users = readJsonFile("user.json");
|
||||||
QJsonObject blogs = readJsonFile("blogs.json");
|
QJsonObject blogs = readJsonFile("blogs.json");
|
||||||
|
|
||||||
QString id = ui->inputLoginID_2->text();
|
QString id = ui->inputLoginID_2->text();
|
||||||
if(users.find(id) != users.end())
|
if (!idExists(id, users, "THIS USER ID DOES NOT EXIST!", false)) return;
|
||||||
{
|
QString enteredPassword = ui->inputPassword->text();
|
||||||
QJsonValue user = users.take(id);
|
if (!sameString(enteredPassword, "password", users, "WRONG PASSWORD!")) return;
|
||||||
QString enteredPassword = ui->inputPassword->text();
|
|
||||||
QString currentBlogId;
|
|
||||||
if (user["password"] == enteredPassword)
|
QString currentBlogId = findCurrentBlogId(blogs, id);
|
||||||
{
|
if (stringEmpty(currentBlogId, "COULD NOT FOUND BLOG ID FOR THIS LOGIN \n SOMETHING WENT TERRIBLY WRONG WITH JSON FILE!")) return;
|
||||||
QStringList keys = blogs.keys();
|
|
||||||
for(int i = 0; i <= keys.size(); i++)
|
loginSuccessful(id, currentBlogId);
|
||||||
{
|
|
||||||
QJsonObject currentBlog = blogs[keys.at(i)].toObject();
|
|
||||||
if(currentBlog["ownerId"] == id)
|
|
||||||
{
|
|
||||||
currentBlogId = (currentBlog.take("blogId")).toString();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qDebug() << "Current blog id: " << currentBlogId;
|
|
||||||
loginSuccessful(id, currentBlogId);
|
|
||||||
}else wrongPassword();
|
|
||||||
}else thisIDDoesNotExist();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,18 +14,16 @@ class login : public QMainWindow
|
|||||||
public:
|
public:
|
||||||
explicit login(QWidget *parent = nullptr);
|
explicit login(QWidget *parent = nullptr);
|
||||||
~login();
|
~login();
|
||||||
void thisIDDoesNotExist();
|
|
||||||
void loginUser();
|
|
||||||
void wrongPassword();
|
|
||||||
void loginSuccessful(const QString &id, const QString &blogId);
|
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void loginUser();
|
||||||
|
void loginSuccessful(const QString &id, const QString &blogId);
|
||||||
void defineConnections() const;
|
void defineConnections() const;
|
||||||
void goRegister();
|
void goRegister();
|
||||||
void exit() const;
|
void exit() const;
|
||||||
|
QString findCurrentBlogId(const QJsonObject &blogs, const QString &id);
|
||||||
Ui::login *ui;
|
Ui::login *ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -71,8 +71,32 @@
|
|||||||
<height>19</height>
|
<height>19</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QMenu" name="menuApp">
|
||||||
|
<property name="title">
|
||||||
|
<string>App</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionExit"/>
|
||||||
|
<addaction name="actionLogin"/>
|
||||||
|
<addaction name="actionRegister"/>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuApp"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
<action name="actionExit">
|
||||||
|
<property name="text">
|
||||||
|
<string>Exit</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionLogin">
|
||||||
|
<property name="text">
|
||||||
|
<string>Login</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionRegister">
|
||||||
|
<property name="text">
|
||||||
|
<string>Register</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
@ -100,11 +100,11 @@ void MainWindow::saveRegisteredUser()
|
|||||||
|
|
||||||
QString id = ui->inputId->text();
|
QString id = ui->inputId->text();
|
||||||
if (stringEmpty(id, "THIS USER ID IS EMPTY!")) return;
|
if (stringEmpty(id, "THIS USER ID IS EMPTY!")) return;
|
||||||
if (idExists(id, users, "THIS USER ID IS ALREADY TAKEN!")) return;
|
if (idExists(id, users, "THIS USER ID IS ALREADY TAKEN!", true)) return;
|
||||||
|
|
||||||
QString blogId = ui -> inputBlogID->text();
|
QString blogId = ui -> inputBlogID->text();
|
||||||
if (stringEmpty(blogId, "THIS BLOG ID IS EMPTY!")) return;
|
if (stringEmpty(blogId, "THIS BLOG ID IS EMPTY!")) return;
|
||||||
if (idExists(blogId, blogs, "THIS BLOG ID IS ALREADY TAKEN!")) return;
|
if (idExists(blogId, blogs, "THIS BLOG ID IS ALREADY TAKEN!", true)) return;
|
||||||
|
|
||||||
registerUser(users, blogs, id, blogId);
|
registerUser(users, blogs, id, blogId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,15 +52,25 @@ bool stringEmpty(const QString &string, const QString &messageBoxMessage)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool idExists(const QString &id, const QJsonObject &json, const QString &message)
|
bool idExists(const QString &id, const QJsonObject &json, const QString &message, const bool &whenMessage)
|
||||||
{
|
{
|
||||||
qDebug() << id;
|
|
||||||
if (json.find(id) != json.end())
|
if (json.find(id) != json.end())
|
||||||
{
|
{
|
||||||
outputMessageBox(message);
|
if (whenMessage) outputMessageBox(message);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!whenMessage) outputMessageBox(message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sameString(const QString &stringToCompare, const QString &jsonId, const QJsonObject &json, const QString &message)
|
||||||
|
{
|
||||||
|
if(json[jsonId].toString() != stringToCompare)
|
||||||
|
{
|
||||||
|
outputMessageBox(message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -8,6 +8,7 @@ void saveJsonFile(QJsonObject &users, const QString name);
|
|||||||
void outputMessageBox(const QString messageBoxText);
|
void outputMessageBox(const QString messageBoxText);
|
||||||
void exit();
|
void exit();
|
||||||
bool stringEmpty(const QString &string, const QString &messageBoxMessage);
|
bool stringEmpty(const QString &string, const QString &messageBoxMessage);
|
||||||
bool idExists(const QString &id, const QJsonObject &json, const QString &message);
|
bool idExists(const QString &id, const QJsonObject &json, const QString &message, const bool &whenMessage);
|
||||||
|
bool sameString(const QString &stringToCompare, const QString &jsonId, const QJsonObject &json, const QString &message);
|
||||||
|
|
||||||
#endif // UNIVERSALFUNCTIONS_H
|
#endif // UNIVERSALFUNCTIONS_H
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user