diff --git a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/blogentry.o b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/blogentry.o index d6312715..a0a9c50a 100644 Binary files a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/blogentry.o and b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/blogentry.o differ diff --git a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/blogs.json b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/blogs.json index d7876c66..1069ce60 100644 --- a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/blogs.json +++ b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/blogs.json @@ -2,16 +2,6 @@ "": { "blogId": "", "items": [ - { - "content": "", - "datetime": "01:05:33 Wed Apr 6 2022", - "title": "Title" - }, - { - "content": "notempty", - "datetime": "01:05:44 Wed Apr 6 2022", - "title": "anotherTitle" - } ], "ownerId": "1", "title": "" diff --git a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/lab1 b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/lab1 index e0b88596..4f4d90a1 100755 Binary files a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/lab1 and b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/lab1 differ diff --git a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/moc_blogentry.cpp b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/moc_blogentry.cpp index bca111c5..808d99fc 100644 --- a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/moc_blogentry.cpp +++ b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/moc_blogentry.cpp @@ -22,8 +22,8 @@ QT_BEGIN_MOC_NAMESPACE QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED struct qt_meta_stringdata_blogEntry_t { - const uint offsetsAndSize[20]; - char stringdata0[98]; + const uint offsetsAndSize[24]; + char stringdata0[132]; }; #define QT_MOC_LITERAL(ofs, len) \ uint(offsetof(qt_meta_stringdata_blogEntry_t, stringdata0) + ofs), len @@ -38,12 +38,15 @@ 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(93, 4), // "name" +QT_MOC_LITERAL(98, 11), // "removeEntry" +QT_MOC_LITERAL(110, 21) // "on_pushButton_clicked" }, "blogEntry\0on_saveEntry_clicked\0\0" "saveEntry\0readJsonFile\0title\0saveJsonFile\0" - "QJsonObject&\0users\0name" + "QJsonObject&\0users\0name\0removeEntry\0" + "on_pushButton_clicked" }; #undef QT_MOC_LITERAL @@ -53,7 +56,7 @@ static const uint qt_meta_data_blogEntry[] = { 10, // revision 0, // classname 0, 0, // classinfo - 4, 14, // methods + 6, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors @@ -61,16 +64,20 @@ static const uint qt_meta_data_blogEntry[] = { 0, // signalCount // slots: name, argc, parameters, tag, flags, initial metatype offsets - 1, 0, 38, 2, 0x08, 1 /* Private */, - 3, 0, 39, 2, 0x08, 2 /* Private */, - 4, 1, 40, 2, 0x08, 3 /* Private */, - 6, 2, 43, 2, 0x108, 5 /* Private | MethodIsConst */, + 1, 0, 50, 2, 0x08, 1 /* Private */, + 3, 0, 51, 2, 0x08, 2 /* Private */, + 4, 1, 52, 2, 0x08, 3 /* Private */, + 6, 2, 55, 2, 0x108, 5 /* Private | MethodIsConst */, + 10, 0, 60, 2, 0x08, 8 /* Private */, + 11, 0, 61, 2, 0x08, 9 /* Private */, // slots: parameters QMetaType::Void, QMetaType::Void, QMetaType::QJsonObject, QMetaType::QString, 5, QMetaType::Void, 0x80000000 | 7, QMetaType::QString, 8, 9, + QMetaType::Void, + QMetaType::Void, 0 // eod }; @@ -86,6 +93,8 @@ void blogEntry::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, v case 2: { QJsonObject _r = _t->readJsonFile((*reinterpret_cast< std::add_pointer_t>(_a[1]))); if (_a[0]) *reinterpret_cast< QJsonObject*>(_a[0]) = std::move(_r); } break; case 3: _t->saveJsonFile((*reinterpret_cast< std::add_pointer_t>(_a[1])),(*reinterpret_cast< std::add_pointer_t>(_a[2]))); break; + case 4: _t->removeEntry(); break; + case 5: _t->on_pushButton_clicked(); break; default: ; } } @@ -99,7 +108,7 @@ const QMetaObject blogEntry::staticMetaObject = { { nullptr, qt_incomplete_metaTypeArray -, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete +, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete, QtPrivate::TypeAndForceComplete >, @@ -126,13 +135,13 @@ int blogEntry::qt_metacall(QMetaObject::Call _c, int _id, void **_a) if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { - if (_id < 4) + if (_id < 6) qt_static_metacall(this, _c, _id, _a); - _id -= 4; + _id -= 6; } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { - if (_id < 4) + if (_id < 6) *reinterpret_cast(_a[0]) = QMetaType(); - _id -= 4; + _id -= 6; } return _id; } diff --git a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/moc_blogentry.o b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/moc_blogentry.o index bac830e5..54b19277 100644 Binary files a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/moc_blogentry.o and b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/moc_blogentry.o differ diff --git a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/ui_blogentry.h b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/ui_blogentry.h index 092921f9..c8121481 100644 --- a/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/ui_blogentry.h +++ b/EGUI/build-lab1-Desktop_Qt_6_2_4_GCC_64bit-Debug/ui_blogentry.h @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -25,12 +24,12 @@ class Ui_blogEntry { public: QFormLayout *formLayout; - QCheckBox *checkBox; QLineEdit *lineEdit; QLabel *ownerID; QLabel *dateTime; QTextEdit *textEdit; QPushButton *saveEntry; + QPushButton *pushButton; void setupUi(QWidget *blogEntry) { @@ -39,36 +38,36 @@ public: blogEntry->resize(400, 300); formLayout = new QFormLayout(blogEntry); formLayout->setObjectName(QString::fromUtf8("formLayout")); - checkBox = new QCheckBox(blogEntry); - checkBox->setObjectName(QString::fromUtf8("checkBox")); - - formLayout->setWidget(0, QFormLayout::FieldRole, checkBox); - lineEdit = new QLineEdit(blogEntry); lineEdit->setObjectName(QString::fromUtf8("lineEdit")); - formLayout->setWidget(1, QFormLayout::FieldRole, lineEdit); + formLayout->setWidget(0, QFormLayout::FieldRole, lineEdit); ownerID = new QLabel(blogEntry); ownerID->setObjectName(QString::fromUtf8("ownerID")); - formLayout->setWidget(2, QFormLayout::FieldRole, ownerID); + formLayout->setWidget(1, QFormLayout::FieldRole, ownerID); dateTime = new QLabel(blogEntry); dateTime->setObjectName(QString::fromUtf8("dateTime")); - formLayout->setWidget(3, QFormLayout::FieldRole, dateTime); + formLayout->setWidget(2, QFormLayout::FieldRole, dateTime); textEdit = new QTextEdit(blogEntry); textEdit->setObjectName(QString::fromUtf8("textEdit")); textEdit->setReadOnly(false); - formLayout->setWidget(4, QFormLayout::FieldRole, textEdit); + formLayout->setWidget(3, QFormLayout::FieldRole, textEdit); saveEntry = new QPushButton(blogEntry); saveEntry->setObjectName(QString::fromUtf8("saveEntry")); - formLayout->setWidget(5, QFormLayout::FieldRole, saveEntry); + formLayout->setWidget(4, QFormLayout::FieldRole, saveEntry); + + pushButton = new QPushButton(blogEntry); + pushButton->setObjectName(QString::fromUtf8("pushButton")); + + formLayout->setWidget(5, QFormLayout::FieldRole, pushButton); retranslateUi(blogEntry); @@ -79,11 +78,11 @@ public: void retranslateUi(QWidget *blogEntry) { blogEntry->setWindowTitle(QCoreApplication::translate("blogEntry", "Form", nullptr)); - checkBox->setText(QCoreApplication::translate("blogEntry", "Remove", nullptr)); lineEdit->setText(QCoreApplication::translate("blogEntry", "Title", nullptr)); ownerID->setText(QCoreApplication::translate("blogEntry", "ownerID", nullptr)); dateTime->setText(QCoreApplication::translate("blogEntry", "Date Time", nullptr)); saveEntry->setText(QCoreApplication::translate("blogEntry", "Save Entry", nullptr)); + pushButton->setText(QCoreApplication::translate("blogEntry", "Remove Entry", nullptr)); } // retranslateUi }; diff --git a/EGUI/lab1/blogentry.cpp b/EGUI/lab1/blogentry.cpp index 127998b7..1eea5a4e 100644 --- a/EGUI/lab1/blogentry.cpp +++ b/EGUI/lab1/blogentry.cpp @@ -11,12 +11,17 @@ blogEntry::blogEntry(QWidget *parent) : ui(new Ui::blogEntry) { ui->setupUi(this); - QString Time = QTime::currentTime().toString(); - QString Date = QDate::currentDate().toString(); - ui -> dateTime -> setText(Date + " " + Time); - qDebug() << "blogEntry id: " << userId; - qDebug() << Time; +} + +void blogEntry::setUpBlogEntryFromJson(const QJsonObject entry) +{ + ui -> lineEdit-> setText(entry["title"].toString()); + ui -> textEdit -> setText(entry["content"].toString()); + ui -> dateTime -> setText(entry["datetime"].toString()); + ui -> ownerID -> setText("Owner ID: " + userId); + ui -> textEdit -> setReadOnly(true); + ui -> lineEdit -> setReadOnly(true); } blogEntry::~blogEntry() @@ -72,7 +77,9 @@ void blogEntry::saveEntry() entry["title"] = ui -> lineEdit -> text(); QString Time = QTime::currentTime().toString(); QString Date = QDate::currentDate().toString(); + entry["datetime"] = Time + " " + Date; + ui -> dateTime -> setText( Time + " " + Date); entry["content"] = ui -> textEdit -> toPlainText(); QJsonArray items = blogEntryJson["items"].toArray(); items.append(entry); @@ -82,8 +89,36 @@ void blogEntry::saveEntry() } +void blogEntry::removeEntry() +{ + QJsonObject blogsFile = readJsonFile("blogs.json"); + QJsonObject blogEntryJson = blogsFile[blogId].toObject(); + QJsonArray items = blogEntryJson["items"].toArray(); + for(int i = 0; i < items.size(); i++) + { + QJsonObject currentItem = items[i].toObject(); + qDebug() << currentItem["datetime"].toString(); + qDebug() << ui -> dateTime -> text(); + if(currentItem["datetime"].toString() == ui -> dateTime -> text()) + { + items.removeAt(i); + break; + } + } + blogEntryJson.insert("items", items); + blogsFile.insert(blogId, blogEntryJson); + saveJsonFile(blogsFile, "blogs.json"); + this -> ~blogEntry(); +} + void blogEntry::on_saveEntry_clicked() { saveEntry(); } + +void blogEntry::on_pushButton_clicked() +{ + removeEntry(); +} + diff --git a/EGUI/lab1/blogentry.h b/EGUI/lab1/blogentry.h index 21e3092d..93763f22 100644 --- a/EGUI/lab1/blogentry.h +++ b/EGUI/lab1/blogentry.h @@ -19,17 +19,21 @@ public: ~blogEntry(); void setUserId(const QString &userId); void setBlogId(const QString &blogId); + void setUpBlogEntryFromJson(const QJsonObject entry); 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(); private: Ui::blogEntry *ui; QString userId; QString blogId; + }; #endif // BLOGENTRY_H diff --git a/EGUI/lab1/blogentry.ui b/EGUI/lab1/blogentry.ui index 9e6cd561..a17aef06 100644 --- a/EGUI/lab1/blogentry.ui +++ b/EGUI/lab1/blogentry.ui @@ -15,47 +15,47 @@ - - - Remove - - - - Title - + ownerID - + Date Time - + false - + Save Entry + + + + Remove Entry + + + diff --git a/EGUI/lab1/blogsview.cpp b/EGUI/lab1/blogsview.cpp index 2609e3ae..5da89b33 100644 --- a/EGUI/lab1/blogsview.cpp +++ b/EGUI/lab1/blogsview.cpp @@ -2,15 +2,18 @@ #include "ui_blogsview.h" #include "blogentry.h" #include "ui_blogentry.h" +#include #include #include #include +#include blogsView::blogsView(QWidget *parent) : QMainWindow(parent), ui(new Ui::blogsView) { ui->setupUi(this); + displayBlogEntries(); } blogsView::~blogsView() @@ -65,6 +68,23 @@ void blogsView::createNewBlogEntry() ui -> blogsLayout -> addWidget(e); } +void blogsView::displayBlogEntries() +{ + QJsonObject blogsFile = readJsonFile("blogs.json"); + QJsonObject userBlog = blogsFile[blogId].toObject(); + QJsonArray blogEntries = userBlog["items"].toArray(); + 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::on_actionCreate_new_Blog_entry_triggered() { createNewBlogEntry(); diff --git a/EGUI/lab1/blogsview.h b/EGUI/lab1/blogsview.h index 171beee4..6bba4701 100644 --- a/EGUI/lab1/blogsview.h +++ b/EGUI/lab1/blogsview.h @@ -22,6 +22,7 @@ public: private slots: void on_actionCreate_new_Blog_entry_triggered(); + void displayBlogEntries(); private: